Is my Menu Class's system bad?

Started by
2 comments, last by Tasche 11 years, 2 months ago

I have a class called Menu which I use for main menu's, other types of menus, pretty much all menus. To make a specific menu, you would define a class which inherits from it.

It starts out blank, and you add buttons to it by calling menu.addButton(). AddButton takes a position, an image address, and the buttons name. Later, whenever you check if the mouse is hovering over / clicking on a button, you call menu.checkHover(). You pass a name to checkHover(). checkHover() then sees if there are any buttons with that name and if the mouse is hovering over the button with that name.

This system is giving me a bad feeling. What do you think?

Cheers :)!

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

Advertisement

I'd do it more event/callback based.

Presumably you have some sort of window manager which knows the hit rect of your menu items.

Provide a pure virtual OnHover function which is called by the window manager when the mouse is over the window (either for a specified amount of time, or pass the time as a parameter to OnHover and let the function decide whether to handle the event yet).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

I changed my system and increased efficiency in a separate way.

However, thank you for your suggestions :)!

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

this may be too late, but unless you are doing this for educational reasons, try a GUI library, for example CEGUI (LGPL, new version MIT, iirc) or if you got tons of cash, Scaleform or something. i strongly recommend using a library for this, im talking from experience here, tried doing it all from scratch. it was painful. CEGUI is also *very* easy to setup and use, only your artist may be a bit annoyed that it isn't as WYSIWYG as one would wish (this is being worked on atm, in form of an appropriate editor, but which wont be under a lenient license...).

This topic is closed to new replies.

Advertisement