Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


- - - - -

XML and angelscript UI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 greeniekin   Members   -  Reputation: 153

Like
0Likes
Like

Posted 04 September 2012 - 11:00 PM

I have created an xml ui library and I originally was going to link v8 up to it so it kind of works like html. Though v8 has issues with mingw and I always planed to use Angel-script for everything else.

The problem is I was planning to have separate script file the defined behavior of different elements. Which is something I always would have liked in html. Of course there would be a script in each xml ui document for the specific needs of that page like changing settings.

I am stuck on how I would implement scripts for each xml element. It seems like the game example is kind of what I want but I have no idea how I could pass callback functions out of a as script and into c++ to be called later by some c++. It would need to be specific to each object.

For example(not necessarily exactly like this)
class Dialog: IController
{
const ElementObj @self;
const ElementObj @button;
Dialog(ElementObj @obj)
{
// Keep the owner for later reference
@self = obj;
button = document.create("button");
self.append(button);
button.addEvent(@self.ClickCallback,"click");
}

void ClickCallback(ElementObj @element)
{
self.setProperty("backgroundColor","red");
}
}


Also any other ideas about this general problem and what is the best way to implement it would be much appreciated.

Edited by greeniekin, 04 September 2012 - 11:07 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 05 September 2012 - 08:16 AM

It's currently not possible to take the address of a class method, so doing it exactly how you wrote it will not work. In a future version of AngelScript I'll add support for taking the address of class methods (probably with something similar to delegates in C#), but until then you have two different alternatives:

1. Use global functions as event handlers. The global function can receive the object pointer and call the desired class method.

2. Inform the name of the class method, and then the application can determine the correct method to call with asIObjectType::GetMethodByName.


I really can't say what the best way is, it will mostly depend on your needs and preferred ways of doing things. However if I were you I would try to provide a more flexible solution. Most of the event handlers that you'll tie to the xml nodes probably won't do much more than call a single function from the application, so implementing a full script class just to be able to bind one of the class methods as the event handlers is overkill. On the other hand, in some cases you'll likely have need for a more a complex implementation that a single function cannot do.

I would probably do it something like this:

<doc>
  <button text="simple button" onClick="StartGame();" />
  <button text="animated button" controller="ButtonAnimator" />
</doc>

The onClick attribute has an inline script that can be executed directly with something similar to the ExecuteString helper function.

The controller attribute in the second button gives the name of the script class that will be instanciated to control the animation of the button. That controller could be implemented similarly to your own example.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 greeniekin   Members   -  Reputation: 153

Like
0Likes
Like

Posted 05 September 2012 - 08:51 PM

Thanks a lot Andreas.

I will probably have the features you mentioned as it makes writing xml easier. Though I still want to be able to make events like I mentioned as-well.

It sounds like I can do it with a function like

[source lang="java"]button.addEvent(self,"myClickCallback","click");[/source]

Which sounds great and pretty much functionally the same as what i wanted.

#4 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 06 September 2012 - 08:12 AM

Yes, that should work well. The only drawback is that you don't have a compile time check for the existance of the method, but that should just be a minor issue.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS