Skip to content

Instantly share code, notes, and snippets.

@kurapica
Last active July 10, 2021 14:29
Show Gist options
  • Save kurapica/d59577269b1e1086a478d62c273a32b3 to your computer and use it in GitHub Desktop.
Save kurapica/d59577269b1e1086a478d62c273a32b3 to your computer and use it in GitHub Desktop.
Simple SpellCooldownPanel For WOW with mover
Scorpio "SpellCooldown" ""
class "Scorpio.Widget.SpellCooldownPanel" (function(_ENV)
inherit "ElementPanel"
import "System.Reactive"
class "Icon" { Frame }
__Indexer__() __Observable__()
property "AuraIcon" { set = Toolset.fakefunc }
__Indexer__() __Observable__()
property "AuraCooldown" { set = Toolset.fakefunc }
function __ctor(self)
self.OnElementCreated = self.OnElementCreated + function(self, ele)
return ele:InstantApplyStyle()
end
end
end)
Style.UpdateSkin("Default", {
[SpellCooldownPanel] = {
elementType = SpellCooldownPanel.Icon,
elementWidth = 36,
elementHeight = 36,
rowCount = 3,
columnCount = 6,
movable = true,
location = { Anchor("TOP", 0, - 40) },
},
[SpellCooldownPanel.Icon] = {
IconTexture = {
setAllPoints = true,
file = Wow.FromPanelProperty("AuraIcon"),
},
CooldownLabel = {
font = FontType(STANDARD_TEXT_FONT, 24, "THICK", true),
cooldown = Wow.FromPanelProperty("AuraCooldown")
}
}
})
Panel = SpellCooldownPanel("SpellCooldownLinePanel")
Mover = Scorpio.Widget.Mover("Mover", Panel)
GUID = UnitGUID("player")
cooldownQueue = {}
cooldown = CooldownStatus()
function queueCooldown(id)
local start, duration = GetSpellCooldown(id)
if start and duration and duration > 1.5 and duration <= 3600 then
tinsert(cooldownQueue, id)
FireSystemEvent("SPELL_COOLDOWN_REFRESH")
end
end
__CombatEvent__ "SPELL_CAST_SUCCESS"
function SPELL_CAST_SUCCESS(_, _, _, sguid, _, _, _, _, _, _, _, id, name, school)
return sguid == GUID and Next(queueCooldown, id)
end
RunAsService(function ()
while true do
while cooldownQueue[1] do
Next()
local count = #cooldownQueue
local now = GetTime()
local index = 1
local iconidx = 1
local max = Panel.MaxCount
local minstop = now + 10000
while iconidx <= max and index <= count do
local id = cooldownQueue[index]
local start, duration = GetSpellCooldown(id)
local stop = start and duration and duration > 1.5 and (start + duration)
if stop and stop > now then
cooldown.start = start
cooldown.duration = duration
Panel.Elements[iconidx]:Show()
Panel.AuraIcon[iconidx] = GetSpellTexture(id)
Panel.AuraCooldown[iconidx] = cooldown
iconidx = iconidx + 1
if minstop > stop then minstop = stop end
else
cooldownQueue[index] = nil
end
index = index + 1
end
Panel.Count = iconidx - 1
for i = count, 1, - 1 do
if cooldownQueue[i] == nil then
tremove(cooldownQueue, i)
end
end
if cooldownQueue[1] then
Wait(minstop - now, "SPELL_COOLDOWN_REFRESH")
end
end
NextEvent("SPELL_COOLDOWN_REFRESH")
end
end, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment