Game states can be stacked, but only the topmost state will get the Update() and Draw() calls.
In the design I envision, the menu is opened by the active state (because it is part of the state - for example, the 'save game' button has its callback in the running GameplayState). I'm generally not using the game state system for popups and such, but
maybe there are valid cases where this makes sense?
- One problem when adding this feature would be with distributing input to the different states. The states stacked below the current would have to be notified that they're now in the background (scenario: game uses event-based input, thus has to disconnect
the events or ignore them while the player is in the popup menu)
- Developers expecting the current behavior might just stack several game states (eg. my current game stacks MenuState -> GameplayState -> ConstructBuildingsState) and be unaware that the states below are still wasting time rendering themselves - or
an unlucky mouse click might have the MenuState quit the game :)
How do you think this should be implemented?
- I could add an optional parameter to the Push() method (bool isPopup or something) that tells the game state manager that the state below should continue to be updated and drawn. Should the game state being put in the background still receive the Pause()
and Resume() methods in this case?
- Another option would be to have pop-up game states implement a special interface or inherit from a special PopupGameState class. This would introduce more complexity to the system, however, and disallow using one game state both as a popup and standalone
(but is there even a use case for that?)