From 8d904ad02dc596c302e1c02ca2ff25fce2f04c26 Mon Sep 17 00:00:00 2001 From: MDGitHubRepo Date: Sat, 14 Dec 2024 14:04:16 -0500 Subject: [PATCH] Updated pending totem logic Pending totem logic was only storing the latest pending totem. Refactored it to have a pending totem for each element type so that they do not overwrite when using throwset. --- COE_TotemData.lua | 6 + COE_TotemLogic.lua | 222 ++++- COE_TotemVisual.lua | 2214 +++++++++++++++++++++---------------------- CallOfElements.lua | 20 +- Localization.lua | 4 +- 5 files changed, 1305 insertions(+), 1161 deletions(-) diff --git a/COE_TotemData.lua b/COE_TotemData.lua index 9b55c11..5710623 100644 --- a/COE_TotemData.lua +++ b/COE_TotemData.lua @@ -47,6 +47,12 @@ COE.TotemsAvailable["Air"] = 0; -------------------------------------------------------------------]] COE["ActiveTotems"] = {Earth = nil, Fire = nil, Water = nil, Air = nil}; COE["TotemPending"] = {Totem = nil, UseRank = 0, Timeout = 0.75}; +COE["PendingTotems"] = { + Earth = {Totem = nil, Rank = 0, TimeoutStartMS = 0}, + Fire = {Totem = nil, Rank = 0, TimeoutStartMS = 0}, + Water = {Totem = nil, Rank = 0, TimeoutStartMS = 0}, + Air = {Totem = nil, Rank = 0, TimeoutStartMS = 0} +}; --[[ ---------------------------------------------------------------- COE.CleansingTotems stores pointers to the buttons and totems diff --git a/COE_TotemLogic.lua b/COE_TotemLogic.lua index 0573101..7d784d5 100644 --- a/COE_TotemLogic.lua +++ b/COE_TotemLogic.lua @@ -49,7 +49,8 @@ end PURPOSE: Throws the totem with the specified named id -------------------------------------------------------------------]] function COE_Totem:ThrowTotem(element, id) - + COE:DebugMessage( + "COE_Totem:ThrowTotem element and id: " .. element .. " " .. id); if (not COE.Initialized) then return; end -- get associated button @@ -57,6 +58,7 @@ function COE_Totem:ThrowTotem(element, id) local button = getglobal("COETotem" .. element .. id); if (button == nil) then COE:Message("Invalid Totem"); + return; end @@ -538,6 +540,7 @@ end yet thrown -------------------------------------------------------------------]] function COE_Totem:ThrowSet() + COE:DebugMessage("Method Executing: ThrowSet"); if (COE_Config:GetSaved(COEOPT_ENABLESETS) == 1) then @@ -545,14 +548,19 @@ function COE_Totem:ThrowSet() -- check which totem to throw -- ======================================================================= local activeset = COE_Config:GetSaved(COEOPT_ACTIVESET); + COE:DebugMessage("ThrowSet activeset value: " .. activeset); - local k; for k = 1, 4 do + COE:DebugMessage("ThrowSet k value: " .. k); local element = COE:LocalizedElement( COE.TotemSets[activeset].CastOrder[k]); + COE:DebugMessage("ThrowSet element value: " .. element); + local totem = COE.TotemSets[activeset][element]; + COE:DebugMessage("ThrowSet COE.SetCycle[element] value: " .. + tostring(COE.SetCycle[element])); if (COE.SetCycle[element] == false and totem) then if (totem.isTrinket) then @@ -570,15 +578,24 @@ function COE_Totem:ThrowSet() end else + + COE:DebugMessage("ThrowSet casting totem: " .. element); -- first check if the totem is already usable -- ------------------------------------------- local start, duration = GetSpellCooldown( totem.Ranks[totem.MaxRank] .SpellID, BOOKTYPE_SPELL); + COE:DebugMessage("ThrowSet spell cooldown duration: " .. + duration); if (start == 0 and duration == 0) then + + COE:DebugMessage( + "ThrowSet casting spell: " .. + COE.TotemSets[activeset][element].SpellName); CastSpellByName(COE.TotemSets[activeset][element] .SpellName); + -- COE_Totem:SetPendingTotem(totem, totem.MaxRank); return; end end @@ -611,29 +628,38 @@ end PURPOSE: Sets up or clears a pending totem The pending totem's timer is activated on the next successful SPELLCAST_STOP or removed if it times out first + + PURPOSE: Sets up or clears a pending totem. The pending totem's + timer is activated when the spell is identified as cast. If + the spell is not identified as cast within 1 seconds, then + the pending status is removed. -------------------------------------------------------------------]] function COE_Totem:SetPendingTotem(totem, rank) + COE:DebugMessage("Method Executing: SetPendingTotem"); if (totem) then - COE:DebugMessage("Setting pending totem: " .. totem.SpellName .. - " with rank: " .. rank); - COE.TotemPending.Totem = totem; - COE.TotemPending.UseRank = rank; - -- get the current lag + -- Set PendingTotems for the given totem element type + COE:DebugMessage("SetPendingTotem PendingTotems being set: " .. + totem.SpellName .. " with rank: " .. rank); + COE.PendingTotems[totem.Element].Totem = totem; + COE.PendingTotems[totem.Element].Rank = rank; + -- COE.PendingTotems[totem.Element].TimeoutStartMS = GetTime(); + + -- get the current lag - Not used but saving if needed -- -------------------- - local _, _, lag = GetNetStats(); - local timeout = lag / 1000 + COE.TotemPending.Timeout; + -- local _, _, lag = GetNetStats(); + -- local timeout = lag / 1000 + COE.TotemPending.Timeout; + local timeoutSec = 1; -- use lag + 0.5 seconds as pending timeout -- ----------------------------------------- - COE:DebugMessage("Setting pending timeout to: " .. timeout .. " msec"); + COE:DebugMessage("SetPendingTotem Setting pending timeout to: " .. + timeoutSec .. " seconds"); + + Chronos.scheduleByName("COE_Pending", timeoutSec, + COESched_CheckPendingTotem, totem.Element); - Chronos.scheduleByName("COE_Pending", timeout, - COESched_CheckPendingTotem); - else - COE.TotemPending.Totem = nil; - COE.TotemPending.UseRank = 0; end end @@ -642,20 +668,160 @@ end METHOD: COESched_CheckPendingTotem PURPOSE: Clears the pending totem if it is still active --------------------------------------------------------------------]] -function COESched_CheckPendingTotem() - -- if there is still a pending totem it has timed out - -- --------------------------------------------------- - if (COE.TotemPending.Totem) then - COE:DebugMessage("Pending totem has timed out: " .. - COE.TotemPending.Totem.SpellName); - COE_Totem:SetPendingTotem(nil); + PURPOSE: Clears the pending totem if it is still pending. +-------------------------------------------------------------------]] +function COESched_CheckPendingTotem(element) + COE:DebugMessage("Executing Method: COESched_CheckPendingTotem"); + + if (element) then + COE:DebugMessage("COESched_CheckPendingTotem for element: " .. element); + + COE_Totem:ClearPendingTotem(COE.PendingTotems[element]); end end --[[ ---------------------------------------------------------------- + METHOD: ClearPendingTotem + + PURPOSE: Clears the pending totem. +-------------------------------------------------------------------]] +function COE_Totem:ClearPendingTotem(pendingTotem) + COE:DebugMessage("Executing Method: ClearPendingTotem"); + + if (pendingTotem) then + pendingTotem.Totem = nil; + pendingTotem.Rank = nil; + end +end + +--[[ ---------------------------------------------------------------- + METHOD: COE_Totem:GetTotemFromText + + PURPOSE: Identifies a totem from the text value passed in. Can + return a nil totem. +-------------------------------------------------------------------]] +function COE_Totem:GetTotemFromText(text) + local totem; + COE:DebugMessage("GetTotemFromText for text value: " .. text); + + -- find the totem + for k = 1, COE.TotemCount do + if (string.find(text, COE.TotemData[k].SpellName)) then + -- use existing totem object + -- -------------------------- + totem = COE.TotemData[k]; + + COE:DebugMessage("GetTotemFromText found totem: " .. totem.SpellName); + break + end + end + + return totem; + +end + +--[[ ---------------------------------------------------------------- + METHOD: COE_Totem:ActivateTotem + + PURPOSE: Activates the totem timer and deactivates a + still active timer of the same element +-------------------------------------------------------------------]] +function COE_Totem:ActivateTotem(totem) + COE:DebugMessage("Method Executing: ActivateTotem with totem parameter " .. + totem.SpellName); + + local pendingTotemObj = COE.PendingTotems[totem.Element]; + + if (pendingTotemObj and pendingTotemObj.Totem) then + COE:DebugMessage("ActivateTotem identified pending totem : " .. + pendingTotemObj.Totem.SpellName); + + -- deactivate still active totem of the same element + -- -------------------------------------------------- + local active = COE.ActiveTotems[totem.Element]; + if (active) then COE_Totem:DeactivateTimer(active); end + + local pendingTotem = pendingTotemObj.Totem; + local pendingTotemRank = pendingTotemObj.Rank; + + -- activate timer + -- --------------- + Chronos.startTimer("COE" .. totem.SpellName); + totem.CurDuration = pendingTotem.Ranks[pendingTotemRank].Duration; + totem.CurHealth = pendingTotem.Ranks[pendingTotemRank].Health; + + -- activate cooldown timer if this totem has a cooldown + -- ----------------------------------------------------- + if (pendingTotem.Ranks[pendingTotemRank].Cooldown > 0) then + totem.CurCooldown = pendingTotem.Ranks[pendingTotemRank].Cooldown; + Chronos.startTimer("COECooldown" .. totem.SpellName); + Chronos.scheduleByName("COECooldownSwitch" .. totem.SpellName, + totem.CurCooldown, COESched_CooldownEnd, + totem); + end + + -- activate warning timers + -- ------------------------ + if (totem.CurDuration >= 10) then + Chronos.scheduleByName("COEWarn10" .. totem.SpellName, + totem.CurDuration - 10, + COESched_ExpirationWarning, 10, totem); + end + Chronos.scheduleByName("COEWarn5" .. totem.SpellName, + totem.CurDuration - 5, + COESched_ExpirationWarning, 5, totem); + Chronos.scheduleByName("COEWarn0" .. totem.SpellName, totem.CurDuration, + COESched_ExpirationWarning, 0, totem); + + -- mark totem as active + -- --------------------- + COE.ActiveTotems[pendingTotem.Element] = totem; + totem.isActive = true; + + -- set totem in timer frame + -- ------------------------- + if (COE_Config:GetSaved(COEOPT_TIMERFRAME) == 1) then + getglobal("COETimer" .. pendingTotem.Element).totem = totem; + COETimerFrame:Show(); + end + + -- mark totem as thrown if in current set + -- --------------------------------------- + local activeset = COE_Config:GetSaved(COEOPT_ACTIVESET); + + if (COE.TotemSets[activeset][totem.Element] and + COE.TotemSets[activeset][totem.Element].SpellName == totem.SpellName) then + + COE:DebugMessage("ActivateTotem Element " .. totem.Element .. + " in current cycle: SET"); + COE.SetCycle[totem.Element] = true; + end + + -- clear pending totem + -- -------------------- + COE_Totem:ClearPendingTotem(pendingTotemObj); + + -- if in timers only mode, reconfigure the totem bar + -- -------------------------------------------------- + if (COE_Config:GetSaved(COEOPT_DISPLAYMODE) == COEMODE_TIMERSONLY) then + COE_Totem:Invalidate(getglobal("COE" .. totem.Element .. "Frame"), + true, true, true); + COETotemFrame.Reconfigure = true; + else + -- otherwise just invalidate the dynamic buttons + -- ---------------------------------------------- + COE_Totem:Invalidate(getglobal("COE" .. totem.Element .. "Frame"), + false, false, true); + end + + end + +end + +--[[ ---------------------------------------------------------------- + DEPRECATED: Use ActivateTotem METHOD: COE_Totem:ActivatePendingTotem PURPOSE: Activates the pending totem timer and deactivates a @@ -669,7 +835,7 @@ function COE_Totem:ActivatePendingTotem(totem) -- deactivate still active totem of the same element -- -------------------------------------------------- COE:DebugMessage( - "Method Executing: ActivatePendingTotem - identifying active totems of type" .. + "ActivatePendingTotem - identifying active totems of type" .. COE.TotemPending.Totem.Element); local active = COE.ActiveTotems[COE.TotemPending.Totem.Element]; if (active) then COE_Totem:DeactivateTimer(active); end @@ -783,7 +949,7 @@ function COE_Totem:DeactivateTimer(totem) if (COE.TotemSets[activeset][totem.Element] and COE.TotemSets[activeset][totem.Element].SpellName == totem.SpellName) then - COE:DebugMessage("Element " .. totem.Element .. + COE:DebugMessage("DeactivateTimer Element " .. totem.Element .. " in current cycle: UNSET"); COE.SetCycle[totem.Element] = false; end @@ -975,6 +1141,7 @@ end original function afterwards -------------------------------------------------------------------]] function COE_Totem:SetupTimerHooks() + COE:DebugMessage("Method Executing: SetupTimerHooks"); COE_Totem.TimerHooks["UseAction"] = UseAction; UseAction = function(id, book, onself) @@ -1009,7 +1176,7 @@ end a totem -------------------------------------------------------------------]] function COE_Totem:HookUseAction(id, book) - + COE:DebugMessage("Method Executing: HookUseAction"); -- use only when timers are enabled -- --------------------------------- if (COE_Config:GetSaved(COEOPT_ENABLETIMERS) == 0) then return; end @@ -1074,6 +1241,7 @@ end a totem -------------------------------------------------------------------]] function COE_Totem:HookCastSpell(id, book) + COE:DebugMessage("Method Executing: HookCastSpell"); -- use only when timers are enabled -- --------------------------------- @@ -1107,6 +1275,7 @@ end a totem -------------------------------------------------------------------]] function COE_Totem:HookCastSpellByName(SpellName) + COE:DebugMessage("Method Executing: HookCastSpellByName"); -- use only when timers are enabled -- --------------------------------- @@ -1149,6 +1318,7 @@ end a totem -------------------------------------------------------------------]] function COE_Totem:HookUseInventoryItem(slotid) + COE:DebugMessage("Method Executing: HookUseInventoryItem"); -- use only when timers are enabled -- --------------------------------- diff --git a/COE_TotemVisual.lua b/COE_TotemVisual.lua index 8461098..216adb1 100644 --- a/COE_TotemVisual.lua +++ b/COE_TotemVisual.lua @@ -8,20 +8,20 @@ Totem Module / Visual -]] - -if( not COE_Totem ) then - COE_Totem = {}; -end +]] if (not COE_Totem) then COE_Totem = {}; end COEUI_BUTTONGAP = 4; COE_Totem.FlexTime = 0.3; -COEFramePositions = { Earth = { x = 0, y = 0 }, Fire = { x = 0, y = 0 }, - Water = { x = 0, y = 0 }, Air = { x = 0, y = 0 } } +COEFramePositions = { + Earth = {x = 0, y = 0}, + Fire = {x = 0, y = 0}, + Water = {x = 0, y = 0}, + Air = {x = 0, y = 0} +} -COEDynamic = { n = 7, nil, nil, nil, nil, nil, nil, nil }; +COEDynamic = {n = 7, nil, nil, nil, nil, nil, nil, nil}; --[[ ============================================================================================= @@ -44,105 +44,98 @@ COEDynamic = { n = 7, nil, nil, nil, nil, nil, nil, nil }; PURPOSE: Initializes the totem module and registers events -------------------------------------------------------------------]] function COE_Totem:InitMainFrame() - -- addon loaded? - -- -------------- - if( not COE.Initialized ) then - return; - end + -- addon loaded? + -- -------------- + if (not COE.Initialized) then return; end - -- init frame properties - -- ---------------------- - this.AdvisorTime = 0; - this.Reconfigure = true; + -- init frame properties + -- ---------------------- + this.AdvisorTime = 0; + this.Reconfigure = true; - -- setup timer hooks - -- ------------------ - COE_Totem:SetupTimerHooks(); + -- setup timer hooks + -- ------------------ + COE_Totem:SetupTimerHooks(); - -- register events - -- ---------------- - this:RegisterEvent( "PLAYER_ENTERING_WORLD" ); - this:RegisterEvent( "LEARNED_SPELL_IN_TAB" ); - this:RegisterEvent( "PLAYER_TARGET_CHANGED" ); - this:RegisterEvent( "PLAYER_DEAD" ); + -- register events + -- ---------------- + this:RegisterEvent("PLAYER_ENTERING_WORLD"); + this:RegisterEvent("LEARNED_SPELL_IN_TAB"); + this:RegisterEvent("PLAYER_TARGET_CHANGED"); + this:RegisterEvent("PLAYER_DEAD"); - this:RegisterEvent( "CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS" ); - this:RegisterEvent( "CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS" ); - this:RegisterEvent( "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE" ); - this:RegisterEvent( "CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE" ); + this:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS"); + this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS"); + this:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE"); + this:RegisterEvent("CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE"); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:OnMainFrameEvent PURPOSE: Handles UI events -------------------------------------------------------------------]] -function COE_Totem:OnMainFrameEvent( event ) +function COE_Totem:OnMainFrameEvent(event) - if( event == "PLAYER_ENTERING_WORLD" ) then - -- fix saved variables - -- -------------------- - COE:Fix_DisplayedTotems(); + if (event == "PLAYER_ENTERING_WORLD") then + -- fix saved variables + -- -------------------- + COE:Fix_DisplayedTotems(); - -- scan for available totems. do this here instead of inside COE:Init - -- because spells cannot be retrieved there yet - -- ------------------------------------------------------------------- - COE_Totem:Rescan(); + -- scan for available totems. do this here instead of inside COE:Init + -- because spells cannot be retrieved there yet + -- ------------------------------------------------------------------- + COE_Totem:Rescan(); - -- start advisor schedule - -- ----------------------- - if( COE_Config:GetSaved( COEOPT_ADVISOR ) == 1 ) then - Chronos.scheduleByName( "COEAdvise", COE.AdvisorInterval, COESched_RunAdvisor ); - end + -- start advisor schedule + -- ----------------------- + if (COE_Config:GetSaved(COEOPT_ADVISOR) == 1) then + Chronos.scheduleByName("COEAdvise", COE.AdvisorInterval, + COESched_RunAdvisor); + end - -- get current element frame coordinates - -- -------------------------------------- - COE_Totem:UpdateFrameCoordinates(); + -- get current element frame coordinates + -- -------------------------------------- + COE_Totem:UpdateFrameCoordinates(); - elseif( event == "LEARNED_SPELL_IN_TAB" ) then - -- learned a new spell. rescan totems - -- ----------------------------------- - COE_Totem:Rescan(); + elseif (event == "LEARNED_SPELL_IN_TAB") then + -- learned a new spell. rescan totems + -- ----------------------------------- + COE_Totem:Rescan(); - elseif( event == "PLAYER_TARGET_CHANGED" ) then + elseif (event == "PLAYER_TARGET_CHANGED") then - if( COE_Config:GetSaved( COEOPT_ENABLETOTEMBAR ) == 0 ) then - return; - end + if (COE_Config:GetSaved(COEOPT_ENABLETOTEMBAR) == 0) then return; end - -- Switch to named set if appropriate - -- ----------------------------------- - if( not COE_Totem:SwitchNamedSet() ) then - -- Switch to class set if appropriate - -- ----------------------------------- - COE_Totem:SwitchPVPSet(); - end + -- Switch to named set if appropriate + -- ----------------------------------- + if (not COE_Totem:SwitchNamedSet()) then + -- Switch to class set if appropriate + -- ----------------------------------- + COE_Totem:SwitchPVPSet(); + end - elseif( event == "PLAYER_DEAD" ) then + elseif (event == "PLAYER_DEAD") then - -- reset all timers upon death - -- ---------------------------- - COE_Totem:ResetTimers(); + -- reset all timers upon death + -- ---------------------------- + COE_Totem:ResetTimers(); - elseif ( event == "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE" or - event == "CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS" or - event == "CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE" or - event == "CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS" ) then + elseif (event == "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE" or event == + "CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS" or event == + "CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE" or event == + "CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS") then - if( COE_Config:GetSaved( COEOPT_ENABLETOTEMBAR ) == 0 ) then - return; - end + if (COE_Config:GetSaved(COEOPT_ENABLETOTEMBAR) == 0) then return; end - -- Assign totem damage - -- -------------------- - COE_Totem:TotemDamage(); - end + -- Assign totem damage + -- -------------------- + COE_Totem:TotemDamage(); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:ConfigureTotemButtons @@ -151,141 +144,140 @@ end -------------------------------------------------------------------]] function COE_Totem:ConfigureTotemButtons() - -- reconfiguration necessary? - -- --------------------------- - if( not COETotemFrame.Reconfigure ) then - return; - end + -- reconfiguration necessary? + -- --------------------------- + if (not COETotemFrame.Reconfigure) then return; end - local i; - local buttons = { Earth = 0, Fire = 0, Water = 0, Air = 0 }; - local indices = { "Earth", "Fire", "Water", "Air" }; + local i; + local buttons = {Earth = 0, Fire = 0, Water = 0, Air = 0}; + local indices = {"Earth", "Fire", "Water", "Air"}; - local mode = COE_Config:GetSaved( COEOPT_DISPLAYMODE ); - local activeset = COE_Config:GetSaved( COEOPT_ACTIVESET ); + local mode = COE_Config:GetSaved(COEOPT_DISPLAYMODE); + local activeset = COE_Config:GetSaved(COEOPT_ACTIVESET); - -- assign placeholder totem - -- ------------------------- - for i = 1, 4 do - local button = getglobal( "COETotem" .. COE_Element[i] .. "None" ); + -- assign placeholder totem + -- ------------------------- + for i = 1, 4 do + local button = getglobal("COETotem" .. COE_Element[i] .. "None"); - button.totem = COE.NoTotem; - end + button.totem = COE.NoTotem; + end - -- clear all buttons or we could get double totems - -- when switching from customize to another mode - -- ------------------------------------------------ - for i = 1, 4 do - for k = 1, COE.MaxTotems[indices[i]] do - local button = getglobal( "COETotem" .. indices[i] .. k ); + -- clear all buttons or we could get double totems + -- when switching from customize to another mode + -- ------------------------------------------------ + for i = 1, 4 do + for k = 1, COE.MaxTotems[indices[i]] do + local button = getglobal("COETotem" .. indices[i] .. k); - button.totem = nil; - end - end + button.totem = nil; + end + end - -- assign totems - -- -------------- - for i = 1, COE.TotemCount do - local totem = COE.TotemData[i]; + -- assign totems + -- -------------- + for i = 1, COE.TotemCount do + local totem = COE.TotemData[i]; - -- increase button counter - -- ------------------------ + -- increase button counter + -- ------------------------ - buttons[totem.Element] = buttons[totem.Element] + 1; + buttons[totem.Element] = buttons[totem.Element] + 1; - local order = COE_DisplayedTotems[totem.SpellName].Order; - local button; + local order = COE_DisplayedTotems[totem.SpellName].Order; + local button; - --=================================================== - -- find out the button to store the totem in - --=================================================== - if( mode == COEMODE_ALLTOTEMS ) then - button = getglobal( "COETotem" .. totem.Element .. order ); + -- =================================================== + -- find out the button to store the totem in + -- =================================================== + if (mode == COEMODE_ALLTOTEMS) then + button = getglobal("COETotem" .. totem.Element .. order); - elseif( mode == COEMODE_TIMERSONLY ) then - if( COE.ActiveTotems[totem.Element] ) then - if( COE.ActiveTotems[totem.Element] == totem ) then - -- this totem is/was last active. store at pos 1 - -- ---------------------------------------------- - button = getglobal( "COETotem" .. totem.Element .. "1" ); + elseif (mode == COEMODE_TIMERSONLY) then + if (COE.ActiveTotems[totem.Element]) then + if (COE.ActiveTotems[totem.Element] == totem) then + -- this totem is/was last active. store at pos 1 + -- ---------------------------------------------- + button = getglobal("COETotem" .. totem.Element .. "1"); - else - -- check if this totem's order is before or after - -- the normal order of this element's active totem - -- ------------------------------------------------ - local activeorder = COE_DisplayedTotems[COE.ActiveTotems[totem.Element].SpellName].Order; - if( order < activeorder ) then - order = order + 1; - end + else + -- check if this totem's order is before or after + -- the normal order of this element's active totem + -- ------------------------------------------------ + local activeorder = + COE_DisplayedTotems[COE.ActiveTotems[totem.Element] + .SpellName].Order; + if (order < activeorder) then + order = order + 1; + end - button = getglobal( "COETotem" .. totem.Element .. order ); - end + button = getglobal("COETotem" .. totem.Element .. order); + end - else - -- there has not been any active totem for this element yet - -- use the normal ordering - -- --------------------------------------------------------- - button = getglobal( "COETotem" .. totem.Element .. order ); - end + else + -- there has not been any active totem for this element yet + -- use the normal ordering + -- --------------------------------------------------------- + button = getglobal("COETotem" .. totem.Element .. order); + end - else - if( COE.TotemSets[activeset][totem.Element] == totem ) then - -- this totem is in the active set. store at pos 1 - -- ------------------------------------------------ - button = getglobal( "COETotem" .. totem.Element .. "1" ); + else + if (COE.TotemSets[activeset][totem.Element] == totem) then + -- this totem is in the active set. store at pos 1 + -- ------------------------------------------------ + button = getglobal("COETotem" .. totem.Element .. "1"); - elseif( COE.TotemSets[activeset][totem.Element] ) then - -- check if this totem's order is before or after - -- the normal order of this set's element totem - -- ----------------------------------------------- - local activeorder = COE_DisplayedTotems[COE.TotemSets[activeset][totem.Element].SpellName].Order; - if( order < activeorder ) then - order = order + 1; - end + elseif (COE.TotemSets[activeset][totem.Element]) then + -- check if this totem's order is before or after + -- the normal order of this set's element totem + -- ----------------------------------------------- + local activeorder = + COE_DisplayedTotems[COE.TotemSets[activeset][totem.Element] + .SpellName].Order; + if (order < activeorder) then order = order + 1; end - button = getglobal( "COETotem" .. totem.Element .. order ); - else - -- there is no totem for this element in the set - -- use the normal ordering - -- ---------------------------------------------- - button = getglobal( "COETotem" .. totem.Element .. order ); - end - end + button = getglobal("COETotem" .. totem.Element .. order); + else + -- there is no totem for this element in the set + -- use the normal ordering + -- ---------------------------------------------- + button = getglobal("COETotem" .. totem.Element .. order); + end + end - --=================================================== - -- store the totem - --=================================================== - if( button ~= nil ) then - -- store totem object in button - -- ----------------------------- - button.totem = totem; + -- =================================================== + -- store the totem + -- =================================================== + if (button ~= nil) then + -- store totem object in button + -- ----------------------------- + button.totem = totem; - -- assign button for cleansing advisory - -- ------------------------------------- - if( totem == COE.CleansingTotems.Poison.Totem ) then - COE.CleansingTotems.Poison.Button = button; - elseif( totem == COE.CleansingTotems.Disease.Totem ) then - COE.CleansingTotems.Disease.Button = button; - elseif( totem == COE.CleansingTotems.Tremor.Totem ) then - COE.CleansingTotems.Tremor.Button = button; - end - end - end + -- assign button for cleansing advisory + -- ------------------------------------- + if (totem == COE.CleansingTotems.Poison.Totem) then + COE.CleansingTotems.Poison.Button = button; + elseif (totem == COE.CleansingTotems.Disease.Totem) then + COE.CleansingTotems.Disease.Button = button; + elseif (totem == COE.CleansingTotems.Tremor.Totem) then + COE.CleansingTotems.Tremor.Button = button; + end + end + end - -- invalidate all frames - -- ---------------------- - COE_Totem:Invalidate( COEEarthFrame, true, true, true ); - COE_Totem:Invalidate( COEFireFrame, true, true, true ); - COE_Totem:Invalidate( COEWaterFrame, true, true, true ); - COE_Totem:Invalidate( COEAirFrame, true, true, true ); + -- invalidate all frames + -- ---------------------- + COE_Totem:Invalidate(COEEarthFrame, true, true, true); + COE_Totem:Invalidate(COEFireFrame, true, true, true); + COE_Totem:Invalidate(COEWaterFrame, true, true, true); + COE_Totem:Invalidate(COEAirFrame, true, true, true); - -- only reconfigure the next time it is really necessary - -- ------------------------------------------------------ - COETotemFrame.Reconfigure = false; + -- only reconfigure the next time it is really necessary + -- ------------------------------------------------------ + COETotemFrame.Reconfigure = false; end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateAllFrames @@ -293,41 +285,40 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateAllFrames() - if( COE_Config:GetSaved( COEOPT_ENABLETOTEMBAR ) == 1 ) then - if( COE.TotemsAvailable.Earth > 0 ) then - COEEarthFrame:Show(); - COE_Totem:Invalidate( COEEarthFrame, true, true, true ); - else - COEEarthFrame:Hide(); - end - if( COE.TotemsAvailable.Fire > 0 ) then - COEFireFrame:Show(); - COE_Totem:Invalidate( COEFireFrame, true, true, true ); - else - COEFireFrame:Hide(); - end - if( COE.TotemsAvailable.Water > 0 ) then - COEWaterFrame:Show(); - COE_Totem:Invalidate( COEWaterFrame, true, true, true ); - else - COEWaterFrame:Hide(); - end - if( COE.TotemsAvailable.Air > 0 ) then - COEAirFrame:Show(); - COE_Totem:Invalidate( COEAirFrame, true, true, true ); - else - COEAirFrame:Hide(); - end - else - COEEarthFrame:Hide(); - COEFireFrame:Hide(); - COEWaterFrame:Hide(); - COEAirFrame:Hide(); - end + if (COE_Config:GetSaved(COEOPT_ENABLETOTEMBAR) == 1) then + if (COE.TotemsAvailable.Earth > 0) then + COEEarthFrame:Show(); + COE_Totem:Invalidate(COEEarthFrame, true, true, true); + else + COEEarthFrame:Hide(); + end + if (COE.TotemsAvailable.Fire > 0) then + COEFireFrame:Show(); + COE_Totem:Invalidate(COEFireFrame, true, true, true); + else + COEFireFrame:Hide(); + end + if (COE.TotemsAvailable.Water > 0) then + COEWaterFrame:Show(); + COE_Totem:Invalidate(COEWaterFrame, true, true, true); + else + COEWaterFrame:Hide(); + end + if (COE.TotemsAvailable.Air > 0) then + COEAirFrame:Show(); + COE_Totem:Invalidate(COEAirFrame, true, true, true); + else + COEAirFrame:Hide(); + end + else + COEEarthFrame:Hide(); + COEFireFrame:Hide(); + COEWaterFrame:Hide(); + COEAirFrame:Hide(); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:ResetFrames @@ -335,20 +326,19 @@ end -------------------------------------------------------------------]] function COE_Totem:ResetFrames() - COEEarthFrame:ClearAllPoints(); - COEEarthFrame:SetPoint( "CENTER", "UIParent", "CENTER", -75, 75 ); - COEFireFrame:ClearAllPoints(); - COEFireFrame:SetPoint( "CENTER", "UIParent", "CENTER", 75, 75 ); - COEWaterFrame:ClearAllPoints(); - COEWaterFrame:SetPoint( "CENTER", "UIParent", "CENTER", -75, -75 ); - COEAirFrame:ClearAllPoints(); - COEAirFrame:SetPoint( "CENTER", "UIParent", "CENTER", 75, -75 ); + COEEarthFrame:ClearAllPoints(); + COEEarthFrame:SetPoint("CENTER", "UIParent", "CENTER", -75, 75); + COEFireFrame:ClearAllPoints(); + COEFireFrame:SetPoint("CENTER", "UIParent", "CENTER", 75, 75); + COEWaterFrame:ClearAllPoints(); + COEWaterFrame:SetPoint("CENTER", "UIParent", "CENTER", -75, -75); + COEAirFrame:ClearAllPoints(); + COEAirFrame:SetPoint("CENTER", "UIParent", "CENTER", 75, -75); - COE_Totem:UpdateFrameCoordinates(); + COE_Totem:UpdateFrameCoordinates(); end - --[[ ============================================================================================= F R A M E @@ -379,175 +369,150 @@ end ------------------------------------------------------------------------------------------------]] - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:InitFrame PURPOSE: Initializes the element frame -------------------------------------------------------------------]] function COE_Totem:InitFrame() - -- addon loaded? - -- -------------- - if( not COE.Initialized ) then - return; - end + -- addon loaded? + -- -------------- + if (not COE.Initialized) then return; end - -- init update timer - -- ------------------ - this.UpdateTime = 0; + -- init update timer + -- ------------------ + this.UpdateTime = 0; - -- initially update all frame parts - -- --------------------------------- - this.Updates = { Anchor = true, Static = true, Dynamic = true }; + -- initially update all frame parts + -- --------------------------------- + this.Updates = {Anchor = true, Static = true, Dynamic = true}; - -- frame doesn't move initially - -- ----------------------------- - this.IsMoving = false; + -- frame doesn't move initially + -- ----------------------------- + this.IsMoving = false; - -- register events - -- ---------------- - this:RegisterEvent( "PLAYER_ENTERING_WORLD" ); + -- register events + -- ---------------- + this:RegisterEvent("PLAYER_ENTERING_WORLD"); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:OnFrameEvent PURPOSE: Handles UI events -------------------------------------------------------------------]] -function COE_Totem:OnFrameEvent( event ) +function COE_Totem:OnFrameEvent(event) - if( event == "PLAYER_ENTERING_WORLD" ) then - -- load frame settings from saved variables - -- ----------------------------------------- - COE_Totem:SetFrameDirection( this, COE_TotemBars[this.Element].Direction ); - this.Mode = COE_TotemBars[this.Element].Mode; - this.FlexCount = COE_TotemBars[this.Element].FlexCount; - this.MouseHover = false; - this.Expanded = false; - this.AnchorTotem = nil; + if (event == "PLAYER_ENTERING_WORLD") then + -- load frame settings from saved variables + -- ----------------------------------------- + COE_Totem:SetFrameDirection(this, COE_TotemBars[this.Element].Direction); + this.Mode = COE_TotemBars[this.Element].Mode; + this.FlexCount = COE_TotemBars[this.Element].FlexCount; + this.MouseHover = false; + this.Expanded = false; + this.AnchorTotem = nil; - -- update all frame parts now that we - -- know which totems and options we have - -- -------------------------------------- - COE_Totem:Invalidate( this, true, true, true ); - end + -- update all frame parts now that we + -- know which totems and options we have + -- -------------------------------------- + COE_Totem:Invalidate(this, true, true, true); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:Invalidate PURPOSE: Invalidates anchor button, static and/or dynamic buttons if any or all are set to true -------------------------------------------------------------------]] -function COE_Totem:Invalidate( frame, Anchor, Static, Dynamic ) +function COE_Totem:Invalidate(frame, Anchor, Static, Dynamic) - -- don't set any flag to false to prevent overwriting - -- a previous call to Invaldiate with a true parameter - -- ---------------------------------------------------- + -- don't set any flag to false to prevent overwriting + -- a previous call to Invaldiate with a true parameter + -- ---------------------------------------------------- - if( Anchor ) then - frame.Updates.Anchor = true; - end + if (Anchor) then frame.Updates.Anchor = true; end - if( Static ) then - frame.Updates.Static = true; - end + if (Static) then frame.Updates.Static = true; end - if( Dynamic ) then - frame.Updates.Dynamic = true; - end + if (Dynamic) then frame.Updates.Dynamic = true; end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateFrame PURPOSE: Configures the totem buttons and adjusts the frame size -------------------------------------------------------------------]] -function COE_Totem:UpdateFrame( elapsed ) +function COE_Totem:UpdateFrame(elapsed) - -- check if visual update is necessary - -- ------------------------------------ - this.UpdateTime = this.UpdateTime + elapsed; - if( this.UpdateTime <= COE.UpdateInterval ) then - return; - end + -- check if visual update is necessary + -- ------------------------------------ + this.UpdateTime = this.UpdateTime + elapsed; + if (this.UpdateTime <= COE.UpdateInterval) then return; end - -- show frame? - -- ------------ - if( COE_Config:GetSaved( COEOPT_ENABLETOTEMBAR ) == 1 and - COE_TotemBars[this.Element].Mode ~= "Hidden" ) then - this:Show(); - else - this:Hide(); - return; - end + -- show frame? + -- ------------ + if (COE_Config:GetSaved(COEOPT_ENABLETOTEMBAR) == 1 and + COE_TotemBars[this.Element].Mode ~= "Hidden") then + this:Show(); + else + this:Hide(); + return; + end - -- set scaling - -- ------------ - this:SetScale( COE_Config:GetSaved( COEOPT_SCALING ) ); + -- set scaling + -- ------------ + this:SetScale(COE_Config:GetSaved(COEOPT_SCALING)); - -- invalidate all if moving - -- ------------------------- - if( this.isMoving ) then - COE_Totem:Invalidate( this, true, true, true ); - end + -- invalidate all if moving + -- ------------------------- + if (this.isMoving) then COE_Totem:Invalidate(this, true, true, true); end - -- configure buttons for this frame - -- --------------------------------- - COE_Totem:ConfigureTotemButtons(); + -- configure buttons for this frame + -- --------------------------------- + COE_Totem:ConfigureTotemButtons(); - -- configure anchor button - -- ------------------------ - if( this.Updates.Anchor ) then - COE_Totem:UpdateAnchorButton(); - end + -- configure anchor button + -- ------------------------ + if (this.Updates.Anchor) then COE_Totem:UpdateAnchorButton(); end - -- only update if at least the anchor - -- totem button has a totem assigned - -- ----------------------------------- - if( COE.TotemsAvailable[this.Element] > 0 ) then - this.AnchorTotem:Show(); + -- only update if at least the anchor + -- totem button has a totem assigned + -- ----------------------------------- + if (COE.TotemsAvailable[this.Element] > 0) then + this.AnchorTotem:Show(); - -- update the static flex-totems - -- ------------------------------ - if( this.Updates.Static ) then - COE_Totem:UpdateStatic(); - end + -- update the static flex-totems + -- ------------------------------ + if (this.Updates.Static) then COE_Totem:UpdateStatic(); end - -- update the dynamic flex-totems - -- ------------------------------- - if( this.Updates.Dynamic ) then - COE_Totem:UpdateDynamic(); - end - else - this.AnchorTotem:Hide(); - end + -- update the dynamic flex-totems + -- ------------------------------- + if (this.Updates.Dynamic) then COE_Totem:UpdateDynamic(); end + else + this.AnchorTotem:Hide(); + end - -- adjust other frames when dragging - -- ---------------------------------- - if( this.IsMoving ) then - COE_Totem:AdjustDraggedFrames(); - end + -- adjust other frames when dragging + -- ---------------------------------- + if (this.IsMoving) then COE_Totem:AdjustDraggedFrames(); end - -- reset invalidation flags - -- ------------------------- - this.Updates.Anchor = false; - this.Updates.Static = false; - this.Updates.Dynamic = false; + -- reset invalidation flags + -- ------------------------- + this.Updates.Anchor = false; + this.Updates.Static = false; + this.Updates.Dynamic = false; - -- reset update time - -- ------------------ - COETotemFrame.UpdateTime = 0; + -- reset update time + -- ------------------ + COETotemFrame.UpdateTime = 0; end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateAnchorButton @@ -556,40 +521,41 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateAnchorButton() - local mode = COE_Config:GetSaved( COEOPT_DISPLAYMODE ); - local activeset = COE_Config:GetSaved( COEOPT_ACTIVESET ); + local mode = COE_Config:GetSaved(COEOPT_DISPLAYMODE); + local activeset = COE_Config:GetSaved(COEOPT_ACTIVESET); - if( mode == COEMODE_ALLTOTEMS ) then - this.AnchorTotem = getglobal( "COETotem" .. this.Element .. "1" ); + if (mode == COEMODE_ALLTOTEMS) then + this.AnchorTotem = getglobal("COETotem" .. this.Element .. "1"); - elseif( mode == COEMODE_TIMERSONLY ) then - if( COE.ActiveTotems[this.Element] or COE_TotemBars[this.Element].Mode == "Open" ) then - this.AnchorTotem = getglobal( "COETotem" .. this.Element .. "1" ); - else - this.AnchorTotem = getglobal( "COETotem" .. this.Element .. "None" ); - return; - end + elseif (mode == COEMODE_TIMERSONLY) then + if (COE.ActiveTotems[this.Element] or COE_TotemBars[this.Element].Mode == + "Open") then + this.AnchorTotem = getglobal("COETotem" .. this.Element .. "1"); + else + this.AnchorTotem = getglobal("COETotem" .. this.Element .. "None"); + return; + end - else - if( COE.TotemSets[activeset][this.Element] or COE_TotemBars[this.Element].Mode == "Open" ) then - this.AnchorTotem = getglobal( "COETotem" .. this.Element .. "1" ); - else - this.AnchorTotem = getglobal( "COETotem" .. this.Element .. "None" ); - return; - end - end + else + if (COE.TotemSets[activeset][this.Element] or + COE_TotemBars[this.Element].Mode == "Open") then + this.AnchorTotem = getglobal("COETotem" .. this.Element .. "1"); + else + this.AnchorTotem = getglobal("COETotem" .. this.Element .. "None"); + return; + end + end - -- hide the no-totem button - -- ------------------------- - getglobal( "COETotem" .. this.Element .. "None" ):Hide(); + -- hide the no-totem button + -- ------------------------- + getglobal("COETotem" .. this.Element .. "None"):Hide(); - this.AnchorTotem:SetScale( 1 ); - this.AnchorTotem:ClearAllPoints(); - this.AnchorTotem:SetPoint( "TOPLEFT", this, "TOPLEFT" ); + this.AnchorTotem:SetScale(1); + this.AnchorTotem:ClearAllPoints(); + this.AnchorTotem:SetPoint("TOPLEFT", this, "TOPLEFT"); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateStatic @@ -597,53 +563,55 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateStatic() - local inConfig = COE.ConfigureBarMode or COE.ConfigureOrderMode or COE.ConfigureSetsMode; + local inConfig = COE.ConfigureBarMode or COE.ConfigureOrderMode or + COE.ConfigureSetsMode; - if( this.Mode == "Closed" and not COE.ConfigureBarMode and - not COE.ConfigureOrderMode and not COE.ConfigureSetsMode ) then - return; - end + if (this.Mode == "Closed" and not COE.ConfigureBarMode and + not COE.ConfigureOrderMode and not COE.ConfigureSetsMode) then + return; + end - -- show all buttons in "Open" mode and - -- FlexCount buttons in "Flex" mode - -- ------------------------------------- - local count; - if( this.Mode == "Open" or inConfig ) then - count = COE.MaxTotems[this.Element]; - else - count = this.FlexCount; - end + -- show all buttons in "Open" mode and + -- FlexCount buttons in "Flex" mode + -- ------------------------------------- + local count; + if (this.Mode == "Open" or inConfig) then + count = COE.MaxTotems[this.Element]; + else + count = this.FlexCount; + end - -- align and show buttons - -- ----------------------- - local i, start, button, lastvisible; - lastvisible = this.AnchorTotem; + -- align and show buttons + -- ----------------------- + local i, start, button, lastvisible; + lastvisible = this.AnchorTotem; - if( this.AnchorTotem.totem == COE.NoTotem ) then - start = 1; - else - start = 2; - end + if (this.AnchorTotem.totem == COE.NoTotem) then + start = 1; + else + start = 2; + end - for i = start, count do - button = getglobal( "COETotem" .. this.Element .. i ); - button:ClearAllPoints(); - button:SetScale( 1 ); + for i = start, count do + button = getglobal("COETotem" .. this.Element .. i); + button:ClearAllPoints(); + button:SetScale(1); - -- only show button if it has a totem - -- ----------------------------------- - if( button.totem and (COE_DisplayedTotems[button.totem.SpellName].Visible or inConfig) ) then - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; - else - button:Hide(); - end - end + -- only show button if it has a totem + -- ----------------------------------- + if (button.totem and + (COE_DisplayedTotems[button.totem.SpellName].Visible or inConfig)) then + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; + else + button:Hide(); + end + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateDynamic @@ -652,203 +620,211 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateDynamic() - -- no dynamic buttons in configuration - -- ------------------------------------ - if( COE.ConfigureBarMode or COE.ConfigureOrderMode or COE.ConfigureSetsMode ) then - return; - end + -- no dynamic buttons in configuration + -- ------------------------------------ + if (COE.ConfigureBarMode or COE.ConfigureOrderMode or COE.ConfigureSetsMode) then + return; + end - if( this.Mode == "Flex" ) then + if (this.Mode == "Flex") then - local i, start, lastvisible, idx; - idx = 1; + local i, start, lastvisible, idx; + idx = 1; - if( this.AnchorTotem.totem == COE.NoTotem ) then - if( this.FlexCount > 1 ) then - lastvisible = getglobal( "COETotem" .. this.Element .. this.FlexCount - 1 ); - else - lastvisible = getglobal( "COETotem" .. this.Element .. "None" ); - end - start = this.FlexCount; - else - lastvisible = getglobal( "COETotem" .. this.Element .. this.FlexCount ); - start = this.FlexCount + 1; - end + if (this.AnchorTotem.totem == COE.NoTotem) then + if (this.FlexCount > 1) then + lastvisible = getglobal("COETotem" .. this.Element .. + this.FlexCount - 1); + else + lastvisible = getglobal("COETotem" .. this.Element .. "None"); + end + start = this.FlexCount; + else + lastvisible = + getglobal("COETotem" .. this.Element .. this.FlexCount); + start = this.FlexCount + 1; + end - -- we need two passes now. the first one aligns all - -- "docked" totems and the second pass adds all other totems. - -- this way, the docked totems are shown first in the expanded bar - -- ---------------------------------------------------------------- + -- we need two passes now. the first one aligns all + -- "docked" totems and the second pass adds all other totems. + -- this way, the docked totems are shown first in the expanded bar + -- ---------------------------------------------------------------- - for i = start, COE.MaxTotems[this.Element] do - button = getglobal( "COETotem" .. this.Element .. i ); - button:ClearAllPoints(); + for i = start, COE.MaxTotems[this.Element] do + button = getglobal("COETotem" .. this.Element .. i); + button:ClearAllPoints(); - if( button.totem and COE_DisplayedTotems[button.totem.SpellName].Visible ) then - if( COE.ActiveTotems[this.Element] == button.totem and COE_Totem:IsTimerActive( button.totem ) ) then - -- show button if it is active - -- ---------------------------- - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + if (button.totem and + COE_DisplayedTotems[button.totem.SpellName].Visible) then + if (COE.ActiveTotems[this.Element] == button.totem and + COE_Totem:IsTimerActive(button.totem)) then + -- show button if it is active + -- ---------------------------- + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - elseif( COE_Totem:GetCooldownLeft( button.totem ) > 0 ) then - -- show button if it has a running cooldown - -- ----------------------------------------- - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + elseif (COE_Totem:GetCooldownLeft(button.totem) > 0) then + -- show button if it has a running cooldown + -- ----------------------------------------- + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - elseif( COE_Totem:IsAdvisedTotem( button.totem ) ) then - -- show button if it is advised - -- ----------------------------- - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + elseif (COE_Totem:IsAdvisedTotem(button.totem)) then + -- show button if it is advised + -- ----------------------------- + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - elseif( this.Expanded ) then - -- process totem in second pass - -- ----------------------------- - COEDynamic[idx] = button; - idx = idx + 1; + elseif (this.Expanded) then + -- process totem in second pass + -- ----------------------------- + COEDynamic[idx] = button; + idx = idx + 1; - else - button:SetScale( 1 ); - button:Hide(); - end + else + button:SetScale(1); + button:Hide(); + end - else - button:SetScale( 1 ); - button:Hide(); - end - end + else + button:SetScale(1); + button:Hide(); + end + end - for i = 1, idx - 1 do - button = COEDynamic[i]; + for i = 1, idx - 1 do + button = COEDynamic[i]; - -- show button if it has a totem and the bar is expanded - -- ------------------------------------------------------ - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + -- show button if it has a totem and the bar is expanded + -- ------------------------------------------------------ + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - COEDynamic[i] = nil; - end + COEDynamic[i] = nil; + end - elseif( this.Mode == "Closed" ) then + elseif (this.Mode == "Closed") then - local i, start, lastvisible; - lastvisible = this.AnchorTotem; + local i, start, lastvisible; + lastvisible = this.AnchorTotem; - if( this.AnchorTotem.totem == COE.NoTotem ) then - start = 1; - else - start = 2; - end + if (this.AnchorTotem.totem == COE.NoTotem) then + start = 1; + else + start = 2; + end - for i = start, COE.MaxTotems[this.Element] do - button = getglobal( "COETotem" .. this.Element .. i ); - button:ClearAllPoints(); + for i = start, COE.MaxTotems[this.Element] do + button = getglobal("COETotem" .. this.Element .. i); + button:ClearAllPoints(); - if( button.totem and COE.ActiveTotems[this.Element] == button.totem and - COE_Totem:IsTimerActive( button.totem ) ) then - -- show button if it is active - -- ---------------------------- - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + if (button.totem and COE.ActiveTotems[this.Element] == button.totem and + COE_Totem:IsTimerActive(button.totem)) then + -- show button if it is active + -- ---------------------------- + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - elseif( button.totem and COE_Totem:GetCooldownLeft( button.totem ) > 0 ) then - -- show button if it has a running cooldown - -- ----------------------------------------- - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + elseif (button.totem and COE_Totem:GetCooldownLeft(button.totem) > 0) then + -- show button if it has a running cooldown + -- ----------------------------------------- + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - elseif( COE_Totem:IsAdvisedTotem( button.totem ) ) then - -- show button if it isa advised - -- ------------------------------ - button:SetScale( 0.8 ); - button:SetPoint( this.Point, lastvisible, this.RelPoint, this.XSpacing, this.YSpacing ); - button:Show(); - lastvisible = button; + elseif (COE_Totem:IsAdvisedTotem(button.totem)) then + -- show button if it isa advised + -- ------------------------------ + button:SetScale(0.8); + button:SetPoint(this.Point, lastvisible, this.RelPoint, + this.XSpacing, this.YSpacing); + button:Show(); + lastvisible = button; - else - button:SetScale( 1 ); - button:Hide(); - end - end + else + button:SetScale(1); + button:Hide(); + end + end - end + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:COESched_HideDynamicButtons PURPOSE: Set the expanded state to false to hide the dynamic buttons of this frame -------------------------------------------------------------------]] -function COESched_HideDynamicButtons( frame ) +function COESched_HideDynamicButtons(frame) - COE_Totem:Invalidate( frame, false, false, true ); - frame.Expanded = false; + COE_Totem:Invalidate(frame, false, false, true); + frame.Expanded = false; end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:SetFrameDirection PURPOSE: Sets the frame parameters responsible for aligning the totem buttons in a specific direction -------------------------------------------------------------------]] -function COE_Totem:SetFrameDirection( frame, direction ) +function COE_Totem:SetFrameDirection(frame, direction) - if( direction == "Up" ) then - frame.Direction = direction; - frame.Point = "BOTTOM"; - frame.RelPoint = "TOP"; - frame.XSpacing = 0; - frame.YSpacing = COEUI_BUTTONGAP; + if (direction == "Up") then + frame.Direction = direction; + frame.Point = "BOTTOM"; + frame.RelPoint = "TOP"; + frame.XSpacing = 0; + frame.YSpacing = COEUI_BUTTONGAP; - elseif( direction == "Down" ) then - frame.Direction = direction; - frame.Point = "TOP"; - frame.RelPoint = "BOTTOM"; - frame.XSpacing = 0; - frame.YSpacing = -COEUI_BUTTONGAP; + elseif (direction == "Down") then + frame.Direction = direction; + frame.Point = "TOP"; + frame.RelPoint = "BOTTOM"; + frame.XSpacing = 0; + frame.YSpacing = -COEUI_BUTTONGAP; - elseif( direction == "Left" ) then - frame.Direction = direction; - frame.Point = "RIGHT"; - frame.RelPoint = "LEFT"; - frame.XSpacing = -COEUI_BUTTONGAP; - frame.YSpacing = 0; + elseif (direction == "Left") then + frame.Direction = direction; + frame.Point = "RIGHT"; + frame.RelPoint = "LEFT"; + frame.XSpacing = -COEUI_BUTTONGAP; + frame.YSpacing = 0; - elseif( direction == "Right" ) then - frame.Direction = direction; - frame.Point = "LEFT"; - frame.RelPoint = "RIGHT"; - frame.XSpacing = COEUI_BUTTONGAP; - frame.YSpacing = 0; + elseif (direction == "Right") then + frame.Direction = direction; + frame.Point = "LEFT"; + frame.RelPoint = "RIGHT"; + frame.XSpacing = COEUI_BUTTONGAP; + frame.YSpacing = 0; - end + end - -- invalidate static and dynamic buttons - -- -------------------------------------- - COE_Totem:Invalidate( frame, false, true, true ); + -- invalidate static and dynamic buttons + -- -------------------------------------- + COE_Totem:Invalidate(frame, false, true, true); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:AdjustDraggedFrames @@ -858,45 +834,43 @@ end -------------------------------------------------------------------]] function COE_Totem:AdjustDraggedFrames() - if( COE_Config:GetSaved( COEOPT_GROUPBARS ) == 0 ) then - return; - end + if (COE_Config:GetSaved(COEOPT_GROUPBARS) == 0) then return; end - local x, y, k, dx, dy; + local x, y, k, dx, dy; - -- get current frame position - -- --------------------------- - x = this:GetLeft(); - y = this:GetTop(); + -- get current frame position + -- --------------------------- + x = this:GetLeft(); + y = this:GetTop(); - -- get the offset from the old position - -- ------------------------------------- - dx = x - COEFramePositions[this.Element].x; - dy = y - COEFramePositions[this.Element].y; + -- get the offset from the old position + -- ------------------------------------- + dx = x - COEFramePositions[this.Element].x; + dy = y - COEFramePositions[this.Element].y; - -- adjust all other frames' positions - -- ----------------------------------- - for k = 1, 4 do - if( this.Element ~= COE_Element[k] ) then - local frame = getglobal( "COE" .. COE_Element[k] .. "Frame" ); + -- adjust all other frames' positions + -- ----------------------------------- + for k = 1, 4 do + if (this.Element ~= COE_Element[k]) then + local frame = getglobal("COE" .. COE_Element[k] .. "Frame"); - -- calculate the frame's new position by retaining - -- the relative position to the frame being dragged - -- ------------------------------------------------- - frame:ClearAllPoints(); - frame:SetPoint( "TOPLEFT", UIParent, "BOTTOMLEFT", COEFramePositions[frame.Element].x + dx, - COEFramePositions[frame.Element].y + dy ); + -- calculate the frame's new position by retaining + -- the relative position to the frame being dragged + -- ------------------------------------------------- + frame:ClearAllPoints(); + frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", + COEFramePositions[frame.Element].x + dx, + COEFramePositions[frame.Element].y + dy); - -- invalidate all parts - -- --------------------- - COE_Totem:Invalidate( frame, true, true, true ); + -- invalidate all parts + -- --------------------- + COE_Totem:Invalidate(frame, true, true, true); - end - end + end + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateFrameCoordinates @@ -904,21 +878,20 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateFrameCoordinates() - local k; - for k = 1, 4 do - local frame = getglobal( "COE" .. COE_Element[k] .. "Frame" ); + local k; + for k = 1, 4 do + local frame = getglobal("COE" .. COE_Element[k] .. "Frame"); - COEFramePositions[COE_Element[k]].x = frame:GetLeft(); - COEFramePositions[COE_Element[k]].y = frame:GetTop(); + COEFramePositions[COE_Element[k]].x = frame:GetLeft(); + COEFramePositions[COE_Element[k]].y = frame:GetTop(); - -- Invalidate all parts - -- --------------------- - COE_Totem:Invalidate( frame, true, true, true ); - end + -- Invalidate all parts + -- --------------------- + COE_Totem:Invalidate(frame, true, true, true); + end end - --[[ ============================================================================================= B U T T O N @@ -943,193 +916,183 @@ end -------------------------------------------------------------------]] function COE_Totem:OnTotemButtonLoad() - if( not COE.Initialized ) then - return; - end + if (not COE.Initialized) then return; end - -- init properties - -- ---------------- - this.UpdateTime = 0; - this.Flashtime = 0; - this.ElementFrame = this:GetParent(); + -- init properties + -- ---------------- + this.UpdateTime = 0; + this.Flashtime = 0; + this.ElementFrame = this:GetParent(); - -- register for drag - -- ------------------ - this:RegisterForDrag( "LeftButton" ); + -- register for drag + -- ------------------ + this:RegisterForDrag("LeftButton"); - -- register events - -- ---------------- - this:RegisterEvent( "ACTIONBAR_UPDATE_STATE" ); - this:RegisterEvent( "ACTIONBAR_UPDATE_USABLE" ); - this:RegisterEvent( "ACTIONBAR_UPDATE_COOLDOWN" ); - this:RegisterEvent( "UNIT_MANA" ); - this:RegisterEvent( "UNIT_INVENTORY_CHANGED" ); - this:RegisterEvent( "BAG_UPDATE" ); - this:RegisterEvent( "UPDATE_BINDINGS" ); - this:RegisterEvent( "SPELLCAST_STOP" ); + -- register events + -- ---------------- + this:RegisterEvent("ACTIONBAR_UPDATE_STATE"); + this:RegisterEvent("ACTIONBAR_UPDATE_USABLE"); + this:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN"); + this:RegisterEvent("UNIT_MANA"); + this:RegisterEvent("UNIT_INVENTORY_CHANGED"); + this:RegisterEvent("BAG_UPDATE"); + this:RegisterEvent("UPDATE_BINDINGS"); + this:RegisterEvent("SPELLCAST_STOP"); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:OnTotemButtonEvent PURPOSE: Handles UI events for the totem button -------------------------------------------------------------------]] -function COE_Totem:OnTotemButtonEvent( event ) +function COE_Totem:OnTotemButtonEvent(event) - if( event == "ACTIONBAR_UPDATE_STATE" ) then - if( this.totem ) then - COE_Totem:UpdateTotemButton( COE.ForceUpdate ); - end + if (event == "ACTIONBAR_UPDATE_STATE") then + if (this.totem) then + COE_Totem:UpdateTotemButton(COE.ForceUpdate); + end - elseif( event == "ACTIONBAR_UPDATE_USABLE" ) then - if( this.totem ) then - COE_Totem:UpdateTotemButtonIsUsable(); - end + elseif (event == "ACTIONBAR_UPDATE_USABLE") then + if (this.totem) then COE_Totem:UpdateTotemButtonIsUsable(); end - elseif( event == "ACTIONBAR_UPDATE_COOLDOWN" ) then - if( this.totem ) then - COE_Totem:UpdateTotemButtonCooldown(); - end + elseif (event == "ACTIONBAR_UPDATE_COOLDOWN") then + if (this.totem) then COE_Totem:UpdateTotemButtonCooldown(); end - elseif( event == "UNIT_MANA" and arg1 == "player" ) then - if( this.totem ) then - COE_Totem:UpdateTotemButtonIsUsable(); - end + elseif (event == "UNIT_MANA" and arg1 == "player") then + if (this.totem) then COE_Totem:UpdateTotemButtonIsUsable(); end - elseif( event == "UNIT_INVENTORY_CHANGED" or event == "BAG_UPDATE" ) then - -- check for presence of totem tools - -- ---------------------------------- - local totem = this.totem; - if( totem and totem ~= COE.NoTotem ) then + elseif (event == "UNIT_INVENTORY_CHANGED" or event == "BAG_UPDATE") then + -- check for presence of totem tools + -- ---------------------------------- + local totem = this.totem; + if (totem and totem ~= COE.NoTotem) then - if( totem.isTrinket ) then - local slot; - totem.ToolPresent, slot = COE:IsTrinketPresent(); + if (totem.isTrinket) then + local slot; + totem.ToolPresent, slot = COE:IsTrinketPresent(); - if( slot and slot ~= totem.TrinketSlot and totem.CurCooldown < 30 ) then - -- trinket has been (re-)equipped - -- start item cooldown - -- ------------------------------- - totem.CurCooldown = 30; - Chronos.startTimer( "COECooldown" .. totem.SpellName ); - Chronos.scheduleByName( "COECooldownSwitch" .. totem.SpellName, totem.CurCooldown, COESched_CooldownEnd, totem ); + if (slot and slot ~= totem.TrinketSlot and totem.CurCooldown < + 30) then + -- trinket has been (re-)equipped + -- start item cooldown + -- ------------------------------- + totem.CurCooldown = 30; + Chronos.startTimer("COECooldown" .. totem.SpellName); + Chronos.scheduleByName( + "COECooldownSwitch" .. totem.SpellName, + totem.CurCooldown, COESched_CooldownEnd, totem); - end + end - totem.TrinketSlot = slot; - else - totem.ToolPresent = COE:IsToolPresent( totem.Ranks[1].SpellID ); - end - end + totem.TrinketSlot = slot; + else + totem.ToolPresent = COE:IsToolPresent(totem.Ranks[1].SpellID); + end + end - elseif( event == "UPDATE_BINDINGS" ) then - if( this.totem ) then - COE_Totem:UpdateTotemButtonHotKey(); - end + elseif (event == "UPDATE_BINDINGS") then + if (this.totem) then COE_Totem:UpdateTotemButtonHotKey(); end - elseif( event == "SPELLCAST_STOP" ) then - -- activate timer if totem is pending - -- ----------------------------------- - if( COE_Config:GetSaved( COEOPT_ENABLETIMERS ) == 1 and - this.totem and this.totem == COE.TotemPending.Totem ) then - COE_Totem:ActivatePendingTotem( this.totem ); - end + -- UPDATED single totem pending logic to handle multiple pending and fire when totem cast is reported from event + -- elseif (event == "SPELLCAST_STOP") then + -- -- activate timer if totem is pending + -- -- ----------------------------------- + -- if (COE_Config:GetSaved(COEOPT_ENABLETIMERS) == 1 and this.totem and + -- this.totem == COE.TotemPending.Totem) then + -- COE_Totem:ActivatePendingTotem(this.totem); + -- end - end + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateTotemButton PURPOSE: Updates the button state -------------------------------------------------------------------]] -function COE_Totem:UpdateTotemButton( elapsed ) +function COE_Totem:UpdateTotemButton(elapsed) - -- check if visual update is necessary - -- ------------------------------------ - this.UpdateTime = this.UpdateTime + elapsed; - if( this.UpdateTime <= COE.UpdateInterval ) then - return; - end + -- check if visual update is necessary + -- ------------------------------------ + this.UpdateTime = this.UpdateTime + elapsed; + if (this.UpdateTime <= COE.UpdateInterval) then return; end - if( this.totem == nil ) then - this:Hide(); - return; - end + if (this.totem == nil) then + this:Hide(); + return; + end - -- set the icon - -- ------------- - icon = getglobal( this:GetName() .. "Icon" ); - icon:SetTexture( this.totem.Texture ); + -- set the icon + -- ------------- + icon = getglobal(this:GetName() .. "Icon"); + icon:SetTexture(this.totem.Texture); - -- update usability state - -- ----------------------- - COE_Totem:UpdateTotemButtonIsUsable(); + -- update usability state + -- ----------------------- + COE_Totem:UpdateTotemButtonIsUsable(); - -- update cooldown - -- ---------------- - COE_Totem:UpdateTotemButtonCooldown(); + -- update cooldown + -- ---------------- + COE_Totem:UpdateTotemButtonCooldown(); - -- update hotkey - -- -------------- - COE_Totem:UpdateTotemButtonHotKey(); + -- update hotkey + -- -------------- + COE_Totem:UpdateTotemButtonHotKey(); - -- flash button if advisor warning is active - -- ------------------------------------------ - COE_Totem:UpdateTotemButtonFlash( elapsed ); + -- flash button if advisor warning is active + -- ------------------------------------------ + COE_Totem:UpdateTotemButtonFlash(elapsed); - if( this.totem ~= COE.NoTotem ) then - local border = getglobal( this:GetName() .. "Border" ); - if( COE.ConfigureBarMode ) then - -- set a green border when this totem - -- should be visible and we are in config bar mode - -- ------------------------------------------------ - if( COE_DisplayedTotems[this.totem.SpellName].Visible ) then - border:SetVertexColor( 0, 1.0, 0, 0.75 ); - border:Show(); - else - border:Hide(); - end + if (this.totem ~= COE.NoTotem) then + local border = getglobal(this:GetName() .. "Border"); + if (COE.ConfigureBarMode) then + -- set a green border when this totem + -- should be visible and we are in config bar mode + -- ------------------------------------------------ + if (COE_DisplayedTotems[this.totem.SpellName].Visible) then + border:SetVertexColor(0, 1.0, 0, 0.75); + border:Show(); + else + border:Hide(); + end - elseif( COE.ConfigureOrderMode ) then - -- set a blue border when this totem - -- is the first totem to be swapped - -- ---------------------------------- - if( COE_Config.ConfigureOrderTotem == this.totem ) then - border:SetVertexColor( 1.0, 0, 1.0, 0.75 ); - border:Show(); - else - border:Hide(); - end + elseif (COE.ConfigureOrderMode) then + -- set a blue border when this totem + -- is the first totem to be swapped + -- ---------------------------------- + if (COE_Config.ConfigureOrderTotem == this.totem) then + border:SetVertexColor(1.0, 0, 1.0, 0.75); + border:Show(); + else + border:Hide(); + end - elseif( COE_Config:GetSaved( COEOPT_ENABLESETS ) == 1 and - COE.TotemSets[COE_Config:GetSaved( COEOPT_ACTIVESET )][this.totem.Element] == this.totem ) then + elseif (COE_Config:GetSaved(COEOPT_ENABLESETS) == 1 and + COE.TotemSets[COE_Config:GetSaved(COEOPT_ACTIVESET)][this.totem + .Element] == this.totem) then - -- set a red border when this totem - -- belongs to the current totem set - -- ----------------------------------- - border:SetVertexColor( 1.0, 0, 0, 0.75 ); - border:Show(); - else - border:Hide(); - end - end + -- set a red border when this totem + -- belongs to the current totem set + -- ----------------------------------- + border:SetVertexColor(1.0, 0, 0, 0.75); + border:Show(); + else + border:Hide(); + end + end - this:SetChecked( false ); + this:SetChecked(false); - -- update timer text - -- ------------------ - COE_Totem:SetTimerText(); + -- update timer text + -- ------------------ + COE_Totem:SetTimerText(); - this.UpdateTime = 0; + this.UpdateTime = 0; end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateTotemButtonCooldown @@ -1137,38 +1100,36 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateTotemButtonCooldown() - if( this.totem == COE.NoTotem ) then - return; - end; + if (this.totem == COE.NoTotem) then return; end - local cooldown = getglobal( this:GetName() .. "Cooldown" ); + local cooldown = getglobal(this:GetName() .. "Cooldown"); - -- don't show the cooldown texture for totems with a real - -- cooldown to make the cooldown timer more readable - -- ------------------------------------------------------- - if( this:IsVisible() and this.totem.CurCooldown == 0 ) then - local start, duration, enable; + -- don't show the cooldown texture for totems with a real + -- cooldown to make the cooldown timer more readable + -- ------------------------------------------------------- + if (this:IsVisible() and this.totem.CurCooldown == 0) then + local start, duration, enable; - if( this.totem.isTrinket ) then - if( this.totem.ToolPresent ) then - start, duration, enable = GetInventoryItemCooldown( "player", this.totem.TrinketSlot ); - else - cooldown:Hide(); - return; - end - else - local SpellID = this.totem.Ranks[this.totem.MaxRank].SpellID; - start, duration, enable = GetSpellCooldown( SpellID, BOOKTYPE_SPELL ); - end + if (this.totem.isTrinket) then + if (this.totem.ToolPresent) then + start, duration, enable = + GetInventoryItemCooldown("player", this.totem.TrinketSlot); + else + cooldown:Hide(); + return; + end + else + local SpellID = this.totem.Ranks[this.totem.MaxRank].SpellID; + start, duration, enable = GetSpellCooldown(SpellID, BOOKTYPE_SPELL); + end - CooldownFrame_SetTimer( cooldown, start, duration, enable ); - else - cooldown:Hide(); - end + CooldownFrame_SetTimer(cooldown, start, duration, enable); + else + cooldown:Hide(); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateTotemButtonIsUsable @@ -1179,44 +1140,41 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateTotemButtonIsUsable() - if( this.totem == COE.NoTotem ) then - return; - end; + if (this.totem == COE.NoTotem) then return; end - local icon = getglobal( this:GetName() .. "Icon" ); - local normalTexture = getglobal( this:GetName() .. "NormalTexture" ); + local icon = getglobal(this:GetName() .. "Icon"); + local normalTexture = getglobal(this:GetName() .. "NormalTexture"); - -- assume the player doesn't have the required tool - -- ------------------------------------------------- - icon:SetVertexColor( 0.4, 0.4, 0.4 ); - normalTexture:SetVertexColor( 1.0, 1.0, 1.0 ); + -- assume the player doesn't have the required tool + -- ------------------------------------------------- + icon:SetVertexColor(0.4, 0.4, 0.4); + normalTexture:SetVertexColor(1.0, 1.0, 1.0); - -- check if totem tool is present - -- ------------------------------- - if( this.totem.ToolPresent ) then - icon:SetVertexColor( 1.0, 1.0, 1.0 ); - normalTexture:SetVertexColor( 1.0, 1.0, 1.0 ); - end + -- check if totem tool is present + -- ------------------------------- + if (this.totem.ToolPresent) then + icon:SetVertexColor(1.0, 1.0, 1.0); + normalTexture:SetVertexColor(1.0, 1.0, 1.0); + end - if( not this.totem.isTrinket ) then - -- now check for enough mana - -- -------------------------- - local rank; - if( COE_Totem:RankModifierDown() ) then - rank = this.totem.Ranks[1]; - else - rank = this.totem.Ranks[this.totem.MaxRank]; - end + if (not this.totem.isTrinket) then + -- now check for enough mana + -- -------------------------- + local rank; + if (COE_Totem:RankModifierDown()) then + rank = this.totem.Ranks[1]; + else + rank = this.totem.Ranks[this.totem.MaxRank]; + end - if( rank.Mana > UnitMana( "player" ) ) then - icon:SetVertexColor(0.5, 0.5, 1.0); - normalTexture:SetVertexColor(0.5, 0.5, 1.0); - end - end + if (rank.Mana > UnitMana("player")) then + icon:SetVertexColor(0.5, 0.5, 1.0); + normalTexture:SetVertexColor(0.5, 0.5, 1.0); + end + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateTotemButtonHotKey @@ -1224,77 +1182,76 @@ end -------------------------------------------------------------------]] function COE_Totem:UpdateTotemButtonHotKey() - if( this.totem == COE.NoTotem ) then - return; - end; + if (this.totem == COE.NoTotem) then return; end - -- get the binding name - -- --------------------- - local binding = "TOTEM" .. string.upper( this.totem.Element ); - local id = this:GetID() - getglobal( "COETotem" .. this.totem.Element .. "1" ):GetID() + 1; - binding = binding .. id; + -- get the binding name + -- --------------------- + local binding = "TOTEM" .. string.upper(this.totem.Element); + local id = this:GetID() - + getglobal("COETotem" .. this.totem.Element .. "1"):GetID() + + 1; + binding = binding .. id; - -- get the binding text - -- --------------------- - local text = GetBindingText( GetBindingKey( binding ), "KEY_" ); + -- get the binding text + -- --------------------- + local text = GetBindingText(GetBindingKey(binding), "KEY_"); - -- replace modifiers - -- ------------------ - text = gsub( text, COEMODIFIER_ALT, COEMODIFIER_ALT_SHORT ); - text = gsub( text, COEMODIFIER_CTRL, COEMODIFIER_CTRL_SHORT ); - text = gsub( text, COEMODIFIER_SHIFT, COEMODIFIER_SHIFT_SHORT ); - text = gsub( text, COEMODIFIER_NUMPAD, COEMODIFIER_NUMPAD_SHORT ); + -- replace modifiers + -- ------------------ + text = gsub(text, COEMODIFIER_ALT, COEMODIFIER_ALT_SHORT); + text = gsub(text, COEMODIFIER_CTRL, COEMODIFIER_CTRL_SHORT); + text = gsub(text, COEMODIFIER_SHIFT, COEMODIFIER_SHIFT_SHORT); + text = gsub(text, COEMODIFIER_NUMPAD, COEMODIFIER_NUMPAD_SHORT); - -- set button text - -- ---------------- - local hotkey = getglobal( this:GetName() .. "HotKey" ); - hotkey:SetText( text ); + -- set button text + -- ---------------- + local hotkey = getglobal(this:GetName() .. "HotKey"); + hotkey:SetText(text); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateTotemButtonFlash PURPOSE: Updates the button flash if it has a cleansing totem and the corresponding warning is active -------------------------------------------------------------------]] -function COE_Totem:UpdateTotemButtonFlash( elapsed ) +function COE_Totem:UpdateTotemButtonFlash(elapsed) - if( (this.totem == COE.NoTotem) or this.totem.isTrinket ) then - return; - end; + if ((this.totem == COE.NoTotem) or this.totem.isTrinket) then return; end - if( COE_Config:GetSaved( COEOPT_ADVISOR ) == 1 ) then - if( (this == COE.CleansingTotems.Tremor.Button and COE.CleansingTotems.Tremor.Warn) or - (this == COE.CleansingTotems.Disease.Button and COE.CleansingTotems.Disease.Warn) or - (this == COE.CleansingTotems.Poison.Button and COE.CleansingTotems.Poison.Warn) ) then + if (COE_Config:GetSaved(COEOPT_ADVISOR) == 1) then + if ((this == COE.CleansingTotems.Tremor.Button and + COE.CleansingTotems.Tremor.Warn) or + (this == COE.CleansingTotems.Disease.Button and + COE.CleansingTotems.Disease.Warn) or + (this == COE.CleansingTotems.Poison.Button and + COE.CleansingTotems.Poison.Warn)) then - this.Flashtime = this.Flashtime - elapsed; - if ( this.Flashtime <= 0 ) then - local overtime = - this.Flashtime; - if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then - overtime = 0; - end - this.Flashtime = ATTACK_BUTTON_FLASH_TIME - overtime; + this.Flashtime = this.Flashtime - elapsed; + if (this.Flashtime <= 0) then + local overtime = -this.Flashtime; + if (overtime >= ATTACK_BUTTON_FLASH_TIME) then + overtime = 0; + end + this.Flashtime = ATTACK_BUTTON_FLASH_TIME - overtime; - local flashTexture = getglobal( this:GetName().."Flash" ); - if ( flashTexture:IsVisible() ) then - flashTexture:Hide(); - else - flashTexture:Show(); - end - end + local flashTexture = getglobal(this:GetName() .. "Flash"); + if (flashTexture:IsVisible()) then + flashTexture:Hide(); + else + flashTexture:Show(); + end + end - return; - end - end + return; + end + end - getglobal( this:GetName().."Flash" ):Hide(); + getglobal(this:GetName() .. "Flash"):Hide(); end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:OnEnterTotemButton @@ -1303,41 +1260,41 @@ end -------------------------------------------------------------------]] function COE_Totem:OnEnterTotemButton() - -- show tooltip if enabled - -- ------------------------ - if( COEUI_TTALIGN[COE_Config:GetSaved( COEOPT_TTALIGNMENT )][1] ~= "DISABLED" and - this.totem ~= COE.NoTotem ) then + -- show tooltip if enabled + -- ------------------------ + if (COEUI_TTALIGN[COE_Config:GetSaved(COEOPT_TTALIGNMENT)][1] ~= "DISABLED" and + this.totem ~= COE.NoTotem) then - GameTooltip:SetOwner( this, COEUI_TTALIGN[COE_Config:GetSaved( COEOPT_TTALIGNMENT )][1] ); + GameTooltip:SetOwner(this, COEUI_TTALIGN[COE_Config:GetSaved( + COEOPT_TTALIGNMENT)][1]); - if( this.totem.isTrinket ) then - -- show item tooltip if equipped - -- else show name of the item - -- ------------------------------ - if( this.totem.ToolPresent ) then - GameTooltip:SetInventoryItem( "player", this.totem.TrinketSlot ); - else - GameTooltip:SetText( COESTR_TRINKET_TOOLTIP ); - end - else - -- show spell tooltip - -- ------------------- - local SpellID = this.totem.Ranks[this.totem.MaxRank].SpellID; - GameTooltip:SetSpell( SpellID, BOOKTYPE_SPELL ); - end - end + if (this.totem.isTrinket) then + -- show item tooltip if equipped + -- else show name of the item + -- ------------------------------ + if (this.totem.ToolPresent) then + GameTooltip:SetInventoryItem("player", this.totem.TrinketSlot); + else + GameTooltip:SetText(COESTR_TRINKET_TOOLTIP); + end + else + -- show spell tooltip + -- ------------------- + local SpellID = this.totem.Ranks[this.totem.MaxRank].SpellID; + GameTooltip:SetSpell(SpellID, BOOKTYPE_SPELL); + end + end - -- show dynamic buttons - -- --------------------- - if( this.ElementFrame.Mode == "Flex" ) then - this.ElementFrame.Expanded = true; - COE_Totem:Invalidate( this.ElementFrame, false, false, true ); - Chronos.unscheduleByName( "COEFlex" .. this.ElementFrame.Element ); - end + -- show dynamic buttons + -- --------------------- + if (this.ElementFrame.Mode == "Flex") then + this.ElementFrame.Expanded = true; + COE_Totem:Invalidate(this.ElementFrame, false, false, true); + Chronos.unscheduleByName("COEFlex" .. this.ElementFrame.Element); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:OnLeaveTotemButton @@ -1345,20 +1302,21 @@ end -------------------------------------------------------------------]] function COE_Totem:OnLeaveTotemButton() - -- hide tooltip if enabled - -- ------------------------ - if( COEUI_TTALIGN[COE_Config:GetSaved( COEOPT_TTALIGNMENT )][1] ~= "DISABLED" ) then - GameTooltip:Hide(); - end + -- hide tooltip if enabled + -- ------------------------ + if (COEUI_TTALIGN[COE_Config:GetSaved(COEOPT_TTALIGNMENT)][1] ~= "DISABLED") then + GameTooltip:Hide(); + end - -- schedule hiding of the dynamic buttons - -- --------------------------------------- - if( this.ElementFrame.Mode == "Flex" ) then - Chronos.scheduleByName( "COEFlex" .. this.ElementFrame.Element, COE_Totem.FlexTime, COESched_HideDynamicButtons, this.ElementFrame ); - end + -- schedule hiding of the dynamic buttons + -- --------------------------------------- + if (this.ElementFrame.Mode == "Flex") then + Chronos.scheduleByName("COEFlex" .. this.ElementFrame.Element, + COE_Totem.FlexTime, COESched_HideDynamicButtons, + this.ElementFrame); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:OnTotemButtonClick @@ -1367,109 +1325,109 @@ end -------------------------------------------------------------------]] function COE_Totem:OnTotemButtonClick() - if( this.totem == COE.NoTotem ) then - return; - end; + if (this.totem == COE.NoTotem) then return; end - if( COE.ConfigureBarMode ) then + if (COE.ConfigureBarMode) then - -- toggle totem visibility - -- ------------------------ - if( COE_DisplayedTotems[this.totem.SpellName].Visible ) then - COE_DisplayedTotems[this.totem.SpellName].Visible = false; - else - COE_DisplayedTotems[this.totem.SpellName].Visible = true; - end + -- toggle totem visibility + -- ------------------------ + if (COE_DisplayedTotems[this.totem.SpellName].Visible) then + COE_DisplayedTotems[this.totem.SpellName].Visible = false; + else + COE_DisplayedTotems[this.totem.SpellName].Visible = true; + end - elseif( COE.ConfigureOrderMode ) then + elseif (COE.ConfigureOrderMode) then - if( COE_Config.ConfigureOrderTotem == nil or - COE_Config.ConfigureOrderTotem.Element ~= this.totem.Element ) then + if (COE_Config.ConfigureOrderTotem == nil or + COE_Config.ConfigureOrderTotem.Element ~= this.totem.Element) then - -- set first totem to be swapped - -- ------------------------------ - COE_Config.ConfigureOrderTotem = this.totem; + -- set first totem to be swapped + -- ------------------------------ + COE_Config.ConfigureOrderTotem = this.totem; - elseif( COE_Config.ConfigureOrderTotem == this.totem ) then - -- unset first totem - -- ------------------ - COE_Config.ConfigureOrderTotem = nil; + elseif (COE_Config.ConfigureOrderTotem == this.totem) then + -- unset first totem + -- ------------------ + COE_Config.ConfigureOrderTotem = nil; - else - -- swap this totem with the first one - -- ----------------------------------- - local swap = COE_DisplayedTotems[COE_Config.ConfigureOrderTotem.SpellName].Order; - COE_DisplayedTotems[COE_Config.ConfigureOrderTotem.SpellName].Order = COE_DisplayedTotems[this.totem.SpellName].Order; - COE_DisplayedTotems[this.totem.SpellName].Order = swap; + else + -- swap this totem with the first one + -- ----------------------------------- + local swap = COE_DisplayedTotems[COE_Config.ConfigureOrderTotem + .SpellName].Order; + COE_DisplayedTotems[COE_Config.ConfigureOrderTotem.SpellName].Order = + COE_DisplayedTotems[this.totem.SpellName].Order; + COE_DisplayedTotems[this.totem.SpellName].Order = swap; - COE_Config.ConfigureOrderTotem = nil; + COE_Config.ConfigureOrderTotem = nil; - end; + end - -- reconfigure totem bar - -- ---------------------- - COETotemFrame.Reconfigure = true; + -- reconfigure totem bar + -- ---------------------- + COETotemFrame.Reconfigure = true; - elseif( COE.ConfigureSetsMode ) then - local activeset = COE_Config:GetSaved( COEOPT_ACTIVESET ); + elseif (COE.ConfigureSetsMode) then + local activeset = COE_Config:GetSaved(COEOPT_ACTIVESET); - if( COE.TotemSets[activeset][this.totem.Element] == this.totem ) then - -- already in the set, remove - -- --------------------------- - COE.TotemSets[activeset][this.totem.Element] = nil; - if( activeset <= COESET_DEFAULT ) then - COE_SavedTotemSets[activeset][this.totem.Element] = ""; - else - COE_CustomTotemSets[activeset - COESET_DEFAULT][this.totem.Element] = ""; - end - else - -- store in set - -- ------------- - COE.TotemSets[activeset][this.totem.Element] = this.totem; - if( activeset <= COESET_DEFAULT ) then - COE_SavedTotemSets[activeset][this.totem.Element] = this.totem.SpellName; - else - COE_CustomTotemSets[activeset - COESET_DEFAULT][this.totem.Element] = this.totem.SpellName; - end - end + if (COE.TotemSets[activeset][this.totem.Element] == this.totem) then + -- already in the set, remove + -- --------------------------- + COE.TotemSets[activeset][this.totem.Element] = nil; + if (activeset <= COESET_DEFAULT) then + COE_SavedTotemSets[activeset][this.totem.Element] = ""; + else + COE_CustomTotemSets[activeset - COESET_DEFAULT][this.totem + .Element] = ""; + end + else + -- store in set + -- ------------- + COE.TotemSets[activeset][this.totem.Element] = this.totem; + if (activeset <= COESET_DEFAULT) then + COE_SavedTotemSets[activeset][this.totem.Element] = this.totem + .SpellName; + else + COE_CustomTotemSets[activeset - COESET_DEFAULT][this.totem + .Element] = this.totem.SpellName; + end + end - -- reconfigure totem bar - -- ---------------------- - COETotemFrame.Reconfigure = true; + -- reconfigure totem bar + -- ---------------------- + COETotemFrame.Reconfigure = true; - else + else - -- if the ctrl key is down, make this totem the anchor totem - -- ---------------------------------------------------------- - if( IsControlKeyDown() ) then - COE_Totem:MakeAnchorTotem( this ); - end + -- if the ctrl key is down, make this totem the anchor totem + -- ---------------------------------------------------------- + if (IsControlKeyDown()) then COE_Totem:MakeAnchorTotem(this); end - if( this.totem.isTrinket ) then + if (this.totem.isTrinket) then - if( this.totem.TrinketSlot ) then - UseInventoryItem( this.totem.TrinketSlot ); - end + if (this.totem.TrinketSlot) then + UseInventoryItem(this.totem.TrinketSlot); + end - else - local spellid = this.totem.Ranks[this.totem.MaxRank].SpellID; + else + local spellid = this.totem.Ranks[this.totem.MaxRank].SpellID; - -- check if the override key is down - -- ---------------------------------- - if( COE_Totem:RankModifierDown() ) then - spellid = this.totem.Ranks[1].SpellID; - end + -- check if the override key is down + -- ---------------------------------- + if (COE_Totem:RankModifierDown()) then + spellid = this.totem.Ranks[1].SpellID; + end - -- throw totem - -- ------------ - CastSpell( spellid, BOOKTYPE_SPELL ); - end + -- throw totem + -- ------------ + CastSpell(spellid, BOOKTYPE_SPELL); + end - end + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:ButtonStartDrag @@ -1477,32 +1435,33 @@ end -------------------------------------------------------------------]] function COE_Totem:ButtonStartDrag() - if( this:GetParent() == COETimerFrame ) then - this:GetParent():StartMoving(); + if (this:GetParent() == COETimerFrame) then + this:GetParent():StartMoving(); - -- When the Shift key is held, pickup the spell instead. - -- Additionally holding the control key while doing so - -- picks up Rank 1. - --------------------------------------------------------- - elseif( (this.totem ~= COE.NoTotem) and (not this.totem.isTrinket) and IsShiftKeyDown() ) then - local rank; - if( IsControlKeyDown() ) then - rank = 1; - else - rank = this.totem.MaxRank; - end + -- When the Shift key is held, pickup the spell instead. + -- Additionally holding the control key while doing so + -- picks up Rank 1. + --------------------------------------------------------- + elseif ((this.totem ~= COE.NoTotem) and (not this.totem.isTrinket) and + IsShiftKeyDown()) then + local rank; + if (IsControlKeyDown()) then + rank = 1; + else + rank = this.totem.MaxRank; + end - local SpellID = this.totem.Ranks[rank].SpellID; - PickupSpell( SpellID, BOOKTYPE_SPELL ); + local SpellID = this.totem.Ranks[rank].SpellID; + PickupSpell(SpellID, BOOKTYPE_SPELL); - elseif( COE_Config:GetSaved( COEOPT_FIXBAR ) == 0 and this == this.ElementFrame.AnchorTotem ) then - this:GetParent():StartMoving(); - this:GetParent().IsMoving = true; - end + elseif (COE_Config:GetSaved(COEOPT_FIXBAR) == 0 and this == + this.ElementFrame.AnchorTotem) then + this:GetParent():StartMoving(); + this:GetParent().IsMoving = true; + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:ButtonStopDrag @@ -1510,16 +1469,15 @@ end -------------------------------------------------------------------]] function COE_Totem:ButtonStopDrag() - this:GetParent():StopMovingOrSizing(); + this:GetParent():StopMovingOrSizing(); - if( this:GetParent() ~= COETimerFrame ) then - this:GetParent().IsMoving = false; - COE_Totem:UpdateFrameCoordinates(); - end + if (this:GetParent() ~= COETimerFrame) then + this:GetParent().IsMoving = false; + COE_Totem:UpdateFrameCoordinates(); + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:MakeAnchorTotem @@ -1528,33 +1486,34 @@ end Customize mode. In Active Set mode, it is also replaces the element totem in the current set -------------------------------------------------------------------]] -function COE_Totem:MakeAnchorTotem( button ) +function COE_Totem:MakeAnchorTotem(button) - local mode = COE_Config:GetSaved( COEOPT_DISPLAYMODE ); - local totem = button.totem; - local anchor = button:GetParent().AnchorTotem.totem; + local mode = COE_Config:GetSaved(COEOPT_DISPLAYMODE); + local totem = button.totem; + local anchor = button:GetParent().AnchorTotem.totem; - if( totem ~= anchor ) then - if( mode == COEMODE_ALLTOTEMS ) then - -- swap this totem with the anchor totem - -- -------------------------------------- - local swap = COE_DisplayedTotems[anchor.SpellName].Order; - COE_DisplayedTotems[anchor.SpellName].Order = COE_DisplayedTotems[totem.SpellName].Order; - COE_DisplayedTotems[totem.SpellName].Order = swap; + if (totem ~= anchor) then + if (mode == COEMODE_ALLTOTEMS) then + -- swap this totem with the anchor totem + -- -------------------------------------- + local swap = COE_DisplayedTotems[anchor.SpellName].Order; + COE_DisplayedTotems[anchor.SpellName].Order = + COE_DisplayedTotems[totem.SpellName].Order; + COE_DisplayedTotems[totem.SpellName].Order = swap; - elseif( mode == COEMODE_ACTIVESET ) then - -- replace the set totem with this one - -- ------------------------------------ - COE.TotemSets[COE_Config:GetSaved( COEOPT_ACTIVESET )][totem.Element] = totem; - end + elseif (mode == COEMODE_ACTIVESET) then + -- replace the set totem with this one + -- ------------------------------------ + COE.TotemSets[COE_Config:GetSaved(COEOPT_ACTIVESET)][totem.Element] = + totem; + end - COE_Totem:Invalidate( button.ElementFrame, true, true, true ); - COETotemFrame.Reconfigure = true; - end + COE_Totem:Invalidate(button.ElementFrame, true, true, true); + COETotemFrame.Reconfigure = true; + end end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:SetTimerText @@ -1562,99 +1521,96 @@ end associated totem has an active timer -------------------------------------------------------------------]] function COE_Totem:SetTimerText() - if( this.totem == COE.NoTotem ) then - return; - end; + if (this.totem == COE.NoTotem) then return; end - local timertext = getglobal( this:GetName() .. "Text" ); - local overlaytex = getglobal( this:GetName().. "OverlayTex" ); + local timertext = getglobal(this:GetName() .. "Text"); + local overlaytex = getglobal(this:GetName() .. "OverlayTex"); - -- show timers only in timerframe and this is a bar button? - -- --------------------------------------------------------- - if( COE_Config:GetSaved( COEOPT_FRAMETIMERSONLY ) == 1 and - this:GetParent() ~= COETimerFrame ) then - timertext:Hide(); - overlaytex:Hide(); - return; - end; + -- show timers only in timerframe and this is a bar button? + -- --------------------------------------------------------- + if (COE_Config:GetSaved(COEOPT_FRAMETIMERSONLY) == 1 and this:GetParent() ~= + COETimerFrame) then + timertext:Hide(); + overlaytex:Hide(); + return; + end - if( COE_Config:GetSaved( COEOPT_ENABLETIMERS ) == 1 ) then - if( COE_Totem:IsTimerActive( this.totem ) ) then - -- format text - -- ------------ - local time = COE_Totem:GetTimeLeft( this.totem ); - local min = math.floor( time / 60 ); - local sec = math.mod( math.floor( time ), 60 ); - local text; + if (COE_Config:GetSaved(COEOPT_ENABLETIMERS) == 1) then + if (COE_Totem:IsTimerActive(this.totem)) then + -- format text + -- ------------ + local time = COE_Totem:GetTimeLeft(this.totem); + local min = math.floor(time / 60); + local sec = math.mod(math.floor(time), 60); + local text; - if( min > 0 ) then - text = string.format( "%d:%02d", min, sec ); - else - text = sec; - end + if (min > 0) then + text = string.format("%d:%02d", min, sec); + else + text = sec; + end - -- set text - -- --------- - timertext:SetText( text ); + -- set text + -- --------- + timertext:SetText(text); - -- set the color - -- -------------- - overlaytex:SetVertexColor( 0.1, 0.1, 0.1, 0.75 ); - timertext:SetVertexColor( 1, 1, 1, 1 ); + -- set the color + -- -------------- + overlaytex:SetVertexColor(0.1, 0.1, 0.1, 0.75); + timertext:SetVertexColor(1, 1, 1, 1); - -- show text and overlay - -- ---------------------- - timertext:Show(); - overlaytex:Show(); + -- show text and overlay + -- ---------------------- + timertext:Show(); + overlaytex:Show(); - elseif( this.totem.CurCooldown > 0 ) then + elseif (this.totem.CurCooldown > 0) then - -- format text - -- ------------ - local time = COE_Totem:GetCooldownLeft( this.totem ); - local min = math.floor( time / 60 ); - local sec = math.mod( math.floor( time ), 60 ); - local text; + -- format text + -- ------------ + local time = COE_Totem:GetCooldownLeft(this.totem); + local min = math.floor(time / 60); + local sec = math.mod(math.floor(time), 60); + local text; - if( min > 0 ) then - text = string.format( "%d:%02d", min, sec ); - else - text = sec; - end + if (min > 0) then + text = string.format("%d:%02d", min, sec); + else + text = sec; + end - -- set text - -- --------- - timertext:SetText( text ); + -- set text + -- --------- + timertext:SetText(text); - -- set the color - -- -------------- - overlaytex:SetVertexColor( 1, 1, 1, 1 ); - timertext:SetVertexColor( 1, 0, 0, 1 ); + -- set the color + -- -------------- + overlaytex:SetVertexColor(1, 1, 1, 1); + timertext:SetVertexColor(1, 0, 0, 1); - -- show text and overlay - -- ---------------------- - timertext:Show(); - overlaytex:Show(); + -- show text and overlay + -- ---------------------- + timertext:Show(); + overlaytex:Show(); - else - -- if timer has just expired, deactivate it - -- if it isn't active anyway, the call doesn't hurt - -- ------------------------------------------------- --- TODO: I'm removing this as it appears entirely unnecessary to be done in this method - --COE:DebugMessage("Calling DeactivateTimer with totem: ".. this.totem.SpellName); - --COE_Totem:DeactivateTimer( this.totem ); + else + -- if timer has just expired, deactivate it + -- if it isn't active anyway, the call doesn't hurt + -- ------------------------------------------------- + -- TODO: I'm removing this as it appears entirely unnecessary to be done in this method + -- COE:DebugMessage("Calling DeactivateTimer with totem: ".. this.totem.SpellName); + -- COE_Totem:DeactivateTimer( this.totem ); - timertext:Hide(); - overlaytex:Hide(); - end - else - timertext:Hide(); - overlaytex:Hide(); - end + timertext:Hide(); + overlaytex:Hide(); + end + else + timertext:Hide(); + overlaytex:Hide(); + end end - --[[ ============================================================================================= T I M E R F R A M E @@ -1667,75 +1623,75 @@ end PURPOSE: Initializes the timer frame -------------------------------------------------------------------]] function COE_Totem:InitTimerFrame() - -- addon loaded? - -- -------------- - if( not COE.Initialized ) then - return; - end + -- addon loaded? + -- -------------- + if (not COE.Initialized) then return; end - this.UpdateTime = 0; + this.UpdateTime = 0; end - --[[ ---------------------------------------------------------------- METHOD: COE_Totem:UpdateTimerFrame PURPOSE: Updates the timer frame -------------------------------------------------------------------]] -function COE_Totem:UpdateTimerFrame( elapsed ) +function COE_Totem:UpdateTimerFrame(elapsed) - -- check if visual update is necessary - -- ------------------------------------ - this.UpdateTime = this.UpdateTime + elapsed; - if( this.UpdateTime <= COE.UpdateInterval ) then - return; - end + -- check if visual update is necessary + -- ------------------------------------ + this.UpdateTime = this.UpdateTime + elapsed; + if (this.UpdateTime <= COE.UpdateInterval) then return; end - -- set scaling - -- ------------ - this:SetScale( COE_Config:GetSaved( COEOPT_SCALING ) ); + -- set scaling + -- ------------ + this:SetScale(COE_Config:GetSaved(COEOPT_SCALING)); + local k; + local lastbutton = nil; + local count = 0; - local k; - local lastbutton = nil; - local count = 0; + for k = 1, 4 do + local button = getglobal("COETimer" .. COE_Element[k]); - for k = 1,4 do - local button = getglobal( "COETimer" .. COE_Element[k] ); + if (button.totem) then + button:ClearAllPoints(); - if( button.totem ) then - button:ClearAllPoints(); + if (lastbutton) then + if (COE_Config:GetSaved(COEOPT_DISPLAYALIGN) == COEMODE_BOX) then + if (count == 2) then + button:SetPoint("TOPRIGHT", lastbutton:GetName(), + "BOTTOMLEFT", -COEUI_BUTTONGAP, + -COEUI_BUTTONGAP); + lastbutton = button; + else + button:SetPoint("TOPLEFT", lastbutton:GetName(), + "TOPRIGHT", COEUI_BUTTONGAP, 0); + lastbutton = button; + end + elseif (COE_Config:GetSaved(COEOPT_DISPLAYALIGN) == + COEMODE_VERTICAL) then + button:SetPoint("TOPLEFT", lastbutton:GetName(), + "BOTTOMLEFT", 0, -COEUI_BUTTONGAP); + lastbutton = button; + else + button:SetPoint("TOPLEFT", lastbutton:GetName(), "TOPRIGHT", + COEUI_BUTTONGAP, 0); + lastbutton = button; + end + else + button:SetPoint("TOPLEFT", 0, 0); + lastbutton = button; + end - if( lastbutton ) then - if( COE_Config:GetSaved( COEOPT_DISPLAYALIGN ) == COEMODE_BOX ) then - if( count == 2 ) then - button:SetPoint( "TOPRIGHT", lastbutton:GetName(), "BOTTOMLEFT", -COEUI_BUTTONGAP, -COEUI_BUTTONGAP ); - lastbutton = button; - else - button:SetPoint( "TOPLEFT", lastbutton:GetName(), "TOPRIGHT", COEUI_BUTTONGAP, 0 ); - lastbutton = button; - end - elseif( COE_Config:GetSaved( COEOPT_DISPLAYALIGN ) == COEMODE_VERTICAL ) then - button:SetPoint( "TOPLEFT", lastbutton:GetName(), "BOTTOMLEFT", 0, -COEUI_BUTTONGAP ); - lastbutton = button; - else - button:SetPoint( "TOPLEFT", lastbutton:GetName(), "TOPRIGHT", COEUI_BUTTONGAP, 0 ); - lastbutton = button; - end - else - button:SetPoint( "TOPLEFT", 0, 0 ); - lastbutton = button; - end - - button:Show(); - count = count + 1; - else - -- button is not active - -- --------------------- - button:Hide(); - end - end + button:Show(); + count = count + 1; + else + -- button is not active + -- --------------------- + button:Hide(); + end + end end diff --git a/CallOfElements.lua b/CallOfElements.lua index 9d00881..32684d8 100644 --- a/CallOfElements.lua +++ b/CallOfElements.lua @@ -96,6 +96,10 @@ end PURPOSE: Handles frame events -------------------------------------------------------------------]] function COE:OnEvent(event) + if (COE.EventPrintMode) then + COE:DebugMessage("Event: " .. event); + if (arg1) then COE:DebugMessage("arg1: " .. arg1); end + end if (event == "VARIABLES_LOADED") then -- fix saved variables if this update has to do so @@ -103,14 +107,16 @@ function COE:OnEvent(event) COE:FixSavedVariables(); elseif (event == "CHAT_MSG_SPELL_SELF_BUFF") then + -- resolve Totemic Recall event if (string.find(arg1, "Mana from Totemic Recall")) then COE:DebugMessage("Totemic Recall initiating reset of timers."); COE_Totem:ResetTimers(); + + -- Resolve Totem cast event + elseif (string.find(arg1, "Totem")) then + local totem = COE_Totem:GetTotemFromText(arg1); + if (totem) then COE_Totem:ActivateTotem(totem); end end - - elseif (COE.EventPrintMode) then - COE:DebugMessage(event); - end end @@ -190,9 +196,12 @@ function COEProcessShellCommand(msg) if (msg == "" or msg == "config") then COE:ToggleConfigFrame(); - elseif (msg == "list") then + elseif (msg == "list" or msg == "help") then COE:DisplayShellCommands(); + elseif (msg == "debug") then + COE["DebugMode"] = not COE.DebugMode; + COE:Message(tostring(COE.DebugMode)); elseif (msg == "nextset") then COE_Totem:SwitchToNextSet(); @@ -255,6 +264,7 @@ function COE:DisplayShellCommands() COE:Message(COESHELL_MACRONOTE); COE:Message(COESHELL_THROWSET); COE:Message(COESHELL_ADVISED); + COE:Message(COESHELL_DEBUG); end diff --git a/Localization.lua b/Localization.lua index 1d0088b..4e54011 100644 --- a/Localization.lua +++ b/Localization.lua @@ -218,7 +218,7 @@ COEMODIFIER_NUMPAD_SHORT = "NP"; -- --------------- COESHELL_INTRO = "Available shell commands for Call Of Elements:"; COESHELL_CONFIG = "'/coe' or '/coe config' - Shows the configuration dialog"; -COESHELL_LIST = "'/coe list' - Shows this list"; +COESHELL_LIST = "'/coe list' or '/coe help' - Shows this list"; COESHELL_NEXTSET = "'/coe nexset' - Switches to the next custom totem set or the default set"; COESHELL_PRIORSET = @@ -237,3 +237,5 @@ COESHELL_MACRONOTE = "The following commands only work as macros dragged to your action bars:"; COESHELL_THROWSET = "'/coe throwset' - Throws the active totem set"; COESHELL_ADVISED = "'/coe advised' - Throws the next advised totem"; +COESHELL_DEBUG = +"'/coe debug' - Toggles debug message printing (disable by default)";