I’ve implemented a navigation stack for screens in the game.
It used to be that when I would press “Play” in the main menu, the active screen would be changed to the episode selection screen. After pressing “back” there, it would say “open main menu” to return. All screen transitions were hardcoded in both ways like that.
Now when I press “Play”, it pushes the next screen onto the navigation stack. The “Back” button on the next screen doesn’t need to know where to go back to. It just tells the navigation controller to “pop” from the stack. The connection is now only one way and that makes it much easier to add new screens or change the order they are presented.
There are a few special cases, such as cutscenes, which effectively disappear once they are done. Other than that, the system is really simple and it only took an hour or so to implement, including the debug window shown above.