Quantcast

Added backdrop options

p3lim-52096 [09-14-08 - 21:45]
Added backdrop options
(!) Massive rewrite

git-svn-id: svn://svn.wowinterface.com/pMinimap-54/trunk@20 ae24c21f-2f0c-4c94-9256-0092abe71e0d
Filename
pMinimap/pMinimap.lua
pMinimap/pMinimapConfig.lua
diff --git a/pMinimap/pMinimap.lua b/pMinimap/pMinimap.lua
index b3bb397..fc8361f 100644
--- a/pMinimap/pMinimap.lua
+++ b/pMinimap/pMinimap.lua
@@ -1,63 +1,18 @@
---[[-------------------------------------------------------------------------
-  Copyright (c) 2006, Trond A Ekseth
-  Copyright (c) 2008, Adrian L Lange
-  All rights reserved.
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions are
-  met:
-
-      * Redistributions of source code must retain the above copyright
-        notice, this list of conditions and the following disclaimer.
-      * Redistributions in binary form must reproduce the above
-        copyright notice, this list of conditions and the following
-        disclaimer in the documentation and/or other materials provided
-        with the distribution.
-      * Neither the name of pMinimap nor the names of its contributors
-        may be used to endorse or promote products derived from this
-        software without specific prior written permission.
-
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------]]
-
-
-function GetMinimapShape() return 'SQUARE' end
-
-local addon = CreateFrame('Frame', 'pMinimap', Minimap)
-local frames = {
-	MinimapBorder,
-	MinimapBorderTop,
-	MinimapToggleButton,
-	MinimapZoomIn,
-	MinimapZoomOut,
-	MinimapZoneText,
-	MinimapZoneTextButton,
-	MiniMapTrackingBackground,
-	MiniMapBattlefieldBorder,
-	MiniMapMeetingStoneFrame,
-	MiniMapVoiceChatFrame,
-	MiniMapWorldMapButton,
-	MiniMapMailBorder,
-	MiniMapMailIcon,
-	BattlegroundShine,
-	GameTimeFrame,
-}
-
-function addon.PLAYER_LOGIN(self)
-	local db = _G.pMinimapDB
-
-	Minimap:EnableMouseWheel(true)
-	Minimap:SetScript('OnMouseWheel', function(self, dir)
+pMinimap = CreateFrame('Frame', 'pMinimap', UIParent)
+pMinimap:SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)
+pMinimap:RegisterEvent('ADDON_LOADED')
+
+function pMinimap:ADDON_LOADED()
+	local db = pMinimapDB or {point = {'TOPRIGHT', UIParent, 'TOPRIGHT', -15, -15}, scale = 0.9, offset = 1, colors = {0, 0, 0}, durability = true}
+
+	MinimapBorder:SetTexture()
+	MinimapBorderTop:Hide()
+	MinimapToggleButton:Hide()
+
+	MinimapZoomIn:Hide()
+	MinimapZoomOut:Hide()
+	Minimap:EnableMouseWheel()
+	Minimap:SetScript('OnMouseWheel', function(dir)
 		if(dir > 0) then
 			Minimap_ZoomIn()
 		else
@@ -65,56 +20,71 @@ function addon.PLAYER_LOGIN(self)
 		end
 	end)

-	if(select(4, GetBuildInfo()) >= 3e4) then
-		MiniMapTrackingIconOverlay:SetAlpha(0)
-		MiniMapTrackingButtonBorder:Hide()
-	else
-		MiniMapTrackingBorder:Hide()
-	end
+	MinimapZoneText:Hide()
+	MinimapZoneTextButton:Hide()
+
+	MiniMapTrackingBorder:SetTexture()
+	MiniMapTrackingBackground:Hide()
 	MiniMapTrackingIcon:SetTexCoord(0.065, 0.935, 0.065, 0.935)
 	MiniMapTracking:SetParent(Minimap)
 	MiniMapTracking:ClearAllPoints()
 	MiniMapTracking:SetPoint('TOPLEFT', -2, 2)

+	BattlegroundShine:Hide()
+	MiniMapBattlefieldBorder:SetTexture()
 	MiniMapBattlefieldFrame:SetParent(Minimap)
 	MiniMapBattlefieldFrame:ClearAllPoints()
 	MiniMapBattlefieldFrame:SetPoint('TOPRIGHT', -2, -2)

