Jump to content
  • Advertisement
Sign in to follow this  
gamestupid7

[help] better structure of GUI in RPG game?

This topic is 3893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am programming a RPG game with CEGUI personally. Now i am thinking about the GUI structure in game. In CEGUI, i could subscribe event function when player interact with GUI. (press button, select item list, check button...) All of actions of player will send events to my event manager and event manager will handle all of the actions. So what's the problem here? If i want to handle all the actions about the interaction between player and GUI. I need write all the action functions and subscribe them to all of the events (of the GUI). likes: void func_startMenu_start_button(){...} void func_startMenu_option_button(){...} void func_startMenu_exit_button(){...} void func_systemMenu_ok_button(){...} void func_systemMenu_cancel_button(){...} void func_buyGUI_buy_button(){....} .... If like this, there will be a lot of functions...... The Question==> The best/better way(GUI structure) to handle the interaction between player and GUI. Any reference/links or suggestions are appreciated. Sincerely, Alan. [Edited by - gamestupid7 on March 15, 2008 12:31:20 PM]

Share this post


Link to post
Share on other sites
Advertisement
I designed a GUI for a java programming class a while ago and I encountered the same problem. My solution was a bit messy, but it worked. Basically, the event manager had a single function
void handleEvent(int id, void *data) // It was actually Object data since there are no void pointers in java
When there was an event, the event detector (whatever you want to call it) called the handleEvent function, with the id of the element that recieved the event and a pointer to some extra data. The handleEvent basically contained a huge switch/case block. To make this less messy, you could have multiple functions, such as
 void handleButtonClicked(int buttonID, int mouseX, int mouseY);
void handleTextTyped(int textboxID, char typedChar);
void handleTextClicked(int textboxID, int mouseX, int mouseY);
...

Each component would then have to be assigned an id. I used a two digit code for this. If I wanted to make a button on the first panel, it's ID would be 11. If I wanted to add another button to the same panel, it woule be 12. If I wanted to add a button to the second panel, it would be 21. You get the idea.

Hopefully this works for you.

Share this post


Link to post
Share on other sites
Quote:
Original post by AcePilot
 void handleButtonClicked(int buttonID, int mouseX, int mouseY);
void handleTextTyped(int textboxID, char typedChar);
void handleTextClicked(int textboxID, int mouseX, int mouseY);
...

Each component would then have to be assigned an id. I used a two digit code for this. If I wanted to make a button on the first panel, it's ID would be 11. If I wanted to add another button to the same panel, it woule be 12. If I wanted to add a button to the second panel, it would be 21. You get the idea.

Hopefully this works for you.


Thank for the help.
If i don't miss what you are saying, the flow will be liked this:
1. player/user clicked on button
2. send an event to event manager with button id
3. event manager process the event and ask GUI/overlay manager to find the purpose with the button id
4. GUI/overlay manager say player/user clicked the "exit" button and return to the event manager
5. event manager do the action based on the return value that get from the GUI/overlay manager

Thank for the help again.

Sincerely,

Alan.

Share this post


Link to post
Share on other sites
Quote:
If i don't miss what you are saying, the flow will be liked this:
1. player/user clicked on button
2. send an event to event manager with button id
3. event manager process the event and ask GUI/overlay manager to find the purpose with the button id
4. GUI/overlay manager say player/user clicked the "exit" button and return to the event manager
5. event manager do the action based on the return value that get from the GUI/overlay manager



Exactly. Step 3 is a pretty elegant way to do things. I just hardcoded the id's into the event manager [rolleyes]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!