Quantcast

Added EasyMenu dropdown system

p3lim-52096 [06-08-09 - 21:34]
Added EasyMenu dropdown system
Added help lines to dropdown
Added right-click to open GearManager
Added forcing of equipment manager turned on at load
Added event handler
Removed Alt-key modifier
Removed help lines from tooltip

git-svn-id: svn://svn.wowinterface.com/Broker_Equipment-429/trunk@19 ec0254a7-aafd-4d69-bcb1-797bd6548cda
Filename
Broker_Equipment/Broker_Equipment.lua
diff --git a/Broker_Equipment/Broker_Equipment.lua b/Broker_Equipment/Broker_Equipment.lua
index 1699b43..bcf3919 100644
--- a/Broker_Equipment/Broker_Equipment.lua
+++ b/Broker_Equipment/Broker_Equipment.lua
@@ -11,52 +11,55 @@

 local L = {}
 if(GetLocale() == 'deDE') then -- Katharsis
-	L.TOOLTIP1 = 'Klicke hier um das set zu wechsein'
-	L.TOOLTIP2 = 'Klicke mit Strg+Alt im men/195/188 um dein set zu aktualisieren'
-	L.TOOLTIP3 = 'Klicke mit Shift+Alt im men/195/188 um dein set zu l/195/182schen'
 	L.NOSET = 'Kein set'
+	L.TOOLTIP1 = 'Left-click to change your set'
+	L.TOOLTIP2 = 'Right-click to open GearManager'
+	L.HINT = {' ', '|cff00ff00Shift-click to update set|r', '|cff00ff00Ctrl-click to delete set|r'}
 elseif(GetLocale() == 'frFR') then -- Soeters
-	L.TOOLTIP1 = 'Cliquez ici pour changer de set'
-	L.TOOLTIP2 = 'Ctrl+Alt click in menu to update your set (NYI)'
-	L.TOOLTIP3 = 'Shift+Alt click in menu to delete your set (NYI)'
 	L.NOSET = 'Pas de set'
-elseif(GetLocale() == 'zhCN') then -- yleaf & yaroot
-	L.TOOLTIP1 = '点击选择套装'
-	L.TOOLTIP2 = 'Ctrl+Alt 点击更新套装'
-	L.TOOLTIP3 = 'Shift+Alt 点击删除套装'
+	L.TOOLTIP1 = 'Left-click to change your set'
+	L.TOOLTIP2 = 'Right-click to open GearManager'
+	L.HINT = {' ', '|cff00ff00Maj-clic pour mettre à jour le set|r', '|cff00ff00Ctrl-clic pour supprimer le set|r'}
+elseif(GetLocale() == 'zhCN') then -- yleaf
 	L.NOSET = '无套装'
-elseif(GetLocale() == 'zhTW') then -- yleaf & yaroot
-	L.TOOLTIP1 = '點擊選擇套裝'
-	L.TOOLTIP2 = 'Ctrl+Alt 點擊更新套裝'
-	L.TOOLTIP3 = 'Shift+Alt 點擊刪除套裝'
+	L.TOOLTIP1 = 'Left-click to change your set'
+	L.TOOLTIP2 = 'Right-click to open GearManager'
+	L.HINT = {' ', '|cff00ff00Shift点击覆盖套装|r', '|cff00ff00Ctrl点击删除套装|r'}
+elseif(GetLocale() == 'zhTW') then -- yleaf
 	L.NOSET = '無套裝'
+	L.TOOLTIP1 = 'Left-click to change your set'
+	L.TOOLTIP2 = 'Right-click to open GearManager'
+	L.HINT = {' ', '|cff00ff00Shift點擊覆蓋套裝|r', '|cff00ff00Ctrl點擊刪除套裝|r'}
 elseif(GetLocale() == 'koKR') then -- mrgyver
