libgdx/libgdx — pull request #2181 by nooone (2014-07-30 10:27:16+00:00)
Title: New StackMachine with a Stack

Since `StackMachine`s are also handy in case of hierarchical menu structures for example, I added another implemenation which does not only save the previous state, but all states until the current one.

When displaying a games menu this could be very useful. One would only need a single `MenuScreen implements Screen` and could then have a state machine for the menus. Each menu would be one state. For example MainMenu, LevelSelectionMenu, LevelLoadingMenu, OptionsMenu, GraphicsSettingsMenu, InputSettingsMenu, ReallyQuitMenu etc...

Now the initial state would be MainMenu, clicking the "Options" button might cause a Telegram which will cause a switch of the state to OptionsMenu. Then clicking on "GraphicsSettingsMenu" will again cause a transition. What players these days expect is that they can quickly return from there via the Escape key. That's where StackStateMachine is necessary and we can go back all the way from the GraphicsSettingsMenu to the MainMenu, just by using stateMachine.revertToPreviousState(). The default implementation would only allow us to go back a single step.

Implementation details:
I have added a `boolean` return value to the `revertToPreviousState()` method. In case there was no previous state yet (initial state), this returns false and does nothing. I have also applied this behaviour to the default implementation.

I also made some fields of the DefaultStateMachine protected so I did not have to re-implement all the common functionality and was able to `extend DefaultStateMachine`.

@davebaol What do you think?