diff --git a/Broker_Equipment.lua b/Broker_Equipment.lua
index d982948..62cf020 100644
--- a/Broker_Equipment.lua
+++ b/Broker_Equipment.lua
@@ -9,39 +9,21 @@
--]]
-local LDB
-local pendingName
-local pendingIcon
-
-local menu = {}
-local parent = CreateFrame('Frame')
-
-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
+local Broker_Equipment = CreateFrame('Frame')
+Broker_Equipment:RegisterEvent('PLAYER_LOGIN')
+Broker_Equipment:SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)
+Broker_Equipment:Hide()
- if(not located) then
- return
- end
- end
-
- return true
-end
+local LDB, pending
local function UpdateDisplay()
- if(InCombatLockdown() and pendingName) then
- LDB.text = '|cffff0000'..pendingName
- LDB.icon = pendingIcon
+ if(InCombatLockdown() and pending) then
+ LDB.text = '|cffffff00' .. pending
+ LDB.icon = 'Interface\\Icons\\' .. GetEquipmentSetInfoByName(pending)
else
for index = 1, GetNumEquipmentSets() do
- local name, icon = GetEquipmentSetInfo(index)
- if(EquipmentLocated(name)) then
+ local name, icon, _, equipped = GetEquipmentSetInfo(index)
+ if(equipped) then
LDB.text = name
LDB.icon = icon
return
@@ -53,28 +35,27 @@ local function UpdateDisplay()
end
end
-local function ModifiedClick(button, name, icon)
- if(IsShiftKeyDown() and not pendingName) then
+local function ClickDropdown(self, name)
+ if(IsShiftKeyDown() and not pending) then
local dialog = StaticPopup_Show('CONFIRM_SAVE_EQUIPMENT_SET', name)
dialog.data = name
- elseif(IsControlKeyDown() and not pendingName) then
+ elseif(IsControlKeyDown() and not pending) then
local dialog = StaticPopup_Show('CONFIRM_DELETE_EQUIPMENT_SET', name)
dialog.data = name
else
- EquipmentManager_EquipSet(name)
-
if(InCombatLockdown()) then
- parent:RegisterEvent('PLAYER_REGEN_ENABLED')
+ Broker_Equipment:RegisterEvent('PLAYER_REGEN_ENABLED')
+ pending = name
- pendingName = name
- pendingIcon = icon
UpdateDisplay()
+ else
+ EquipmentManager_EquipSet(name)
end
end
end
local function OnTooltipShow(self)
- self:AddLine('|cff0090ffBroker Equipment|r')
+ self:SetEquipmentSet(LDB.text)
end
local function OnClick(self, button)
@@ -83,7 +64,7 @@ local function OnClick(self, button)
end
if(button ~= 'RightButton' and GetNumEquipmentSets() > 0) then
- ToggleDropDownMenu(1, nil, parent, self, 0, 0)
+ ToggleDropDownMenu(1, nil, Broker_Equipment, self, 0, 0)
else
if(not PaperDollFrame:IsVisible()) then
ToggleCharacter('PaperDollFrame')
@@ -95,30 +76,34 @@ local function OnClick(self, button)
end
if(not _G[PAPERDOLL_SIDEBARS[3].frame]:IsShown()) then
- parent:Show()
+ Broker_Equipment:Show()
end
end
end
-local function CreateMenu()
+local info = {}
+local function CreateDropdown()
for index = 1, GetNumEquipmentSets() do
- local name, icon = GetEquipmentSetInfo(index)
- menu.func = ModifiedClick
- menu.text = string.format('%s%s', pendingName and pendingName == name and '|cffff0000' or '', name)
- menu.icon = icon
- menu.arg1 = name
- menu.arg2 = icon
- menu.checked = EquipmentLocated(name)
-
- UIDropDownMenu_AddButton(menu)
+ local name, icon, _, equipped, _, _, _, missing = GetEquipmentSetInfo(index)
+ info.func = ClickDropdown
+ info.icon = icon
+ info.arg1 = name
+ info.checked = equipped
+
+ if(pending == name) then
+ info.text = string.format('|cffffff00%s|r', name)
+ elseif(missing > 0) then
+ info.text = string.format('|cffff0000%s|r', name)
+ else
+ info.text = name
+ end
+
+ UIDropDownMenu_AddButton(info)
end
end
-function parent:PLAYER_LOGIN()
+function Broker_Equipment:PLAYER_LOGIN()
LDB = LibStub('LibDataBroker-1.1'):NewDataObject('Broker_Equipment', {
- icon = [=[Interface\PaperDollInfoFrame\UI-EquipmentManager-Toggle]=],
- iconCoords = {0.08, 0.92, 0.08, 0.92},
- text = 'Broker Equipment',
type = 'data source',
OnTooltipShow = OnTooltipShow,
OnClick = OnClick,
@@ -128,29 +113,26 @@ function parent:PLAYER_LOGIN()
self:RegisterEvent('EQUIPMENT_SETS_CHANGED')
self.EQUIPMENT_SETS_CHANGED = UpdateDisplay
- self.initialize = CreateMenu
+ self.initialize = CreateDropdown
self.displayMode = 'MENU'
UpdateDisplay()
end
-function parent:UNIT_INVENTORY_CHANGED(unit)
+function Broker_Equipment:UNIT_INVENTORY_CHANGED(unit)
if(unit == 'player') then
UpdateDisplay()
end
end
-function parent:PLAYER_REGEN_ENABLED()
+function Broker_Equipment:PLAYER_REGEN_ENABLED()
self:UnregisterEvent('PLAYER_REGEN_ENABLED')
- ModifiedClick(nil, pendingName, pendingIcon)
- pendingName, pendingIcon = nil, nil
+
+ ClickDropdown(nil, pending)
+ pending = nil
end
-parent:SetScript('OnUpdate', function(self)
+Broker_Equipment:SetScript('OnUpdate', function(self)
PaperDollFrame_SetSidebar(nil, 3)
self:Hide()
end)
-
-parent:SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)
-parent:RegisterEvent('PLAYER_LOGIN')
-parent:Hide()