-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAutoBarClassPopupButton.lua
More file actions
161 lines (130 loc) · 4.9 KB
/
Copy pathAutoBarClassPopupButton.lua
File metadata and controls
161 lines (130 loc) · 4.9 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--
-- AutoBarClassPopupButton
-- Copyright 2007+ Toadkiller of Proudmoore.
--
-- Popup Buttons for AutoBar
-- Popup Buttons are contained by AutoBar.Class.Button
-- http://muffinmangames.com
--
--GLOBALS: InCombatLockdown, GameTooltip, CreateFrame, SecureHandlerWrapScript
local _, AB = ...
local AutoBar = AutoBar
local ABGData = AutoBarGlobalDataObject
local code = AB.code ---@class ABCode
local Class = AutoBar.Class.new_class
local L = AutoBarGlobalDataObject.locale
local Masque = LibStub("Masque", true)
local _G = _G
local _
-- Basic Button with textures, highlighting, keybindText, tooltips etc.
-- Bound to the underlying AutoBarButton which provides its state information, icon etc.
AutoBar.Class.PopupButton = Class(AutoBar.Class.BasicButton)
function AutoBar.Class.PopupButton:GetPopupButton(parentButton, popupButtonIndex, popupHeader, popupKeyHandler)
local popupButtonList = popupHeader.popupButtonList
if (popupButtonList[popupButtonIndex]) then
popupButtonList[popupButtonIndex]:Refresh(parentButton, popupButtonIndex, popupHeader)
else
popupButtonList[popupButtonIndex] = AutoBar.Class.PopupButton:new(parentButton, popupButtonIndex, popupHeader, popupKeyHandler)
end
return popupButtonList[popupButtonIndex]
end
function AutoBar.Class.PopupButton:init(parentButton, popupButtonIndex, popupHeader, popupKeyHandler)
AutoBar.Class.PopupButton.super.init(self)
self.parentBar = parentButton.parentBar
self.parentButton = parentButton
self.buttonDB = parentButton.buttonDB
self.buttonName = self.buttonDB.buttonKey
self.popupButtonIndex = popupButtonIndex
self.popupHeader = popupHeader
self.popupKeyHandler = popupKeyHandler
self:CreateButtonFrame()
self:Refresh(parentButton, popupButtonIndex, popupHeader)
end
function AutoBar.Class.PopupButton:Refresh(parentButton, popupButtonIndex, popupHeader)
end
local function funcOnEnter(self)
local noTooltip = not (AutoBarDB2.settings.show_tooltip and self.needsTooltip or AutoBar.moveButtonsMode)
noTooltip = noTooltip or (InCombatLockdown() and not AutoBarDB2.settings.show_tooltip_in_combat)
if (noTooltip) then
self.UpdateTooltip = nil
GameTooltip:Hide()
else
AutoBar.Class.BasicButton.TooltipShow(self)
end
-- self.popupHeader:Show()
end
local function funcOnLeave(self)
GameTooltip:Hide()
end
-- Return the name of the global frame for the button. Keybinds are made to it.
function AutoBar.Class.PopupButton:GetButtonFrameName(popupButtonIndex)
return self.parentButton:GetButtonFrameName() .. "Popup" .. popupButtonIndex
end
function AutoBar.Class.PopupButton:CreateButtonFrame()
local popupButtonIndex = self.popupButtonIndex
local popupHeader = self.popupHeader
local popupKeyHandler = self.popupKeyHandler
local popupButtonName = self:GetButtonFrameName(popupButtonIndex)
local frame = CreateFrame("Button", popupButtonName, popupKeyHandler or popupHeader, "ActionButtonTemplate SecureActionButtonTemplate SecureHandlerBaseTemplate")
self.frame = frame
frame.class = self
frame:SetMouseClickEnabled()
code.RegisterForClicks(frame)
frame:SetFrameRef("popupHeader", popupHeader)
frame.popupHeader = popupHeader
frame:SetScript("OnEnter", funcOnEnter)
frame:SetScript("OnLeave", funcOnLeave)
SecureHandlerWrapScript(frame, "OnEnter", frame, [[ self:GetFrameRef("popupHeader"):Show() ]])
SecureHandlerWrapScript(frame, "OnLeave", frame, [[ self:GetFrameRef("popupHeader"):Hide() ]])
frame:ClearAllPoints()
frame:SetWidth(ABGData.default_button_width)
frame:SetHeight(ABGData.default_button_height)
--- frame:SetScript("PostClick", self.PostClick)
frame.icon = _G[("%sIcon"):format(popupButtonName)]
frame.cooldown = _G[("%sCooldown"):format(popupButtonName)]
frame.macroName = _G[("%sName"):format(popupButtonName)]
frame.hotKey = _G[("%sHotKey"):format(popupButtonName)]
frame.count = _G[("%sCount"):format(popupButtonName)]
frame.flash = _G[("%sFlash"):format(popupButtonName)]
if (Masque) then
local group = self.parentBar.frame.MasqueGroup
frame.MasqueButtonData = {
Border = frame.border,
Cooldown = frame.cooldown,
Count = frame.count,
Flash = frame.flash,
HotKey = frame.hotKey,
Icon = frame.icon,
Name = frame.macroName,
}
group:AddButton(frame, frame.MasqueButtonData)
end
frame.border = _G[("%sBorder"):format(popupButtonName)]
if frame.Arrow then
frame.Arrow:Hide()
end
end
function AutoBar.Class.PopupButton:UpdateIcon()
local frame = self.frame
local texture, borderColor = self:GetIconTexture(frame)
frame:SetAttribute("icon", texture)
if (texture) then
frame.icon:SetTexture(texture)
frame.icon:Show()
frame.tex = texture
else
frame.icon:Hide()
frame.cooldown:Hide()
frame.hotKey:SetVertexColor(0.6, 0.6, 0.6)
frame.tex = nil
end
if (borderColor) then
frame.border:SetVertexColor(borderColor.r, borderColor.g, borderColor.b, borderColor.a)
frame.border:Show()
else
frame.border:Hide()
end
end
function AutoBar.Class.PopupButton:IsActive()
return self.frame:GetAttribute("type")
end