Quantcast

Some cleaning and minor alterations

Adrian L Lange [06-25-10 - 15:37]
Some cleaning and minor alterations
Filename
Broker_Equipment.lua
Broker_Equipment.toc
Localization.lua
diff --git a/Broker_Equipment.lua b/Broker_Equipment.lua
index 0f33a70..bb927c2 100644
--- a/Broker_Equipment.lua
+++ b/Broker_Equipment.lua
@@ -10,16 +10,24 @@
 --]]

 local addonName, ns = ...
-local L = ns.L

-local pendingName, pendingIcon
+local pending = {}
 local addon = CreateFrame('Frame', addonName)
 local broker = LibStub('LibDataBroker-1.1'):NewDataObject(addonName, {
-	type = 'data source',
-	iconCoords = {0.065, 0.935, 0.065, 0.935}
+	iconCoords = {0.08, 0.92, 0.08, 0.92},
+	type = 'data source'
 })

--- Borrowed from tekkub's EquipSetUpdater
+local function Update(name, icon)
+	broker.text = pending.name and '|cffff0000'..pending.name or name
+	broker.icon = pending.icon or icon
+
+	Broker_EquipmentDB.name = pending.name or name
+	Broker_EquipmentDB.icon = pending.icon or icon
+end
+
+-- Borrowed from tekkub's EquipSetUpdater (modified)
+-- We really need a proper API for this
 local function GetTextureIndex(tex)
 	RefreshEquipmentSetIconInfo()
 	tex = tex:lower()
@@ -31,26 +39,7 @@ local function GetTextureIndex(tex)
 	end
 end

-local function equipped(name)
-	for slot, location in next, GetEquipmentSetLocations(name) do
-		local located = true
-
-		if(location == 0) then
-			located = not GetInventoryItemLink('player', slot)
-		elseif(location ~= 1) then
-			local player, bank, bags = EquipmentManager_UnpackLocation(location)
-			located = player and not bank and not bags
-		end
-
-		if(not located) then
-			return
-		end
-	end
-
-	return true
-end
-
-local function menuClick(button, name, icon)
+local function ModifiedClick(button, name, icon)
 	if(IsShiftKeyDown()) then
 		local dialog = StaticPopup_Show('CONFIRM_OVERWRITE_EQUIPMENT_SET', name)
 		dialog.data = name
@@ -62,117 +51,113 @@ local function menuClick(button, name, icon)
 		EquipmentManager_EquipSet(name)

 		if(InCombatLockdown()) then
-			pendingName, pendingIcon = name, icon
+			pending.name, pending.icon = name, icon
 			addon:RegisterEvent('PLAYER_REGEN_ENABLED')
 		end
 	end
 end

-local function updateInfo(name, icon)
-	broker.text = pendingName and '|cffff0000'..pendingName or name
-	broker.icon = pendingIcon or icon
-
-	Broker_EquipmentDB.text = pendingName or name
-	Broker_EquipmentDB.icon = pendingIcon or icon
-end
+local function EquipmentLocated(name)
+	for slot, location in pairs(GetEquipmentSetLocations(name)) do
+		local located = true
+		if(location == 0) then
+			located = not GetInventoryItemLink('player', slot)
+		elseif(location ~= 1) then
+			local player, bank, bags = EquipmentManager_UnpackLocation(location)
+			located = player and not bank and not bags
+		end

-function broker:OnClick(button)
-	if(button == 'RightButton') then
-		if(GearManagerDialog:IsVisible()) then
-			if(PaperDollFrame:IsVisible()) then
-				ToggleCharacter('PaperDollFrame')
-			end
-			GearManagerDialog:Hide()
-		else
-			if(not PaperDollFrame:IsVisible()) then
-				ToggleCharacter('PaperDollFrame')
-			end
-			GearManagerDialog:Show()
+		if(not located) then
+			return
 		end
-	elseif(GetNumEquipmentSets() > 0) then
-		ToggleDropDownMenu(1, nil, addon, self, 0, 0)
 	end

-	if(GameTooltip:GetOwner() == self) then
-		GameTooltip:Hide()
-	end
+	return true
 end

 function broker:OnTooltipShow()
 	self:AddLine('|cff0090ffBroker Equipment|r')
-	self:AddLine(L[2])
+	self:AddLine(ns.L[1])
+	self:AddLine(ns.L[2])
 end

-function addon:initialize(level)
+function broker:OnClick(button)
+	if(button ~= 'RightButton' and GetNumEquipmentSets() > 0) then
+		ToggleDropDownMenu(1, nil, addon, self, 0, 0)
+	else
+		local paperdoll = PaperDollFrame:IsVisible()
+		if(not paperdoll or paperdoll and not GearManagerDialog:IsVisible()) then
+			ToggleCharacter('PaperDollFrame')
+			GearManagerDialog:Show()
+		end
+	end
+end
+
+function addon:initialize(...)
 	local info = wipe(self.info)
 	info.isTitle = 1
 	info.notCheckable = 1
 	info.text = '|cff0090ffBroker Equipment|r\n '
