Changeset - r10148:ec65442a5187
[Not reviewed]
master
0 17 0
smatz - 16 years ago 2008-09-15 19:02:50
smatz@openttd.org
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
17 files changed with 145 insertions and 90 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -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)
src/engine.cpp
Show inline comments
 
@@ -494,15 +494,33 @@ static bool IsUniqueEngineName(const cha
 
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;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 

	
 
	if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	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();
 
	}
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -171,18 +171,22 @@ static bool IsUniqueGroupName(const char
 
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);
 
	}
src/group_gui.cpp
Show inline comments
 
@@ -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)
src/lang/english.txt
Show inline comments
 
@@ -268,6 +268,7 @@ STR_012A_DESERT                         
 
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
src/misc_cmd.cpp
Show inline comments
 
@@ -224,14 +224,17 @@ static bool IsUniqueCompanyName(const ch
 
 */
 
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 
 
 */
 
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();
 
	}
 

	
src/misc_gui.cpp
Show inline comments
 
@@ -1049,6 +1049,7 @@ void QueryStringBaseWindow::DrawEditBox(
 

	
 
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 QueryS
 
				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_widget
 
{   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, Strin
 

	
 
	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;
src/player_gui.cpp
Show inline comments
 
@@ -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) {
src/station_cmd.cpp
Show inline comments
 
@@ -2814,17 +2814,20 @@ static bool IsUniqueStationName(const ch
 
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);
src/station_gui.cpp
Show inline comments
 
@@ -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)
src/textbuf_gui.h
Show inline comments
 
@@ -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)
src/town_cmd.cpp
Show inline comments
 
@@ -2094,15 +2094,19 @@ static bool IsUniqueTownName(const char 
 
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);
src/town_gui.cpp
Show inline comments
 
@@ -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));
 
	}
 
};
 

	
src/vehicle.cpp
Show inline comments
 
@@ -1680,17 +1680,20 @@ static bool IsUniqueVehicleName(const ch
 
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();
 
	}
src/vehicle_gui.cpp
Show inline comments
 
@@ -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)
src/waypoint.cpp
Show inline comments
 
@@ -386,26 +386,24 @@ CommandCost CmdRenameWaypoint(TileIndex 
 
	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);
 
	if (flags & DC_EXEC) {
 
		free(wp->name);
 

	
 
		if (reset) {
 
			MakeDefaultWaypointName(wp); // sets wp->name = NULL
 
		} else {
 
			wp->name = strdup(_cmd_text);
 
			wp->town_cn = 0;
 

	
 
			UpdateWaypointSign(wp);
 
			MarkWholeScreenDirty();
 
		}
 
	} else {
 
		if (flags & DC_EXEC) {
 
			free(wp->name);
 

	
 
			MakeDefaultWaypointName(wp);
 
			UpdateWaypointSign(wp);
 
			MarkWholeScreenDirty();
 
		}
 
		UpdateWaypointSign(wp);
 
		MarkWholeScreenDirty();
 
	}
 
	return CommandCost();
 
}
src/waypoint_gui.cpp
Show inline comments
 
@@ -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));
 
	}
 

	
 
};
0 comments (0 inline, 0 general)