-	L.TOOLTIP1 = '당신의 세트를 변경하려면 여기를 클릭하세요.'
-	L.TOOLTIP2 = 'Ctrl+Alt click in menu to update your set (NYI)'
-	L.TOOLTIP3 = 'Shift+Alt click in menu to delete your set (NYI)'
 	L.NOSET = '세트 없음'
+	L.TOOLTIP1 = 'Left-click to change your set'
+	L.TOOLTIP2 = 'Right-click to open GearManager'
+	L.HINT = {' ', '|cff00ff00Shift-click to update set|r', '|cff00ff00Ctrl-click to delete set|r'}
 else
-	L.TOOLTIP1 = 'Click here to change your set'
-	L.TOOLTIP2 = 'Ctrl+Alt click in menu to update your set'
-	L.TOOLTIP3 = 'Shift+Alt click in menu to delete your set'
 	L.NOSET = 'No set'
+	L.TOOLTIP1 = 'Left-click to change your set'
+	L.TOOLTIP2 = 'Right-click to open GearManager'
+	L.HINT = {' ', '|cff00ff00Shift-click to update set|r', '|cff00ff00Ctrl-click to delete set|r'}
 end

-local menuList = {}
-local pendingName = nil
-local pendingUpdate = true

-local addonName = 'Broker_Equipment'
+local BEQ = CreateFrame('Frame', 'Broker_EquipmentMenu', UIParent, 'UIDropDownMenuTemplate')
+BEQ:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end)
+
+local failIcon = [=[Interface\Icons\ability_seal]=]
+local defaultIcon = [=[Interface\PaperDollInfoFrame\UI-EquipmentManager-Toggle]=]