+	MiniMapMailBorder:SetTexture()
+	MiniMapMailIcon:Hide()
 	MiniMapMailFrame:SetParent(Minimap)
 	MiniMapMailFrame:ClearAllPoints()
 	MiniMapMailFrame:SetPoint('TOP')
 	MiniMapMailFrame:SetHeight(8)

 	MiniMapMailText = MiniMapMailFrame:CreateFontString(nil, 'OVERLAY')
-	MiniMapMailText:SetFont('Interface\\AddOns\\pMinimap\\font.ttf', 13, 'OUTLINE')
+	MiniMapMailText:SetFont([[Interface\AddOns\pMinimap\font.ttf]], 13, 'OUTLINE')
 	MiniMapMailText:SetPoint('BOTTOM', 0, 2)
 	MiniMapMailText:SetText('New Mail!')
 	MiniMapMailText:SetTextColor(1, 1, 1)

-	MinimapNorthTag:SetAlpha(0)
+	GameTimeFrame:Hide()
+	MiniMapWorldMapButton:Hide()
+	MiniMapVoiceChatFrame:Hide()
+	MiniMapMeetingStoneFrame:Hide()
 	MiniMapMeetingStoneFrame:SetAlpha(0)
+	MinimapNorthTag:SetAlpha(0)

-	Minimap:SetMaskTexture('Interface\\ChatFrame\\ChatFrameBackground')
-	Minimap:SetFrameStrata('LOW')
-
-	self:SetFrameStrata('BACKGROUND')
-	self:SetAllPoints(Minimap)
-	self:SetBackdrop({bgFile = 'Interface\\ChatFrame\\ChatFrameBackground', insets = {top = -1, left = -1, bottom = -1, right = -1}})
-	self:SetBackdropColor(0, 0, 0, 0)
-
-	if(db.backdrop) then
-		self:SetBackdropColor(0, 0, 0, 1)
-
-		if(db.durability) then
-			self:RegisterEvent('UPDATE_INVENTORY_ALERTS')
-			DurabilityFrame:SetAlpha(0)
-		end
+	self:SetPoint(unpack(db.point))
+	self:SetWidth(Minimap:GetWidth() * db.scale)
+	self:SetHeight(Minimap:GetHeight() * db.scale)
+	self:SetBackdrop({bgFile = [[Interface\ChatFrame\ChatFrameBackground]]})
+	self:SetBackdropColor(0, 1, 0, 0.5)
+	self:SetAlpha(0)
+	self:SetMovable(true)
+	self:EnableMouse(false)
+	self:SetScript('OnMouseDown', function() self:StartMoving() end)
+	self:SetScript('OnMouseUp', function() self:StopMovingOrSizing() end)
+
+	Minimap:ClearAllPoints()
+	Minimap:SetPoint('CENTER', self)
+	Minimap:SetScale(db.scale)
+	Minimap:SetMaskTexture([[Interface\ChatFrame\ChatFrameBackground]])
+	Minimap:SetBackdrop({bgFile = [[Interface\ChatFrame\ChatFrameBackground]], insets = {top = - db.offset, left = - db.offset, bottom = - db.offset, right = - db.offset}})
+	Minimap:SetBackdropColor(unpack(db.colors))
+
+	if(db.durability) then
+		self:RegisterEvent('UPDATE_INVENTORY_ALERTS')
+		DurabilityFrame:SetAlpha(0)
 	end

-	for i,obj in pairs(frames) do obj:Hide() end
+	self:RegisterEvent('PLAYER_ENTERING_WORLD')
+	self:UnregisterEvent('ADDON_LOADED')
 end

-function addon.UPDATE_INVENTORY_ALERTS(self)
+function pMinimap:UPDATE_INVENTORY_ALERTS()
+	local db = pMinimapDB or {colors = {0, 0, 0, 1}}
 	local maxStatus = 0
 	for id in pairs(INVENTORY_ALERT_STATUS_SLOTS) do
 		local status = GetInventoryAlertStatus(id)
@@ -125,11 +95,11 @@ function addon.UPDATE_INVENTORY_ALERTS(self)

 	local color = INVENTORY_ALERT_COLORS[maxStatus]
 	if(color) then
-		self:SetBackdropColor(color.r, color.g, color.b, 1)
+		Minimap:SetBackdropColor(color.r, color.g, color.b)
 	else
-		self:SetBackdropColor(0, 0, 0, 1)
+		Minimap:SetBackdropColor(unpack(db.colors))
 	end
 end

