Scripting in my project

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

Nomonkeybusiness
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Sep 09, 2009 11:20

Scripting in my project

Postby Nomonkeybusiness » Wed Sep 09, 2009 12:57

Hi! I'm new to the forum, but not all new to CEGUI.
I've been working on a moderately small project with some people from my town. The game we're making is about two years old and is starting to shape up.
It's a round-based strategy game, and now the GUI-system is getting redone...by me.
Since the gui changes a lot between different states, we need a swift and versatile solution to handeling the gui. Instead of creating a bunch of buttons and images at each InitState(),
we wan't to be able to load a premade gui-file with all the necessary data.
This shouldn't be a problem for me. The problem is with scripting the buttons. As you can imagine, we have a bunch of different buttons, all with different behaviours.
Since we are a small "novice"-studio, we have no real experience from the industry, but after some researching, I've gotten the impression that scripting is The Way To Go.
So I have some questions: Can the script-file access any code in the system, or do I have to "expose" the functions I want to use in some way?
For example: I have a button that is used to select a specific soldier in the world (Each soldier will have it's own button like this). When I push a button, I want a script-function to run, which in turn
tells the game to runt the functions to actually make that soldier the selected one.
How do I go about writing the scriptfile? Do I just open up notepad and start scribbling away, and then save it as "btnPush.lua"?

I've read the tutorials, but they really didn't provide all the answers I needed.

Regards
Christoffer

ps. Sorry if my english is bad. I'm from sweden =P

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Scripting in my project

Postby Jamarr » Wed Sep 09, 2009 13:59

I've never added lua to one of my projects, and I have very little experience writing scripts in lua. That being said, I would assume you need to expose your internal functions to lua to make them accessible via script. I believe that toLua, which I think is packaged with the SDK download, is used to automatically expose pieces of your code to lua. As far as writing scripts, as you said just open your favorite text editor and have at it - though I wouldn't be surprised if there where editors available that support lua syntax for code highlighting, etc.

Have you looked through these tutorials? They should provide enough information to get started.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Scripting in my project

Postby CrazyEddie » Wed Sep 09, 2009 19:57

Can the script-file access any code in the system,

With this, do you mean the CEGUI system, or your own, or just code in general. The lua binding we provide as part of the LuaScriptModule expose a majority of the CEGUI system - there are some things that are not exposed, though these are generally things that are not useful in scripts (such as interfaces that deal with raw pointers and such).

If you're looking to expose your own code to lua, there are various options for creating the bindings. As jamarr mentions, we use tolua++, which actually requires a 'cleaned header' file - generally called a package, the entire set of these are then parsed via a binding generator that spits out a c++ file which is compiled using your usual compiler, you then call a function that loads all the definitions and tables into your lua state.

There are other options, such as luabind which is template based and overall is more automatic; you do not need cleaned header files or anything like that, nor do you have to manually generate the binding. Pretty much exposes all of your c++ constructs can be exposed, it also gives you a good OO interface in lua, and allows subclassing and other things in a very painless manner. You may wonder if luabind is so great, why we do not use it!? Well, the first proof of concept did use it, though there were a lot of issues with compilers not being able to handle the templates and such it uses. tolua++ affords us some extra control over what and how we expose things, so we prefer this now to luabind. It's possible to mix the two, if you decide to go with luabind - there's a post on the forum somewhere that details how that can be done.

Nomonkeybusiness wrote:ps. Sorry if my english is bad. I'm from sweden =P

It's fine. A large number of so-called native English speakers do not write this well :)

Nomonkeybusiness
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Sep 09, 2009 11:20

Re: Scripting in my project

Postby Nomonkeybusiness » Fri Sep 11, 2009 11:39

Thanks for all the help. I'll definetly try tolua++. Btw, I did mean that i want to access my own code in lua, not CEGUI-code.
My project-leader has put me in charge of GUI as I may have mentioned. So I started looking at the CELayoutEditor. My plan is to write my own lookandfeel-file,
and then let the artists play around in the editor, so that we coders can focus on code. The thing is that I feel that CELayoutEditor will not obey me at all.
When I try to change the name of a button, I type in the new name, press enter, and as soon as I mark any other "component" the name is resetted.
I also wonder about setting images on a "static image" object. Is it even possible to do it through CELayoutEditor, or do I have to find the image-property in the layout-file
and manually type in the image-name?

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Scripting in my project

Postby Jamarr » Fri Sep 11, 2009 17:53

Nomonkeybusiness wrote:The thing is that I feel that CELayoutEditor will not obey me at all.
When I try to change the name of a button, I type in the new name, press enter, and as soon as I mark any other "component" the name is resetted.


Never seen this problem, though I am using an older version (0.6.0). Which version of CELayoutEditor are you using? And was it pre-compiled or did you build it yourself? I cannot imagine a significant issue like this being overlooked.

I also wonder about setting images on a "static image" object. Is it even possible to do it through CELayoutEditor, or do I have to find the image-property in the layout-file
and manually type in the image-name?


Searching will usually answer most questions: CELayoutEditor+StaticImage
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

Nomonkeybusiness
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Sep 09, 2009 11:20

Re: Scripting in my project

Postby Nomonkeybusiness » Tue Sep 22, 2009 11:50

Thanks for the help.
Now I've got a new problem. It seems that the callback function for a specific window gets called two times upon clicking it.
This is not acceptable for me, since I resize the window upon clicking, and then size back when clicking again.
Here's some code:

Code: Select all

// Subscibe event
CombatLog->subscribeEvent(CEGUI::Listbox::EventMouseClick, &CallBackManager::CombatLogPressed);


Code: Select all

static bool CombatLogPressed(const CEGUI::EventArgs &e)
{
   const CEGUI::WindowEventArgs &we = static_cast<const CEGUI::WindowEventArgs&>(e);

   CEGUI::Editbox* chatEdit = static_cast<CEGUI::Editbox*>(GuiManager::getSingletonPtr()->GetRoot()->getChild("GuiRoot")->getChild("GuiRoot/ChatEditBG"));
   
        CEGUI::Editbox* chatBox = static_cast<CEGUI::Editbox*>(GuiManager::getSingletonPtr()->GetRoot()->getChild("GuiRoot")->getChild("GuiRoot/ChatBoxBG"));

   float h = we.window->getParent()->getYPosition().d_scale;

   if(h > 0.84f && h < 0.86)
   {
      we.window->getParent()->setYPosition(CEGUI::UDim(0.65, 0));
      we.window->getParent()->setHeight(CEGUI::UDim(0.28, 0));
   } else if(h > 0.64 && h < 0.66)
   {
      we.window->getParent()->setYPosition(CEGUI::UDim(0.85, 0));
      we.window->getParent()->setHeight(CEGUI::UDim(0.14499998, 0));
   }
   return true;
}


User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Scripting in my project

Postby CrazyEddie » Tue Sep 22, 2009 13:29

It seems that the callback function for a specific window gets called two times upon clicking it.

This should not happen (obviously!). Are you sure you're not inadvertently subscribing the same handler multiple times - as it will be called once for each time you subscribe :)

CE.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 6 guests