Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

GUI isn't an easy or simple problem, especially when you get into games and their desire to have dynamic, interesting menus.

One "easy" thing you can do is try to use middleware. There's a question on that herehere.

If you're going to roll it yourself, there are a few things I would suggest.

  • GUI elements generally have a "parent", either another GUI element or a "window", or something like that. Either by pointing up or having the parent point down means you can set state/position/etc on everything that's a child.

  • You can build GUI elements by composition. A lot of widgets have labels (pretty much all of them), and it might make sense to make the concept of a label a component or a child of your other UI elements than copy/pasting the code or trying to inherit from a base class with label functionality.

  • A lot of so-called specialized widgets are just buttons in disguise. Checkboxes are just buttons with states and special images. Radio buttons are just checkboxes that have meta-state (one and only one is active at any given time) with other radio buttons. Use this to your advantage. In one game I worked on, "checkboxes" were done with regular buttons entirely through scripting and art.

  • For your first project, consider taking the more direct route. Yes, make your actionable events delegates and assign what you need on element creation (i.e. onMouseButtonDown, onMouseButtonUp, onHover etc), but consider just hard coding what you want to happen otherwise (i.e. hover color changes, button press sounds) until you get something functional. Once you're at that point, consider making that behavior data (i.e. have a variable on button for "press sound", or maybe consider having components that your UI elements use to define behavior that you just attach to them when you create them.

  • delegates aren't that slow, you probably won't have so many widgets that it would be an issue, and menu code generally isn't that high impact anyway. I wouldn't worry too much about performance at this point in the game. Don't pick naive algorithms and profile once you get your code up and running.

GUI isn't an easy or simple problem, especially when you get into games and their desire to have dynamic, interesting menus.

One "easy" thing you can do is try to use middleware. There's a question on that here.

If you're going to roll it yourself, there are a few things I would suggest.

  • GUI elements generally have a "parent", either another GUI element or a "window", or something like that. Either by pointing up or having the parent point down means you can set state/position/etc on everything that's a child.

  • You can build GUI elements by composition. A lot of widgets have labels (pretty much all of them), and it might make sense to make the concept of a label a component or a child of your other UI elements than copy/pasting the code or trying to inherit from a base class with label functionality.

  • A lot of so-called specialized widgets are just buttons in disguise. Checkboxes are just buttons with states and special images. Radio buttons are just checkboxes that have meta-state (one and only one is active at any given time) with other radio buttons. Use this to your advantage. In one game I worked on, "checkboxes" were done with regular buttons entirely through scripting and art.

  • For your first project, consider taking the more direct route. Yes, make your actionable events delegates and assign what you need on element creation (i.e. onMouseButtonDown, onMouseButtonUp, onHover etc), but consider just hard coding what you want to happen otherwise (i.e. hover color changes, button press sounds) until you get something functional. Once you're at that point, consider making that behavior data (i.e. have a variable on button for "press sound", or maybe consider having components that your UI elements use to define behavior that you just attach to them when you create them.

  • delegates aren't that slow, you probably won't have so many widgets that it would be an issue, and menu code generally isn't that high impact anyway. I wouldn't worry too much about performance at this point in the game. Don't pick naive algorithms and profile once you get your code up and running.

GUI isn't an easy or simple problem, especially when you get into games and their desire to have dynamic, interesting menus.

One "easy" thing you can do is try to use middleware. There's a question on that here.

If you're going to roll it yourself, there are a few things I would suggest.

  • GUI elements generally have a "parent", either another GUI element or a "window", or something like that. Either by pointing up or having the parent point down means you can set state/position/etc on everything that's a child.

  • You can build GUI elements by composition. A lot of widgets have labels (pretty much all of them), and it might make sense to make the concept of a label a component or a child of your other UI elements than copy/pasting the code or trying to inherit from a base class with label functionality.

  • A lot of so-called specialized widgets are just buttons in disguise. Checkboxes are just buttons with states and special images. Radio buttons are just checkboxes that have meta-state (one and only one is active at any given time) with other radio buttons. Use this to your advantage. In one game I worked on, "checkboxes" were done with regular buttons entirely through scripting and art.

  • For your first project, consider taking the more direct route. Yes, make your actionable events delegates and assign what you need on element creation (i.e. onMouseButtonDown, onMouseButtonUp, onHover etc), but consider just hard coding what you want to happen otherwise (i.e. hover color changes, button press sounds) until you get something functional. Once you're at that point, consider making that behavior data (i.e. have a variable on button for "press sound", or maybe consider having components that your UI elements use to define behavior that you just attach to them when you create them.

  • delegates aren't that slow, you probably won't have so many widgets that it would be an issue, and menu code generally isn't that high impact anyway. I wouldn't worry too much about performance at this point in the game. Don't pick naive algorithms and profile once you get your code up and running.

Source Link
Tetrad
  • 30.1k
  • 12
  • 96
  • 143

GUI isn't an easy or simple problem, especially when you get into games and their desire to have dynamic, interesting menus.

One "easy" thing you can do is try to use middleware. There's a question on that here.

If you're going to roll it yourself, there are a few things I would suggest.

  • GUI elements generally have a "parent", either another GUI element or a "window", or something like that. Either by pointing up or having the parent point down means you can set state/position/etc on everything that's a child.

  • You can build GUI elements by composition. A lot of widgets have labels (pretty much all of them), and it might make sense to make the concept of a label a component or a child of your other UI elements than copy/pasting the code or trying to inherit from a base class with label functionality.

  • A lot of so-called specialized widgets are just buttons in disguise. Checkboxes are just buttons with states and special images. Radio buttons are just checkboxes that have meta-state (one and only one is active at any given time) with other radio buttons. Use this to your advantage. In one game I worked on, "checkboxes" were done with regular buttons entirely through scripting and art.

  • For your first project, consider taking the more direct route. Yes, make your actionable events delegates and assign what you need on element creation (i.e. onMouseButtonDown, onMouseButtonUp, onHover etc), but consider just hard coding what you want to happen otherwise (i.e. hover color changes, button press sounds) until you get something functional. Once you're at that point, consider making that behavior data (i.e. have a variable on button for "press sound", or maybe consider having components that your UI elements use to define behavior that you just attach to them when you create them.

  • delegates aren't that slow, you probably won't have so many widgets that it would be an issue, and menu code generally isn't that high impact anyway. I wouldn't worry too much about performance at this point in the game. Don't pick naive algorithms and profile once you get your code up and running.