-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLibDropDownMenuTemplates.lua
133 lines (102 loc) · 3.89 KB
/
LibDropDownMenuTemplates.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
local CreateFromMixins,_G,select = CreateFromMixins,_G,select
local ExecuteFrameScript,PlaySound,SOUNDKIT = ExecuteFrameScript,PlaySound,SOUNDKIT;
setfenv(1,LibStub("LibDropDownMenu"));
-- start of content from UIDropDownMenuTemplates.lua
-- Custom dropdown buttons are instantiated by some external system.
-- When calling UIDropDownMenu_AddButton that system sets info.customFrame to the instance of the frame it wants to place on the menu.
-- The dropdown menu creates its button for the entry as it normally would, but hides all elements. The custom frame is then anchored
-- to that button and assumes responsibility for all relevant dropdown menu operations.
-- The hidden button will request a size that it should become from the custom frame.
DropDownMenuButtonMixin = {}
function DropDownMenuButtonMixin:OnEnter(...)
ExecuteFrameScript(self:GetParent(), "OnEnter", ...);
end
function DropDownMenuButtonMixin:OnLeave(...)
ExecuteFrameScript(self:GetParent(), "OnLeave", ...);
end
function DropDownMenuButtonMixin:OnMouseDown(button)
if self:IsEnabled() then
ToggleDropDownMenu(nil, nil, self:GetParent());
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
end
end
LargeDropDownMenuButtonMixin = CreateFromMixins(DropDownMenuButtonMixin);
function LargeDropDownMenuButtonMixin:OnMouseDown(button)
if self:IsEnabled() then
local parent = self:GetParent();
ToggleDropDownMenu(nil, nil, parent, parent, -8, 8);
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
end
end
DropDownExpandArrowMixin = {};
function DropDownExpandArrowMixin:OnEnter()
local level = self:GetParent():GetParent():GetID() + 1;
CloseDropDownMenus(level);
if self:IsEnabled() then
local listFrame = _G["LibDropDownMenu_List"..level];
if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint(1)) ~= self ) then
ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self, nil, self:GetParent().menuListDisplayMode);
end
end
end
function DropDownExpandArrowMixin:OnMouseDown(button)
if self:IsEnabled() then
ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self, nil, self:GetParent().menuListDisplayMode);
end
end
UIDropDownCustomMenuEntryMixin = {};
function UIDropDownCustomMenuEntryMixin:OnEnter()
UIDropDownMenu_StopCounting(self:GetOwningDropdown());
end
function UIDropDownCustomMenuEntryMixin:OnLeave()
UIDropDownMenu_StartCounting(self:GetOwningDropdown());
end
function UIDropDownCustomMenuEntryMixin:GetPreferredEntryWidth()
return self:GetWidth();
end
function UIDropDownCustomMenuEntryMixin:GetPreferredEntryHeight()
return self:GetHeight();
end
function UIDropDownCustomMenuEntryMixin:OnSetOwningButton()
-- for derived objects to implement
end
function UIDropDownCustomMenuEntryMixin:SetOwningButton(button)
self:SetParent(button:GetParent());
self.owningButton = button;
self:OnSetOwningButton();
end
function UIDropDownCustomMenuEntryMixin:GetOwningDropdown()
return self.owningButton:GetParent();
end
function UIDropDownCustomMenuEntryMixin:SetContextData(contextData)
self.contextData = contextData;
end
function UIDropDownCustomMenuEntryMixin:GetContextData()
return self.contextData;
end
ColorSwatchMixin = {}
function ColorSwatchMixin:SetColor(color)
self.Color:SetVertexColor(color:GetRGB());
end
-- copied from SharedXML/NewFeatureLabel.lua; not present in classic
NewFeatureLabelMixin = {};
function NewFeatureLabelMixin:OnLoad()
self.BGLabel:SetText(self.label);
self.Label:SetText(self.label);
self.Label:SetJustifyH(self.justifyH);
self.BGLabel:SetJustifyH(self.justifyH);
end
function NewFeatureLabelMixin:ClearAlert()
-- derive
self:SetShown(false);
end
function NewFeatureLabelMixin:OnShow()
if self.animateGlow then
self.Fade:Play();
end
end
function NewFeatureLabelMixin:OnHide()
if self.animateGlow then
self.Fade:Stop();
end
end