Thread Tools Display Modes
07-27-14, 08:00 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Custom Scripts

I'm not very experience in callbacks, but is it possible to create a custom scripts for a frame which will get triggered just like the "OnShow"/"OnHide" ones but i manage what will trigger them?
  Reply With Quote
07-27-14, 09:58 AM   #2
Malakahh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 30
If I understand you correctly, you're looking to create custom events?
  Reply With Quote
07-27-14, 10:12 AM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Well. The only events you can rely on are the events provided by the API.

If there is no event in the API that is triggering whatever you need to ask for you can fall back to an OnUpdate script checking stuff every now and then.

And there is :HookScript. http://www.wowwiki.com/API_Frame_HookScript
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
07-27-14, 11:54 AM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You can fire custom events using AceEvent-3.0 or even simpler with Callbackhandler-1.0
  Reply With Quote
07-27-14, 02:33 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I have a total custom dropdown, each time the user changes it's value, i would like to update it's propesions, however there are more dropdowns created by the same template, so i need something like the OnValueChanged script for sliders.

The only workaround i managed to pull out, is to hide/show a totally irrelevant invisible frame and listen it's OnShow/OnHide. But it's sounds like a pretty dumb solution.

Last edited by Resike : 07-27-14 at 02:59 PM.
  Reply With Quote
07-27-14, 07:39 PM   #6
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Well, if you only need one event handler for one frame's event, it's simple to do it , just add one method to your frame, like :

Lua Code:
  1. ------------------------------
  2. -- Template part
  3. ------------------------------
  4. local function Fire(self, event, ...)
  5.     return type(self[event]) == "function" and self[event](self, ...)
  6. end
  7.  
  8. local function OnClick(self)
  9.     return self.Parent:Fire("OnValueChanged", self:GetID())
  10. end
  11.  
  12. function CreateDropDownMenu( ... )
  13.     local menu = CreateFrame("Frame", ...)
  14.  
  15.     -- Give it a new method
  16.     menu.Fire = Fire
  17.  
  18.     -- Create menu buttons
  19.     for i = 1, 10 do
  20.         local btn = CreateFrame("Button", nil, menu)
  21.         btn:SetID(i)
  22.         btn.Parent = menu
  23.  
  24.         btn:SetScript("OnClick", OnClick)
  25.     end
  26.  
  27.     return menu
  28. end
  29.  
  30. ------------------------------
  31. -- Test part
  32. ------------------------------
  33. local menu = CreateDropDownMenu()
  34.  
  35. function menu:OnValueChanged(value)
  36.     -- action
  37. end

Last edited by kurapica.igas : 07-27-14 at 07:50 PM.
  Reply With Quote
07-27-14, 08:32 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
I have a total custom dropdown, each time the user changes it's value, i would like to update it's propesions, however there are more dropdowns created by the same template, so i need something like the OnValueChanged script for sliders.
This seems pretty straightforward... without seeing your code (sigh) it's impossible to give you a specific solution, but I assume your template already has some way to detect when the user clicks on an item in the menu and call some function (eg. to update a value in your settings table) so why can't you just update whatever you want to update (I'm not sure what you meant there where you wrote "propesions") in that function?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Custom Scripts


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