Mercurial > hg > openttd
changeset 15172:e9741bd69a65 draft
(svn r19801) -Add [FS#3691]: custom naming of depots. Based on work by sbr
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 12 May 2010 20:50:10 +0000 |
parents | af63fbdbbf80 |
children | 02887c1c4d78 |
files | projects/openttd_vs80.vcproj projects/openttd_vs90.vcproj source.list src/command.cpp src/command_type.h src/depot_base.h src/depot_cmd.cpp src/depot_gui.cpp src/depot_type.h src/lang/english.txt src/strings.cpp |
diffstat | 11 files changed, 133 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -1992,6 +1992,10 @@ > </File> <File + RelativePath=".\..\src\depot_cmd.cpp" + > + </File> + <File RelativePath=".\..\src\disaster_cmd.cpp" > </File>
--- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -1989,6 +1989,10 @@ > </File> <File + RelativePath=".\..\src\depot_cmd.cpp" + > + </File> + <File RelativePath=".\..\src\disaster_cmd.cpp" > </File>
--- a/source.list +++ b/source.list @@ -426,6 +426,7 @@ autoreplace_cmd.cpp clear_cmd.cpp company_cmd.cpp +depot_cmd.cpp disaster_cmd.cpp dummy_land.cpp group_cmd.cpp
--- a/src/command.cpp +++ b/src/command.cpp @@ -110,6 +110,7 @@ CommandProc CmdRenamePresident; CommandProc CmdRenameStation; +CommandProc CmdRenameDepot; CommandProc CmdSellAircraft; CommandProc CmdBuildAircraft; @@ -260,6 +261,7 @@ 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
--- a/src/command_type.h +++ b/src/command_type.h @@ -210,6 +210,7 @@ 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
--- a/src/depot_base.h +++ b/src/depot_base.h @@ -20,7 +20,7 @@ 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)
new file mode 100644 --- /dev/null +++ b/src/depot_cmd.cpp @@ -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(); +}
--- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -53,6 +53,8 @@ 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 @@ 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 @@ 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 @@ DEPOT_WIDGET_SELL_ALL, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_CLONE, + DEPOT_WIDGET_RENAME, DEPOT_WIDGET_AUTOREPLACE, WIDGET_LIST_END); @@ -734,6 +742,12 @@ } 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 @@ } } + 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;
--- a/src/depot_type.h +++ b/src/depot_type.h @@ -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 */
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2783,6 +2783,9 @@ # 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_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 @@ # 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}
--- a/src/strings.cpp +++ b/src/strings.cpp @@ -950,8 +950,13 @@ if (vt == VEH_AIRCRAFT) { int64 temp[] = { GetInt32(&argv) }; buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_AIRCRAFT + vt, temp, last); + break; + } + + const Depot *d = Depot::Get(GetInt32(&argv)); + if (d->name != NULL) { + buff = strecpy(buff, d->name, last); } else { - const Depot *d = Depot::Get(GetInt32(&argv)); 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); }