The software architecture pattern you are looking for is a state machine.
Your user interface should have different modes (or "states") in which it shows different UI elements and reacts differently to user input.
When the user clicks on "Build", your UI should switch to the "select build tile" state where the tiles where the user can build are highlighted. When the user clicks a tile, switch to the "Select building" state. In that state the selected tile gets highlighted, no other tile can be selected, but the player can select what to build. When the player selected the build option, apply it and return back to the default UI state. Each of these modes should also have some way to navigate back to the previous state, in case the player changes their mind or selected the wrong tile.
There are different ways to implement this architecture-wise.
A common one is to implement each state with an own class. Have all the state-classes implement an interface with a method enter
(which shows all state-specific UI elements and sets up their event handlers) and leave
(which hides everything state-specific and deactivates the event-handlers). Your main UI handling class should have a public method switchState(state)
which leave
s the current state and enter
s the new one.
When developing native Android applications, you might be able to get away with implementing each state with nothing but a different View
. Put the code for entering or leaving a view into the onAttachedToWindow()
and onDetachedFromWindow()
event handlers. Have the main UI handler detach the current view and attach the new one.