-addon:SetScript('OnEvent', function(self, event, ...) self[event](self) end)
-addon:RegisterEvent('PLAYER_LOGIN')
\ No newline at end of file
+-- http://www.wowwiki.com/GetMinimapShape
+function GetMinimapShape() return 'SQUARE' end
\ No newline at end of file
diff --git a/pMinimap/pMinimapConfig.lua b/pMinimap/pMinimapConfig.lua
index f8922f7..0515f12 100644
--- a/pMinimap/pMinimapConfig.lua
+++ b/pMinimap/pMinimapConfig.lua
@@ -1,48 +1,30 @@
-local _G = getfenv(0)
+local locked = true
 local LibSimpleOptions = LibStub('LibSimpleOptions-1.0')

 local function Options(self, anchor, db)
 	local title, subText = self:MakeTitleTextAndSubText('pMinimap', 'These options allow you to change the position of pMinimap')
-
 	local lock = self:MakeToggle(
 		'name', 'Toggle Minimap Locked State',
 		'description', 'Set whether Minimap is locked or not',
 		'default', true,
-		'current', db.locked,
+		'current', locked,
 		'setFunc', function(value)
-			db.locked = value
+			locked = value
 			if(value) then
 				local p1, p, p2, x, y = anchor:GetPoint()
-				db.p1 = p1
-				db.p2 = p2
-				db.x = x
-				db.y = y
+				db.point[1] = p1
+				db.point[3] = p2
+				db.point[4] = x
+				db.point[5] = y
 				anchor:SetAlpha(0)
 				anchor:EnableMouse(false)
-				anchor:SetFrameStrata('BACKGROUND')
 			else
 				anchor:SetAlpha(1)
 				anchor:EnableMouse(true)
-				anchor:SetFrameStrata('DIALOG')
 			end
 		end)
 	lock:SetPoint('TOPLEFT', subText, 'BOTTOMLEFT', 0, -8)

-	local reset = self:MakeButton(
-		'name', 'Reset Position',
-		'description', 'Reset Minimap position to default',
-		'func', function()
-			db.p1 = 'TOPRIGHT'
-			db.p2 = 'TOPRIGHT'
-			db.x = -15
-			db.y = -15
-			db.locked = true
-			anchor:ClearAllPoints()
-			anchor:SetPoint(db.p1, UIParent, db.p2, db.x, db.y)
-			self:Refresh()
-		end)
-	reset:SetPoint('TOPLEFT', lock, 'BOTTOMLEFT', 0, -8)
-
 	local scale = self:MakeSlider(
 		'name', 'Minimap Scale',
 		'description', 'Drag to change the Minimap scale',
@@ -59,8 +41,10 @@ local function Options(self, anchor, db)
 			anchor:SetWidth(Minimap:GetWidth() * value)
 			anchor:SetHeight(Minimap:GetHeight() * value)
 		end,
-		'currentTextFunc', function(num) return ('%.1f'):format(num) end)
-	scale:SetPoint('TOPLEFT', reset, 'BOTTOMLEFT', 0, -16)
+		'currentTextFunc', function(num)
+			return ('%.1f'):format(num)
+		end)
+	scale:SetPoint('TOPLEFT', lock, 'BOTTOMLEFT', 0, -16)

 	local dura = self:MakeToggle(
 		'name', 'Toggle Durability',
@@ -73,76 +57,61 @@ local function Options(self, anchor, db)
 			if(db.backdrop) then
 				if(value) then
 					pMinimap:RegisterEvent('UPDATE_INVENTORY_ALERTS')
-					pMinimap.UPDATE_INVENTORY_ALERTS(pMinimap)
+					pMinimap.UPDATE_INVENTORY_ALERTS()
 					DurabilityFrame:SetAlpha(0)
 				else
 					pMinimap:UnregisterEvent('UPDATE_INVENTORY_ALERTS')
-					pMinimap:SetBackdropColor(0, 0, 0, 1)
+					Minimap:SetBackdropColor(unpack(db.colors))
 					DurabilityFrame:SetAlpha(1)
 				end
 			end
 		end)
 	dura:SetPoint('TOPLEFT', scale, 'BOTTOMLEFT', 0, -8)

