-
Notifications
You must be signed in to change notification settings - Fork 2
/
OutfitterLDB.lua
102 lines (82 loc) · 2.83 KB
/
OutfitterLDB.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Outfitter.LDB = {}
function Outfitter.LDB:Initialize()
self.LDB = LibStub("LibDataBroker-1.1", true)
self.DataObj = self.LDB:NewDataObject(Outfitter.cTitle,
{
type = "launcher",
icon = "Interface\\AddOns\\Outfitter\\Textures\\Icon",
text = "Outfitter",
OnClick = function(pFrame, pButton) self:OnClick(pFrame, pButton) end
})
Outfitter:RegisterOutfitEvent("WEAR_OUTFIT", function (...) self:OutfitEvent(...) end)
Outfitter:RegisterOutfitEvent("UNWEAR_OUTFIT", function (...) self:OutfitEvent(...) end)
Outfitter:RegisterOutfitEvent("OUTFITTER_INIT", function (...) self:OutfitEvent(...) end)
end
function Outfitter.LDB:CreateIcon(minimapButton)
self.icon = LibStub("LibWithFreeDragDBIcon-1.0")
self.icon:Register(Outfitter.cTitle, self.DataObj, minimapButton)
end
function Outfitter.LDB:ShowIcon()
self.icon:Show(Outfitter.cTitle)
end
function Outfitter.LDB:HideIcon()
self.icon:Hide(Outfitter.cTitle)
end
function Outfitter.LDB:OnClick(pFrame, pButton)
if pButton == "LeftButton" then
self:ToggleMenu()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
else
Outfitter:ToggleUI(true)
end
end
function Outfitter.LDB:OutfitEvent(pEvent, pOutfitName, pOutfit)
local vOutfitName, vOutfit = Outfitter:GetCurrentOutfitInfo()
if vOutfit then
self.DataObj.text = vOutfitName
self.DataObj.icon = Outfitter.OutfitBar:GetOutfitTexture(vOutfit)
else
self.DataObj.text = Outfitter.cTitle
self.DataObj.icon = "Interface\\AddOns\\Outfitter\\Textures\\Icon"
end
end
function Outfitter.LDB:ToggleMenu()
if self.dropDownMenu then
self:HideMenu()
else
self:ShowMenu()
end
end
function Outfitter.LDB:ShowMenu()
assert(not self.dropDownMenu, "can't show the LDB menu while it's already up")
-- Create the items
items = Outfitter:New(Outfitter.UIElementsLib._DropDownMenuItems, function ()
-- Close the menu after a short delay when a menu item is selected
Outfitter.SchedulerLib:ScheduleTask(0.1, function ()
self:HideMenu()
end)
end)
-- Get the items
Outfitter:GetMinimapDropdownItems(items)
-- Get the cursor position
local cursorX, cursorY = GetCursorPosition()
local scaling = UIParent:GetEffectiveScale()
cursorX = cursorX / scaling
cursorY = cursorY / scaling
-- Use the screen quadrant as an anchor for the menu
local quadrant = Outfitter:GetScreenQuadrantFromCoordinates(cursorX, cursorY)
-- Show the menu
self.dropDownMenu = Outfitter:New(Outfitter.UIElementsLib._DropDownMenu)
self.dropDownMenu:Show(items, quadrant, UIParent, "BOTTOMLEFT", cursorX, cursorY)
self.dropDownMenu.cleanup = function ()
self.dropDownMenu = nil
end
end
function Outfitter.LDB:HideMenu()
if not self.dropDownMenu then
return
end
self.dropDownMenu:Hide()
self.dropDownMenu = nil
end
Outfitter.LDB:Initialize()