View Single Post
06-25-21, 05:40 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
This is how nUI handles clicking a button during combat ( it switches display panels linked to the button ), I only maintain the addon so not all elements of the addon are fully understandable to me but I have dabbled with secure frames to fix action button issues so some of this does make some element of sense to me now. Hopefully, reading through it will give you something to help you with your own button.

Lua Code:
  1. local frame      = CreateFrame( "Frame", "nUI_InfoPanelSelector", background, "SecureFrameTemplate" );
  2. frame.button     = CreateFrame( "Button", "$parent_Button", frame, "SecureHandlerClickTemplate" );
  3.  
  4. frame.button:SetAttribute(
  5.     "_onclick",
  6.     [[
  7.         if not IsAltKeyDown() or not IsControlKeyDown() or IsShiftKeyDown() then
  8.                
  9.             if button == "LeftButton" then 
  10.                 if CurrentPanel == #PanelList then
  11.                     CurrentPanel = 1;
  12.                 else
  13.                     CurrentPanel = CurrentPanel+1;
  14.                 end
  15.             elseif button == "RightButton" then
  16.                 if CurrentPanel == 1 then
  17.                     CurrentPanel = #PanelList;
  18.                 else
  19.                     CurrentPanel = CurrentPanel-1;
  20.                 end
  21.             end
  22.        
  23.             for i=1,#PanelList do
  24.                 local frame = self:GetFrameRef( PanelList[i] );
  25.                
  26.                 if i == CurrentPanel then
  27.                     frame:Show();
  28.                 else
  29.                     frame:Hide();
  30.                 end
  31.             end
  32.         end
  33.     ]]
  34. );
  35. frame.button:SetAllPoints( frame );
  36. frame:SetAttribute( "addchild", frame.button );


Elsewhere in the code the panel list is also setup in secure mode
Lua Code:
  1. for item in pairs( rotation ) do       
  2.             local name = rotation[item].name;          
  3.             frame.button:SetAttribute( "nUI_InfoPanel"..item, name );
  4.             frame.button:SetFrameRef( name, rotation[item].frame );
  5.         end
  6.  
  7.         frame.button:Execute(
  8.             [[
  9.                 local i = 1;
  10.                
  11.                 PanelList = newtable();
  12.                
  13.                 while true do
  14.                    
  15.                     local panel_name = self:GetAttribute( "nUI_InfoPanel"..i );
  16.                    
  17.                     if not panel_name then
  18.                         break;
  19.                     end
  20.                    
  21.                     PanelList[i] = panel_name;
  22.                     i = i+1;
  23.                    
  24.                 end
  25.                
  26.                 CurrentPanel = self:GetAttribute( "state" ) or 1;
  27.             ]]
  28.         );
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 06-25-21 at 05:43 AM.
  Reply With Quote