Page 1 of 1

What's the meaning of PushButton's "onClick" Property ?

Posted: Sat Jan 30, 2010 06:03
by chenltm
I saw this at TorchLight's bottomhud.layout:
<Window Type="GuiLook/ImageButton" Name="StatsButton" >
......
<Property Name="onClick" Value="guiToggleStats"/>

The property "onClick" Can't be find at the wiki's PushBtton Properties but it can be used without any error on log.
I've written a funtion named "guiToggleStats" , onfortunately it can not work with the button when it's clicked.

I'd wish to know what this "onClick" means and how could it be used.

Thanks for reading.

Re: What's the meaning of PushButton's "onClick" Property ?

Posted: Sat Jan 30, 2010 09:41
by CrazyEddie
Hi,

There is no "onClick" property in the basic CEGUI, which means it's a property added by the Torchlight developers, most likely as a means of attaching functions or scripts to actions (as an aside to this, there also exists an <Event> tag for layout XML that serves a similar purpose, though perhaps not in a way the Torchlight devs needed, so they added the property instead).

So that covers what you probably already knew ;) The issues as to why your own function does not get called in response to the click is best answered by the Torchlight guys, though I guess that perhaps they have some requirement as to the way that functions are registered within the game. For example, perhaps they have a table that contains all the valid functions or function names, and new or replacement functions would need to be added to this table in some way? Can't know for sure, just a guess :)

CE.

Re: What's the meaning of PushButton's "onClick" Property ?

Posted: Sun Jan 31, 2010 01:42
by chenltm
:hammer: Thanks,deer CE.
I also thought they do some changes .But when I found that it can be worked with the code from www.cegui.org ,I can't be sure .
Now I know the truth and wont waste time to try to use it directly ,though I've waste two days. :cry:

Thank you very much. :rofl:

Re: What's the meaning of PushButton's "onClick" Property ?

Posted: Sun Jan 31, 2010 13:27
by scriptkid
Hi,

You can fairly easy work around their setup with the 'pristine' cegui code by using an ordinary click handler. Something like:

Code: Select all

// Subscribe handler that toggles the gui stats
WindowManager::getSingleton().getWindow("StatsButton")->
  subscribeEvent(PushButton::EventClicked, Event::Subscriber(&MyApp::handleToggleStats, this));


And as an implementation:

Code: Select all

bool MyApp::handleToggleStats(const CEGUI::EventArgs&)
{
    // toggle
   
    // event was handled
    return true;
}


To me, it looks like the devs register a global event, and then inspect that onClick property from their generic click handler. This way (using the layout) the gui designer(s) don't have to poke any source code :)

Re: What's the meaning of PushButton's "onClick" Property ?

Posted: Wed Feb 03, 2010 06:14
by chenltm
:D Thanks,scriptkid.

I've found out a way just as you said.
It can work !
Now I'm trying to use lua script. I thought it's more efficient for debugging. :rofl:


Forgive my poor english please. :cry: