Menu System
Folks,
I am trying to create a custom menu system for my game and i was hoping for some ideas on how to implement.
What I have is a series of menu choices (in the form of buttons on the left side of the screen). When the user click a button, the buttons change into a new menu as so on.
However, my question is in how to implement this. Do I create a series of functions to handle this
e.g.
function menu1
{
if button1 is pressed
menu2
}
function menu2
{
if esc is pressed
menu1
}
This seems like an easy way to implement, but a little cumbersome and not to easy to make any changes later on.
I just want to get your folks opinions on how you would do this. If it matters, I am using C++
Thanks,
Mike Hocking
I did a little utility I once made like this..
There is a list (Array) of structures (User-Defined-Types in VB, Structures in C/++). Each item has these properties...
(I''ve written this in C and VB, for friendliness purposes. Anyone who''s seen either or both will understand quick enough.)
CHAR mScreen As Byte
CHAR* mCaption As String * 16
CHAR mIcon As Byte
CHAR cAction As Byte
INT cData As Integer
mScreen - Screen the item belongs to. 0 to 255.
mCaption - Text label.
mIcon - Index to an icon.
cAction - Index to an on-click action. (I''ve got some constants for this)
cData - Extra data for the action.
Now, you keep a system variable called cScreen.
When cScreen changes, you create a list of items on the current screen by going through the complete list, and adding those items with a matching mScreen value.
Now, you simply go through the current-screen list every update, and draw only the items there. And as far as changing menus goes...
ON CLICKONMENU...
IF cAction =...
ACTION_CHANGEMENU, THEN cScreen = cData
ACTION_RETURNTOGAME, THEN HideMenu
ACTION_..., THEN... you get the point.
Hope this helps!
There is a list (Array) of structures (User-Defined-Types in VB, Structures in C/++). Each item has these properties...
(I''ve written this in C and VB, for friendliness purposes. Anyone who''s seen either or both will understand quick enough.)
CHAR mScreen As Byte
CHAR* mCaption As String * 16
CHAR mIcon As Byte
CHAR cAction As Byte
INT cData As Integer
mScreen - Screen the item belongs to. 0 to 255.
mCaption - Text label.
mIcon - Index to an icon.
cAction - Index to an on-click action. (I''ve got some constants for this)
cData - Extra data for the action.
Now, you keep a system variable called cScreen.
When cScreen changes, you create a list of items on the current screen by going through the complete list, and adding those items with a matching mScreen value.
Now, you simply go through the current-screen list every update, and draw only the items there. And as far as changing menus goes...
ON CLICKONMENU...
IF cAction =...
ACTION_CHANGEMENU, THEN cScreen = cData
ACTION_RETURNTOGAME, THEN HideMenu
ACTION_..., THEN... you get the point.
Hope this helps!
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement