Template replacement: Allow naming templates

See: #481
pull/484/head
Jonathan G Rennison 1 year ago
parent 6d91e8ce36
commit 17f1d92072

@ -213,6 +213,7 @@ CommandProc CmdToggleReuseDepotVehicles;
CommandProc CmdToggleKeepRemainingVehicles;
CommandProc CmdToggleRefitAsTemplate;
CommandProc CmdToggleTemplateReplaceOldOnly;
CommandProc CmdRenameTemplateReplace;
CommandProc CmdVirtualTrainFromTemplateVehicle;
CommandProc CmdVirtualTrainFromTrain;
@ -466,6 +467,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdToggleKeepRemainingVehicles, CMD_ALL_TILES, CMDT_VEHICLE_MANAGEMENT ), // CMD_TOGGLE_KEEP_REMAINING_VEHICLES
DEF_CMD(CmdToggleRefitAsTemplate, CMD_ALL_TILES, CMDT_VEHICLE_MANAGEMENT ), // CMD_TOGGLE_REFIT_AS_TEMPLATE
DEF_CMD(CmdToggleTemplateReplaceOldOnly, CMD_ALL_TILES, CMDT_VEHICLE_MANAGEMENT ), // CMD_TOGGLE_TMPL_REPLACE_OLD_ONLY
DEF_CMD(CmdRenameTemplateReplace, CMD_ALL_TILES, CMDT_VEHICLE_MANAGEMENT ), // CMD_RENAME_TMPL_REPLACE
DEF_CMD(CmdVirtualTrainFromTemplateVehicle, CMD_CLIENT_ID | CMD_NO_TEST | CMD_ALL_TILES, CMDT_VEHICLE_MANAGEMENT), // CMD_VIRTUAL_TRAIN_FROM_TEMPLATE_VEHICLE
DEF_CMD(CmdVirtualTrainFromTrain, CMD_CLIENT_ID | CMD_NO_TEST | CMD_ALL_TILES, CMDT_VEHICLE_MANAGEMENT), // CMD_VIRTUAL_TRAIN_FROM_TRAIN

@ -435,6 +435,7 @@ enum Commands {
CMD_TOGGLE_KEEP_REMAINING_VEHICLES, ///< toggle 'keep remaining vehicles' on template
CMD_TOGGLE_REFIT_AS_TEMPLATE, ///< toggle 'refit as template' on template
CMD_TOGGLE_TMPL_REPLACE_OLD_ONLY, ///< toggle 'replace old vehicles only' on template
CMD_RENAME_TMPL_REPLACE, ///< rename a template
CMD_VIRTUAL_TRAIN_FROM_TEMPLATE_VEHICLE, ///< Creates a virtual train from a template
CMD_VIRTUAL_TRAIN_FROM_TRAIN, ///< Creates a virtual train from a regular train

@ -7312,6 +7312,7 @@ STR_TMPL_DEFINE_TEMPLATE :{BLACK}New
STR_TMPL_EDIT_TEMPLATE :{BLACK}Edit
STR_TMPL_CREATE_CLONE_VEH :{BLACK}Clone
STR_TMPL_DELETE_TEMPLATE :{BLACK}Delete
STR_TMPL_RENAME_TEMPLATE :{BLACK}Rename template
STR_TMPL_RPL_ALL_TMPL :{BLACK}Replace All Templates
STR_TMPL_NEW_VEHICLE :{BLACK}New Vehicle
STR_TMPL_CONFIRM :{BLACK}Ok
@ -7329,7 +7330,8 @@ STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING1
STR_TMPL_WARNING_FREE_WAGON :{RED}Free Chain: not runnable!
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Train not buildable: vehicle unavailable!
STR_TMPL_WARNING_VEH_NO_COMPATIBLE_RAIL_TYPE :{RED}Train not buildable: chain not compatible with any rail type
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Template in use: {NUM}
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Template in use: {STRING2}
STR_TMPL_NAME :{NUM}: {RAW_STRING}
STR_TMP_TEMPLATE_IN_USE :Template is in use
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :Using template from parent group
STR_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}
@ -7376,6 +7378,7 @@ STR_TMPL_RPLALLGUI_BUTTON_CANCEL :{BLACK}Cancel
STR_TMPL_RPLALLGUI_USE_TIP :{BLACK}Select a vehicle type from each list and press 'Replace All'. If you are happy with the result displayed in the template list, press 'Apply' to actually apply these changes.
STR_TMPL_CANT_CREATE :{WHITE}Can't create template or virtual vehicle...
STR_TMPL_CANT_RENAME :{WHITE}Can't rename template...
# Scheduled Dispatch
STR_SCHDISPATCH_CAPTION :{WHITE}{VEHICLE} (Scheduled Dispatch)

@ -6960,7 +6960,7 @@ STR_TMPL_TEMPLATE_OVR_RUNNING_COST :{BLACK}Custo es
STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING}{BLACK} {STRING}
STR_TMPL_WARNING_FREE_WAGON :{RED}Convoio libre: Non pode moverse!
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Tren non construíble: vehículo non dispoñible!
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Modelo en uso: {NUM}
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Modelo en uso: {STRING}
STR_TMP_TEMPLATE_IN_USE :O Modelo está en uso
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :Usando modelo do grupo pai
STR_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}

@ -7176,7 +7176,7 @@ STR_TMPL_TEMPLATE_OVR_RUNNING_COST :{BLACK}Erwartet
STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING}{BLACK} {STRING}
STR_TMPL_WARNING_FREE_WAGON :{RED}Unvollständiger Antriebsstrang: Zug kann nicht bewegt werden!
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Zug nicht erstellbar: Fahrzeug nicht verfügbar!
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Vorlage in Benutzung: {NUM}
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Vorlage in Benutzung: {STRING}
STR_TMP_TEMPLATE_IN_USE :Vorlage ist in Benutzung
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :Benutze Vorlage von übergeordneter Gruppe
STR_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}

@ -7319,7 +7319,7 @@ STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING}
STR_TMPL_WARNING_FREE_WAGON :{RED}객차/화차만 있음: 운행할 수 없습니다!
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}열차 구성 불가: 차량을 사용할 수 없습니다!
STR_TMPL_WARNING_VEH_NO_COMPATIBLE_RAIL_TYPE :{RED}열차 구성 불가: 이 편성을 사용할 수 있는 선로가 없습니다
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}{NUM}번 템플릿 사용 중
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}{STRING}번 템플릿 사용 중
STR_TMP_TEMPLATE_IN_USE :템플릿이 사용 중입니다.
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :상위 그룹의 템플릿 사용
STR_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}

@ -7320,7 +7320,7 @@ STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING}
STR_TMPL_WARNING_FREE_WAGON :{RED}没有接触网:跑不了!
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}火车建造失败:车辆不可用!
STR_TMPL_WARNING_VEH_NO_COMPATIBLE_RAIL_TYPE :{RED}火车建造失败:接触网不兼容当前轨道类型
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}正在使用的模板:{NUM}
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}正在使用的模板:{STRING}
STR_TMP_TEMPLATE_IN_USE :正在使用的模板
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :使用父组模板
STR_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}

@ -104,7 +104,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_REVERSE_AT_WAYPOINT, XSCF_NULL, 1, 1, "reverse_at_waypoint", nullptr, nullptr, nullptr },
{ XSLFI_VEH_LIFETIME_PROFIT, XSCF_NULL, 1, 1, "veh_lifetime_profit", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 1, 1, "linkgraph_day_scale", nullptr, nullptr, nullptr },
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 8, 8, "template_replacement", nullptr, nullptr, "TRPL,TMPL" },
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 9, 9, "template_replacement", nullptr, nullptr, "TRPL,TMPL" },
{ XSLFI_MORE_RAIL_TYPES, XSCF_NULL, 0, 1, "more_rail_types", nullptr, nullptr, nullptr },
{ XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 3, 3, "cargo_type_orders", nullptr, nullptr, "ORDX,VEOX" },
{ XSLFI_EXTENDED_GAMELOG, XSCF_NULL, 1, 1, "extended_gamelog", nullptr, nullptr, nullptr },

@ -43,6 +43,7 @@ const SaveLoadTable GTD() {
SLE_CONDVAR_X(TemplateVehicle, air_drag, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 8)),
SLE_CONDVAR_X(TemplateVehicle, ctrl_flags, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 7)),
SLE_CONDSSTR_X(TemplateVehicle, name, SLE_STR | SLF_ALLOW_CONTROL, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 9)),
SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 1)),

