From c3643e3ee07296d52bdc9fe62d32b03b8204bdb4 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 7 Feb 2025 17:03:53 +0000 Subject: [PATCH] Codechange: Pass raw string to editable query window. (#13481) This avoids separating string id and parameters. EncodedString is not needed as it is the raw text that is editable. --- src/build_vehicle_gui.cpp | 3 +-- src/cheat_gui.cpp | 9 +++------ src/company_gui.cpp | 11 ++++------- src/depot_gui.cpp | 5 ++--- src/game/game_gui.cpp | 3 +-- src/genworld_gui.cpp | 30 ++++++++++-------------------- src/group_gui.cpp | 9 ++++----- src/industry_gui.cpp | 6 ++---- src/misc_gui.cpp | 4 ++-- src/network/network_gui.cpp | 20 +++++++------------- src/newgrf_debug_gui.cpp | 4 ++-- src/newgrf_gui.cpp | 3 +-- src/order_gui.cpp | 3 +-- src/script/script_gui.cpp | 3 +-- src/settings_gui.cpp | 20 +++++++------------- src/signs_gui.cpp | 3 +-- src/station_gui.cpp | 3 +-- src/textbuf.cpp | 9 --------- src/textbuf_gui.h | 2 +- src/textbuf_type.h | 1 - src/timetable_gui.cpp | 12 +++++------- src/toolbar_gui.cpp | 3 +-- src/town_gui.cpp | 3 +-- src/vehicle_gui.cpp | 3 +-- src/waypoint_gui.cpp | 3 +-- 25 files changed, 60 insertions(+), 115 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index cb91798a7f..991a339a08 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1701,8 +1701,7 @@ struct BuildVehicleWindow : Window { EngineID sel_eng = this->sel_engine; if (sel_eng != INVALID_ENGINE) { this->rename_engine = sel_eng; - SetDParam(0, PackEngineNameDParam(sel_eng, EngineNameContext::Generic)); - ShowQueryString(STR_ENGINE_NAME, STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + ShowQueryString(GetString(STR_ENGINE_NAME, PackEngineNameDParam(sel_eng, EngineNameContext::Generic)), STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); } break; } diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index cf903fb08a..cfe35b8d0c 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -451,13 +451,11 @@ struct CheatWindow : Window { if (btn == CHT_CHANGE_DATE && x >= SETTING_BUTTON_WIDTH) { /* Click at the date text directly. */ clicked_cheat = CHT_CHANGE_DATE; - SetDParam(0, value); - ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); + ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); return; } else if (btn == CHT_EDIT_MAX_HL && x >= SETTING_BUTTON_WIDTH) { clicked_cheat = CHT_EDIT_MAX_HL; - SetDParam(0, value); - ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); + ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); return; } @@ -518,10 +516,9 @@ struct CheatWindow : Window { if (sd->min < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input this->valuewindow_entry = sd; - SetDParam(0, value64); /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */ - ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, value64), STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QSF_ENABLE_DEFAULT); } this->clicked_setting = sd; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 46f81d90ac..9b9bd46c30 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1631,8 +1631,7 @@ public: /* 'Company manager face number' button, view and/or set company manager face number */ case WID_SCMF_FACECODE: - SetDParam(0, this->face); - ShowQueryString(STR_JUST_INT, STR_FACE_FACECODE_CAPTION, 10 + 1, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, this->face), STR_FACE_FACECODE_CAPTION, 10 + 1, this, CS_NUMERAL, QSF_NONE); break; /* Save button */ @@ -2458,14 +2457,12 @@ struct CompanyWindow : Window case WID_C_PRESIDENT_NAME: this->query_widget = WID_C_PRESIDENT_NAME; - SetDParam(0, this->window_number); - ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + ShowQueryString(GetString(STR_PRESIDENT_NAME, this->window_number), STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; case WID_C_COMPANY_NAME: this->query_widget = WID_C_COMPANY_NAME; - SetDParam(0, this->window_number); - ShowQueryString(STR_COMPANY_NAME, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + ShowQueryString(GetString(STR_COMPANY_NAME, this->window_number), STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; case WID_C_VIEW_HQ: { @@ -2509,7 +2506,7 @@ struct CompanyWindow : Window case WID_C_GIVE_MONEY: this->query_widget = WID_C_GIVE_MONEY; - ShowQueryString(STR_EMPTY, STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION, 30, this, CS_NUMERAL, QSF_NONE); + ShowQueryString({}, STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION, 30, this, CS_NUMERAL, QSF_NONE); break; case WID_C_HOSTILE_TAKEOVER: diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 4ae6b1792a..281dc8b47d 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -808,9 +808,8 @@ struct DepotWindow : Window { break; case WID_D_RENAME: // Rename button - SetDParam(0, this->type); - SetDParam(1, Depot::GetByTile(TileIndex(this->window_number))->index); - ShowQueryString(STR_DEPOT_NAME, STR_DEPOT_RENAME_DEPOT_CAPTION, MAX_LENGTH_DEPOT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + ShowQueryString(GetString(STR_DEPOT_NAME, this->type, Depot::GetByTile(TileIndex(this->window_number))->index), STR_DEPOT_RENAME_DEPOT_CAPTION, + MAX_LENGTH_DEPOT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; case WID_D_STOP_ALL: diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index f2aa2cb35d..a5494603f9 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -345,8 +345,7 @@ struct GSConfigWindow : public Window { } } else if (!bool_item && !config_item.complete_labels) { /* Display a query box so users can enter a custom value. */ - SetDParam(0, old_val); - ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE); } this->SetDirty(); break; diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 41080ccdd3..8416a8e2a7 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -737,8 +737,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_HEIGHTMAP_HEIGHT_TEXT: // Height level text this->widget_id = WID_GL_HEIGHTMAP_HEIGHT_TEXT; - SetDParam(0, _settings_newgame.game_creation.heightmap_height); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_HEIGHTMAP_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.heightmap_height), STR_MAPGEN_HEIGHTMAP_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); break; @@ -756,8 +755,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_START_DATE_TEXT: // Year text this->widget_id = WID_GL_START_DATE_TEXT; - SetDParam(0, _settings_newgame.game_creation.starting_year); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); break; case WID_GL_SNOW_COVERAGE_DOWN: @@ -774,8 +772,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_SNOW_COVERAGE_TEXT: // Snow coverage text this->widget_id = WID_GL_SNOW_COVERAGE_TEXT; - SetDParam(0, _settings_newgame.game_creation.snow_coverage); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.snow_coverage), STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); break; case WID_GL_DESERT_COVERAGE_DOWN: @@ -792,8 +789,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_DESERT_COVERAGE_TEXT: // Desert line text this->widget_id = WID_GL_DESERT_COVERAGE_TEXT; - SetDParam(0, _settings_newgame.game_creation.desert_coverage); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_DESERT_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.desert_coverage), STR_MAPGEN_DESERT_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT); break; case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation @@ -890,8 +886,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_TOWN_PULLDOWN: if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) { this->widget_id = widget; - SetDParam(0, _settings_newgame.game_creation.custom_town_number); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_town_number), STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE); } _settings_newgame.difficulty.number_towns = index; break; @@ -906,8 +901,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_INDUSTRY_PULLDOWN: if ((uint)index == ID_CUSTOM) { this->widget_id = widget; - SetDParam(0, _settings_newgame.game_creation.custom_industry_number); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_INDUSTRIES, 5, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_industry_number), STR_MAPGEN_NUMBER_OF_INDUSTRIES, 5, this, CS_NUMERAL, QSF_NONE); } _settings_newgame.difficulty.industry_density = index; break; @@ -915,8 +909,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_TERRAIN_PULLDOWN: { if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) { this->widget_id = widget; - SetDParam(0, _settings_newgame.game_creation.custom_terrain_type); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_terrain_type), STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE); } _settings_newgame.difficulty.terrain_type = index; break; @@ -925,8 +918,7 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_WATER_PULLDOWN: { if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) { this->widget_id = widget; - SetDParam(0, _settings_newgame.game_creation.custom_sea_level); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_SEA_LEVEL, 3, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_sea_level), STR_MAPGEN_SEA_LEVEL, 3, this, CS_NUMERAL, QSF_NONE); } _settings_newgame.difficulty.quantity_sea_lakes = index; break; @@ -1191,8 +1183,7 @@ struct CreateScenarioWindow : public Window case WID_CS_START_DATE_TEXT: // Year text this->widget_id = WID_CS_START_DATE_TEXT; - SetDParam(0, _settings_newgame.game_creation.starting_year); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE); break; case WID_CS_FLAT_LAND_HEIGHT_DOWN: @@ -1209,8 +1200,7 @@ struct CreateScenarioWindow : public Window case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT; - SetDParam(0, _settings_newgame.game_creation.se_flat_world_height); - ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.se_flat_world_height), STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE); break; } } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index e2443bf0b2..ea16a60877 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -1099,12 +1099,11 @@ public: { assert(Group::IsValidID(group)); this->group_rename = group; + /* Show empty query for new groups */ - StringID str = STR_EMPTY; - if (!empty) { - SetDParam(0, group); - str = STR_GROUP_NAME; - } + std::string str; + if (!empty) str = GetString(STR_GROUP_NAME, group); + ShowQueryString(str, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index b3c90c8e8a..a2904e1aad 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1090,13 +1090,11 @@ public: this->editbox_line = line; switch (this->editable) { case EA_MULTIPLIER: - SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT)); - ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT)), STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE); break; case EA_RATE: - SetDParam(0, i->produced[line - IL_RATE1].rate * 8); - ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, i->produced[line - IL_RATE1].rate * 8), STR_CONFIG_GAME_PRODUCTION, 10, this, CS_ALPHANUMERAL, QSF_NONE); break; default: NOT_REACHED(); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 45a68187b0..5de355942c 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -951,7 +951,7 @@ struct QueryStringWindow : public Window QueryString editbox; ///< Editbox. QueryStringFlags flags; ///< Flags controlling behaviour of the window. - QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc &desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) : + QueryStringWindow(std::string_view str, StringID caption, uint max_bytes, uint max_chars, WindowDesc &desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) : Window(desc), editbox(max_bytes, max_chars) { this->editbox.text.Assign(str); @@ -1056,7 +1056,7 @@ static WindowDesc _query_string_desc( * @param afilter filters out unwanted character input * @param flags various flags, @see QueryStringFlags */ -void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags) +void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags) { assert(parent != nullptr); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index a8091d7ab2..e55a830852 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -750,9 +750,8 @@ public: break; case WID_NG_ADD: // Add a server - SetDParamStr(0, _settings_client.network.connect_to_ip); ShowQueryString( - STR_JUST_RAW_STRING, + _settings_client.network.connect_to_ip, STR_NETWORK_SERVER_LIST_ENTER_SERVER_ADDRESS, NETWORK_HOSTNAME_PORT_LENGTH, // maximum number of characters including '\0' this, CS_ALPHANUMERAL, QSF_ACCEPT_UNCHANGED); @@ -1045,8 +1044,7 @@ struct NetworkStartServerWindow : public Window { case WID_NSS_SETPWD: // Set password button this->widget_id = WID_NSS_SETPWD; - SetDParamStr(0, _settings_client.network.server_password); - ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_START_SERVER_SET_PASSWORD, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(_settings_client.network.server_password, STR_NETWORK_START_SERVER_SET_PASSWORD, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_NONE); break; case WID_NSS_CONNTYPE_BTN: // Connection type @@ -1074,14 +1072,12 @@ struct NetworkStartServerWindow : public Window { case WID_NSS_CLIENTS_TXT: // Click on number of clients this->widget_id = WID_NSS_CLIENTS_TXT; - SetDParam(0, _settings_client.network.max_clients); - ShowQueryString(STR_JUST_INT, STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS, 4, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_client.network.max_clients), STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS, 4, this, CS_NUMERAL, QSF_NONE); break; case WID_NSS_COMPANIES_TXT: // Click on number of companies this->widget_id = WID_NSS_COMPANIES_TXT; - SetDParam(0, _settings_client.network.max_companies); - ShowQueryString(STR_JUST_INT, STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES, 3, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, _settings_client.network.max_companies), STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES, 3, this, CS_NUMERAL, QSF_NONE); break; case WID_NSS_GENERATE_GAME: // Start game @@ -1744,15 +1740,13 @@ public: if (!_network_server) break; this->query_widget = WID_CL_SERVER_NAME_EDIT; - SetDParamStr(0, _settings_client.network.server_name); - ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_CLIENT_LIST_SERVER_NAME_QUERY_CAPTION, NETWORK_NAME_LENGTH, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS); + ShowQueryString(_settings_client.network.server_name, STR_NETWORK_CLIENT_LIST_SERVER_NAME_QUERY_CAPTION, NETWORK_NAME_LENGTH, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS); break; case WID_CL_CLIENT_NAME_EDIT: { const NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id); this->query_widget = WID_CL_CLIENT_NAME_EDIT; - SetDParamStr(0, own_ci != nullptr ? own_ci->client_name : _settings_client.network.client_name); - ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_CLIENT_LIST_PLAYER_NAME_QUERY_CAPTION, NETWORK_CLIENT_NAME_LENGTH, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS); + ShowQueryString(own_ci != nullptr ? own_ci->client_name : _settings_client.network.client_name, STR_NETWORK_CLIENT_LIST_PLAYER_NAME_QUERY_CAPTION, NETWORK_CLIENT_NAME_LENGTH, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS); break; } case WID_CL_SERVER_VISIBILITY: @@ -2216,7 +2210,7 @@ void ShowNetworkNeedPassword(std::shared_ptrrequest = request; - ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_GAME_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString({}, STR_NETWORK_NEED_GAME_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_NONE); } /** diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index ae4e452848..789c6a8224 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -614,7 +614,7 @@ struct NewGRFInspectWindow : Window { if (!HasVariableParameter(niv.var)) break; this->current_edit_param = niv.var; - ShowQueryString(STR_EMPTY, STR_NEWGRF_INSPECT_QUERY_CAPTION, 9, this, CS_HEXADECIMAL, QSF_NONE); + ShowQueryString({}, STR_NEWGRF_INSPECT_QUERY_CAPTION, 9, this, CS_HEXADECIMAL, QSF_NONE); } } } @@ -1007,7 +1007,7 @@ struct SpriteAlignerWindow : Window { break; case WID_SA_GOTO: - ShowQueryString(STR_EMPTY, STR_SPRITE_ALIGNER_GOTO_CAPTION, 7, this, CS_NUMERAL, QSF_NONE); + ShowQueryString({}, STR_SPRITE_ALIGNER_GOTO_CAPTION, 7, this, CS_NUMERAL, QSF_NONE); break; case WID_SA_NEXT: diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 5cd629879d..32b613f865 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -421,8 +421,7 @@ struct NewGRFParametersWindow : public Window { } } else if (par_info.type == PTYPE_UINT_ENUM && !par_info.complete_labels && click_count >= 2) { /* Display a query box so users can enter a custom value. */ - SetDParam(0, old_val); - ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE); } this->SetDirty(); break; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index c3ed9250bf..db0f3f363b 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1364,8 +1364,7 @@ public: assert(order != nullptr); uint value = order->GetConditionValue(); if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type); - SetDParam(0, value); - ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, value), STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE); break; } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 7b07d4a44f..d6c8b6212b 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -495,8 +495,7 @@ struct ScriptSettingsWindow : public Window { } } else if (!bool_item && !config_item.complete_labels) { /* Display a query box so users can enter a custom value. */ - SetDParam(0, old_val); - ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE); + ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE); } this->SetDirty(); break; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 187dabd31c..e7d1f102f9 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2711,9 +2711,8 @@ struct GameSettingsWindow : Window { if (min_val < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input this->valuewindow_entry = pe; - SetDParam(0, value64); /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */ - ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, value64), STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QSF_ENABLE_DEFAULT); } this->SetDisplayedHelpText(pe); } @@ -3050,7 +3049,7 @@ struct CustomCurrencyWindow : Window { { int line = 0; int len = 0; - StringID str = STR_NULL; + std::string str; CharSetFilter afilter = CS_ALPHANUMERAL; switch (widget) { @@ -3067,8 +3066,7 @@ struct CustomCurrencyWindow : Window { break; case WID_CC_RATE: - SetDParam(0, GetCustomCurrency().rate); - str = STR_JUST_INT; + str = GetString(STR_JUST_INT, GetCustomCurrency().rate); len = 5; line = WID_CC_RATE; afilter = CS_NUMERAL; @@ -3076,24 +3074,21 @@ struct CustomCurrencyWindow : Window { case WID_CC_SEPARATOR_EDIT: case WID_CC_SEPARATOR: - SetDParamStr(0, GetCustomCurrency().separator); - str = STR_JUST_RAW_STRING; + str = GetCustomCurrency().separator; len = 7; line = WID_CC_SEPARATOR; break; case WID_CC_PREFIX_EDIT: case WID_CC_PREFIX: - SetDParamStr(0, GetCustomCurrency().prefix); - str = STR_JUST_RAW_STRING; + str = GetCustomCurrency().prefix; len = 15; line = WID_CC_PREFIX; break; case WID_CC_SUFFIX_EDIT: case WID_CC_SUFFIX: - SetDParamStr(0, GetCustomCurrency().suffix); - str = STR_JUST_RAW_STRING; + str = GetCustomCurrency().suffix; len = 15; line = WID_CC_SUFFIX; break; @@ -3111,8 +3106,7 @@ struct CustomCurrencyWindow : Window { break; case WID_CC_YEAR: - SetDParam(0, GetCustomCurrency().to_euro); - str = STR_JUST_INT; + str = GetString(STR_JUST_INT, GetCustomCurrency().to_euro); len = 7; line = WID_CC_YEAR; afilter = CS_NUMERAL; diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 574d42bbc3..ca0edb89f0 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -428,8 +428,7 @@ struct SignWindow : Window, SignList { { /* Display an empty string when the sign hasn't been edited yet */ if (!si->name.empty()) { - SetDParam(0, si->index); - this->name_editbox.text.Assign(STR_SIGN_NAME); + this->name_editbox.text.Assign(GetString(STR_SIGN_NAME, si->index)); } else { this->name_editbox.text.DeleteAll(); } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index f3f45e6338..e344f55bbd 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2002,8 +2002,7 @@ struct StationViewWindow : public Window { } case WID_SV_RENAME: - SetDParam(0, this->window_number); - ShowQueryString(STR_STATION_NAME, STR_STATION_VIEW_RENAME_STATION_CAPTION, MAX_LENGTH_STATION_NAME_CHARS, + ShowQueryString(GetString(STR_STATION_NAME, this->window_number), STR_STATION_VIEW_RENAME_STATION_CAPTION, MAX_LENGTH_STATION_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; diff --git a/src/textbuf.cpp b/src/textbuf.cpp index 5ca5721dcb..942edd389b 100644 --- a/src/textbuf.cpp +++ b/src/textbuf.cpp @@ -424,15 +424,6 @@ Textbuf::~Textbuf() free(this->buf); } -/** - * Render a string into the textbuffer. - * @param string String - */ -void Textbuf::Assign(StringID string) -{ - this->Assign(GetString(string)); -} - /** * Copy a string into the textbuffer. * @param text Source. diff --git a/src/textbuf_gui.h b/src/textbuf_gui.h index 491b3305dc..c52210d3ba 100644 --- a/src/textbuf_gui.h +++ b/src/textbuf_gui.h @@ -27,7 +27,7 @@ DECLARE_ENUM_AS_BIT_SET(QueryStringFlags) /** Callback procedure for the ShowQuery method. */ typedef void QueryCallbackProc(Window*, bool); -void ShowQueryString(StringID str, StringID caption, uint max_len, Window *parent, CharSetFilter afilter, QueryStringFlags flags); +void ShowQueryString(std::string_view str, StringID caption, uint max_len, Window *parent, CharSetFilter afilter, QueryStringFlags flags); void ShowQuery(StringID caption, StringID message, Window *w, QueryCallbackProc *callback, bool focus = false); /** The number of 'characters' on the on-screen keyboard. */ diff --git a/src/textbuf_type.h b/src/textbuf_type.h index 26ad5fc8b4..c57b5471ef 100644 --- a/src/textbuf_type.h +++ b/src/textbuf_type.h @@ -45,7 +45,6 @@ struct Textbuf { explicit Textbuf(uint16_t max_bytes, uint16_t max_chars = UINT16_MAX); ~Textbuf(); - void Assign(StringID string); void Assign(const std::string_view text); void DeleteAll(); diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 8b771ec25b..41d9096534 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -653,7 +653,7 @@ struct TimetableWindow : Window { if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) { this->query_widget = WID_VT_START_DATE; this->change_timetable_all = _ctrl_pressed; - ShowQueryString(STR_EMPTY, STR_TIMETABLE_START_SECONDS_QUERY, 6, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); + ShowQueryString({}, STR_TIMETABLE_START_SECONDS_QUERY, 6, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); } else { ShowSetDateWindow(this, v->index, TimerGameEconomy::date, TimerGameEconomy::year, TimerGameEconomy::year + MAX_TIMETABLE_START_YEARS, ChangeTimetableStartCallback, reinterpret_cast(static_cast(_ctrl_pressed))); } @@ -667,15 +667,14 @@ struct TimetableWindow : Window { if (real >= v->GetNumOrders()) real = 0; const Order *order = v->GetOrder(real); - StringID current = STR_EMPTY; + std::string current; if (order != nullptr) { uint time = (selected % 2 != 0) ? order->GetTravelTime() : order->GetWaitTime(); time /= TicksPerTimetableUnit(); if (time != 0) { - SetDParam(0, time); - current = STR_JUST_INT; + current = GetString(STR_JUST_INT, time); } } @@ -691,12 +690,11 @@ struct TimetableWindow : Window { if (real >= v->GetNumOrders()) real = 0; - StringID current = STR_EMPTY; + std::string current; const Order *order = v->GetOrder(real); if (order != nullptr) { if (order->GetMaxSpeed() != UINT16_MAX) { - SetDParam(0, ConvertKmhishSpeedToDisplaySpeed(order->GetMaxSpeed(), v->type)); - current = STR_JUST_INT; + current = GetString(STR_JUST_INT, ConvertKmhishSpeedToDisplaySpeed(order->GetMaxSpeed(), v->type)); } } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 0ee17fb047..44e3eecbe5 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1203,8 +1203,7 @@ static CallBackFunction ToolbarSwitchClick(Window *w) */ static CallBackFunction ToolbarScenDatePanel(Window *w) { - SetDParam(0, _settings_game.game_creation.starting_year); - ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT); + ShowQueryString(GetString(STR_JUST_INT, _settings_game.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT); return CBF_NONE; } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 6ab59abe0a..0d961bba41 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -513,8 +513,7 @@ public: break; case WID_TV_CHANGE_NAME: // rename - SetDParam(0, this->window_number); - ShowQueryString(STR_TOWN_NAME, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + ShowQueryString(GetString(STR_TOWN_NAME, this->window_number), STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; case WID_TV_CATCHMENT: diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index e2ce4431a1..d68f422971 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3302,8 +3302,7 @@ public: switch (widget) { case WID_VV_RENAME: { // rename - SetDParam(0, v->index); - ShowQueryString(STR_VEHICLE_NAME, STR_QUERY_RENAME_TRAIN_CAPTION + v->type, + ShowQueryString(GetString(STR_VEHICLE_NAME, v->index), STR_QUERY_RENAME_TRAIN_CAPTION + v->type, MAX_LENGTH_VEHICLE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; } diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index aa3821e6fa..472e0239ce 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -135,8 +135,7 @@ public: break; case WID_W_RENAME: // rename - SetDParam(0, this->wp->index); - ShowQueryString(STR_WAYPOINT_NAME, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_STATION_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + ShowQueryString(GetString(STR_WAYPOINT_NAME, this->wp->index), STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_STATION_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; case WID_W_SHOW_VEHICLES: // show list of vehicles having this waypoint in their orders