Quantcast

Feature: Saving set name between sessions

p3lim-52096 [03-07-09 - 23:12]
Feature: Saving set name between sessions
Feature: Colored text when set is queued in combat
Better handling of tables and dropdowns


git-svn-id: svn://svn.wowinterface.com/Broker_Equipment-429/trunk@5 ec0254a7-aafd-4d69-bcb1-797bd6548cda
Filename
Broker_Equipment/Broker_Equipment.lua
Broker_Equipment/Broker_Equipment.toc
diff --git a/Broker_Equipment/Broker_Equipment.lua b/Broker_Equipment/Broker_Equipment.lua
index 2cc418a..7dafeda 100644
--- a/Broker_Equipment/Broker_Equipment.lua
+++ b/Broker_Equipment/Broker_Equipment.lua
@@ -1,65 +1,108 @@
-local locale = GetLocale()
-local dummy = CreateFrame('Frame', 'Broker_EquipmentDummy', UIParent, 'UIDropDownMenuTemplate')
+local L = {}
+if(GetLocale() == 'deDE') then
+	L.TOOLTIP = 'Klicke hier um das set zu wechsein'
+	L.NOSET = 'Kein set'
+else
+	L.TOOLTIP = 'Click here to change your set'
+	L.NOSET = 'No set'
+end
+
+
+local menuList = {}
+local pendingName = nil
+local pendingUpdate = true
+
+local frame = CreateFrame('Frame', 'Broker_EquipmentDropDown', UIParent, 'UIDropDownMenuTemplate')
 local broker = LibStub:GetLibrary('LibDataBroker-1.1'):NewDataObject('Broker_Equipment', {
 	type = 'data source',
-	text = 'Equipment',
-	icon = 'Interface\\PaperDollInfoFrame\\UI-EquipmentManager-Toggle',
+	text = L.NOSET,
+	icon = [=[Interface\PaperDollInfoFrame\UI-EquipmentManager-Toggle]=],
 	iconCoords = {0.065, 0.935, 0.065, 0.935}
 })

-local CHANGESET
-if(locale == 'frFR') then
-	CHANGESET = 'Click here to change your set' -- todo
-elseif(locale == 'deDE') then
-	CHANGESET = 'Klicke hier um das set zu wechsein'
-elseif(locale == 'koKR') then
-	CHANGESET = 'Click here to change your set' -- todo
-elseif(locale == 'zhCN') then
-	CHANGESET = 'Click here to change your set' -- todo
-elseif(locale == 'zhTW') then
-	CHANGESET = 'Click here to change your set' -- todo
-elseif(locale == 'ruRU') then
-	CHANGESET = 'Click here to change your set' -- todo
-elseif(locale == 'esES') then
-	CHANGESET = 'Click here to change your set' -- todo
-elseif(locale == 'esMX') then
-	CHANGESET = 'Click here to change your set' -- todo
-else
-	CHANGESET = 'Click here to change your set'
-end

-function broker.OnClick(self, button)
-	local menu = {}
+local function equipSet(name, icon)
+	EquipmentManager_EquipSet(name)
+
+	if(InCombatLockdown()) then
+		pendingName = name
+		broker.text = '|cffff0000'..name
+	else
+		broker.text = name
+	end
+
+	broker.icon = icon
+	EquipmentDB.text = name
+	EquipmentDB.icon = icon
+end
+
+local function createDropDown()
+	wipe(menuList)
+
 	for index = 1, GetNumEquipmentSets() do
-		local name, texture = GetEquipmentSetInfo(index)
-		table.insert(menu, {
-			tooltipTitle = name,
-			index = index,
-			text = name,
-			icon = texture,
-			func = function()
-				EquipmentManager_EquipSet(name)
-				broker.text = name
-				broker.icon = texture
-			end
-		})
+		local name, icon = GetEquipmentSetInfo(index)
+		local info = {}
+		info.index = index
+		info.text = name
+		info.icon = icon
+		info.func = function() equipSet(name, icon) end
+
+		menuList[index] = info
+	end
+
+	table.sort(menuList, function(a,b) return a.index < b.index end)
+	UIDropDownMenu_Initialize(frame, initDropDown, 'MENU')
+	pendingUpdate = nil
+end
+
+local function initDropDown()
+	for k,v in next, menuList do
+		UIDropDownMenu_AddButton(v, level or 1)
+	end
+end
+
+
+function frame:PLAYER_REGEN_ENABLED()
+	if(pendingName) then
+		broker.text = pendingName
+		combatName = nil
+	end
+end
+
+function frame:EQUIPMENT_SETS_CHANGED()
+	needUpdate = true
+end
+
+function frame:ADDON_LOADED(event, addon)
+	if(addon ~= 'Broker_Equipment') then return end
+
+	EquipmentDB = EquipmentDB or {text = L.NOSET, icon = broker.icon}
+	broker.text = EquipmentDB.text
+	broker.icon = EquipmentDB.icon
+
+	self:UnregisterEvent(event)
+end
+
+
+function broker:OnClick()
+	if(GameTooltip:GetOwner() == self) then
+		GameTooltip:Hide()
 	end

-	table.sort(menu, function(a,b) return a.index < b.index end)
-	EasyMenu(menu, dummy, self, 20, 0, 'MENU')
+	if(pendingUpdate) then
+		createDropDown()
+	end

-	if(GameTooltip:GetOwner() == self) then GameTooltip:Hide() end
+	ToggleDropDownMenu(1, nil, frame, self, 0, 0)
 end

-function broker.OnTooltipShow(self)
+function broker:OnTooltipShow()
 	self:AddLine('|cff0090ffBroker Equipment|r')
-	self:AddLine(CHANGESET)
+	self:AddLine(L.TOOLTIP)
 end

-dummy:RegisterEvent('PLAYER_LOGIN')
-dummy:SetScript('OnEvent', function()
-	SetCVar('equipmentManager', 1)
-	GearManagerToggleButton:Show()

-	-- Todo: Set the name of the set that you are wearing on load
-end)
\ No newline at end of file
+frame:RegisterEvent('ADDON_LOADED')
+frame:RegisterEvent('PLAYER_REGEN_ENABLED')
+frame:RegisterEvent('EQUIPMENT_SETS_CHANGED')
+frame:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end)
\ No newline at end of file
diff --git a/Broker_Equipment/Broker_Equipment.toc b/Broker_Equipment/Broker_Equipment.toc
index 55edb92..b042408 100644
--- a/Broker_Equipment/Broker_Equipment.toc
+++ b/Broker_Equipment/Broker_Equipment.toc
@@ -3,6 +3,7 @@
 ## Version: 30100.wowi:revision
 ## Title: Broker Equipment
 ## Notes: LDB Equipment Manager plug-in
+## SavedVariablesPerCharacter: EquipmentDB

 Libs\LibStub.lua
 Libs\CallbackHandler-1.0.lua