forked from townforge/townforge
game: add appropriate message in hunt screen if no non-road building
This commit is contained in:
parent
5b070cd0bd
commit
4a23415de3
@ -59,6 +59,12 @@ TBLayout: axis: y, distribution-position: "left top", distribution: "gravity"
|
||||
TBSeparator
|
||||
TBSeparator
|
||||
|
||||
TBToggleContainer: id: "building-container", toggle: "expanded"
|
||||
TBLayout: axis: y
|
||||
TBTextField: text: "You must have at least one non-road building in this city to hunt there"
|
||||
TBSeparator
|
||||
TBSeparator
|
||||
|
||||
TBLayout: axis: x
|
||||
TBButton: text: "Hunt moose", id: "hunt-moose"
|
||||
TBButton: text: "Hunt bears", id: "hunt-bears"
|
||||
|
@ -31,6 +31,7 @@ UIHuntDialog::UIHuntDialog(Context *ctx, const GameState *game):
|
||||
bearAttackContainer = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("bear-attack-container"));
|
||||
militaryContainer = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("military-container"));
|
||||
militaryWidget = GetWidgetByIDAndType<TBTextField>(TBIDC("military"));
|
||||
buildingContainer = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("building-container"));
|
||||
bonusBearAttackWidget = GetWidgetByIDAndType<TBTextField>(TBIDC("bonus-bear-attack"));
|
||||
bonusNoBearAttackWidget = GetWidgetByIDAndType<TBTextField>(TBIDC("bonus-no-bear-attack"));
|
||||
huntMooseButton = GetWidgetByIDAndType<TBButton>(TBIDC("hunt-moose"));
|
||||
@ -78,11 +79,23 @@ void UIHuntDialog::UpdateData(const std::shared_ptr<GameWallet> &w)
|
||||
bonusBearAttackWidget->SetText(String(bonus).CString());
|
||||
bonusNoBearAttackWidget->SetText(String(bonus).CString());
|
||||
|
||||
bool has_building = false;
|
||||
for (uint32_t flag_id: game->playerState.flags)
|
||||
{
|
||||
const std::shared_ptr<Flag> flag = game->map.get_flag(flag_id);
|
||||
if (flag && flag->role != ROLE_EMPTY && flag->role != ROLE_ROAD)
|
||||
{
|
||||
has_building = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
buildingContainer->SetValue(has_building ? 0 : 1);
|
||||
|
||||
const auto i = game->playerState.item_balances.find(ITEM_LABOUR);
|
||||
const uint32_t labour_in_inventory = i == game->playerState.item_balances.end() ? 0 : i->second;
|
||||
labourInInventoryWidget->SetText(String(labour_in_inventory).CString());
|
||||
huntMooseButton->SetState(WIDGET_STATE_DISABLED, labour > labour_in_inventory);
|
||||
huntBearsButton->SetState(WIDGET_STATE_DISABLED, labour > labour_in_inventory);
|
||||
huntMooseButton->SetState(WIDGET_STATE_DISABLED, !has_building || labour > labour_in_inventory);
|
||||
huntBearsButton->SetState(WIDGET_STATE_DISABLED, !has_building || labour > labour_in_inventory);
|
||||
|
||||
ResizeToFitContent();
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ private:
|
||||
tb::TBTextField *labourWidget;
|
||||
tb::TBToggleContainer *bearAttackContainer;
|
||||
tb::TBToggleContainer *militaryContainer;
|
||||
tb::TBToggleContainer *buildingContainer;
|
||||
tb::TBTextField *militaryWidget;
|
||||
tb::TBTextField *bonusBearAttackWidget;
|
||||
tb::TBTextField *bonusNoBearAttackWidget;
|
||||
|
Loading…
Reference in New Issue
Block a user