game: disable ok button in the service screen when a flag offer none

This commit is contained in:
Crypto City 2022-06-22 16:19:52 +00:00
parent b50f129e07
commit 5165b90d54
2 changed files with 8 additions and 2 deletions

View File

@ -16,7 +16,8 @@ using namespace tb;
UIServiceDialog::UIServiceDialog(Context *ctx, const GameState *game, const std::shared_ptr<Flag> &flag):
UITBWindow(ctx, "cc/service.tb.txt"),
flag(flag)
flag(flag),
hasService(false)
{
noneContainer = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("service-none"));
firefightingContainer = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("service-firefighting"));
@ -29,6 +30,7 @@ UIServiceDialog::UIServiceDialog(Context *ctx, const GameState *game, const std:
case ROLE_MILITARY:
noneContainer->SetValue(0);
firefightingContainer->SetValue(1);
hasService = true;
break;
default:
noneContainer->SetValue(1);
@ -39,6 +41,8 @@ UIServiceDialog::UIServiceDialog(Context *ctx, const GameState *game, const std:
offerServiceWidget->SetValue(flag->service_price != 0);
servicePriceWidget->SetText(cryptonote::print_money(flag->service_price).c_str());
okButton->SetState(WIDGET_STATE_DISABLED, !hasService);
ResizeToFitContent();
SubscribeToEvent(this, E_TB_WIDGET_EVENT, URHO3D_HANDLER(UIServiceDialog, HandleTBMessage));
@ -57,7 +61,7 @@ void UIServiceDialog::HandleServicePriceChanged(StringHash eventType, VariantMap
{
uint64_t price;
const bool valid = cryptonote::parse_amount(price, servicePriceWidget->GetText().CStr());
okButton->SetState(WIDGET_STATE_DISABLED, offerServiceWidget->GetValue() && !valid);
okButton->SetState(WIDGET_STATE_DISABLED, !hasService || (offerServiceWidget->GetValue() && !valid));
ResizeToFitContent(RESIZE_FIT_PREFERRED);
}

View File

@ -46,6 +46,8 @@ private:
private:
const std::shared_ptr<Flag> flag;
bool hasService;
tb::TBToggleContainer *noneContainer;
tb::TBToggleContainer *firefightingContainer;
tb::TBCheckBox *offerServiceWidget;