forked from Bastion/Bastion
parent
3b2a60e0f6
commit
0c92f0a236
@ -0,0 +1,55 @@ |
||||
local |
||||
Tinkr, |
||||
---@type Bastion |
||||
Bastion = ... |
||||
|
||||
local IcyVeins = Bastion.SpellBook:GetSpell(12472) |
||||
local FrozenOrb = Bastion.SpellBook:GetSpell(84714) |
||||
local Blizzard = Bastion.SpellBook:GetSpell(190356) |
||||
|
||||
local FrostOptions = { |
||||
CdsEnabled = false, |
||||
FrozenOrbEnabled = false, |
||||
AutoAOE = true |
||||
} |
||||
|
||||
Bastion.ToggleManager:Add({ |
||||
id = 'Frost_CdsEnabled', |
||||
icon = IcyVeins:GetIcon(), |
||||
state = FrostOptions.CdsEnabled |
||||
}) |
||||
|
||||
Bastion.ToggleManager:Add({ |
||||
id = 'Frost_FrozenOrbEnabled', |
||||
icon = FrozenOrb:GetIcon(), |
||||
state = FrostOptions.FrozenOrbEnabled |
||||
}) |
||||
|
||||
Bastion.ToggleManager:Add({ |
||||
id = 'Frost_AutoAOE', |
||||
icon = Blizzard:GetIcon(), |
||||
state = FrostOptions.AutoAOE |
||||
}) |
||||
|
||||
---@alias GetFrostOption fun(option: "CdsEnabled" | "FrozenOrbEnabled" | 'AutoAOE'): boolean |
||||
|
||||
---@type GetFrostOption |
||||
local function GetFrostOption(option) |
||||
return FrostOptions[option] |
||||
end |
||||
|
||||
local Command = Bastion.Command:New('frost') |
||||
|
||||
Command:Register('aoe', 'Toggle bastion on/off', function() |
||||
Bastion.ToggleManager:Toggle("Frost_AutoAOE") |
||||
end) |
||||
|
||||
Command:Register('cds', 'Toggle bastion on/off', function() |
||||
Bastion.ToggleManager:Toggle("Frost_CdsEnabled") |
||||
end) |
||||
|
||||
Command:Register('orb', 'Toggle bastion on/off', function() |
||||
Bastion.ToggleManager:Toggle("Frost_FrozenOrbEnabled") |
||||
end) |
||||
|
||||
return GetFrostOption |
@ -0,0 +1,89 @@ |
||||
local |
||||
Tinkr, |
||||
---@type Bastion |
||||
Bastion = ... |
||||
|
||||
---@alias Toggle { x: number, icon: number, state: boolean, id: string, texture?: Texture } |
||||
|
||||
local BUTTON_SIZE = 54 |
||||
|
||||
---@class ToggleManager |
||||
local ToggleManager = { |
||||
---@type table<string, Toggle> |
||||
toggles = {} |
||||
} |
||||
|
||||
---@return number |
||||
function ToggleManager:NumActiveToggles() |
||||
local count = 0 |
||||
|
||||
for i, toggle in pairs(self.toggles) do |
||||
count = count + 1 |
||||
end |
||||
|
||||
return count |
||||
end |
||||
|
||||
---@param newToggle { icon: number, state: boolean, id: string } |
||||
function ToggleManager:Add(newToggle) |
||||
if self.toggles[newToggle.id] then |
||||
self.toggles[newToggle.id].icon = newToggle.icon |
||||
self.toggles[newToggle.id].state = newToggle.state |
||||
else |
||||
local highestX = nil |
||||
|
||||
for i, toggle in pairs(self.toggles) do |
||||
if highestX == nil or toggle.x > highestX then |
||||
highestX = toggle.x |
||||
end |
||||
end |
||||
|
||||
if highestX == nil then |
||||
highestX = 2 |
||||
else |
||||
highestX = highestX + BUTTON_SIZE |
||||
end |
||||
|
||||
self.toggles[newToggle.id] = { |
||||
x = highestX, |
||||
state = newToggle.state, |
||||
icon = newToggle.icon, |
||||
id = newToggle.id |
||||
} |
||||
end |
||||
end |
||||
|
||||
function ToggleManager:Refresh() |
||||
for i, toggle in pairs(self.toggles) do |
||||
if not toggle.texture then |
||||
local frame = CreateFrame("Frame", nil, UIParent) |
||||
frame:SetSize(BUTTON_SIZE, BUTTON_SIZE) |
||||
frame:SetPoint("BOTTOMLEFT", toggle.x, 230) |
||||
|
||||
local Texture = frame:CreateTexture() |
||||
Texture:SetAllPoints(frame) |
||||
Texture:SetTexture(toggle.icon) |
||||
if not toggle.state then |
||||
Texture:SetDesaturated(true) |
||||
end |
||||
self.toggles[toggle.id].texture = Texture |
||||
else |
||||
local desaturation = toggle.texture:GetDesaturation() |
||||
|
||||
if not toggle.state and desaturation == 0 then |
||||
toggle.texture:SetDesaturated(true) |
||||
elseif toggle.state and desaturation == 1 then |
||||
toggle.texture:SetDesaturated(false) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
---@param id string |
||||
function ToggleManager:Toggle(id) |
||||
if self.toggles[id] then |
||||
self.toggles[id].state = not self.toggles[id].state |
||||
end |
||||
end |
||||
|
||||
return ToggleManager |
Loading…
Reference in new issue