GUI and UniGUI coding
19 years 6 months ago #18434
by Joco
GUI and UniGUI coding was created by Joco
This thread is to document my learnings as I brave the arcane world which is EoC POG GUI development. Specifically with respect to UniGUI.
Of course if anyone has information that they would like to contribute, then please drop it in here.
Otherwise stay tuned for specific info over the next few days.
Cheers,
Joco.
Of course if anyone has information that they would like to contribute, then please drop it in here.
Otherwise stay tuned for specific info over the next few days.
Cheers,
Joco.
Please Log in or Create an account to join the conversation.
19 years 6 months ago #12957
by Joco
Replied by Joco on topic GUI and UniGUI coding
General EoC GUI Concepts
All controls are considered windows. Buttons, listboxes, scrollbars, text areas etc are all windows.
Windows accept events. You can link/wire pog functions to many of these events. Such functions must be exported functions with no parameters. This means you need to gain a handle to the control firing the event through code. The standard approach is usually along the lines of:
Layout
You lay your controls out using frame co-ordinates. However you can also use use windows as a means to group controls into logical chunks. The radio buttons take this a stage further in that they use the window they are grouped to drive their selection behaviour. So each group of radio buttons must be in there in there own layout window to which they are parented.
There are some specialist layout windows provided. Such as the splitter window. See the POG GUI help file for further details.
All controls are considered windows. Buttons, listboxes, scrollbars, text areas etc are all windows.
Windows accept events. You can link/wire pog functions to many of these events. Such functions must be exported functions with no parameters. This means you need to gain a handle to the control firing the event through code. The standard approach is usually along the lines of:
Code:
MyButtonPushed()
{
hwindow button = GUI.FocusedWindow();
// do things from here
}
Layout
You lay your controls out using frame co-ordinates. However you can also use use windows as a means to group controls into logical chunks. The radio buttons take this a stage further in that they use the window they are grouped to drive their selection behaviour. So each group of radio buttons must be in there in there own layout window to which they are parented.
There are some specialist layout windows provided. Such as the splitter window. See the POG GUI help file for further details.
Please Log in or Create an account to join the conversation.
19 years 6 months ago #12958
by Shane
Seriously; go slow and work item by item. When I built the GUI's for the Sandbox I tried to put everything on the screen at once my first try (reasoning that I could test multiple things at one time). Of course I ended up with a jumbled mess which took a week to sort out. If I had to do it all over again I'd place a button... get it right... then move on to the next.
Replied by Shane on topic GUI and UniGUI coding
Drink lots of coffee. And when you start pulling your hair out go for a walk.Of course if anyone has information that they would like to contribute, then please drop it in here.
Seriously; go slow and work item by item. When I built the GUI's for the Sandbox I tried to put everything on the screen at once my first try (reasoning that I could test multiple things at one time). Of course I ended up with a jumbled mess which took a week to sort out. If I had to do it all over again I'd place a button... get it right... then move on to the next.
Please Log in or Create an account to join the conversation.
- GrandpaTrout
- Offline
- King of Space
19 years 6 months ago #12959
by GrandpaTrout
Replied by GrandpaTrout on topic GUI and UniGUI coding
When creating lists that need to be updated, put a parent window under them that you can delete. This causes all child windows to delete and avoids some bugs. The windows are simple and they create and destroy very quickly. The location finder code has several good examples.
See this note written in the Location Finder code:
Globals are used to communicate between all the event functions. To keep from flooding the save game files with useless global handles, use the GA_NoSave flag when creating globals. For Example:
See this note written in the Location Finder code:
Code:
// Set a global for the window so we can delete it when we re-create this screen.
// Note: Originally I was simply going to remove all the buttons from the list
// box and create a new list of buttons when changing system.
// Unfortunately, the scrollbar wouldn't reset and the list box wouldn't
// scroll properly. I then tried to delete the list box and re-create it.
// Unfortunately that crashed the game, so in the end whenever the system
// is changed the entire location window, along with its child windows are
// is deleted and re-created.
Globals are used to communicate between all the event functions. To keep from flooding the save game files with useless global handles, use the GA_NoSave flag when creating globals. For Example:
Code:
Global.CreateSet("gt_etrade_station_set", GA_Write|GA_NoSave, generate_trade_set());
Please Log in or Create an account to join the conversation.
19 years 6 months ago #12963
by Joco
Replied by Joco on topic GUI and UniGUI coding
Another approach to the global variables that is worth considering is attaching data directly to the control/window using the Object package.
I would presume that when the control is removed the associated attributes get auto cleaned for you. The global var approach will require you to explicitly clean things up.
I would presume that when the control is removed the associated attributes get auto cleaned for you. The global var approach will require you to explicitly clean things up.
Please Log in or Create an account to join the conversation.
- GrandpaTrout
- Offline
- King of Space
19 years 6 months ago #12964
by GrandpaTrout
Replied by GrandpaTrout on topic GUI and UniGUI coding
Yes, that is a good point. And it fits well with your example. The standard way to handle lists of items (such as a list of cargo objects the player will pick from) is to attach the object directly to the button. Then inside the button event function, you can retrieve the object
Code:
MyButtonPushed()
{
hwindow button = GUI.FocusedWindow();
hcargo cargo = Object.HandleProperty(button,"MyCargo");
// do things from here
}
Please Log in or Create an account to join the conversation.