-	UIDropDownMenu_AddButton(info, level)
+	UIDropDownMenu_AddButton(info, ...)

 	wipe(info)
 	for index = 1, GetNumEquipmentSets() do
 		local name, icon = GetEquipmentSetInfo(index)
-		info.text = string.format('|T%s:20|t %s', icon, name)
+		info.text = '|T'..icon..':20|t '..name
 		info.arg1 = name
 		info.arg2 = icon
-		info.func = menuClick
-		info.checked = equipped(name) or pending and pending == name
-		UIDropDownMenu_AddButton(info, level)
+		info.func = ModifiedClick
+		info.checked = EquipmentLocated(name) or pending.name and pending.name == name
+		UIDropDownMenu_AddButton(info, ...)
 	end

 	wipe(info)
-	info.text = ' '
 	info.disabled = 1
 	info.notCheckable = 1
-	UIDropDownMenu_AddButton(info, level)

-	info.text = L[3]
-	UIDropDownMenu_AddButton(info, level)
+	info.text = ns.L[3]
+	UIDropDownMenu_AddButton(info, ...)
+
+	info.text = ns.L[4]
+	UIDropDownMenu_AddButton(info, ...)
 end

-function addon:ADDON_LOADED(event, name)
+function addon:ADDON_LOADED(name, event)
 	if(name ~= addonName) then return end
-
-	Broker_EquipmentDB = Broker_EquipmentDB or {text = L[1], icon = [=[Interface\PaperDollInfoFrame\UI-EquipmentManager-Toggle]=]}
+	Broker_EquipmentDB = Broker_EquipmentDB or {}

 	self.info = {}
 	self.displayMode = 'MENU'
-
-	updateInfo(Broker_EquipmentDB.text, Broker_EquipmentDB.icon)
-	self:RegisterEvent('EQUIPMENT_SETS_CHANGED')
 	self:RegisterEvent('UNIT_INVENTORY_CHANGED')
 	self:RegisterEvent('VARIABLES_LOADED')
 	self:UnregisterEvent(event)
+	self:UNIT_INVENTORY_CHANGED()
 end

-function addon:VARIABLES_LOADED(event)
-	SetCVar('equipmentManager', 1)
-	GearManagerToggleButton:Show()
-
-	self:UnregisterEvent(event)
-end
-
-function addon:PLAYER_REGEN_ENABLED(event)
-	EquipmentManager_EquipSet(pendingName)
-	pendingName, pendingIcon = nil, nil
-	self:UnregisterEvent(event)
-end
-
-function addon:UNIT_INVENTORY_CHANGED(event, unit)
+function addon:UNIT_INVENTORY_CHANGED(unit)
 	if(unit and unit ~= 'player') then return end

 	for index = 1, GetNumEquipmentSets() do
 		local name, icon = GetEquipmentSetInfo(index)
-		if(equipped(name)) then
-			updateInfo(name, icon)
-			break
+		if(EquipmentLocated(name)) then
+			return Update(name, icon)
 		else
-			updateInfo(UNKNOWN, [=[Interface\Icons\INV_Misc_QuestionMark]=])
+			Update(UNKNOWN, [=[Interface\Icons\INV_Misc_QuestionMark]=])
 		end
 	end
 end

-addon.EQUIPMENT_SETS_CHANGED = addon.UNIT_INVENTORY_CHANGED
+function addon:PLAYER_REGEN_ENABLED(event)
+	ModifiedClick(nil, pending.name, pending.icon)
+	self:UnregisterEvent(event)
+	pending = {}
+end
+
+function addon:VARIABLES_LOADED(var, event)
+	SetCVar('equipmentManager', 1)
+	GearManagerToggleButton:Show()
+	self:UnregisterEvent(event)
+end
+
 addon:RegisterEvent('ADDON_LOADED')
-addon:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end)
+addon:SetScript('OnEvent', function(self, event, ...) self[event](self, ..., event) end)
diff --git a/Broker_Equipment.toc b/Broker_Equipment.toc
index bf56fad..14e67a6 100644
--- a/Broker_Equipment.toc
+++ b/Broker_Equipment.toc
@@ -5,10 +5,9 @@
 ## Notes: LDB Equipment Manager plug-in
 ## SavedVariablesPerCharacter: Broker_EquipmentDB

-Localization.lua
-
 libs\LibStub.lua
 libs\CallbackHandler-1.0.lua
 libs\LibDataBroker-1.1.lua

+Localization.lua
 Broker_Equipment.lua
