Thread Tools Display Modes
Prev Previous Post   Next Post Next
03-26-16, 11:09 AM   #1
Sharji
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2015
Posts: 14
Reusing frames the proper way

Hi

I have a wierd bug with my addon and I have really no idea how to fix it. First how it works:
Once you get to combat addon scans your action bars and remebers them by spell that are on specific button. If external module (ex. TDDps_Warlock) calls for a glowing a button, main addon (TDDps) creates overlay on specific button spell (ex Immolate) and shows a glow on it. Everything works EXCEPT changing specializations.

I am listening on 'PLAYER_TALENT_UPDATE' event and calling TDDps_DisableAddon();. Enable/disable/init sequence is like this:

Lua Code:
  1. ----------------------------------------------
  2. -- Disable dps addon functionality
  3. ----------------------------------------------
  4. function TDDps_DisableAddon()
  5.     if _TD['DPS_Enabled'] == 0 then
  6.         return;
  7.     end
  8.     TDButton_DestroyAllOverlays();
  9.     print(_tdInfo .. TDDpsName .. ': Disabling');
  10.     TDDps_Frame:SetScript('OnUpdate', nil);
  11.     DPS_Skill = nil;
  12.     TDDps_Frame.rotationEnabled = false;
  13.     _TD['DPS_Enabled'] = 0;
  14. end
  15.  
  16. ----------------------------------------------
  17. -- Initialize dps addon functionality
  18. ----------------------------------------------
  19. function TDDps_InitAddon()
  20.     TDDps_Frame:Show();
  21.  
  22.     TDDps_Frame:RegisterEvent('PLAYER_TARGET_CHANGED');
  23.     TDDps_Frame:RegisterEvent('PLAYER_TALENT_UPDATE');
  24.     TDDps_Frame:RegisterEvent('PLAYER_REGEN_DISABLED');
  25.     TDDps_Frame:RegisterEvent('PLAYER_REGEN_ENABLED');
  26.  
  27.     TDDps_Frame:SetScript('OnEvent', TDDps_OnEvent);
  28.  
  29.     print(_tdInfo .. TDDpsName .. ': Initialized');
  30. end
  31.  
  32. ----------------------------------------------
  33. -- Enable dps addon functionality
  34. ----------------------------------------------
  35. function TDDps_EnableAddon(mode)
  36.     print(_tdInfo .. TDDpsName .. ': Enabling');
  37.    
  38.     if _TD['DPS_NextSpell'] == nil then
  39.         print(_tdError .. TDDpsName .. ': No addon selected, cannot enable');
  40.         return;
  41.     end
  42.    
  43.     if _TD['DPS_Enabled'] == 1 then
  44.         return;
  45.     end
  46.    
  47.     _TD['DPS_Mode'] = mode;
  48.  
  49.     TDButton_Fetch();
  50.    
  51.     if _TD['DPS_OnEnable'] then
  52.         _TD['DPS_OnEnable']();
  53.     end
  54.  
  55.     TDDps_Frame:SetScript('OnUpdate', TDDps_OnUpdate);
  56.    
  57.     _TD['DPS_Enabled'] = 1;
  58.     print(_tdSuccess .. TDDpsName .. ': Enabled');
  59. end

Event system seems to be working fine. I think I have a problem with reusing frames becasue when i change specialization and enter combat 'PLAYER_REGEN_DISABLED' some wierd things are going. Spells are either not overlaying or some random spells are.

Here is my reusing frames system:

Lua Code:
  1. TDButton_FramePool = {};
  2. TDButton_Frames = {};
  3.  
  4. function TDButton_CreateOverlay(parent, id, texture, r, g, b)
  5.     local frame = tremove(TDButton_FramePool);
  6.     if not frame then
  7.         frame = CreateFrame('Frame', 'TDButton_Overlay_' .. id, parent);
  8.     else
  9.         frame:SetAttribute('name', 'TDButton_Overlay_' .. id);
  10.     end
  11.  
  12.     frame:SetParent(parent);
  13.     frame:SetFrameStrata('HIGH');
  14.     frame:SetPoint('CENTER', 0, 0);
  15.     frame:SetWidth(parent:GetWidth() * 1.4);
  16.     frame:SetHeight(parent:GetHeight() * 1.4);
  17.  
  18.     local t = frame.texture;
  19.     if not t then
  20.         t = frame:CreateTexture('GlowOverlay', 'OVERLAY');
  21.     end
  22.  
  23.     t:SetTexture(texture or TDDps_Options_GetTexture());
  24.     t:SetBlendMode('ADD');
  25.     t:SetAllPoints(frame);
  26.  
  27.     t:SetVertexColor(
  28.         r or TDDps_Options.highlightColor.r,
  29.         g or TDDps_Options.highlightColor.g,
  30.         b or TDDps_Options.highlightColor.b,
  31.         TDDps_Options.highlightColor.a
  32.     );
  33.     frame.texture = t;
  34.  
  35.     tinsert(TDButton_Frames, frame);
  36.     return frame;
  37. end
  38.  
  39. function TDButton_DestroyAllOverlays()
  40.     local frame;
  41.     for key, frame in pairs(TDButton_Frames) do
  42.         frame:Hide();
  43.     end
  44.     for key, frame in pairs(TDButton_Frames) do
  45.         tinsert(TDButton_FramePool, frame);
  46.         TDButton_Frames[key] = nil;
  47.     end
  48. end

Any idea what I might be doing wrong here?
  Reply With Quote
 

WoWInterface » Developer Discussions » General Authoring Discussion » Reusing frames the proper way


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off