Making simple menu's in a game

I am making a little tile based game, nothing big and complicated or
anything. But I want to start making a basic menu system for it and I
have never really done it before. What would the general code structure
be for a menu system?

So far I have made a menu class whos goal is to keep track of buttons
and other objects on the menu and draw the whole menu onto a surface
which can be fetched from one of its methods… it works like this…

menu coolmenu
// we add all the elements to the menu
coolmenu.addbutton
coolmenu.addbutton
coolmenu.addbutton
// this gets passed the on screen location, size in tiles of the menu
and background color. Then it draws the menu onto a surface held in the
class.
tileselectmenu.build
// would be used to move the menu around the screen
tileselectmenu.move
// gets passed your display or other surface you want to render it to to
finally draw it somewhere.
tileselectmenu.draw (screen);

this is the actual class declaration to give you a general idea

class menu
{
public:
menu ();
~menu ();
int build (unsigned short tx, unsigned short ty, unsigned char r,
unsigned char g, unsigned char b, unsigned char a,SDL_Surface*
tileset0);
int draw (SDL_Surface* screen);
int move (int x, int y);
int addbutton (unsigned short xrel, unsigned short yrel, unsigned short
w, unsigned short h, SDL_Rect surface_rect, SDL_Surface*
buttonsurface); //returns the button number
int removebutton (int num);
int addtext (unsigned short xrel, unsigned short yrel, const char*
text);
int removetext ();
int checkcollisions (); // this is only a stub so far but it would
return mabe a pointer to the element or button or something that it
collided on? or perhaps just a number… i dnno.
SDL_Surface* getsurface ();

private:
SDL_Surface* surface;
button buttons[MAXBUTTONELEMENTS];
xy loc;
};

So my question is… is this generally how you go about making a menu
system? Any sugguestions about how I should approach it? How would
something like dragging work? (like picking up an item out of one menu
and putting it in annother).

elements I want to add would be buttons, dragable items, and a text
window with a text entry at the bottom.

thanks.–
Matt Pruett <@Matt_Pruett>

So my question is… is this generally how you go about making a menu
system? Any sugguestions about how I should approach it?

I done a menu, with options and so one, but as i needed a lot of different
ui objects (and will need a lot in my game), I wrote my own gui interface
(buttons, list boxes, check buttons, textfields, …), but ow man ! it was a
lod of work and headaches :stuck_out_tongue:

How would something like dragging work? (like picking up an item out of one

menu
and putting it in annother).

Ow, with my menu, i just can’t imagine :stuck_out_tongue:
Simply look when the mouse is pressed on the oject and moved while being
pressed, then follow the mouse movment and look if thw place the mouse were
released is over another object.

elements I want to add would be buttons, dragable items, and a text

window with a text entry at the bottom.

OK, I really think u souldn’t do it like i done ;)–

P.O.M.P.E.I. du 47-20

i was going to do something like this for a game, but decided against it.

the menu system would be re complex than the program!

instead, i made a java program, wich has lots of built in stuff for that
whenever the menu is required, a system(“executable.jar”); was called.

the menu program writes settings to a file that can be parsed by the program

this really depends on what your program actually does though…

most games have a setup menu, but are you talking about using the menu
as part of the user interface of the game( like Civ III or something )

this really depends on what your program actually does though…

Yes, that’s really true ! And also on what you need in your menu.

most games have a setup menu, but are you talking about using the menu

as part of the user interface of the game( like Civ III or something )

In a certain way yes, but i mean in the game (I make a realtime-strategy
game) I will use a tab widget :open_mouth: and a lot of buttons, progress bars and so
one and, yes, use the options menu in the game.
But I also wrote such a gui because my menu is complex, a bit like Age of
Empires 2–

P.O.M.P.E.I. du 47-20