mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
(svn r19801) -Add [FS#3691]: custom naming of depots. Based on work by sbr
This commit is contained in:
parent
e91165ef6e
commit
1a5d7b34d8
@ -1991,6 +1991,10 @@
|
||||
RelativePath=".\..\src\company_cmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\depot_cmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\disaster_cmd.cpp"
|
||||
>
|
||||
|
@ -1988,6 +1988,10 @@
|
||||
RelativePath=".\..\src\company_cmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\depot_cmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\disaster_cmd.cpp"
|
||||
>
|
||||
|
@ -426,6 +426,7 @@ aircraft_cmd.cpp
|
||||
autoreplace_cmd.cpp
|
||||
clear_cmd.cpp
|
||||
company_cmd.cpp
|
||||
depot_cmd.cpp
|
||||
disaster_cmd.cpp
|
||||
dummy_land.cpp
|
||||
group_cmd.cpp
|
||||
|
@ -110,6 +110,7 @@ CommandProc CmdRenameCompany;
|
||||
CommandProc CmdRenamePresident;
|
||||
|
||||
CommandProc CmdRenameStation;
|
||||
CommandProc CmdRenameDepot;
|
||||
|
||||
CommandProc CmdSellAircraft;
|
||||
CommandProc CmdBuildAircraft;
|
||||
@ -260,6 +261,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdRenamePresident, 0), // CMD_RENAME_PRESIDENT
|
||||
|
||||
DEF_CMD(CmdRenameStation, 0), // CMD_RENAME_STATION
|
||||
DEF_CMD(CmdRenameDepot, 0), // CMD_RENAME_DEPOT
|
||||
|
||||
DEF_CMD(CmdSellAircraft, 0), // CMD_SELL_AIRCRAFT
|
||||
|
||||
|
@ -210,6 +210,7 @@ enum {
|
||||
CMD_RENAME_COMPANY, ///< change the company name
|
||||
CMD_RENAME_PRESIDENT, ///< change the president name
|
||||
CMD_RENAME_STATION, ///< rename a station
|
||||
CMD_RENAME_DEPOT, ///< rename a depot
|
||||
|
||||
CMD_SELL_AIRCRAFT, ///< sell an aircraft
|
||||
CMD_BUILD_AIRCRAFT, ///< build an aircraft
|
||||
|
@ -20,7 +20,7 @@ extern DepotPool _depot_pool;
|
||||
|
||||
struct Depot : DepotPool::PoolItem<&_depot_pool> {
|
||||
Town *town;
|
||||
const char *name;
|
||||
char *name;
|
||||
|
||||
TileIndex xy;
|
||||
uint16 town_cn; ///< The Nth depot for this town (consecutive number)
|
||||
|
83
src/depot_cmd.cpp
Normal file
83
src/depot_cmd.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file depot_cmd.cpp Command Handling for depots. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "command_func.h"
|
||||
#include "depot_base.h"
|
||||
#include "functions.h"
|
||||
#include "string_func.h"
|
||||
#include "town.h"
|
||||
#include "vehicle_gui.h"
|
||||
#include "window_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
||||
static bool IsUniqueDepotName(const char *name)
|
||||
{
|
||||
const Depot *d;
|
||||
|
||||
FOR_ALL_DEPOTS(d) {
|
||||
if (d->name != NULL && strcmp(d->name, name) == 0) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a depot.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 id of depot
|
||||
* @param p2 unused
|
||||
* @param text the new name or an empty string when resetting to the default
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
Depot *d = Depot::GetIfValid(p1);
|
||||
if (d == NULL) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = CheckTileOwnership(d->xy);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
bool reset = StrEmpty(text);
|
||||
|
||||
if (!reset) {
|
||||
if (strlen(text) >= MAX_LENGTH_DEPOT_NAME_BYTES) return CMD_ERROR;
|
||||
if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
free(d->name);
|
||||
|
||||
if (reset) {
|
||||
d->name = NULL;
|
||||
MakeDefaultName(d);
|
||||
} else {
|
||||
d->name = strdup(text);
|
||||
}
|
||||
|
||||
/* Update the orders and depot */
|
||||
SetWindowClassesDirty(WC_VEHICLE_ORDERS);
|
||||
SetWindowDirty(WC_VEHICLE_DEPOT, d->xy);
|
||||
|
||||
/* Update the depot list */
|
||||
WindowNumber wno = (d->index << 16) | VLW_DEPOT_LIST | GetTileOwner(d->xy);
|
||||
switch (GetTileType(d->xy)) {
|
||||
default: break;
|
||||
case MP_RAILWAY: SetWindowDirty(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); break;
|
||||
case MP_ROAD: SetWindowDirty(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); break;
|
||||
case MP_WATER: SetWindowDirty(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); break;
|
||||
}
|
||||
}
|
||||
return CommandCost();
|
||||
}
|
@ -53,6 +53,8 @@ enum DepotWindowWidgets {
|
||||
DEPOT_WIDGET_BUILD,
|
||||
DEPOT_WIDGET_CLONE,
|
||||
DEPOT_WIDGET_LOCATION,
|
||||
DEPOT_WIDGET_SHOW_RENAME,
|
||||
DEPOT_WIDGET_RENAME,
|
||||
DEPOT_WIDGET_VEHICLE_LIST,
|
||||
DEPOT_WIDGET_STOP_ALL,
|
||||
DEPOT_WIDGET_START_ALL,
|
||||
@ -83,6 +85,9 @@ static const NWidgetPart _nested_train_depot_widgets[] = {
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, DEPOT_WIDGET_BUILD), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, DEPOT_WIDGET_CLONE), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, DEPOT_WIDGET_LOCATION), SetDataTip(STR_BUTTON_LOCATION, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
||||
NWidget(NWID_SELECTION, INVALID_COLOUR, DEPOT_WIDGET_SHOW_RENAME), // rename button
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, DEPOT_WIDGET_RENAME), SetDataTip(STR_BUTTON_RENAME, STR_DEPOT_RENAME_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
||||
EndContainer(),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, DEPOT_WIDGET_VEHICLE_LIST), SetDataTip(0x0, STR_NULL), SetFill(0, 1),
|
||||
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, DEPOT_WIDGET_STOP_ALL), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_NULL), SetFill(0, 1),
|
||||
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, DEPOT_WIDGET_START_ALL), SetDataTip(SPR_FLAG_VEH_RUNNING, STR_NULL), SetFill(0, 1),
|
||||
@ -222,6 +227,8 @@ struct DepotWindow : Window {
|
||||
this->type = type;
|
||||
|
||||
this->CreateNestedTree(desc);
|
||||
/* Don't show 'rename button' of aircraft hangar */
|
||||
this->GetWidget<NWidgetStacked>(DEPOT_WIDGET_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
|
||||
this->SetupWidgetData(type);
|
||||
this->FinishInitNested(desc, tile);
|
||||
|
||||
@ -689,6 +696,7 @@ struct DepotWindow : Window {
|
||||
DEPOT_WIDGET_SELL_ALL,
|
||||
DEPOT_WIDGET_BUILD,
|
||||
DEPOT_WIDGET_CLONE,
|
||||
DEPOT_WIDGET_RENAME,
|
||||
DEPOT_WIDGET_AUTOREPLACE,
|
||||
WIDGET_LIST_END);
|
||||
|
||||
@ -734,6 +742,12 @@ struct DepotWindow : Window {
|
||||
}
|
||||
break;
|
||||
|
||||
case DEPOT_WIDGET_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_BYTES, MAX_LENGTH_DEPOT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
|
||||
break;
|
||||
|
||||
case DEPOT_WIDGET_STOP_ALL:
|
||||
case DEPOT_WIDGET_START_ALL:
|
||||
DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), CMD_MASS_START_STOP);
|
||||
@ -767,6 +781,14 @@ struct DepotWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
if (str == NULL) return;
|
||||
|
||||
/* Do depot renaming */
|
||||
DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
|
||||
}
|
||||
|
||||
virtual void OnRightClick(Point pt, int widget)
|
||||
{
|
||||
if (widget != DEPOT_WIDGET_MATRIX) return;
|
||||
|
@ -15,4 +15,7 @@
|
||||
typedef uint16 DepotID;
|
||||
struct Depot;
|
||||
|
||||
static const uint MAX_LENGTH_DEPOT_NAME_BYTES = 31; ///< The maximum length of a depot name in bytes including '\0'
|
||||
static const uint MAX_LENGTH_DEPOT_NAME_PIXELS = 180; ///< The maximum length of a depot name in pixels
|
||||
|
||||
#endif /* DEPOT_TYPE_H */
|
||||
|
@ -2783,6 +2783,9 @@ STR_QUERY_RENAME_AIRCRAFT_TYPE_CAPTION :{WHITE}Rename a
|
||||
# Depot window
|
||||
STR_DEPOT_CAPTION :{WHITE}{DEPOT}
|
||||
|
||||
STR_DEPOT_RENAME_TOOLTIP :{BLACK}Change name of depot
|
||||
STR_DEPOT_RENAME_DEPOT_CAPTION :Rename depot
|
||||
|
||||
STR_DEPOT_NO_ENGINE :{BLACK}-
|
||||
STR_DEPOT_VEHICLE_TOOLTIP :{BLACK}{ENGINE}{RAW_STRING}
|
||||
STR_DEPOT_VEHICLE_TOOLTIP_CHAIN :{BLACK}{NUM} vehicle{P "" s}{RAW_STRING}
|
||||
@ -3489,6 +3492,8 @@ STR_ERROR_CAN_T_BUILD_ROAD_DEPOT :{WHITE}Can't bu
|
||||
STR_ERROR_CAN_T_BUILD_TRAM_DEPOT :{WHITE}Can't build tram vehicle depot here...
|
||||
STR_ERROR_CAN_T_BUILD_SHIP_DEPOT :{WHITE}Can't build ship depot here...
|
||||
|
||||
STR_ERROR_CAN_T_RENAME_DEPOT :{WHITE}Can't rename depot...
|
||||
|
||||
STR_TRAIN_MUST_BE_STOPPED :{WHITE}Train must be stopped inside a depot
|
||||
STR_ERROR_ROAD_VEHICLE_MUST_BE_STOPPED_INSIDE_DEPOT :{WHITE}... must be stopped inside a road vehicle depot
|
||||
STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT :{WHITE}Ship must be stopped in depot
|
||||
@ -4092,6 +4097,7 @@ STR_VIEWPORT_WAYPOINT_TINY :{TINYFONT}{WAYP
|
||||
# Simple strings to get specific types of data
|
||||
STR_COMPANY_NAME :{COMPANY}
|
||||
STR_COMPANY_NAME_COMPANY_NUM :{COMPANY} {COMPANYNUM}
|
||||
STR_DEPOT_NAME :{DEPOT}
|
||||
STR_ENGINE_NAME :{ENGINE}
|
||||
STR_GROUP_NAME :{GROUP}
|
||||
STR_INDUSTRY_NAME :{INDUSTRY}
|
||||
|
@ -950,8 +950,13 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
|
||||
if (vt == VEH_AIRCRAFT) {
|
||||
int64 temp[] = { GetInt32(&argv) };
|
||||
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_AIRCRAFT + vt, temp, last);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
const Depot *d = Depot::Get(GetInt32(&argv));
|
||||
if (d->name != NULL) {
|
||||
buff = strecpy(buff, d->name, last);
|
||||
} else {
|
||||
int64 temp[] = { d->town->index, d->town_cn + 1 };
|
||||
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * vt + (d->town_cn == 0 ? 0 : 1), temp, last);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user