@ -27,6 +27,7 @@
#include "rail_gui.h"
#include "network/network.h"
#include "zoom_func.h"
#include "textbuf_gui.h"
#include "table/sprites.h"
#include "table/strings.h"
@ -85,6 +86,7 @@ enum TemplateReplaceWindowWidgets {
TRW_WIDGET_TMPL_BUTTONS_EDIT,
TRW_WIDGET_TMPL_BUTTONS_CLONE,
TRW_WIDGET_TMPL_BUTTONS_DELETE,
TRW_WIDGET_TMPL_BUTTONS_RENAME,
TRW_WIDGET_TMPL_BUTTONS_EDIT_RIGHTPANEL,
@ -162,6 +164,7 @@ static const NWidgetPart _widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TRW_WIDGET_TMPL_BUTTONS_EDIT), SetMinimalSize(75,12), SetResize(0,0), SetDataTip(STR_TMPL_EDIT_TEMPLATE, STR_TMPL_EDIT_TEMPLATE),
NWidget(WWT_TEXTBTN, COLOUR_GREY, TRW_WIDGET_TMPL_BUTTONS_CLONE), SetMinimalSize(75,12), SetResize(0,0), SetDataTip(STR_TMPL_CREATE_CLONE_VEH, STR_TMPL_CREATE_CLONE_VEH),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TRW_WIDGET_TMPL_BUTTONS_DELETE), SetMinimalSize(75,12), SetResize(0,0), SetDataTip(STR_TMPL_DELETE_TEMPLATE, STR_TMPL_DELETE_TEMPLATE),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TRW_WIDGET_TMPL_BUTTONS_RENAME), SetMinimalSize(75,12), SetResize(0,0), SetDataTip(STR_BUTTON_RENAME, STR_TMPL_RENAME_TEMPLATE),
NWidget(WWT_PANEL, COLOUR_GREY, TRW_WIDGET_TMPL_BUTTONS_EDIT_RIGHTPANEL), SetMinimalSize(50,12), SetResize(1,0), EndContainer(),
EndContainer(),
EndContainer(),
@ -427,6 +430,13 @@ public:
}
}
break;
case TRW_WIDGET_TMPL_BUTTONS_RENAME:
if ((this->selected_template_index >= 0) && (this->selected_template_index < (int)this->templates.size()) && !editInProgress) {
const TemplateVehicle *tmp = this->templates[this->selected_template_index];
SetDParamStr(0, tmp->name);
ShowQueryString(STR_JUST_RAW_STRING, STR_TMPL_RENAME_TEMPLATE, MAX_LENGTH_GROUP_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
}
break;
case TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: // Railtype selection dropdown menu
ShowDropDownList(this, GetRailTypeDropDownList(true, true), this->sel_railtype, TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN);
break;
@ -531,6 +541,14 @@ public:
this->SetDirty();
}
void OnQueryTextFinished(char *str) override
{
if (str != nullptr && (this->selected_template_index >= 0) && (this->selected_template_index < (int)this->templates.size()) && !editInProgress) {
const TemplateVehicle *tmp = this->templates[this->selected_template_index];
DoCommandP(0, tmp->index, 0, CMD_RENAME_TMPL_REPLACE | CMD_MSG(STR_TMPL_CANT_RENAME), nullptr, str);
}
}
/** For a given group (id) find the template that is issued for template replacement for this group and return this template's index
* from the gui list */
int FindTemplateIndex(TemplateID tid) const
@ -608,9 +626,12 @@ public:
int text_y = y + WidgetDimensions::scaled.matrix.top;
int col1 = left + (2 * left + right) / 3;
int col2 = left + (left + 2 * right) / 3;
SetDParam(0, g_id);
StringID str = STR_GROUP_NAME;
DrawString(left + ScaleGUITrad(30 + this->indents[i] * 10), right, text_y, str, TC_BLACK);
DrawString(left + ScaleGUITrad(4 + this->indents[i] * 10), col1 - ScaleGUITrad(4), text_y, str, TC_BLACK);
const TemplateID tid = GetTemplateIDByGroupIDRecursive(g_id);
const TemplateID tid_self = GetTemplateIDByGroupID(g_id);
@ -618,12 +639,19 @@ public:
/* Draw the template in use for this group, if there is one */
int template_in_use = FindTemplateIndex(tid);
if (tid != INVALID_TEMPLATE && tid_self == INVALID_TEMPLATE) {
DrawString (left, right, text_y, STR_TMP_TEMPLATE_FROM_PARENT_GROUP, TC_SILVER, SA_HOR_CENTER);
DrawString (col1 + ScaleGUITrad(4), col2 - ScaleGUITrad(4), text_y, STR_TMP_TEMPLATE_FROM_PARENT_GROUP, TC_SILVER, SA_HOR_CENTER);
} else if (template_in_use >= 0) {
SetDParam(0, template_in_use);
DrawString (left, right, text_y, STR_TMPL_GROUP_USES_TEMPLATE, TC_BLACK, SA_HOR_CENTER);
const TemplateVehicle *tv = TemplateVehicle::Get(tid);
SetDParam(1, template_in_use);
if (tv->name.empty()) {
SetDParam(0, STR_JUST_INT);
} else {
SetDParam(0, STR_TMPL_NAME);
SetDParamStr(2, tv->name);
}
DrawString (col1 + ScaleGUITrad(4), col2 - ScaleGUITrad(4), text_y, STR_TMPL_GROUP_USES_TEMPLATE, TC_BLACK, SA_HOR_CENTER);
} else if (tid != INVALID_TEMPLATE) { /* If there isn't a template applied from the current group, check if there is one for another rail type */
DrawString (left, right, text_y, STR_TMPL_TMPLRPL_EX_DIFF_RAILTYPE, TC_SILVER, SA_HOR_CENTER);
DrawString (col1 + ScaleGUITrad(4), col2 - ScaleGUITrad(4), text_y, STR_TMPL_TMPLRPL_EX_DIFF_RAILTYPE, TC_SILVER, SA_HOR_CENTER);
}
/* Draw the number of trains that still need to be treated by the currently selected template replacement */
@ -632,9 +660,9 @@ public:
const int num_trains = NumTrainsNeedTemplateReplacement(g_id, tv);
// Draw number
SetDParam(0, num_trains);
int inner_right = DrawString(left, right - ScaleGUITrad(4), text_y, STR_JUST_INT, num_trains ? TC_ORANGE : TC_GREY, SA_RIGHT);
int inner_right = DrawString(col2 + ScaleGUITrad(4), right - ScaleGUITrad(4), text_y, STR_JUST_INT, num_trains ? TC_ORANGE : TC_GREY, SA_RIGHT);
// Draw text
DrawString(left, inner_right - ScaleGUITrad(4), text_y, STR_TMPL_NUM_TRAINS_NEED_RPL, num_trains ? TC_BLACK : TC_GREY, SA_RIGHT);
DrawString(col2 + ScaleGUITrad(4), inner_right - ScaleGUITrad(4), text_y, STR_TMPL_NUM_TRAINS_NEED_RPL, num_trains ? TC_BLACK : TC_GREY, SA_RIGHT);
}
y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.matrix.Vertical();
@ -695,9 +723,16 @@ public:
int bottom_edge = y + this->bottom_matrix_item_size - FONT_HEIGHT_NORMAL - WidgetDimensions::scaled.framerect.bottom;
bool have_name = !v->name.empty();
/* Buying cost */
SetDParam(0, CalculateOverallTemplateCost(v));
DrawString(left + ScaleGUITrad(35), right, bottom_edge, STR_TMPL_TEMPLATE_OVR_VALUE, TC_BLUE, SA_LEFT);
DrawString(left + ScaleGUITrad(35), have_name ? left + ScaleGUITrad(195) : right - ScaleGUITrad(310), bottom_edge, STR_TMPL_TEMPLATE_OVR_VALUE, TC_BLUE, SA_LEFT);
if (have_name) {
SetDParamStr(0, v->name);
DrawString(left + ScaleGUITrad(200), right - ScaleGUITrad(310), bottom_edge, STR_JUST_RAW_STRING, TC_BLACK, SA_LEFT);
}
/* Index of current template vehicle in the list of all templates for its company */
SetDParam(0, i);

