-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjButtonFlash.lua
More file actions
189 lines (150 loc) · 4.53 KB
/
jButtonFlash.lua
File metadata and controls
189 lines (150 loc) · 4.53 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
-- locals and speed
local AddonName, Addon = ...
local CreateFrame = CreateFrame
local hooksecurefunc = hooksecurefunc
local IsAddOnLoaded = IsAddOnLoaded
local GetActionButtonForID = GetActionButtonForID
local NUM_ACTIONBAR_BUTTONS = NUM_ACTIONBAR_BUTTONS
local TEXTURE_OFFSET = 3
local BARTENDER4_TOKEN = "Bartender4"
local BARTENDER4_NUM_MAX_BUTTONS = 180
local DOMINOS_TOKEN = "Dominos"
local DOMINOS_NUM_MAX_BUTTONS = 14 * NUM_ACTIONBAR_BUTTONS
local DOMINOS_PUSHED_STATE = "PUSHED"
-- main
function Addon:Load()
self.frame = CreateFrame("Frame", nil)
-- set OnEvent handler
self.frame:SetScript("OnEvent", function(_, ...)
self:OnEvent(...)
end)
self.frame:RegisterEvent("PLAYER_LOGIN")
end
-- frame events
function Addon:OnEvent(event, ...)
local action = self[event]
if (action) then
action(self, ...)
end
end
function Addon:PLAYER_LOGIN()
self:SetupButtonFlash()
self:HookActionEvents()
local bt4 = IsAddOnLoaded(BARTENDER4_TOKEN)
if (bt4) then
self:HookBartender4Buttons()
end
local dominos = IsAddOnLoaded(DOMINOS_TOKEN)
if (dominos) then
self:HookDominosButtons()
end
self.frame:UnregisterEvent("PLAYER_LOGIN")
end
function Addon:SetupButtonFlash()
local frame = CreateFrame("Frame", nil)
frame:SetFrameStrata("TOOLTIP")
local texture = frame:CreateTexture()
texture:SetTexture([[Interface\Cooldown\star4]])
texture:SetAlpha(0)
texture:SetAllPoints(frame)
texture:SetBlendMode("ADD")
texture:SetDrawLayer("OVERLAY", 7)
local animation = texture:CreateAnimationGroup()
local alpha = animation:CreateAnimation("Alpha")
alpha:SetFromAlpha(0)
alpha:SetToAlpha(1)
alpha:SetDuration(0)
alpha:SetOrder(1)
local scale1 = animation:CreateAnimation("Scale")
scale1:SetScale(1.5, 1.5)
scale1:SetDuration(0)
scale1:SetOrder(1)
local scale2 = animation:CreateAnimation("Scale")
scale2:SetScale(0, 0)
scale2:SetDuration(.3)
scale2:SetOrder(2)
local rotation = animation:CreateAnimation("Rotation")
rotation:SetDegrees(90)
rotation:SetDuration(.3)
rotation:SetOrder(2)
self.overlay = frame
self.animation = animation
end
-- hooks
-- regular action buttons
do
local function Button_ActionButtonDown(id)
Addon:ActionButtonDown(id)
end
local function Button_MultiActionButtonDown(bar, id)
Addon:MultiActionButtonDown(bar, id)
end
function Addon:HookActionEvents()
hooksecurefunc("ActionButtonDown", Button_ActionButtonDown)
hooksecurefunc("MultiActionButtonDown", Button_MultiActionButtonDown)
end
end
-- bartender4 support
do
local function Button_OnClick(button, _, down)
if (down) then
Addon:AnimateButton(button)
end
end
function Addon:HookBartender4Buttons()
for i = 1, BARTENDER4_NUM_MAX_BUTTONS do
local button = _G["BT4Button" .. i]
if (button) then
button:HookScript("OnClick", Button_OnClick)
end
end
end
end
-- dominos support
do
local function Button_OnClick(button, _, down)
if (down) then
Addon:AnimateButton(button)
end
end
local function Button_SetButtonStateBase(button, state)
if (DOMINOS_PUSHED_STATE == state) then
Addon:AnimateButton(button)
end
end
function Addon:HookDominosButtons()
for i = 1, DOMINOS_NUM_MAX_BUTTONS do
local button = _G["DominosActionButton" .. i]
if (button) then
-- dominos proxy action buttons
-- mirror the pushed state of the target button
hooksecurefunc(button, "SetButtonStateBase", Button_SetButtonStateBase)
-- button mouse clicks
button:HookScript("OnClick", Button_OnClick)
end
end
end
end
function Addon:ActionButtonDown(id)
local button = GetActionButtonForID(id)
if (button) then
self:AnimateButton(button)
end
end
function Addon:MultiActionButtonDown(bar, id)
local button = _G[bar .. "Button" .. id]
if (button) then
self:AnimateButton(button)
end
end
function Addon:AnimateButton(button)
if (not button:IsVisible()) then
return
end
self.overlay:SetPoint("TOPLEFT", button, "TOPLEFT", -TEXTURE_OFFSET, TEXTURE_OFFSET)
self.overlay:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", TEXTURE_OFFSET, -TEXTURE_OFFSET)
self.animation:Stop()
self.animation:Play()
end
-- begin
Addon:Load()