diff options
-rw-r--r-- | src/build_vehicle_gui.cpp | 24 | ||||
-rw-r--r-- | src/engine.cpp | 26 | ||||
-rw-r--r-- | src/group_cmd.cpp | 10 | ||||
-rw-r--r-- | src/group_gui.cpp | 9 | ||||
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/misc_cmd.cpp | 34 | ||||
-rw-r--r-- | src/misc_gui.cpp | 20 | ||||
-rw-r--r-- | src/player_gui.cpp | 6 | ||||
-rw-r--r-- | src/station_cmd.cpp | 11 | ||||
-rw-r--r-- | src/station_gui.cpp | 11 | ||||
-rw-r--r-- | src/textbuf_gui.h | 3 | ||||
-rw-r--r-- | src/town_cmd.cpp | 10 | ||||
-rw-r--r-- | src/town_gui.cpp | 11 | ||||
-rw-r--r-- | src/vehicle.cpp | 11 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 10 | ||||
-rw-r--r-- | src/waypoint.cpp | 26 | ||||
-rw-r--r-- | src/waypoint_gui.cpp | 10 |
17 files changed, 144 insertions, 89 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 806dd9940..d668e98f0 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1094,7 +1094,7 @@ struct BuildVehicleWindow : Window { case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE; break; } SetDParam(0, sel_eng); - ShowQueryString(STR_ENGINE_NAME, str, MAX_LENGTH_ENGINE_NAME_BYTES, MAX_LENGTH_ENGINE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_ENGINE_NAME, str, MAX_LENGTH_ENGINE_NAME_BYTES, MAX_LENGTH_ENGINE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); } break; } @@ -1156,18 +1156,18 @@ struct BuildVehicleWindow : Window { virtual void OnQueryTextFinished(char *str) { - if (!StrEmpty(str)) { - StringID err_str = STR_NULL; - _cmd_text = str; - switch (this->vehicle_type) { - default: NOT_REACHED(); - case VEH_TRAIN: err_str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break; - case VEH_ROAD: err_str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE; break; - case VEH_SHIP: err_str = STR_9839_CAN_T_RENAME_SHIP_TYPE; break; - case VEH_AIRCRAFT: err_str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break; - } - DoCommandP(0, this->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(err_str)); + if (str == NULL) return; + + StringID err_str = STR_NULL; + _cmd_text = str; + switch (this->vehicle_type) { + default: NOT_REACHED(); + case VEH_TRAIN: err_str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break; + case VEH_ROAD: err_str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE; break; + case VEH_SHIP: err_str = STR_9839_CAN_T_RENAME_SHIP_TYPE; break; + case VEH_AIRCRAFT: err_str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break; } + DoCommandP(0, this->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(err_str)); } virtual void OnDropdownSelect(int widget, int index) diff --git a/src/engine.cpp b/src/engine.cpp index 60000ac5b..91d52f5cb 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -494,15 +494,33 @@ static bool IsUniqueEngineName(const char *name) CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { if (!IsEngineIndex(p1)) return CMD_ERROR; - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR; - if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + bool reset = StrEmpty(_cmd_text); + + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR; + if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { Engine *e = GetEngine(p1); free(e->name); - e->name = strdup(_cmd_text); - _vehicle_design_names |= 3; + + if (reset) { + e->name = NULL; + /* if we removed the last custom name, disable the 'Save custom names' button */ + _vehicle_design_names &= ~1; + FOR_ALL_ENGINES(e) { + if (e->name != NULL) { + _vehicle_design_names |= 1; + break; + } + } + } else { + e->name = strdup(_cmd_text); + _vehicle_design_names |= 3; + } + MarkWholeScreenDirty(); } diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index c830d2f13..bc6018ac1 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -171,18 +171,22 @@ static bool IsUniqueGroupName(const char *name) CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { if (!IsValidGroupID(p1)) return CMD_ERROR; - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR; Group *g = GetGroup(p1); if (g->owner != _current_player) return CMD_ERROR; - if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + bool reset = StrEmpty(_cmd_text); + + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR; + if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { /* Delete the old name */ free(g->name); /* Assign the new one */ - g->name = strdup(_cmd_text); + g->name = reset ? NULL : strdup(_cmd_text); InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 5f819dcc1..b9c2abd5e 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -530,7 +530,7 @@ public: const Group *g = GetGroup(this->group_sel); SetDParam(0, g->index); - ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); } break; @@ -623,11 +623,10 @@ public: virtual void OnQueryTextFinished(char *str) { - if (!StrEmpty(str)) { - _cmd_text = str; + if (str == NULL) return; - DoCommandP(0, this->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME)); - } + _cmd_text = str; + DoCommandP(0, this->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME)); } virtual void OnResize(Point new_size, Point delta) diff --git a/src/lang/english.txt b/src/lang/english.txt index 84b35ca7e..01556f754 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -268,6 +268,7 @@ STR_012A_DESERT :{BLACK}{TINYFON STR_012B_SNOW :{BLACK}{TINYFONT}Snow STR_012C_MESSAGE :{WHITE}Message STR_012D :{WHITE}{STRING} +STR_DEFAULT :{BLACK}Default STR_012E_CANCEL :{BLACK}Cancel STR_012F_OK :{BLACK}OK STR_0130_RENAME :{BLACK}Rename diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index b273b1ea2..84287bc1a 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -224,14 +224,17 @@ static bool IsUniqueCompanyName(const char *name) */ CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR; + bool reset = StrEmpty(_cmd_text); - if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR; + if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { Player *p = GetPlayer(_current_player); free(p->name); - p->name = strdup(_cmd_text); + p->name = reset ? NULL : strdup(_cmd_text); MarkWholeScreenDirty(); } @@ -260,22 +263,31 @@ static bool IsUniquePresidentName(const char *name) */ CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR; + bool reset = StrEmpty(_cmd_text); - if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR; + if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { Player *p = GetPlayer(_current_player); free(p->president_name); - p->president_name = strdup(_cmd_text); - if (p->name_1 == STR_SV_UNNAMED && p->name == NULL) { - char buf[80]; + if (reset) { + p->president_name = NULL; + } else { + p->president_name = strdup(_cmd_text); - snprintf(buf, lengthof(buf), "%s Transport", _cmd_text); - _cmd_text = buf; - DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME); + if (p->name_1 == STR_SV_UNNAMED && p->name == NULL) { + char buf[80]; + + snprintf(buf, lengthof(buf), "%s Transport", _cmd_text); + _cmd_text = buf; + DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME); + } } + MarkWholeScreenDirty(); } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 2bafb7aac..75d774909 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1049,6 +1049,7 @@ void QueryStringBaseWindow::DrawEditBox(int wid) enum QueryStringWidgets { QUERY_STR_WIDGET_TEXT = 3, + QUERY_STR_WIDGET_DEFAULT, QUERY_STR_WIDGET_CANCEL, QUERY_STR_WIDGET_OK }; @@ -1093,6 +1094,9 @@ struct QueryStringWindow : public QueryStringBaseWindow ShowOnScreenKeyboard(this, QUERY_STR_WIDGET_TEXT, QUERY_STR_WIDGET_CANCEL, QUERY_STR_WIDGET_OK); break; + case QUERY_STR_WIDGET_DEFAULT: + this->text.buf[0] = '\0'; + /* Fallthrough */ case QUERY_STR_WIDGET_OK: this->OnOk(); /* Fallthrough */ @@ -1138,9 +1142,10 @@ static const Widget _query_string_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 259, 0, 13, STR_012D, STR_NULL}, { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 259, 14, 29, 0x0, STR_NULL}, -{ WWT_EDITBOX, RESIZE_NONE, COLOUR_GREY, 2, 257, 16, 27, 0x0, STR_NULL}, -{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 129, 30, 41, STR_012E_CANCEL, STR_NULL}, -{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 130, 259, 30, 41, STR_012F_OK, STR_NULL}, +{ WWT_EDITBOX, RESIZE_NONE, COLOUR_GREY, 2, 257, 16, 27, 0x0, STR_NULL}, // QUERY_STR_WIDGET_TEXT +{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 86, 30, 41, STR_DEFAULT, STR_NULL}, // QUERY_STR_WIDGET_DEFAULT +{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 87, 172, 30, 41, STR_012E_CANCEL, STR_NULL}, // QUERY_STR_WIDGET_CANCEL +{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 173, 259, 30, 41, STR_012F_OK, STR_NULL}, // QUERY_STR_WIDGET_OK { WIDGETS_END}, }; @@ -1173,6 +1178,15 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, if ((flags & QSF_ACCEPT_UNCHANGED) == 0) w->orig = strdup(w->edit_str_buf); + if ((flags & QSF_ENABLE_DEFAULT) == 0) { + /* without the "Default" button, make "Cancel" and "OK" buttons wider */ + w->SetWidgetHiddenState(QUERY_STR_WIDGET_DEFAULT, true); + w->widget[QUERY_STR_WIDGET_CANCEL].left = 0; + w->widget[QUERY_STR_WIDGET_CANCEL].right = w->width / 2 - 1; + w->widget[QUERY_STR_WIDGET_OK].left = w->width / 2; + w->widget[QUERY_STR_WIDGET_OK].right = w->width - 1; + } + w->LowerWidget(QUERY_STR_WIDGET_TEXT); w->caption = caption; w->afilter = afilter; diff --git a/src/player_gui.cpp b/src/player_gui.cpp index 1d277b105..058522f71 100644 --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -1257,13 +1257,13 @@ struct PlayerCompanyWindow : Window case PCW_WIDGET_PRESIDENT_NAME: this->query_widget = PCW_WIDGET_PRESIDENT_NAME; SetDParam(0, this->window_number); - ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); break; case PCW_WIDGET_COMPANY_NAME: this->query_widget = PCW_WIDGET_COMPANY_NAME; SetDParam(0, this->window_number); - ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); break; case PCW_WIDGET_BUILD_VIEW_HQ: { @@ -1328,7 +1328,7 @@ struct PlayerCompanyWindow : Window virtual void OnQueryTextFinished(char *str) { - if (StrEmpty(str)) return; + if (str == NULL) return; _cmd_text = str; switch (this->query_widget) { diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 056e0d620..1160f433d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2814,17 +2814,20 @@ static bool IsUniqueStationName(const char *name) CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { if (!IsValidStationID(p1)) return CMD_ERROR; - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR; Station *st = GetStation(p1); - if (!CheckOwnership(st->owner)) return CMD_ERROR; - if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + bool reset = StrEmpty(_cmd_text); + + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR; + if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { free(st->name); - st->name = strdup(_cmd_text); + st->name = reset ? NULL : strdup(_cmd_text); UpdateStationVirtCoord(st); InvalidateWindowData(WC_STATION_LIST, st->owner, 1); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index a01cf2661..091cd6884 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -912,7 +912,7 @@ struct StationViewWindow : public Window { case SVW_RENAME: SetDParam(0, this->window_number); - ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); break; case SVW_TRAINS: { // Show a list of scheduled trains to this station @@ -947,11 +947,10 @@ struct StationViewWindow : public Window { virtual void OnQueryTextFinished(char *str) { - if (!StrEmpty(str)) { - _cmd_text = str; - DoCommandP(0, this->window_number, 0, NULL, - CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); - } + if (str == NULL) return; + + _cmd_text = str; + DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); } virtual void OnResize(Point new_size, Point delta) diff --git a/src/textbuf_gui.h b/src/textbuf_gui.h index 422d26469..7d91b67e7 100644 --- a/src/textbuf_gui.h +++ b/src/textbuf_gui.h @@ -31,8 +31,9 @@ void UpdateTextBufferSize(Textbuf *tb); /** Flags used in ShowQueryString() call */ enum QueryStringFlags { - QSF_NONE = 0, + QSF_NONE = 0, QSF_ACCEPT_UNCHANGED = 0x01, ///< return success even when the text didn't change + QSF_ENABLE_DEFAULT = 0x02, ///< enable the 'Default' button ("\0" is returned) }; DECLARE_ENUM_AS_BIT_SET(QueryStringFlags) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 3532fe3c7..319e943ee 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2094,15 +2094,19 @@ static bool IsUniqueTownName(const char *name) CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { if (!IsValidTownID(p1)) return CMD_ERROR; - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR; - if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + bool reset = StrEmpty(_cmd_text); + + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR; + if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { Town *t = GetTown(p1); free(t->name); - t->name = strdup(_cmd_text); + t->name = reset ? NULL : strdup(_cmd_text); UpdateTownVirtCoord(t); InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 5518dec8f..356fbfea1 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -370,7 +370,7 @@ public: case TVW_CHANGENAME: /* rename */ SetDParam(0, this->window_number); - ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); break; case TVW_EXPAND: /* expand town - only available on Scenario editor */ @@ -401,11 +401,10 @@ public: virtual void OnQueryTextFinished(char *str) { - if (!StrEmpty(str)) { - _cmd_text = str; - DoCommandP(0, this->window_number, 0, NULL, - CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); - } + if (str == NULL) return; + + _cmd_text = str; + DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); } }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 943fc7076..d0de000db 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1680,17 +1680,20 @@ static bool IsUniqueVehicleName(const char *name) CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { if (!IsValidVehicleID(p1)) return CMD_ERROR; - if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR; Vehicle *v = GetVehicle(p1); - if (!CheckOwnership(v->owner)) return CMD_ERROR; - if ((flags & DC_AUTOREPLACE) == 0 && !IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + bool reset = StrEmpty(_cmd_text); + + if (!reset) { + if (strlen(_cmd_text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR; + if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } if (flags & DC_EXEC) { free(v->name); - v->name = strdup(_cmd_text); + v->name = reset ? NULL : strdup(_cmd_text); InvalidateWindowClassesData(WC_TRAINS_LIST, 1); MarkWholeScreenDirty(); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index ec162382e..e5a57da66 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1470,7 +1470,7 @@ struct VehicleDetailsWindow : Window { case VLD_WIDGET_RENAME_VEHICLE: {// rename const Vehicle *v = GetVehicle(this->window_number); SetDParam(0, v->index); - ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], MAX_LENGTH_VEHICLE_NAME_BYTES, MAX_LENGTH_VEHICLE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], MAX_LENGTH_VEHICLE_NAME_BYTES, MAX_LENGTH_VEHICLE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); } break; case VLD_WIDGET_INCREASE_SERVICING_INTERVAL: // increase int @@ -1513,10 +1513,10 @@ struct VehicleDetailsWindow : Window { STR_A031_CAN_T_NAME_AIRCRAFT }; - if (!StrEmpty(str)) { - _cmd_text = str; - DoCommandP(0, this->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(_name_vehicle_error[GetVehicle(this->window_number)->type])); - } + if (str == NULL) return; + + _cmd_text = str; + DoCommandP(0, this->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(_name_vehicle_error[GetVehicle(this->window_number)->type])); } virtual void OnResize(Point new_size, Point delta) diff --git a/src/waypoint.cpp b/src/waypoint.cpp index cc7415367..f455dde5f 100644 --- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -386,26 +386,24 @@ CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2 Waypoint *wp = GetWaypoint(p1); if (!CheckOwnership(wp->owner)) return CMD_ERROR; - if (!StrEmpty(_cmd_text)) { + bool reset = StrEmpty(_cmd_text); + + if (!reset) { if (strlen(_cmd_text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR; if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + } - if (flags & DC_EXEC) { - free(wp->name); - wp->name = strdup(_cmd_text); - wp->town_cn = 0; + if (flags & DC_EXEC) { + free(wp->name); - UpdateWaypointSign(wp); - MarkWholeScreenDirty(); + if (reset) { + MakeDefaultWaypointName(wp); // sets wp->name = NULL + } else { + wp->name = strdup(_cmd_text); } - } else { - if (flags & DC_EXEC) { - free(wp->name); - MakeDefaultWaypointName(wp); - UpdateWaypointSign(wp); - MarkWholeScreenDirty(); - } + UpdateWaypointSign(wp); + MarkWholeScreenDirty(); } return CommandCost(); } diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index 11864feb3..995a1630e 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -74,7 +74,7 @@ public: case WAYPVW_RENAME: /* rename */ SetDParam(0, this->wp->index); - ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); break; case WAYPVW_SHOW_TRAINS: /* show list of trains having this waypoint in their orders*/ @@ -92,10 +92,10 @@ public: virtual void OnQueryTextFinished(char *str) { - if (!StrEmpty(str)) { - _cmd_text = str; - DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); - } + if (str == NULL) return; + + _cmd_text = str; + DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); } }; |