@ -120,6 +120,7 @@ public:
uint32 air_drag;
uint32 ctrl_flags; ///< See: TemplateVehicleControlFlags
std::string name;
VehicleSpriteSeq sprite_seq; ///< NOSAVE: Vehicle appearance.
TemplateVehicleImageDimensions image_dimensions; ///< NOSAVE: image dimensions

@ -983,6 +983,43 @@ CommandCost CmdToggleTemplateReplaceOldOnly(TileIndex tile, DoCommandFlag flags,
return CommandCost();
}
/**
* Rename a template vehicle.
* @param tile unused
* @param flags type of operation
* @param p1 the template vehicle's index
* @param p2 unused
* @param text new name
* @return the cost of this operation or an error
*/
CommandCost CmdRenameTemplateReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
if (template_vehicle == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(template_vehicle->owner);
if (ret.Failed()) return ret;
bool reset = StrEmpty(text);
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_GROUP_NAME_CHARS) return CMD_ERROR;
}
if (flags & DC_EXEC) {
/* Assign the new one */
if (reset) {
template_vehicle->name.clear();
} else {
template_vehicle->name = text;
}
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN, 0);
}
return CommandCost();
}
/**
* Create a virtual train from a template vehicle.
* @param tile unused
@ -1233,6 +1270,7 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
bool keep_remaining_vehicles = false;
bool refit_as_template = true;
bool replace_old_only = false;
std::string name;
if (template_vehicle != nullptr) {
old_ID = template_vehicle->index;
@ -1241,6 +1279,7 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
keep_remaining_vehicles = template_vehicle->keep_remaining_vehicles;
refit_as_template = template_vehicle->refit_as_template;
replace_old_only = template_vehicle->replace_old_only;
name = std::move(template_vehicle->name);
delete template_vehicle;
template_vehicle = nullptr;
}
@ -1252,6 +1291,7 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
template_vehicle->keep_remaining_vehicles = keep_remaining_vehicles;
template_vehicle->refit_as_template = refit_as_template;
template_vehicle->replace_old_only = replace_old_only;
template_vehicle->name = std::move(name);
}
// Make sure our replacements still point to the correct thing.

Loading…
Cancel
Save