Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.

Commit 3e7165d

Browse files
committed
significantly cleanup cooldown code and finally fix EXTRABTN showing wrongly
1 parent 961426c commit 3e7165d

File tree

3 files changed

+35
-67
lines changed

3 files changed

+35
-67
lines changed

Objects/BUTTON.lua

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -141,30 +141,51 @@ function BUTTON:ChangeObject(object)
141141
return newObj, newEditor
142142
end
143143

144+
function BUTTON:CancelCooldownTimer(stopAnimation)
145+
--cleanup so on state changes the cooldowns don't persist
146+
if self:TimeLeft(self.iconframecooldown.cooldownTimer) ~= 0 then
147+
self:CancelTimer(self.iconframecooldown.cooldownUpdateTimer)
148+
end
149+
self.iconframecooldown.timer:SetText("")
150+
151+
if self.data.alpha then
152+
self:SetAlpha(self.data.alpha) --try to restore the original alpha
153+
else
154+
self:SetAlpha(1)
155+
end
156+
157+
self.iconframecooldown.showCountdownTimer = false
158+
self.iconframecooldown.showCountdownAlpha = false
159+
160+
--clear previous sweeping cooldown animations
161+
if stopAnimation then
162+
CooldownFrame_Clear(self.iconframecooldown) --clear the cooldown frame
163+
end
164+
end
165+
144166

145167
function BUTTON:SetCooldownTimer(start, duration, enable, showCountdownTimer, modrate, color1, color2, showCountdownAlpha, charges, maxCharges)
146168

147169
if not self.isShown then --if the button isn't shown, don't do set any cooldowns
170+
self:CancelCooldownTimer(true)
148171
return
149172
end
150173

151174
if start and start > 0 and duration > 0 and enable > 0 then
152175

153176
if duration > 2 then --sets non GCD cooldowns
154177
if charges and charges > 0 and maxCharges > 1 then
155-
CooldownFrame_Set(self.iconframechargecooldown, start, duration, enable, true, modrate) --set clock style cooldown animation. Show Draw Edge.
178+
self.iconframecooldown:SetDrawSwipe(false);
179+
CooldownFrame_Set(self.iconframecooldown, start, duration, enable, true, modrate) --set clock style cooldown animation. Show Draw Edge.
156180
else
181+
self.iconframecooldown:SetDrawSwipe(true);
157182
CooldownFrame_Set(self.iconframecooldown, start, duration, enable, true, modrate) --set clock style cooldown animation for ability cooldown. Show Draw Edge.
158183
end
159184
else --sets GCD cooldowns
185+
self.iconframecooldown:SetDrawSwipe(true);
160186
CooldownFrame_Set(self.iconframecooldown, start, duration, enable, false, modrate) --don't show the Draw Edge for the GCD
161187
end
162188

163-
-- Clear the charge cooldown frame if it is still going from a different ability in a different state (i.e. frenzied regen in the same spot as Swiftmend)
164-
if not charges or charges == maxCharges or maxCharges == 1 then --if ability does not support charges then clear the charge cooldown frame
165-
CooldownFrame_Clear(self.iconframechargecooldown)
166-
end
167-
168189
--this is only for abilities that have CD's >4 sec. Any less than that and we don't want to track the CD with text or alpha, just with the standard animation
169190
if (duration >= Neuron.TIMERLIMIT) then --if spells have a cooldown less than 4sec then don't show a full cooldown
170191