-	local bg = self:MakeToggle(
-		'name', 'Toggle Backdrop',
-		'description', 'Set whether backdrop is shown or not\nAlso forces durability recoloring',
-		'default', true,
-		'current', db.backdrop,
+	local offset = self:MakeSlider(
+		'name', 'Backdrop offset',
+		'description', 'Drag to change the bg border size',
+		'minText', '-1',
+		'maxText', '10',
+		'minValue', -1,
+		'maxValue', 10,
+		'step', 1,
+		'default', 1,
+		'current', db.offset,
 		'setFunc', function(value)
-			self:Refresh()
-			db.backdrop = value
-			if(value) then
-				pMinimap:SetBackdropColor(0, 0, 0, 1)
-				if(db.durability) then
-					pMinimap:RegisterEvent('UPDATE_INVENTORY_ALERTS')
-					pMinimap.UPDATE_INVENTORY_ALERTS(pMinimap)
-					DurabilityFrame:SetAlpha(0)
-				end
-			else
-				pMinimap:SetBackdropColor(0, 0, 0, 0)
-				if(db.durability) then
-					pMinimap:UnregisterEvent('UPDATE_INVENTORY_ALERTS')
-					DurabilityFrame:SetAlpha(1)
-				end
-			end
+			db.offset = value
+			Minimap:SetBackdrop({bgFile = [[Interface\ChatFrame\ChatFrameBackground]], insets = {top = - db.offset, left = - db.offset, bottom = - db.offset, right = - db.offset}})
+			Minimap:SetBackdropColor(unpack(db.colors))
+		end,
+		'currentTextFunc', function(num)
+			return ('%.0f'):format(num)
 		end)
-	bg:SetPoint('TOPLEFT', dura, 'BOTTOMLEFT', 0, -8)
-end
+	offset:SetPoint('TOPLEFT', dura, 'BOTTOMLEFT', 0, -16)

-local function OnEvent(self, name)
-	if(name == 'pMinimap') then
-		local db = _G.pMinimapDB
-		if(not db) then
-			db = { p1 = 'TOPRIGHT', p2 = 'TOPRIGHT', x = -15, y = -15, scale = 0.9, locked = true, durability = true, backdrop = true }
-			_G.pMinimapDB = db
-		end
-
-		db.locked = true
-
-		local anchor = CreateFrame('Frame', nil, UIParent)
-		anchor:SetPoint(db.p1, UIParent, db.p2, db.x, db.y)
-		anchor:SetWidth(Minimap:GetWidth() * db.scale)
-		anchor:SetHeight(Minimap:GetHeight() * db.scale)
-		anchor:SetBackdrop({bgFile='Interface\\ChatFrame\\ChatFrameBackground'})
-		anchor:SetBackdropColor(0, 1, 0, 0.5)
-		anchor:SetAlpha(0)
-		anchor:SetMovable(true)
-		anchor:EnableMouse(false)
-		anchor:SetScript('OnMouseDown', function(self) self:StartMoving() end)
-		anchor:SetScript('OnMouseUp', function(self) self:StopMovingOrSizing() end)
-
-		Minimap:ClearAllPoints()
-		Minimap:SetPoint('CENTER', anchor)
-		Minimap:SetScale(db.scale)
+	local color = self:MakeColorPicker(
+		'name', "Custom Color",
+		'description', "Set custom bg color with a palette",
+		'hasAlpha', true,
+		'defaultR', 0,
+		'defaultG', 0,
+		'defaultB', 0,
+		'defaultA', 1,
+		'getFunc', function() return unpack(db.colors) end,
+		'setFunc', function(r, g, b, a)
+			db.colors[1] = r
+			db.colors[2] = g
+			db.colors[3] = b
+			db.colors[4] = a
+			Minimap:SetBackdropColor(unpack(db.colors))
+		end)
+	color:SetPoint("TOPLEFT", offset, "BOTTOMLEFT", 0, -8)
+end

-		LibSimpleOptions.AddOptionsPanel('pMinimap', function(self) Options(self, anchor, db) end)
-		LibSimpleOptions.AddSlashCommand('pMinimap', '/pminimap', '/pmm')
+function pMinimap:PLAYER_ENTERING_WORLD()
+	local db = pMinimapDB or {point = {'TOPRIGHT', 'UIParent', 'TOPRIGHT', -15, -15}, scale = 0.9, offset = 1, colors = {0, 0, 0, 1}, durability = true}

-		self:UnregisterEvent('ADDON_LOADED')
-	end
-end
+	LibSimpleOptions.AddOptionsPanel('pMinimap', function(self) Options(self, pMinimap, db) end)
+	LibSimpleOptions.AddSlashCommand('pMinimap', '/pminimap', '/pmm')

-local event = CreateFrame('Frame')
-event:RegisterEvent('ADDON_LOADED')
-event:SetScript('OnEvent', function(self, event, ...) OnEvent(self, ...) end)
\ No newline at end of file
+	pMinimapDB = db
+end
\ No newline at end of file