From 14200212b7d15c68f989190e3c44a8400e914c4a Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 7 May 2024 21:08:20 +0200 Subject: [PATCH] Codechange: use std::optional over char * for text query results --- src/build_vehicle_gui.cpp | 6 +++--- src/cheat_gui.cpp | 6 +++--- src/company_gui.cpp | 18 +++++++++--------- src/depot_gui.cpp | 6 +++--- src/game/game_gui.cpp | 6 +++--- src/genworld_gui.cpp | 38 ++++++++++++++++++------------------- src/group_gui.cpp | 4 ++-- src/industry_gui.cpp | 6 +++--- src/misc_gui.cpp | 2 +- src/network/network_gui.cpp | 34 ++++++++++++++++----------------- src/newgrf_debug_gui.cpp | 12 ++++++------ src/newgrf_gui.cpp | 12 ++++++------ src/order_gui.cpp | 32 +++++++++++++++---------------- src/script/script_gui.cpp | 6 +++--- src/settings_gui.cpp | 22 ++++++++++----------- src/station_gui.cpp | 6 +++--- src/timetable_gui.cpp | 6 +++--- src/toolbar_gui.cpp | 8 ++++---- src/town_gui.cpp | 6 +++--- src/vehicle_gui.cpp | 6 +++--- src/waypoint_gui.cpp | 6 +++--- src/window_gui.h | 6 +++--- 22 files changed, 127 insertions(+), 127 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 554472e1ffd2b..4d9a2ef6471b2 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1853,11 +1853,11 @@ struct BuildVehicleWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; - Command::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str); + Command::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, *str); } void OnDropdownSelect(WidgetID widget, int index) override diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 353f1f4cd362f..5d3475ee80e4d 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -404,14 +404,14 @@ struct CheatWindow : Window { this->SetDirty(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { /* Was 'cancel' pressed or nothing entered? */ - if (str == nullptr || StrEmpty(str)) return; + if (!str.has_value() || str->empty()) return; const CheatEntry *ce = &_cheats_ui[clicked_widget]; int oldvalue = (int32_t)ReadValue(ce->variable, ce->type); - int value = atoi(str); + int value = atoi(str->c_str()); *ce->been_used = true; value = ce->proc(value, value - oldvalue); diff --git a/src/company_gui.cpp b/src/company_gui.cpp index b745d0c72d4c6..f7acd9831d7f6 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1686,12 +1686,12 @@ class SelectCompanyManagerFaceWindow : public Window } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; /* Set a new company manager face number */ - if (!StrEmpty(str)) { - this->face = std::strtoul(str, nullptr, 10); + if (!str->empty()) { + this->face = std::strtoul(str->c_str(), nullptr, 10); ScaleAllCompanyManagerFaceBits(this->face); ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO); this->UpdateData(); @@ -2520,25 +2520,25 @@ struct CompanyWindow : Window this->RaiseButtons(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; switch (this->query_widget) { default: NOT_REACHED(); case WID_C_GIVE_MONEY: { - Money money = std::strtoull(str, nullptr, 10) / GetCurrency().rate; + Money money = std::strtoull(str->c_str(), nullptr, 10) / GetCurrency().rate; Command::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, (CompanyID)this->window_number); break; } case WID_C_PRESIDENT_NAME: - Command::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, str); + Command::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, *str); break; case WID_C_COMPANY_NAME: - Command::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, str); + Command::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, *str); break; } } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 413de02cf7f4d..e62915fe2c5bb 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -831,12 +831,12 @@ struct DepotWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; /* Do depot renaming */ - Command::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), str); + Command::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), *str); } bool OnRightClick([[maybe_unused]] Point pt, WidgetID widget) override diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index c76f1e28dd919..36c9d1b7c70c8 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -368,10 +368,10 @@ struct GSConfigWindow : public Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str)) return; - int32_t value = atoi(str); + if (!str.has_value() || str->empty()) return; + int32_t value = atoi(str->c_str()); SetValue(value); } diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index d698e68e67ce0..4b16bdab508fe 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -935,14 +935,14 @@ struct GenerateLandscapeWindow : public Window { this->InvalidateData(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { /* Was 'cancel' pressed? */ - if (str == nullptr) return; + if (!str.has_value()) return; int32_t value; - if (!StrEmpty(str)) { - value = atoi(str); + if (!str->empty()) { + value = atoi(str->c_str()); } else { /* An empty string means revert to the default */ switch (this->widget_id) { @@ -1229,25 +1229,25 @@ struct CreateScenarioWindow : public Window this->SetDirty(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (!StrEmpty(str)) { - int32_t value = atoi(str); + if (!str.has_value() || str->empty()) return; - switch (this->widget_id) { - case WID_CS_START_DATE_TEXT: - this->SetWidgetDirty(WID_CS_START_DATE_TEXT); - _settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); - break; - - case WID_CS_FLAT_LAND_HEIGHT_TEXT: - this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT); - _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMapHeightLimit()); - break; - } + int32_t value = atoi(str->c_str()); - this->SetDirty(); + switch (this->widget_id) { + case WID_CS_START_DATE_TEXT: + this->SetWidgetDirty(WID_CS_START_DATE_TEXT); + _settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); + break; + + case WID_CS_FLAT_LAND_HEIGHT_TEXT: + this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT); + _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMapHeightLimit()); + break; } + + this->SetDirty(); } }; diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 59ecf33b551e3..bb2a8d840d410 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -972,9 +972,9 @@ class VehicleGroupWindow : public BaseVehicleListWindow { _cursor.vehchain = false; } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str != nullptr) Command::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, 0, str); + if (str.has_value()) Command::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, 0, *str); this->group_rename = INVALID_GROUP; } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index c42bbb47a3ed6..d083ce261ba61 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1138,12 +1138,12 @@ class IndustryViewWindow : public Window } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str)) return; + if (!str.has_value() || str->empty()) return; Industry *i = Industry::Get(this->window_number); - uint value = atoi(str); + uint value = atoi(str->c_str()); switch (this->editbox_line) { case IL_NONE: NOT_REACHED(); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 1b3d6778c86d2..cb97d7c8c3e15 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1039,7 +1039,7 @@ struct QueryStringWindow : public Window if (!this->editbox.handled && this->parent != nullptr) { Window *parent = this->parent; this->parent = nullptr; // so parent doesn't try to close us again - parent->OnQueryTextFinished(nullptr); + parent->OnQueryTextFinished(std::nullopt); } this->Window::Close(); } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index d254ba6559d96..9525ececba024 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -836,13 +836,13 @@ class NetworkGameWindow : public Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (!StrEmpty(str)) { - _settings_client.network.connect_to_ip = str; - NetworkAddServer(str); - NetworkRebuildHostList(); - } + if (!str.has_value() || str->empty()) return; + + _settings_client.network.connect_to_ip = std::move(*str); + NetworkAddServer(_settings_client.network.connect_to_ip); + NetworkRebuildHostList(); } void OnResize() override @@ -1135,14 +1135,14 @@ struct NetworkStartServerWindow : public Window { this->RaiseWidgetsWhenLowered(WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; if (this->widget_id == WID_NSS_SETPWD) { - _settings_client.network.server_password = str; + _settings_client.network.server_password = std::move(*str); } else { - int32_t value = atoi(str); + int32_t value = atoi(str->c_str()); this->SetWidgetDirty(this->widget_id); switch (this->widget_id) { default: NOT_REACHED(); @@ -1868,9 +1868,9 @@ struct NetworkClientListWindow : Window { this->SetDirty(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; switch (this->query_widget) { default: NOT_REACHED(); @@ -1878,13 +1878,13 @@ struct NetworkClientListWindow : Window { case WID_CL_SERVER_NAME_EDIT: { if (!_network_server) break; - SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), str); + SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), *str); this->InvalidateData(); break; } case WID_CL_CLIENT_NAME_EDIT: { - SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), str); + SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), *str); this->InvalidateData(); break; } @@ -2169,14 +2169,14 @@ struct NetworkJoinStatusWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str) || this->request == nullptr) { + if (!str.has_value() || str->empty() || this->request == nullptr) { NetworkDisconnect(); return; } - this->request->Reply(str); + this->request->Reply(*str); } }; diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 34801d9d47f08..1b6c36752020d 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -595,11 +595,11 @@ struct NewGRFInspectWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str)) return; + if (!str.has_value() || str->empty()) return; - NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = std::strtol(str, nullptr, 16); + NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = std::strtol(str->c_str(), nullptr, 16); this->SetDirty(); } @@ -1074,11 +1074,11 @@ struct SpriteAlignerWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str)) return; + if (!str.has_value() || str->empty()) return; - this->current_sprite = atoi(str); + this->current_sprite = atoi(str->c_str()); if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0; while (GetSpriteType(this->current_sprite) != SpriteType::Normal) { this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 854e32ae4411e..a4e73f626a282 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -443,10 +443,10 @@ struct NewGRFParametersWindow : public Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str)) return; - int32_t value = atoi(str); + if (!str.has_value() || str->empty()) return; + int32_t value = atoi(str->c_str()); GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row); uint32_t val = Clamp(value, par_info.min_value, par_info.max_value); par_info.SetValue(this->grf_config, val); @@ -1195,11 +1195,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { this->InvalidateData(GOID_NEWGRF_CHANGES_MADE); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; - SaveGRFPresetToConfig(str, this->actives); + SaveGRFPresetToConfig(str->c_str(), this->actives); this->grf_presets = GetGRFPresetList(); /* Switch to this preset */ diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 2e88c90240381..77b68d9479b2f 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1375,27 +1375,27 @@ struct OrdersWindow : public Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (!StrEmpty(str)) { - VehicleOrderID sel = this->OrderGetSel(); - uint value = atoi(str); + if (!str.has_value() || str->empty()) return; - switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) { - case OCV_MAX_SPEED: - value = ConvertDisplaySpeedToSpeed(value, this->vehicle->type); - break; + VehicleOrderID sel = this->OrderGetSel(); + uint value = atoi(str->c_str()); - case OCV_RELIABILITY: - case OCV_LOAD_PERCENTAGE: - value = Clamp(value, 0, 100); - break; + switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) { + case OCV_MAX_SPEED: + value = ConvertDisplaySpeedToSpeed(value, this->vehicle->type); + break; - default: - break; - } - Command::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047)); + case OCV_RELIABILITY: + case OCV_LOAD_PERCENTAGE: + value = Clamp(value, 0, 100); + break; + + default: + break; } + Command::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047)); } void OnDropdownSelect(WidgetID widget, int index) override diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index a4ee798adf146..bbe7ae34f3151 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -515,10 +515,10 @@ struct ScriptSettingsWindow : public Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (StrEmpty(str)) return; - int32_t value = atoi(str); + if (!str.has_value() || str->empty()) return; + int32_t value = atoi(str->c_str()); SetValue(value); } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index e87401ddfbc97..fb5c08ec8668b 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2726,17 +2726,17 @@ struct GameSettingsWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { /* The user pressed cancel */ - if (str == nullptr) return; + if (!str.has_value()) return; assert(this->valuewindow_entry != nullptr); const IntSettingDesc *sd = this->valuewindow_entry->setting; int32_t value; - if (!StrEmpty(str)) { - long long llvalue = atoll(str); + if (!str->empty()) { + long long llvalue = atoll(str->c_str()); /* Save the correct currency-translated value */ if (sd->flags & SF_GUI_CURRENCY) llvalue /= GetCurrency().rate; @@ -3128,29 +3128,29 @@ struct CustomCurrencyWindow : Window { this->SetDirty(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; switch (this->query_widget) { case WID_CC_RATE: - GetCustomCurrency().rate = Clamp(atoi(str), 1, UINT16_MAX); + GetCustomCurrency().rate = Clamp(atoi(str->c_str()), 1, UINT16_MAX); break; case WID_CC_SEPARATOR: // Thousands separator - GetCustomCurrency().separator = str; + GetCustomCurrency().separator = std::move(*str); break; case WID_CC_PREFIX: - GetCustomCurrency().prefix = str; + GetCustomCurrency().prefix = std::move(*str); break; case WID_CC_SUFFIX: - GetCustomCurrency().suffix = str; + GetCustomCurrency().suffix = std::move(*str); break; case WID_CC_YEAR: { // Year to switch to euro - TimerGameCalendar::Year val = atoi(str); + TimerGameCalendar::Year val = atoi(str->c_str()); GetCustomCurrency().to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, CalendarTime::MAX_YEAR)); break; diff --git a/src/station_gui.cpp b/src/station_gui.cpp index b9cf9846bf2b6..4ba355b721ac1 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2134,11 +2134,11 @@ struct StationViewWindow : public Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; - Command::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, str); + Command::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, *str); } void OnResize() override diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 7f89bc60c0953..4749477bf8b46 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -740,12 +740,12 @@ struct TimetableWindow : Window { this->SetDirty(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; const Vehicle *v = this->vehicle; - uint64_t val = StrEmpty(str) ? 0 : std::strtoul(str, nullptr, 10); + uint64_t val = str->empty() ? 0 : std::strtoul(str->c_str(), nullptr, 10); auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED); switch (query_widget) { diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 896b495bd86a4..d9494b4fa4e2d 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2458,14 +2458,14 @@ struct ScenarioEditorToolbarWindow : Window { HandleZoomMessage(this, GetMainWindow()->viewport, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { /* Was 'cancel' pressed? */ - if (str == nullptr) return; + if (!str.has_value()) return; TimerGameCalendar::Year value; - if (!StrEmpty(str)) { - value = atoi(str); + if (!str->empty()) { + value = atoi(str->c_str()); } else { /* An empty string means revert to the default */ value = CalendarTime::DEF_START_YEAR.base(); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index caafbf779618b..32ab8c1e29b37 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -607,11 +607,11 @@ struct TownViewWindow : Window { this->ResizeWindowAsNeeded(); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; - Command::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, str); + Command::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, *str); } IntervalTimer daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index ba83859bf8dac..e6123606d4b1a 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3301,11 +3301,11 @@ struct VehicleViewWindow : Window { return Window::OnHotkey(hotkey); } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; - Command::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, this->window_number, str); + Command::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, this->window_number, *str); } void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index f2e85d8d712c6..d6ede96c82957 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -176,11 +176,11 @@ struct WaypointWindow : Window { } } - void OnQueryTextFinished(char *str) override + void OnQueryTextFinished(std::optional str) override { - if (str == nullptr) return; + if (!str.has_value()) return; - Command::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, this->window_number, str); + Command::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, this->window_number, *str); } }; diff --git a/src/window_gui.h b/src/window_gui.h index 796b9b91f6fe3..1c5b7d8d5c84f 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -775,11 +775,11 @@ struct Window : ZeroedMemoryAllocator { /** * The query window opened from this window has closed. - * @param str the new value of the string, nullptr if the window + * @param str the new value of the string, \c std::nullopt if the window * was cancelled or an empty string when the default - * button was pressed, i.e. StrEmpty(str). + * button was pressed, i.e. \c str->empty(). */ - virtual void OnQueryTextFinished([[maybe_unused]] char *str) {} + virtual void OnQueryTextFinished([[maybe_unused]] std::optional str) {} /** * Some data on this window has become invalid.