diff --git a/Localization.lua b/Localization.lua
index 50b4c0f..d62e738 100644
--- a/Localization.lua
+++ b/Localization.lua
@@ -5,39 +5,48 @@

 local _, ns = ...
 ns.L = GetLocale() == 'deDE' and {
-	'Kein set',
-	'Links-Klick um Set zu wechseln\nRechts-Klocl um den Ausrüstungsmanager zu öffnen',
-	'|cff00ff00Shift + Links-Klick um Set zu aktualisieren\nStrg + Links-Klick um Set zu löschen|r',
+	'Links-Klick um Set zu wechseln',
+	'Rechts-Klocl um den Ausrüstungsmanager zu öffnen',
+	'|cff00ff00Shift + Links-Klick um Set zu aktualisieren|r',
+	'|cff00ff00Strg + Links-Klick um Set zu löschen|r',
 } or GetLocale() == 'frFR' and {
-	'Pas de set',
-	'Clic gauche pour changer d\'équipement\nClic droit pour ouvrir le gestionnaire d\'équipement',
-	'|cff00ff00Maj-clic pour mettre à jour le set\nCtrl-clic pour supprimer le set|r',
+	'Clic gauche pour changer d\'équipement',
+	'Clic droit pour ouvrir le gestionnaire d\'équipement',
+	'|cff00ff00Maj-clic pour mettre à jour le set|r',
+	'|cff00ff00Ctrl-clic pour supprimer le set|r',
 } or GetLocale() == 'zhCN' and {
-	'无套装',
-	'左键点击切换套装\n右键打开套装管理器',
-	'|cff00ff00Shift点击覆盖套装\nCtrl点击删除套装|r',
+	'左键点击切换套装',
+	'右键打开套装管理器',
+	'|cff00ff00Shift点击覆盖套装|r',
+	'|cff00ff00Ctrl点击删除套装|r',
 } or GetLocale() == 'zhTW' and {
-	'無套裝',
-	'左鍵點擊切換套裝\n右鍵點擊打開套裝管理器',
-	'|cff00ff00Shift點擊覆蓋套裝\nCtrl點擊刪除套裝|r',
+	'左鍵點擊切換套裝',
+	'右鍵點擊打開套裝管理器',
+	'|cff00ff00Shift點擊覆蓋套裝|r',
+	'|cff00ff00Ctrl點擊刪除套裝|r',
 } or GetLocale() == 'koKR' and {
-	'세트 없음',
-	'좌-클릭 세트 변경\n우-클릭 장비 관리창 열기',
-	'|cff00ff00Shift-클릭 하면 세트 업데이트\nCtrl-클릭 하면 세트 삭제|r',
+	'좌-클릭 세트 변경',
+	'우-클릭 장비 관리창 열기',
+	'|cff00ff00Shift-클릭 하면 세트 업데이트|r',
+	'|cff00ff00Ctrl-클릭 하면 세트 삭제|r',
 } or GetLocale() == 'esES' and {
-	'Sin set',
-	'Click izquierdo para cambiar tu set\nClick derecho para abrir el Administrador de Equipo',
-	'|cff00ff00Shift-click para modificar set\nCtrl-click para eliminar set',
+	'Click izquierdo para cambiar tu set',
+	'Click derecho para abrir el Administrador de Equipo',
+	'|cff00ff00Shift-click para modificar set|r',
+	'|cff00ff00Ctrl-click para eliminar set',
 } or GetLocale() == 'esMX' and {
-	'Sin set',
-	'Click izquierdo para cambiar tu set\nClick derecho para abrir el Administrador de Equipo',
-	'|cff00ff00Shift-click para modificar set\nCtrl-click para eliminar set',
+	'Click izquierdo para cambiar tu set',
+	'Click derecho para abrir el Administrador de Equipo',
+	'|cff00ff00Shift-click para modificar set|r',
+	'|cff00ff00Ctrl-click para eliminar set|r',
 } or GetLocale() == 'ruRU' and {
-	'Нет комплекта',
-	'Левый клик, чтобы изменить комплект\nПравый клик, чтобы открыть менеджер экипировки',
-	'|cff00ff00Shift-клик, чтобы обновить комплект\nCtrl-клик, чтобы удалить комплект',
+	'Левый клик, чтобы изменить комплект',
+	'Правый клик, чтобы открыть менеджер экипировки',
+	'|cff00ff00Shift-клик, чтобы обновить комплект|r',
+	'|cff00ff00Ctrl-клик, чтобы удалить комплект|r',
 } or {
-	'No set',
-	'Left-click to change your set\nRight-click to open GearManager',
-	'|cff00ff00Shift-click to update set\nCtrl-click to delete set|r',
+	'Left-click to change your set',
+	'Right-click to open GearManager',
+	'|cff00ff00Shift-click to update set|r',
+	'|cff00ff00Ctrl-click to delete set|r',
 }