Closed MaanooAk closed 4 years ago
Should there be extra logic here to un-set constructBuildingType also if the player cannot build more than the current amount of buildings of this type, e.g., only one town center?
Based on that, I realized that there was also no check for the cost after the first one. I didn't want to just hack something, so...
I introduced this:
class CommandButton {
// ...
enum class State {
/// Valid and visible
Valid = 0,
/// Cannot be affored by the player, visible but disabled.
CannotAfford,
/// Max limit reached, not visible. (currently only the TownCenter can have this state)
MaxLimitReached,
/// Already researched, not visible.
Researched,
/// The requirements are not met, visible but disabled. (eg. "Advance age" without the
/// building requirements met)
VisibleLocked,
/// The requirements are not met, not visible. (eg. "Castle" in Dark age)
Locked
};
// ...
State GetState(GameController* gameController) const;
// ...
}
Now GetState
is responsible for all the checks, and there is no need to eg. call CanAfford in random places, you just ckeck that the state is State::Valid
.
I also added a
void RenderWindow::ReportNonValidCommandButton(
CommandButton* button, CommandButton::State state)
which based on the state produces a message (for now in the log, but in the future could be ouputed to the gui message system thing). For now there are two messages:
The state check and the report is called both in the press of the button and when the player later places a foundation (which is also handling the placing foundations with shift).
Waiting for feedback.
Added some more comments, and 2 cases where construction mode is interrupted. Ready for merge.
Great, thanks again!
(The fixes are for my code)
(I cant stop writing code... really like this)