diff --git a/TDButtons.lua b/TDButtons.lua index ed2a5b1..7496a43 100644 --- a/TDButtons.lua +++ b/TDButtons.lua @@ -2,48 +2,81 @@ local TDButton_Spells = {}; local TDButton_Flags = {}; local TDButton_SpellsGlowing = {}; +TDButton_FramePool = {}; +TDButton_Frames = {}; + +function TDButton_CreateOverlay(parent, id, texture, r, g, b) + local frame = tremove(TDButton_FramePool); + if not frame then + frame = CreateFrame('Frame', 'TDButton_Overlay_' .. id, parent); + else +-- frame:SetAttribute('name', 'TDButton_Overlay_' .. id); + end + + frame:SetParent(parent); + frame:SetFrameStrata('HIGH'); + frame:SetPoint('CENTER', 0, 0); + frame:SetWidth(parent:GetWidth() * 1.4); + frame:SetHeight(parent:GetHeight() * 1.4); + + local t = frame.texture; + if not t then + t = frame:CreateTexture('GlowOverlay', 'OVERLAY'); + t:SetTexture(texture or TDDps_Options_GetTexture()); + t:SetBlendMode('ADD'); + frame.texture = t; + end + + t:SetAllPoints(frame); + t:SetVertexColor( + r or TDDps_Options.highlightColor.r, + g or TDDps_Options.highlightColor.g, + b or TDDps_Options.highlightColor.b, + TDDps_Options.highlightColor.a + ); + + tinsert(TDButton_Frames, frame); + return frame; +end + +function TDButton_DestroyAllOverlays() + local frame; + for key, frame in pairs(TDButton_Frames) do + frame:GetParent().tdOverlays = nil; + frame:ClearAllPoints(); + frame:Hide(); + frame:SetParent(UIParent); + frame.width = nil; + frame.height = nil; + end + for key, frame in pairs(TDButton_Frames) do + tinsert(TDButton_FramePool, frame); + TDButton_Frames[key] = nil; + end +end ---------------------------------------------- -- Show Overlay on button ---------------------------------------------- -function TDButton_Glow(self, id, r, g, b, texture) - if (self.tdOverlays and self.tdOverlays[id]) then - self.tdOverlays[id]:Show(); +function TDButton_Glow(button, id, r, g, b, texture) + if button.tdOverlays and button.tdOverlays[id] then + button.tdOverlays[id]:Show(); else - if not self.tdOverlays then - self.tdOverlays = {}; + if not button.tdOverlays then + button.tdOverlays = {}; end - texture = texture or TDDps_Options_GetTexture(); - self.tdOverlays[id] = CreateFrame('Frame', 'TDButton_Overlay_' .. id, UIParent); - - self.tdOverlays[id]:SetParent(self); - self.tdOverlays[id]:SetFrameStrata('HIGH') - self.tdOverlays[id]:SetWidth(self:GetWidth() * 1.4) - self.tdOverlays[id]:SetHeight(self:GetHeight() * 1.4) - - local t = self.tdOverlays[id]:CreateTexture(nil, 'OVERLAY') - t:SetTexture(texture) - t:SetBlendMode('ADD'); - t:SetAllPoints(self.tdOverlays[id]); - t:SetVertexColor( - r or TDDps_Options.highlightColor.r, - g or TDDps_Options.highlightColor.g, - b or TDDps_Options.highlightColor.b, - TDDps_Options.highlightColor.a - ); - self.tdOverlays[id].texture = t; - self.tdOverlays[id]:SetPoint('CENTER',0,0); - self.tdOverlays[id]:Show(); + button.tdOverlays[id] = TDButton_CreateOverlay(button, id, texture, r, g, b); + button.tdOverlays[id]:Show(); end end ---------------------------------------------- -- Hide Overlay on button ---------------------------------------------- -function TDButton_HideGlow(self, id) - if (self.tdOverlays[id]) then - self.tdOverlays[id]:Hide(); +function TDButton_HideGlow(button, id) + if button.tdOverlays and button.tdOverlays[id] then + button.tdOverlays[id]:Hide(); end end @@ -53,6 +86,7 @@ end function TDButton_Fetch() TDButton_GlowClear(); TDButton_Spells = {}; + TDButton_Flags = {}; TDButton_SpellsGlowing = {}; local isBartender = IsAddOnLoaded('Bartender4'); local isElv = IsAddOnLoaded('ElvUI'); @@ -153,7 +187,7 @@ end ---------------------------------------------- function TDButton_Dump() for k, button in pairs(TDButton_Spells) do - print(k, button:GetName()); + print(k, button); end end @@ -247,20 +281,4 @@ function TDButton_GlowClear() TDButton_SpellsGlowing[spellName] = 0; end end -end - ----------------------------------------------- --- Clear all spell glows ----------------------------------------------- -function TDButton_ClearAll() --- for spellName, v in pairs(TDButton_SpellsGlowing) do --- if v == 1 then --- for k, button in pairs(TDButton_Spells[spellName]) do --- for k2, id in pairs(button.tdOverlays) do --- button.tdOverlays[k2]:Hide(); --- end --- end --- TDButton_SpellsGlowing[spellName] = 0; --- end --- end end \ No newline at end of file diff --git a/TDDps.lua b/TDDps.lua index f328389..a16cbec 100644 --- a/TDDps.lua +++ b/TDDps.lua @@ -15,15 +15,22 @@ _tdError = '|cFFF0563D'; _tdSuccess = '|cFFBCCF02'; local _DPS_time = 0; -local TDDps_Frame = CreateFrame('frame'); +local TDDps_Frame = CreateFrame('Frame', 'TDDps_Frame'); TDDps_Frame.rotationEnabled = false; ---------------------------------------------- -- Disable dps addon functionality ---------------------------------------------- function TDDps_DisableAddon() + if _TD['DPS_Enabled'] == 0 then + return; + end + TDButton_DestroyAllOverlays(); + print(_tdInfo .. TDDpsName .. ': Disabling'); TDDps_Frame:SetScript('OnUpdate', nil); - TDButton_ClearAll(); + DPS_Skill = nil; + TDDps_Frame.rotationEnabled = false; + _TD['DPS_Enabled'] = 0; end ---------------------------------------------- @@ -33,7 +40,7 @@ function TDDps_InitAddon() TDDps_Frame:Show(); TDDps_Frame:RegisterEvent('PLAYER_TARGET_CHANGED'); - TDDps_Frame:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED'); + TDDps_Frame:RegisterEvent('PLAYER_TALENT_UPDATE'); TDDps_Frame:RegisterEvent('PLAYER_REGEN_DISABLED'); TDDps_Frame:RegisterEvent('PLAYER_REGEN_ENABLED'); @@ -46,8 +53,6 @@ end -- Enable dps addon functionality ---------------------------------------------- function TDDps_EnableAddon(mode) - TDDps_DisableAddon(); - print(_tdInfo .. TDDpsName .. ': Enabling'); if _TD['DPS_NextSpell'] == nil then @@ -98,12 +103,11 @@ function TDDps_OnEvent(self, event) else TDDps_InvokeNextSpell(); end - elseif event == 'ACTIVE_TALENT_GROUP_CHANGED' then - TDDps_LoadModule(); end end - if event == 'PLAYER_REGEN_DISABLED' and TDDps_Options.onCombatEnter - and not TDDps_Frame.rotationEnabled then + if event == 'PLAYER_TALENT_UPDATE' then + TDDps_DisableAddon(); + elseif event == 'PLAYER_REGEN_DISABLED' and TDDps_Options.onCombatEnter and not TDDps_Frame.rotationEnabled then print(_tdSuccess .. TDDpsName .. ': Auto enable on combat!'); TDDps_Frame.rotationEnabled = true; TDDps_LoadModule(); @@ -130,7 +134,6 @@ end -- Load appropriate addon for class ---------------------------------------------- function TDDps_LoadModule() - TDDps_Frame.rotationEnabled = true; local class = UnitClass('player'); diff --git a/TDDps.toc b/TDDps.toc index ea19756..3654018 100644 --- a/TDDps.toc +++ b/TDDps.toc @@ -1,6 +1,6 @@ ## Title: TDDps ## Notes: Rotation helper framework. -## Version: 1.2 +## Version: 1.3 ## Author: Kaminari ## Interface: 62000 ## SavedVariables: TDDps_Options diff --git a/TDHelper.lua b/TDHelper.lua index 8d8077a..0d1ce2b 100644 --- a/TDHelper.lua +++ b/TDHelper.lua @@ -70,7 +70,7 @@ end ---------------------------------------------- function TD_EndCast() local t = GetTime(); - local c = t*1000; + local c = t * 1000; local spell, _, _, _, _, endTime = UnitCastingInfo('player'); local gstart, gduration = GetSpellCooldown(_GlobalCooldown); local gcd = gduration - (t - gstart); diff --git a/TDSettings.lua b/TDSettings.lua index c30564a..6cb5b9d 100644 --- a/TDSettings.lua +++ b/TDSettings.lua @@ -9,8 +9,8 @@ TDDps_textures = { }; TDDps_Options = { - enabled = false, - onCombatEnter = false, + enabled = true, + onCombatEnter = true, texture = '', customTexture = '', highlightColor = { @@ -22,15 +22,12 @@ TDDps_Options = { TDDps_Temp = {}; function TDDps_Options_GetTexture() --- if TDDps_Temp.finalTexture then return TDDps_Temp.finalTexture; end - if TDDps_Options.customTexture ~= '' and TDDps_Options.customTexture ~= nil then TDDps_Temp.finalTexture = TDDps_Options.customTexture; return TDDps_Temp.finalTexture; end TDDps_Temp.finalTexture = TDDps_textures[TDDps_Options.texture]; - if TDDps_Temp.finalTexture == '' or TDDps_Temp.finalTexture == nil then TDDps_Temp.finalTexture = 'Interface\\Cooldown\\ping4'; end