@@ -209,42 +230,12 @@ function BUTTON:SetCooldownTimer(start, duration, enable, showCountdownTimer, mo
209230
end
210231

211232
else
212-
--Cancel Timers as they're unnecessary
213-
self:CancelTimer(self.iconframecooldown.cooldownUpdateTimer)
214-
self.iconframecooldown.timer:SetText("")
215-
216-
if self.data.alpha then
217-
self:SetAlpha(self.data.alpha) --try to restore the original alpha
218-
else
219-
self:SetAlpha(1)
220-
end
221-
222-
self.iconframecooldown.showCountdownTimer = false
223-
self.iconframecooldown.showCountdownAlpha = false
233+
self:CancelCooldownTimer(false)
224234
end
225235
else
226-
--cleanup so on state changes the cooldowns don't persist
227-
self:CancelTimer(self.iconframecooldown.cooldownUpdateTimer)
228-
self.iconframecooldown.timer:SetText("")
229-
230-
if self.data.alpha then
231-
self:SetAlpha(self.data.alpha) --try to restore the original alpha
232-
else
233-
self:SetAlpha(1)
234-
end
235-
236-
self.iconframecooldown.showCountdownTimer = false
237-
self.iconframecooldown.showCountdownAlpha = false
238-
239-
--clear previous sweeping cooldown animations
240-
CooldownFrame_Clear(self.iconframecooldown) --clear the cooldown frame
241-
if not charges or charges == maxCharges or maxCharges == 1 then --if ability does not support charges then clear the charge cooldown frame
242-
CooldownFrame_Clear(self.iconframechargecooldown)
243-
end
236+
self:CancelCooldownTimer(true)
244237
end
245238

246-
--this is important for items like the ExtraActionButton who use Alpha to show and hide itself (to avoid in-combat restrictions). Without it the button would stay visible
247-
self:SetObjectVisibility()
248239
end
249240

250241

@@ -682,6 +673,7 @@ function BUTTON:UpdateCooldown()
682673
--this is super important for removing CD's from empty buttons, like when switching states. You don't want the CD from one state to show on a different state.
683674
self:SetCooldownTimer()
684675
end
676+
685677
end
686678

687679

Objects/EXTRABTN.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@ function EXTRABTN:SetType()
6666

6767
--action content gets set in UpdateButton
6868
self:UpdateButton()
69+
self:SetObjectVisibility()
6970

7071
self:SetScript("OnEnter", function(self, ...) self:OnEnter(...) end)
7172
self:SetScript("OnLeave", GameTooltip_Hide)
7273

73-
self:UpdateIcon()
74-
self:SetObjectVisibility()
74+
7575

7676
self:SetSkinned()
7777
end
7878

7979

8080
function EXTRABTN:OnEvent(event, ...)
8181

82-
self:SetObjectVisibility()
8382
self:UpdateButton()
83+
self:SetObjectVisibility()
8484

8585
if event == "PLAYER_ENTERING_WORLD" then
8686
self.binder:ApplyBindings()
@@ -122,9 +122,9 @@ function EXTRABTN:UpdateButton()
122122
end
123123

124124

125-
function EXTRABTN:SetObjectVisibility(show)
125+
function EXTRABTN:SetObjectVisibility()
126126

127-
if HasExtraActionBar() or show or Neuron.buttonEditMode or Neuron.barEditMode or Neuron.bindingMode then --set alpha instead of :Show or :Hide, to avoid taint and to allow the button to appear in combat
127+
if HasExtraActionBar() or Neuron.buttonEditMode or Neuron.barEditMode or Neuron.bindingMode then --set alpha instead of :Show or :Hide, to avoid taint and to allow the button to appear in combat
128128
self.isShown = true
129129
else
130130
self.isShown = false

XML/NeuronActionButtonTemplate.xml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,6 @@
158158
</OnLoad>
159159
</Scripts>
160160
</Cooldown>
161-
<Cooldown name="$parentChargeCooldown" inherits="CooldownFrameTemplate">
162-
<Anchors>
163-
<Anchor point="TOPLEFT"/>
164-
<Anchor point="BOTTOMRIGHT"/>
165-
</Anchors>
166-
<Layers>
167-
<Layer level="OVERLAY" textureSubLevel="3">
168-
<FontString name="$parentTimer" parentKey="timer" inherits="GameFontNormal">
169-
<Anchors>
170-
<Anchor point="CENTER">
171-
<Offset x="0.5" y="0"/>
172-
</Anchor>
173-
</Anchors>
174-
</FontString>
175-
</Layer>
176-
</Layers>
177-
<Scripts>
178-
<OnLoad>
179-
self:SetFrameLevel(3)
180-
self.button = self:GetParent():GetParent()
181-
self:SetDrawSwipe(false);
182-
</OnLoad>
183-
</Scripts>
184-
</Cooldown>
185161
</Frames>
186162
<Scripts>
187163
<OnLoad>

0 commit comments

Comments
 (0)