Quantcast

Fixed durability toggle

p3lim-52096 [08-30-08 - 15:31]
Fixed durability toggle

git-svn-id: svn://svn.wowinterface.com/pMinimap-54/trunk@14 ae24c21f-2f0c-4c94-9256-0092abe71e0d
Filename
pMinimap/pMinimap.lua
pMinimap/pMinimap.toc
pMinimap/pMinimapConfig.lua
diff --git a/pMinimap/pMinimap.lua b/pMinimap/pMinimap.lua
index e99df55..4c1ada4 100644
--- a/pMinimap/pMinimap.lua
+++ b/pMinimap/pMinimap.lua
@@ -31,13 +31,11 @@
 ---------------------------------------------------------------------------]]


--- global function
-function GetMinimapShape() return "SQUARE" end
+function GetMinimapShape() return 'SQUARE' end

--- addon fluff
 local _G = getfenv(0)
 local wotlk = select(4, GetBuildInfo()) >= 3e4
-local addon = CreateFrame("Frame", "pMinimap", Minimap)
+local addon = CreateFrame('Frame', 'pMinimap', Minimap)
 local frames = {
 	MinimapBorder,
 	MinimapBorderTop,
@@ -59,7 +57,7 @@ local frames = {

 function addon.PLAYER_LOGIN(self)
 	Minimap:EnableMouseWheel(true)
-	Minimap:SetScript("OnMouseWheel", function(self, dir)
+	Minimap:SetScript('OnMouseWheel', function(self, dir)
 		if(dir > 0) then
 			Minimap_ZoomIn()
 		else
@@ -73,65 +71,57 @@ function addon.PLAYER_LOGIN(self)
 	else
 		MiniMapTrackingBorder:Hide()
 	end
-	MiniMapTrackingIcon:SetTexCoord(0.065, 0.935, 0.065, 0.935) -- bloody hell
+	MiniMapTrackingIcon:SetTexCoord(0.065, 0.935, 0.065, 0.935)
 	MiniMapTracking:SetParent(Minimap)
 	MiniMapTracking:ClearAllPoints()
-	MiniMapTracking:SetPoint("TOPLEFT", -2, 2)
+	MiniMapTracking:SetPoint('TOPLEFT', -2, 2)

 	MiniMapBattlefieldFrame:SetParent(Minimap)
 	MiniMapBattlefieldFrame:ClearAllPoints()
-	MiniMapBattlefieldFrame:SetPoint("TOPRIGHT", -2, -2)
+	MiniMapBattlefieldFrame:SetPoint('TOPRIGHT', -2, -2)

 	MiniMapMailFrame:SetParent(Minimap)
 	MiniMapMailFrame:ClearAllPoints()
-	MiniMapMailFrame:SetPoint("TOP")
+	MiniMapMailFrame:SetPoint('TOP')
 	MiniMapMailFrame:SetHeight(8)

-	MiniMapMailText = MiniMapMailFrame:CreateFontString(nil, "OVERLAY")
-	MiniMapMailText:SetFont("Interface\\AddOns\\pMinimap\\font.ttf", 13, "OUTLINE")
-	MiniMapMailText:SetPoint("BOTTOM", 0, 2)
-	MiniMapMailText:SetText("New Mail!")
+	MiniMapMailText = MiniMapMailFrame:CreateFontString(nil, 'OVERLAY')
+	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) -- it pops up on variables, this is an easy way out
-	DurabilityFrame:SetAlpha(0) -- it shows on events, another easy way out
+	MinimapNorthTag:SetAlpha(0)
+	DurabilityFrame:SetAlpha(0)

-	Minimap:SetMaskTexture("Interface\\ChatFrame\\ChatFrameBackground")
-	Minimap:SetFrameStrata("LOW")
+	Minimap:SetMaskTexture('Interface\\ChatFrame\\ChatFrameBackground')
+	Minimap:SetFrameStrata('LOW')

-	self:SetFrameStrata("BACKGROUND")
+	self:SetFrameStrata('BACKGROUND')
 	self:SetAllPoints(Minimap)
-	self:SetBackdrop({bgFile = "Interface\\ChatFrame\\ChatFrameBackground", insets = {top = -1, left = -1, bottom = -1, right = -1}})
+	self:SetBackdrop({bgFile = 'Interface\\ChatFrame\\ChatFrameBackground', insets = {top = -1, left = -1, bottom = -1, right = -1}})
 	self:SetBackdropColor(0, 0, 0)

-	-- hide all listed frames
-	for _,obj in pairs(frames) do obj:Hide() end
+	for x,obj in pairs(frames) do obj:Hide() end
 end

--- durability backdrop recoloring (props to Malreth of WoWAce)
 function addon.UPDATE_INVENTORY_ALERTS(self)
-	local db = _G.pMinimapDB
-	if(db.durability) then
-		local maxStatus = 0
-		for id in pairs(INVENTORY_ALERT_STATUS_SLOTS) do
-			local status = GetInventoryAlertStatus(id)
-			if(status > maxStatus) then
-				maxStatus = status
-			end
+	local maxStatus = 0
+	for id in pairs(INVENTORY_ALERT_STATUS_SLOTS) do
+		local status = GetInventoryAlertStatus(id)
+		if(status > maxStatus) then
+			maxStatus = status
 		end
+	end

-		local color = INVENTORY_ALERT_COLORS[maxStatus]
-		if(color) then
-			self:SetBackdropColor(color.r, color.g, color.b)
-		else
-			self:SetBackdropColor(0, 0, 0)
-		end
+	local color = INVENTORY_ALERT_COLORS[maxStatus]
+	if(color) then
+		self:SetBackdropColor(color.r, color.g, color.b)
 	else
-		self:UnregisterEvent("UPDATE_INVENTORY_ALERTS")
 		self:SetBackdropColor(0, 0, 0)
 	end
 end

-addon:SetScript("OnEvent", function(self, event, ...) self[event](self) end)
-addon:RegisterEvent("UPDATE_INVENTORY_ALERTS")
-addon:RegisterEvent("PLAYER_LOGIN")
\ No newline at end of file
+addon:SetScript('OnEvent', function(self, event, ...) self[event](self) end)
+addon:RegisterEvent('UPDATE_INVENTORY_ALERTS')
+addon:RegisterEvent('PLAYER_LOGIN')
\ No newline at end of file
diff --git a/pMinimap/pMinimap.toc b/pMinimap/pMinimap.toc
index bb3c286..8ce9641 100644
--- a/pMinimap/pMinimap.toc
+++ b/pMinimap/pMinimap.toc
@@ -6,8 +6,8 @@
 ## OptionalDeps: LibSimpleOptions-1.0
 ## SavedVariablesPerCharacter: pMinimapDB

-libs\LibSimpleOptions-1.0\LibStub\LibStub.lua
-libs\LibSimpleOptions-1.0\LibSimpleOptions-1.0.lua
+LibSimpleOptions-1.0\LibStub\LibStub.lua
+LibSimpleOptions-1.0\LibSimpleOptions-1.0.lua

 pMinimap.lua
 pMinimapConfig.lua
diff --git a/pMinimap/pMinimapConfig.lua b/pMinimap/pMinimapConfig.lua
index eb12faf..c3a6134 100644
--- a/pMinimap/pMinimapConfig.lua
+++ b/pMinimap/pMinimapConfig.lua
@@ -1,45 +1,39 @@
-local db
 local _G = getfenv(0)
-local LibSimpleOptions = LibStub("LibSimpleOptions-1.0")
+local LibSimpleOptions = LibStub('LibSimpleOptions-1.0')

-local function Greenie(anchor)
-	anchor:SetWidth(Minimap:GetWidth() * db.scale)
-	anchor:SetHeight(Minimap:GetHeight() * db.scale)
-end
-
-local function Options(self, anchor)
-	local title, subText = self:MakeTitleTextAndSubText("pMinimap", "These options allow you to change the position of pMinimap")
+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",
+		'name', 'Toggle Minimap Locked State',
+		'description', 'Set whether Minimap is locked or not',
 		'default', true,
 		'current', db.locked,
 		'setFunc', function(value)
 			db.locked = value
 			if(value) then
-				anchor:SetAlpha(0)
-				anchor:SetMovable(false)
-				anchor:SetFrameStrata("BACKGROUND")
-				local p1, _, p2, x, y = anchor:GetPoint()
+				local p1, p, p2, x, y = anchor:GetPoint()
 				db.p1 = p1
 				db.p2 = p2
 				db.x = x
 				db.y = y
+				anchor:SetAlpha(0)
+				anchor:SetMovable(value)
+				anchor:SetFrameStrata('BACKGROUND')
 			else
 				anchor:SetAlpha(1)
-				anchor:SetMovable(true)
-				anchor:SetFrameStrata("DIALOG")
+				anchor:SetMovable(value)
+				anchor:SetFrameStrata('DIALOG')
 			end
 		end)
-	lock:SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -8)
+	lock:SetPoint('TOPLEFT', subText, 'BOTTOMLEFT', 0, -8)

 	local reset = self:MakeButton(
-		'name', "Reset Position",
-		'description', "Reset Minimap position to default",
+		'name', 'Reset Position',
+		'description', 'Reset Minimap position to default',
 		'func', function()
-			db.p1 = "TOPRIGHT"
-			db.p2 = "TOPRIGHT"
+			db.p1 = 'TOPRIGHT'
+			db.p2 = 'TOPRIGHT'
 			db.x = -15
 			db.y = -15
 			db.locked = true
@@ -47,75 +41,79 @@ local function Options(self, anchor)
 			anchor:SetPoint(db.p1, UIParent, db.p2, db.x, db.y)
 			self:Refresh()
 		end)
-	reset:SetPoint("TOPLEFT", lock, "BOTTOMLEFT", 0, -8)
+	reset:SetPoint('TOPLEFT', lock, 'BOTTOMLEFT', 0, -8)

 	local scale = self:MakeSlider(
-		'name', "Minimap Scale",
-		'description', "Drag to change the Minimap scale",
-		'minText', "0.4",
-		'maxText', "2.4",
+		'name', 'Minimap Scale',
+		'description', 'Drag to change the Minimap scale',
+		'minText', '0.4',
+		'maxText', '2.4',
 		'minValue', 0.4,
 		'maxValue', 2.4,
 		'step', 0.1,
 		'default', 0.9,
 		'current', db.scale,
-		'setFunc', function(value) Minimap:SetScale(value) db.scale = value Greenie(anchor) end,
-		'currentTextFunc', function(num) return ("%.1f"):format(num) end)
-	scale:SetPoint("TOPLEFT", reset, "BOTTOMLEFT", 0, -16)
+		'setFunc', function(value)
+			db.scale = value
+			Minimap:SetScale(value)
+			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)

 	local dura = self:MakeToggle(
-		'name', "Toggle Durability",
-		'description', "Set whether backdrop is recolored by durability or not",
+		'name', 'Toggle Durability',
+		'description', 'Set whether backdrop is recolored by durability or not',
 		'default', true,
 		'current', db.durability,
-		'setFunc', function(value) db.durability = value
+		'setFunc', function(value)
+			db.durability = value
 			if(value) then
+				pMinimap:RegisterEvent('UPDATE_INVENTORY_ALERTS')
 				DurabilityFrame:SetAlpha(0)
 			else
-				pMinimap:RegisterEvent("UPDATE_INVENTORY_ALERTS")
+				pMinimap:UnregisterEvent('UPDATE_INVENTORY_ALERTS')
+				pMinimap:SetBackdropColor(0, 0, 0)
 				DurabilityFrame:SetAlpha(1)
 			end
 		end)