-local addon = CreateFrame('Frame', addonName..'DropDown', UIParent, 'UIDropDownMenuTemplate')
-local broker = LibStub('LibDataBroker-1.1'):NewDataObject(addonName, {
+local menu = {}
+local pendingUpdate = true
+
+local broker = LibStub('LibDataBroker-1.1'):NewDataObject('Broker_Equipment', {
 	type = 'data source',
 	text = L.NOSET,
-	icon = [=[Interface\PaperDollInfoFrame\UI-EquipmentManager-Toggle]=],
+	icon = defaultIcon,
 	iconCoords = {0.065, 0.935, 0.065, 0.935}
 })

--- borrowed from tekkub's EquipSetUpdater
+-- Borrowed from tekkub's EquipSetUpdater
 local function GetTextureIndex(tex)
 	RefreshEquipmentSetIconInfo()
 	tex = tex:lower()
@@ -69,91 +72,105 @@ local function GetTextureIndex(tex)
 end

 local function handleClick(name, icon)
-	if(IsShiftKeyDown() and IsAltKeyDown()) then
-		local dialog = StaticPopup_Show('CONFIRM_DELETE_EQUIPMENT_SET', name)
-		dialog.data = name
-	elseif(IsControlKeyDown() and IsAltKeyDown()) then
+	if(IsShiftKeyDown()) then
 		local dialog = StaticPopup_Show('CONFIRM_OVERWRITE_EQUIPMENT_SET', name)
 		dialog.data = name
-		dialog.selectedIcon = GetTextureIndex(icon) -- blizzard sucks
-	elseif(EquipmentSetContainsLockedItems(name) or UnitOnTaxi('player') or UnitCastingInfo('player') or InCombatLockdown()) then
-		return
-	else
+		dialog.selectedIcon = GetTextureIndex(icon) -- Blizzard sucks
+	elseif(IsControlKeyDown()) then
+		local dialog = StaticPopup_Show('CONFIRM_DELETE_EQUIPMENT_SET', name)
+		dialog.data = name
+	elseif(not InCombatLockdown()) then
 		EquipmentManager_EquipSet(name)
+
+		Broker_EquipmentDB.text = name
+		Broker_EquipmentDB.icon = icon
 	end
 end

-local function initDropDown()
-	for k, v in next, menuList do
-		UIDropDownMenu_AddButton(v, level or 1)
-	end
-end
+local function updateMenu()
+	pendingUpdate = nil
+	menu = wipe(menu)

-local function createDropDown()
-	wipe(menuList)
+	local title = {text = 'Broker Equipment\n ', isTitle = true}
+	table.insert(menu, title)

 	for index = 1, GetNumEquipmentSets() do
 		local name, icon = GetEquipmentSetInfo(index)
-		local info = {}
-		info.index = index
-		info.text = name
-		info.icon = icon
-		info.func = function() handleClick(name, icon) end
-
-		menuList[index] = info
+		local temp = {
+			text = name,
+			icon = icon,
+			func = function() handleClick(name, icon) end
+		}
+		table.insert(menu, temp)
 	end

-	table.sort(menuList, function(a, b) return a.index < b.index end)
-	UIDropDownMenu_Initialize(addon, initDropDown, 'MENU')
-	pendingUpdate = nil
-end
-
-local function onEvent(self, event, arg1)
-	if(event == 'EQUIPMENT_SETS_CHANGED') then
-		pendingUpdate = true
-	else
-		if(arg1 ~= addonName) 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:UnregisterEvent(event)
+	for index = 1, 3 do
+		local temp = {text = L.HINT[index], disabled = true}
+		table.insert(menu, temp)
 	end
 end

 function broker:OnClick(button)
-	if(GameTooltip:GetOwner() == self) then
-		GameTooltip:Hide()
-	end
+	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()
+		end
+	else
+		if(pendingUpdate) then updateMenu() end
+		EasyMenu(menu, BEQ, self, 0, 0, 'MENU')

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

 function broker:OnTooltipShow()
 	self:AddLine('|cff0090ffBroker Equipment|r')
 	self:AddLine(L.TOOLTIP1)
 	self:AddLine(L.TOOLTIP2)
-	self:AddLine(L.TOOLTIP3)
+end
+
+function BEQ:ADDON_LOADED(event, addon)
+	if(addon ~= 'Broker_Equipment') then return end
+
+	Broker_EquipmentDB = Broker_EquipmentDB or {text = L.NOSET, icon = broker.defaultIcon}
+	broker.text = Broker_EquipmentDB.text
+	broker.icon = Broker_EquipmentDB.icon
+
+	self:UnregisterEvent(event)
+end
+
+function BEQ:EQUIPMENT_SETS_CHANGED()
+	pendingUpdate = true
+end
+
+function BEQ:VARIABLES_LOADED()
+	SetCVar('equipmentManager', 1)
+	GearManagerToggleButton:Show()
 end

 hooksecurefunc('EquipmentManager_EquipSet', function(name)
-	if(name and name ~= broker.text) then
+	if(name) then
 		local icon = GetEquipmentSetInfoByName(name)
-		local propericon = icon:match('Interface') and icon or [=[Interface\Icons\]=] .. icon -- fixing blizzard's bug
+		-- Blizzard has some odd bug not always returning the whole icon location string
+		-- This is a temporary fix around it
+		icon = icon:sub(1, 9) ~= 'Interface' and [=[Interface\Icons\]=] .. icon or icon

 		broker.text = name
-		broker.icon = propericon
-
-		Broker_EquipmentDB.text = name
-		Broker_EquipmentDB.icon = propericon
+		broker.icon = icon or failIcon
+	else
+		broker.text = L.NOSET
+		broker.icon = defaultIcon
 	end
 end)

-addon:RegisterEvent('ADDON_LOADED')
-addon:RegisterEvent('EQUIPMENT_SETS_CHANGED')
-addon:SetScript('OnEvent', onEvent)
\ No newline at end of file
+BEQ:RegisterEvent('ADDON_LOADED')
+BEQ:RegisterEvent('EQUIPMENT_SETS_CHANGED')
+BEQ:RegisterEvent('VARIABLES_LOADED')
\ No newline at end of file