MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnQueryTextFinished

Method OnQueryTextFinished

src/cheat_gui.cpp:600–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

598 }
599
600 void OnQueryTextFinished(std::optional<std::string> str) override
601 {
602 /* Was 'cancel' pressed or nothing entered? */
603 if (!str.has_value() || str->empty()) return;
604
605 if (this->valuewindow_entry != nullptr) {
606 const IntSettingDesc *sd = this->valuewindow_entry->AsIntSetting();
607
608 int32_t value;
609 if (!str->empty()) {
610 auto llvalue = ParseInteger<int64_t>(*str, 10, true);
611 if (!llvalue.has_value()) return;
612
613 /* Save the correct currency-translated value */
614 if (sd->flags.Test(SettingFlag::GuiCurrency)) llvalue = *llvalue / GetCurrency().rate;
615
616 value = ClampTo<int32_t>(*llvalue);
617 } else {
618 value = sd->GetDefaultValue();
619 }
620
621 SetSettingValue(sd, value);
622 } else {
623 const CheatEntry *ce = &_cheats_ui[clicked_cheat];
624 int oldvalue = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
625 auto value = ParseInteger<int32_t>(*str, 10, true);
626 if (!value.has_value()) return;
627 *ce->been_used = true;
628 value = ce->proc(*value, *value - oldvalue);
629
630 if (*value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(*value));
631 }
632
633 this->valuewindow_entry = nullptr;
634 this->SetDirty();
635 }
636
637 const IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [this](auto) {
638 this->SetDirty();

Callers

nothing calls this directly

Calls 8

SetSettingValueFunction · 0.85
ReadValueFunction · 0.85
WriteValueFunction · 0.85
AsIntSettingMethod · 0.80
TestMethod · 0.80
GetDefaultValueMethod · 0.80
emptyMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected