Thread Tools Display Modes
05-27-11, 10:37 AM   #1
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
"Storing" functions

I just encountered a little problem and hope, someone can give me a hint:

I'm working on a ActionBar-Framework.

While setting the button's position (and size), I want to make sure, the button is not moved again (line 11&12).

lua Code:
  1. --[[ VOID noop()
  2.         This prevents the default UI from altering our stuff!
  3.     ]]
  4.     lib.noop = function() end
  5.  
  6.     --[[ VOID MoveButton(BUTTON button, INT sizeX, INT sizeY, ARRAY pos)
  7.         Moves a button (which is in use, meaning visible) to the correct position.
  8.         ARRAY pos is defined as an array which holds the position information as it is used in SetPoint()
  9.     ]]
  10.     lib.MoveButton = function(button, sizeX, sizeY, pos)
  11.  
  12.         button:ClearAllPoints()
  13.         button:SetSize(sizeX, sizeY)
  14.         button:SetPoint(unpack(pos))
  15.  
  16.         button.SetSize = lib.noop                                               -- don't do this anymore!
  17.         button.SetPoint = lib.noop                                              -- don't do this anymore!
  18.     end

Now I want to create an ingame-config, but obviously I can't set the buttons' positions again. I tried to "store" the original function and use it later, but with no success.

Code was:

lua Code:
  1. lib.buttonFunc[button:GetName()..'SetPoint'] = button.SetPoint

lib.buttonFunc is an array and of course, this code was executed before I noop'ed the functions. But the stored value has get noop'ed aswell, I guess because they are only function pointers, not real functions.

Can anybody give me a hint, how I can noop a function, but store it's functionality to use it later on?
__________________
  Reply With Quote
05-27-11, 12:12 PM   #2
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
Your buttonFunc table solution should work. Are you sure you weren't calling MoveButton on the same button twice (and overriding your first copy of SetPoint)?
____
Edit: Just realized this is a library. Do you have two copies of the embedded library running, overriding each others' hooks?

Last edited by Saiket : 05-27-11 at 12:15 PM.
  Reply With Quote
05-27-11, 12:51 PM   #3
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
lib is really just my array holding functions and porting them through the namespace...

Hm, will try again later, can't say definetely, that the function wasn't called twice...

Thx for the reply
__________________
  Reply With Quote
05-27-11, 03:17 PM   #4
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
k, it is working now... I moved the grabbing of the buttons one layer higher:

lua Code:
  1. local lib = {}
  2.     lib.buttonFuncProxy = {}
  3.  
  4.     --[[ VOID noop()
  5.         This prevents the default UI from altering our stuff!
  6.     ]]
  7.     lib.noop = function() end
  8.  
  9.     --[[ VOID MoveButton(BUTTON button, INT sizeX, INT sizeY, ARRAY pos)
  10.         Moves a button (which is in use, meaning visible) to the correct position.
  11.         ARRAY pos is defined as an array which holds the position information as it is used in SetPoint()
  12.     ]]
  13.     lib.MoveButton = function(button, sizeX, sizeY, pos)
  14.  
  15.         button:ClearAllPoints()
  16.         -- button:SetSize(sizeX, sizeY)
  17.         lib.buttonFuncProxy[button:GetName()..'SetSize'](button, sizeX, sizeY)
  18.         -- button:SetPoint(unpack(pos))
  19.         lib.buttonFuncProxy[button:GetName()..'SetPoint'](button, unpack(pos))
  20.  
  21.     end
  22.  
  23.     --[[ VOID HandleButtonBar
  24.         FRAME parent
  25.         STRING key - the string to access settings in arrays
  26.         OTHER INPUT IS DOCUMENTED at lib.HandleButton !!!
  27.     ]]
  28.     lib.HandleButtonBar = function(parent, key, sizeX, sizeY)
  29.         -- lib.debugging('HandleButtonBar() '..key..', '..settings.static.NumButtons[key]..', '..PredatorButtonsSettings[key].buttons)
  30.         local i, button, bname
  31.         for i = 1, settings.static.NumButtons[key] do
  32.             button = _G[settings.static.ButtonPrefix[key]..i]
  33.             bname = button:GetName()
  34.             if ( not lib.buttonFuncProxy[bname..'SetSize'] ) then
  35.                 lib.buttonFuncProxy[bname..'SetSize'] = button.SetSize
  36.                 button.SetSize = lib.noop                                       -- don't do this anymore!
  37.             end
  38.             if ( not lib.buttonFuncProxy[bname..'SetPoint'] ) then
  39.                 lib.buttonFuncProxy[bname..'SetPoint'] = button.SetPoint
  40.                 button.SetPoint = lib.noop                                      -- don't do this anymore!
  41.             end
  42.             if ( i <= PredatorButtonsSettings[key].buttons ) then               -- magic happening here!
  43.                 if ( i == 1 ) then
  44.                     lib.MoveButton(button,
  45.                         sizeX, sizeY,
  46.                         {'TOPLEFT', parent, 'TOPLEFT',
  47.                             PredatorButtonsSettings[key].padding,
  48.                             -PredatorButtonsSettings[key].padding
  49.                         } )
  50.                 else
  51.                     lib.MoveButton(button,
  52.                         sizeX, sizeY,
  53.                         {'TOPLEFT', parent, 'TOPLEFT',
  54.                             ( ((i-1)%PredatorButtonsSettings[key].columns)*(PredatorButtonsSettings[key].buttonSize+2*PredatorButtonsSettings[key].padding)+PredatorButtonsSettings[key].padding ),
  55.                             -( (floor((i-1) / PredatorButtonsSettings[key].columns))*(PredatorButtonsSettings[key].buttonSize+(2*PredatorButtonsSettings[key].padding))+PredatorButtonsSettings[key].padding )
  56.                         } )
  57.                 end
  58.             else
  59.                 button:ClearAllPoints()
  60.                 -- button:SetPoint('BOTTOMRIGHT', UIParent, 'TOPLEFT', -5, 5)       -- out of sight, out of mind!
  61.                 lib.buttonFuncProxy[bname..'SetPoint'](button, 'BOTTOMRIGHT', UIParent, 'TOPLEFT', -5, 5)
  62.             end
  63.         end
  64.     end

Thx for your reply Saiket, your confirmation was necessary and I think you solved it by pointing out, that maybe I'm filling the array twice!
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » "Storing" functions

Thread Tools
Display Modes

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