-	dura:SetPoint("TOPLEFT", scale, "BOTTOMLEFT", 0, -8)
+	dura:SetPoint('TOPLEFT', scale, 'BOTTOMLEFT', 0, -8)
 end

 local function OnEvent(self, name)
-	if(name == "pMinimap") then
-		db = _G.pMinimapDB
+	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 }
+			db = { p1 = 'TOPRIGHT', p2 = 'TOPRIGHT', x = -15, y = -15, scale = 0.9, locked = true, durability = true }
 			_G.pMinimapDB = db
 		end

-		-- reset lock on load
 		db.locked = true

-		-- fix up an anchor
-		local anchor = CreateFrame("Frame", nil, UIParent)
-		anchor:SetFrameStrata("BACKGROUND")
+		local anchor = CreateFrame('Frame', nil, UIParent)
+		anchor:SetFrameStrata('BACKGROUND')
 		anchor:SetWidth(Minimap:GetWidth() * db.scale)
 		anchor:SetHeight(Minimap:GetHeight() * db.scale)
 		anchor:SetAlpha(0)
-		anchor:SetBackdrop({bgFile="Interface\\ChatFrame\\ChatFrameBackground"})
+		anchor:SetBackdrop({bgFile='Interface\\ChatFrame\\ChatFrameBackground'})
 		anchor:SetBackdropColor(0, 1, 0, 0.5)
-		anchor:SetScript("OnMouseDown", function(self) self:StartMoving() end)
-		anchor:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
+		anchor:SetScript('OnMouseDown', function(self) self:StartMoving() end)
+		anchor:SetScript('OnMouseUp', function(self) self:StopMovingOrSizing() end)
 		anchor:SetPoint(db.p1, UIParent, db.p2, db.x, db.y)
 		anchor:EnableMouse(db.locked and false or true)

-		-- add minimap placement and scale
 		Minimap:ClearAllPoints()
-		Minimap:SetPoint("CENTER", anchor)
+		Minimap:SetPoint('CENTER', anchor)
 		Minimap:SetScale(db.scale)

-		-- setup options
-		LibSimpleOptions.AddOptionsPanel("pMinimap", function(self) Options(self, anchor) end)
-		LibSimpleOptions.AddSlashCommand("pMinimap", "/pminimap", "/pmm")
+		LibSimpleOptions.AddOptionsPanel('pMinimap', function(self) Options(self, anchor, db) end)
+		LibSimpleOptions.AddSlashCommand('pMinimap', '/pminimap', '/pmm')

-		self:UnregisterEvent("ADDON_LOADED")
+		self:UnregisterEvent('ADDON_LOADED')
 	end
 end

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