From 1206b9091630089283082ff9fd8927e059b008c5 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Sun, 13 Sep 2009 00:30:03 +0200 Subject: [PATCH] Some cleanup is good --- Broker_Equipment.lua | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/Broker_Equipment.lua b/Broker_Equipment.lua index 1d56922..663aa2e 100644 --- a/Broker_Equipment.lua +++ b/Broker_Equipment.lua @@ -42,6 +42,9 @@ local pendingUpdate = true local pendingName = nil local addon = CreateFrame('Frame', 'Broker_EquipmentMenu', UIParent, 'UIDropDownMenuTemplate') +addon:RegisterEvent('ADDON_LOADED') +addon:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end) + local broker = LibStub('LibDataBroker-1.1'):NewDataObject('Broker_Equipment', { type = 'data source', text = L.NOSET, @@ -61,7 +64,7 @@ local function GetTextureIndex(tex) end end -local function matchEquipped(name) +local function equipped(name) local located for slot, location in next, GetEquipmentSetLocations(name) do if(location == 0) then @@ -79,7 +82,7 @@ local function matchEquipped(name) return true end -local function handleClick(name, icon) +local function menuClick(name, icon) if(IsShiftKeyDown()) then local dialog = StaticPopup_Show('CUSTOM_OVERWRITE_EQUIPMENT_SET', name) -- Custom popup to update the info dialog.name = name @@ -118,7 +121,7 @@ local function updateMenu() notCheckable = true, text = name, icon = icon, - func = function() handleClick(name, icon) end + func = function() menuClick(name, icon) end } table.insert(menu, temp) end @@ -172,35 +175,41 @@ function broker:OnTooltipShow() self:AddLine(L.TOOLTIP) end -function addon:PLAYER_REGEN_ENABLED(event) - EquipmentManager_EquipSet(pendingName) - pendingName = nil - self:UnregisterEvent(event) -end - function addon:ADDON_LOADED(event, addon) if(addon ~= 'Broker_Equipment') then return end Broker_EquipmentDB = Broker_EquipmentDB or {text = L.NOSET, icon = broker.icon} - broker.text = Broker_EquipmentDB.text - broker.icon = Broker_EquipmentDB.icon + self:UNIT_INVENTORY_CHANGED() self:RegisterEvent('EQUIPMENT_SETS_CHANGED') self:RegisterEvent('UNIT_INVENTORY_CHANGED') self:RegisterEvent('VARIABLES_LOADED') self:UnregisterEvent(event) 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 = nil + self:UnregisterEvent(event) +end + function addon:EQUIPMENT_SETS_CHANGED() pendingUpdate = true end function addon:UNIT_INVENTORY_CHANGED(event, unit) - if(unit ~= 'player') then return end + if(unit and unit ~= 'player') then return end for index = 1, GetNumEquipmentSets() do local name, icon = GetEquipmentSetInfo(index) - if(matchEquipped(name)) then + if(equipped(name)) then updateInfo(name, icon) break else @@ -208,13 +217,3 @@ function addon:UNIT_INVENTORY_CHANGED(event, unit) end end end - -function addon:VARIABLES_LOADED(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) -- 1.7.9.5