diff --git a/scripts/frost/frost-gui.lua b/scripts/frost/frost-gui.lua new file mode 100644 index 0000000..793a8da --- /dev/null +++ b/scripts/frost/frost-gui.lua @@ -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 \ No newline at end of file diff --git a/scripts/frost.lua b/scripts/frost/frost.lua similarity index 89% rename from scripts/frost.lua rename to scripts/frost/frost.lua index 98e52f5..f9daebb 100644 --- a/scripts/frost.lua +++ b/scripts/frost/frost.lua @@ -19,22 +19,17 @@ local WintersChill = Bastion.SpellBook:GetSpell(228358) local FrostNova = Bastion.SpellBook:GetSpell(122) local IceNova = Bastion.SpellBook:GetSpell(157997) local IcyVeins = Bastion.SpellBook:GetSpell(12472) +local FrozenOrb = Bastion.SpellBook:GetSpell(84714) +local Blizzard = Bastion.SpellBook:GetSpell(190356) local RuneOfPower = Bastion.SpellBook:GetSpell(116011) -local CDsEnabled = false - -local Command = Bastion.Command:New('frost') - -Command:Register('cooldowns', 'Toggle Frost CDs', function() - CDsEnabled = not CDsEnabled - Bastion:Print('Frost Cooldowns ' .. (CDsEnabled and 'enabled' or 'disabled')) -end) - ---@type GetRangedTargetCount local GetRangedTargetCount = Tinkr:require("scripts/bastion/scripts/shared/get-ranged-target-count", Bastion) local EnableDrawROP = Tinkr:require("scripts/bastion/scripts/shared/draw-rop", Bastion) +---@type GetFrostOption +local GetFrostOption = Tinkr:require("scripts/bastion/scripts/frost/frost-gui", Bastion) ---@param unit Unit local function isUnitFrozen(unit) @@ -92,14 +87,10 @@ end) local function CombatRotation() local targetCount = GetRangedTargetCount(40) - if CDsEnabled and IcyVeins:IsKnownAndUsable() and not Player:IsCastingOrChanneling() then + if GetFrostOption("CdsEnabled") and IcyVeins:IsKnown() and not Player:IsCastingOrChanneling() then IcyVeins:Cast(Player) end - if CDsEnabled and not Player:IsMoving() then - - end - if IceLance:IsKnownAndUsable() and IceLanceTarget:Exists() then return IceLance:Cast(IceLanceTarget) end diff --git a/scripts/shared/draw-rop.lua b/scripts/shared/draw-rop.lua index d6183bb..7ab87ee 100644 --- a/scripts/shared/draw-rop.lua +++ b/scripts/shared/draw-rop.lua @@ -42,4 +42,4 @@ local function EnableDrawROP() end end -return EnableDrawROP() \ No newline at end of file +return EnableDrawROP \ No newline at end of file diff --git a/src/ToggleManager/ToggleManager.lua b/src/ToggleManager/ToggleManager.lua new file mode 100644 index 0000000..22cce04 --- /dev/null +++ b/src/ToggleManager/ToggleManager.lua @@ -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 + 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 diff --git a/src/_bastion.lua b/src/_bastion.lua index eba5608..9c4c05a 100644 --- a/src/_bastion.lua +++ b/src/_bastion.lua @@ -10,8 +10,8 @@ function Bastion.require(class) return Tinkr:require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) end - - +---@type ToggleManager +Bastion.ToggleManager = Bastion.require("ToggleManager") ---@type ClassMagic Bastion.ClassMagic = Bastion.require("ClassMagic") ---@type List @@ -128,6 +128,8 @@ Bastion.Ticker = C_Timer.NewTicker(0.1, function() end end + Bastion.ToggleManager:Refresh() + if Bastion.Enabled then Bastion.ObjectManager:Refresh() for i = 1, #Bastion.modules do @@ -254,7 +256,7 @@ if UnitClass('player') == 'Mage' then Tinkr:require("scripts/bastion/scripts/fire", Bastion) Eval('RunMacroText("/bastion module fire")', 'bastion') elseif GetSpecialization() == 3 then - Tinkr:require("scripts/bastion/scripts/frost", Bastion) + Tinkr:require("scripts/bastion/scripts/frost/frost", Bastion) Eval('RunMacroText("/bastion module frost")', 'bastion') end end