A simple finite state machine. Set a state, react to enter and exit triggers, and push or pop states on a stack.
Simple example