Jump to content

GUI restructuring


Recommended Posts

I've just committed a few changes to the GUI (r7214). Please let me know if anything broke :). I should probably document the changes in some way, so:

The old implementation had a single global GUI object (the CGUI class in C++) for the entire game, and loaded all the XML files and scripts into it, and the scripts hid and unhid various parts of it at various times, so it was all a big mess. The new approach is to split the GUI into a series of independent 'pages' - currently there's one for pre-game menus, one for the loading screen, one for the in-game session UI, and one for message boxes. Each page is defined by a new XML file, which just lists the other XML files to load into it.

There is a stack of currently-loaded pages. Only the page on the top of the stack is active (it receives keyboard/mouse events etc). Scripts can use the functions pushGuiPage(xmlfilename, initdata) to load a new page onto the stack, popGuiPage() to remove the current active page from the stack, and switchGuiPage(xmlfilename, initdata) to replace the entire stack with a new page. xmlfilename is relative to the binaries/data/mods/*/gui/ directory. initdata is an arbitrary JS value that gets passed to the init() function defined by the new page's scripts.

In the current collection of pages (which aren't intended to be a well-designed set, they were just the easiest way to split it) it mostly uses switchGuiPage. Only message boxes make use of the stack - various bits of code can load a new message box page, push it on the stack (it acts like a modal dialog box), and pass some callback functions in initdata to make the buttons do interesting things. It might be good to use the stack in more cases, e.g. split the single-player-game-options screen into a new page (plus maybe extra pages underneath that), at some point in the future.

One benefit of this system is that it can now support hotloading: if you edit a GUI XML or JS file, while you're running the game and have that GUI page visible, it will automatically reload the files and reinitialise the page. So you can tweak the layouts and get near-instant visual feedback, which is nice.

The other intended benefit is that it should be possible to load the session UI page inside the Atlas editor, so you can interactively playtest the game, but that's not implemented yet.

There's still a lot of XML and JS that is loaded into every single page, usually unnecessarily, since I haven't tried hard to split things into pages nicely yet - there's a lot that needs to be cleaned up, but hopefully this will help a bit.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...