Merge branch 'template_train_replacement-sx' into jgrpp

# Conflicts:
#	src/build_vehicle_gui.cpp
#	src/saveload/afterload.cpp
This commit is contained in:
Jonathan G Rennison
2016-02-16 21:08:21 +00:00
25 changed files with 281 additions and 1037 deletions

View File

@@ -32,6 +32,7 @@
#include "cargotype.h"
#include "core/geometry_func.hpp"
#include "autoreplace_func.h"
#include "train.h"
#include "widgets/build_vehicle_widget.h"
@@ -979,11 +980,16 @@ struct BuildVehicleWindow : Window {
int details_height; ///< Minimal needed height of the details panels (found so far).
Scrollbar *vscroll;
bool build_and_refit; ///< Build and refit. This is beauty, but we need some persistence to save user choice for this game session at least
bool virtual_train_mode; ///< Are we building a virtual train?
Train **virtual_train_out; ///< Virtual train ptr
BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc)
BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type, Train **virtual_train_out) : Window(desc)
{
this->vehicle_type = type;
this->window_number = tile == INVALID_TILE ? (int)type : tile;
this->virtual_train_out = virtual_train_out;
this->virtual_train_mode = (virtual_train_out != NULL);
if (this->virtual_train_mode) this->window_number = 0;
this->sel_engine = INVALID_ENGINE;
@@ -1003,7 +1009,7 @@ struct BuildVehicleWindow : Window {
break;
}
this->listview_mode = (this->window_number <= VEH_END);
this->listview_mode = !(this->virtual_train_mode) && (this->window_number <= VEH_END);
this->CreateNestedTree();
@@ -1029,8 +1035,13 @@ struct BuildVehicleWindow : Window {
this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit);
widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + type;
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + type;
if (this->virtual_train_mode) {
widget->widget_data = STR_TMPL_CONFIRM;
widget->tool_tip = STR_TMPL_CONFIRM;
} else {
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + type;
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + type;
}
widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
widget->widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
@@ -1043,7 +1054,7 @@ struct BuildVehicleWindow : Window {
this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
this->FinishInitNested(tile == INVALID_TILE ? (int)type : tile);
this->FinishInitNested(this->window_number);
this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
@@ -1127,7 +1138,7 @@ struct BuildVehicleWindow : Window {
int num_engines = 0;
int num_wagons = 0;
this->filter.railtype = (this->listview_mode) ? RAILTYPE_END : GetRailType(this->window_number);
this->filter.railtype = (this->listview_mode || this->virtual_train_mode) ? RAILTYPE_END : GetRailType(this->window_number);
this->eng_list.Clear();
@@ -1326,16 +1337,25 @@ struct BuildVehicleWindow : Window {
case WID_BV_BUILD: {
EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) {
CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildPrimaryVehicle;
CommandCallback *callback;
uint32 cmd;
if (this->virtual_train_mode) {
callback = CcAddVirtualEngine;
cmd = CMD_BUILD_VIRTUAL_RAIL_VEHICLE;
} else {
callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON)
? CcBuildWagon : CcBuildPrimaryVehicle;
cmd = GetCmdBuildVeh(this->vehicle_type);
}
if (!this->IsWidgetDisabled(WID_BV_BUILD_REFIT) && this->build_and_refit) {
/* build and refit */
char text_buffer[2];
text_buffer[0] = 'R';
text_buffer[1] = this->cargo_filter[this->cargo_filter_criteria];
DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback, text_buffer, true, 2);
DoCommandP(this->window_number, sel_eng, 0, cmd, callback, text_buffer, true, 2);
} else {
/* build only */
DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
DoCommandP(this->window_number, sel_eng, 0, cmd, callback);
}
}
break;
@@ -1375,7 +1395,7 @@ struct BuildVehicleWindow : Window {
{
switch (widget) {
case WID_BV_CAPTION:
if (this->vehicle_type == VEH_TRAIN && !this->listview_mode) {
if (this->vehicle_type == VEH_TRAIN && !this->listview_mode && !this->virtual_train_mode) {
const RailtypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
SetDParam(0, rti->strings.build_caption);
} else {
@@ -1515,8 +1535,34 @@ struct BuildVehicleWindow : Window {
{
this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
}
void AddVirtualEngine(Train *toadd)
{
if (this->virtual_train_out == NULL) return;
if (*(this->virtual_train_out) == NULL) {
*(this->virtual_train_out) = toadd;
} else {
VehicleID target = (*(this->virtual_train_out))->GetLastUnit()->index;
DoCommandP(0, (1 << 21) | toadd->index, target, CMD_MOVE_RAIL_VEHICLE);
}
InvalidateWindowClassesData(WC_CREATE_TEMPLATE);
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN);
}
};
void CcAddVirtualEngine(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
{
if (result.Failed()) return;
Window* window = FindWindowById(WC_BUILD_VIRTUAL_TRAIN, 0);
if (window) {
Train* train = Train::From(Vehicle::Get(_new_vehicle_id));
((BuildVehicleWindow*) window)->AddVirtualEngine(train);
}
}
static WindowDesc _build_vehicle_desc(
WDP_AUTO, "build_vehicle", 240, 268,
WC_BUILD_VEHICLE, WC_NONE,
@@ -1524,6 +1570,13 @@ static WindowDesc _build_vehicle_desc(
_nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets)
);
static WindowDesc _build_template_vehicle_desc(
WDP_AUTO, "build_vehicle", 240, 268,
WC_BUILD_VIRTUAL_TRAIN, WC_CREATE_TEMPLATE,
WDF_CONSTRUCTION,
_nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets)
);
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
{
/* We want to be able to open both Available Train as Available Ships,
@@ -1536,5 +1589,14 @@ void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
DeleteWindowById(WC_BUILD_VEHICLE, num);
new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
new BuildVehicleWindow(&_build_vehicle_desc, tile, type, NULL);
}
void ShowTemplateTrainBuildVehicleWindow(Train **virtual_train)
{
assert(IsCompanyBuildableVehicleType(VEH_TRAIN));
DeleteWindowById(WC_BUILD_VIRTUAL_TRAIN, 0);
new BuildVehicleWindow(&_build_template_vehicle_desc, INVALID_TILE, VEH_TRAIN, virtual_train);
}