2007-01-23 13:26:12 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file autoreplace_gui.cpp GUI for autoreplace handling. */
|
2007-02-23 01:48:53 +00:00
|
|
|
|
2007-01-23 13:26:12 +00:00
|
|
|
#include "stdafx.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-01-23 13:26:12 +00:00
|
|
|
#include "vehicle_gui.h"
|
|
|
|
#include "newgrf_engine.h"
|
2007-12-18 20:58:12 +00:00
|
|
|
#include "rail.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-01-07 09:19:53 +00:00
|
|
|
#include "autoreplace_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-04-29 21:31:29 +00:00
|
|
|
#include "engine_base.h"
|
2008-05-17 13:01:30 +00:00
|
|
|
#include "window_gui.h"
|
2008-05-27 12:24:23 +00:00
|
|
|
#include "engine_gui.h"
|
2009-05-26 13:29:01 +00:00
|
|
|
#include "settings_func.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2011-01-20 12:40:40 +00:00
|
|
|
#include "rail_gui.h"
|
2012-04-17 19:44:02 +00:00
|
|
|
#include "widgets/dropdown_func.h"
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/autoreplace_widget.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
|
2009-11-16 16:22:14 +00:00
|
|
|
uint GetEngineListHeight(VehicleType type);
|
2009-11-16 15:11:54 +00:00
|
|
|
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2009-09-13 17:47:07 +00:00
|
|
|
static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
|
2008-01-01 17:01:06 +00:00
|
|
|
{
|
2012-06-03 15:07:27 +00:00
|
|
|
int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position;
|
2008-01-01 17:01:06 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Rebuild the left autoreplace list if an engine is removed or added
|
2007-02-06 11:11:12 +00:00
|
|
|
* @param e Engine to check if it is removed or added
|
2007-06-27 20:40:20 +00:00
|
|
|
* @param id_g The group the engine belongs to
|
2007-02-06 11:11:12 +00:00
|
|
|
* Note: this function only works if it is called either
|
|
|
|
* - when a new vehicle is build, but before it's counted in num_engines
|
2013-01-08 22:46:42 +00:00
|
|
|
* - when a vehicle is deleted and after it's subtracted from num_engines
|
2007-02-06 11:11:12 +00:00
|
|
|
* - when not changing the count (used when changing replace orders)
|
2007-01-23 13:26:12 +00:00
|
|
|
*/
|
2007-06-27 20:40:20 +00:00
|
|
|
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
|
2007-01-23 13:26:12 +00:00
|
|
|
{
|
2012-01-28 17:56:48 +00:00
|
|
|
if (GetGroupNumEngines(_local_company, id_g, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0) {
|
2007-02-06 11:11:12 +00:00
|
|
|
/* We don't have any of this engine type.
|
|
|
|
* Either we just sold the last one, we build a new one or we stopped replacing it.
|
|
|
|
* In all cases, we need to update the left list */
|
2011-02-23 20:29:48 +00:00
|
|
|
InvalidateWindowData(WC_REPLACE_VEHICLE, Engine::Get(e)->type, 1);
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
|
2007-02-06 11:11:12 +00:00
|
|
|
* @param type The type of engine
|
|
|
|
*/
|
2007-05-18 17:31:41 +00:00
|
|
|
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
|
2007-01-23 13:26:12 +00:00
|
|
|
{
|
2011-02-23 20:29:48 +00:00
|
|
|
InvalidateWindowData(WC_REPLACE_VEHICLE, type, 0); // Update the autoreplace window
|
2007-02-06 11:11:12 +00:00
|
|
|
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
|
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2012-04-17 19:44:02 +00:00
|
|
|
static const StringID _start_replace_dropdown[] = {
|
|
|
|
STR_REPLACE_VEHICLES_NOW,
|
|
|
|
STR_REPLACE_VEHICLES_WHEN_OLD,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
/**
|
|
|
|
* Window for the autoreplacing of vehicles.
|
2007-02-06 11:11:12 +00:00
|
|
|
*/
|
2008-05-10 23:44:15 +00:00
|
|
|
class ReplaceVehicleWindow : public Window {
|
2009-10-11 12:51:15 +00:00
|
|
|
EngineID sel_engine[2]; ///< Selected engine left and right.
|
2009-10-11 13:09:44 +00:00
|
|
|
GUIEngineList engines[2]; ///< Left and right list of engines.
|
2009-10-11 12:51:15 +00:00
|
|
|
bool replace_engines; ///< If \c true, engines are replaced, if \c false, wagons are replaced (only for trains).
|
|
|
|
bool reset_sel_engine; ///< Also reset #sel_engine while updating left and/or right (#update_left and/or #update_right) and no valid engine selected.
|
|
|
|
GroupID sel_group; ///< Group selected to replace.
|
2009-10-17 14:26:40 +00:00
|
|
|
int details_height; ///< Minimal needed height of the details panels (found so far).
|
2009-10-27 20:19:05 +00:00
|
|
|
RailType sel_railtype; ///< Type of rail tracks selected.
|
2010-08-12 08:42:37 +00:00
|
|
|
Scrollbar *vscroll[2];
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Figure out if an engine should be added to a list.
|
2009-06-20 15:48:55 +00:00
|
|
|
* @param e The EngineID.
|
2009-06-20 23:22:46 +00:00
|
|
|
* @param draw_left If \c true, the left list is drawn (the engines specific to the railtype you selected).
|
2009-06-20 15:48:55 +00:00
|
|
|
* @param show_engines If \c true, the locomotives are drawn, else the wagons are drawn (never both).
|
|
|
|
* @return \c true if the engine should be in the list (based on this check), else \c false.
|
2008-05-10 23:44:15 +00:00
|
|
|
*/
|
|
|
|
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
|
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(e);
|
|
|
|
|
|
|
|
/* Ensure that the wagon/engine selection fits the engine. */
|
|
|
|
if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
|
|
|
|
|
|
|
|
if (draw_left && show_engines) {
|
|
|
|
/* Ensure that the railtype is specific to the selected one */
|
|
|
|
if (rvi->railtype != this->sel_railtype) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Generate an engines list
|
2008-05-10 23:44:15 +00:00
|
|
|
* @param draw_left true if generating the left list, otherwise false
|
|
|
|
*/
|
2009-10-11 11:47:21 +00:00
|
|
|
void GenerateReplaceVehList(bool draw_left)
|
2008-05-10 23:44:15 +00:00
|
|
|
{
|
|
|
|
EngineID selected_engine = INVALID_ENGINE;
|
|
|
|
VehicleType type = (VehicleType)this->window_number;
|
2009-10-17 08:18:55 +00:00
|
|
|
byte side = draw_left ? 0 : 1;
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2009-10-17 08:18:55 +00:00
|
|
|
GUIEngineList *list = &this->engines[side];
|
2008-05-28 17:29:27 +00:00
|
|
|
list->Clear();
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
const Engine *e;
|
|
|
|
FOR_ALL_ENGINES_OF_TYPE(e, type) {
|
|
|
|
EngineID eid = e->index;
|
2009-10-17 07:47:59 +00:00
|
|
|
if (type == VEH_TRAIN && !this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
|
2007-05-25 11:01:44 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
if (draw_left) {
|
2009-10-17 08:10:46 +00:00
|
|
|
const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
/* Skip drawing the engines we don't have any of and haven't set for replacement */
|
2009-10-17 08:10:46 +00:00
|
|
|
if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
|
2008-05-10 23:44:15 +00:00
|
|
|
} else {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
*list->Append() = eid;
|
2009-10-17 08:18:55 +00:00
|
|
|
if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|
2009-10-17 08:18:55 +00:00
|
|
|
this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
|
2008-07-20 21:21:51 +00:00
|
|
|
EngList_Sort(list, &EngineNumberSorter);
|
2007-02-06 11:11:12 +00:00
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
/** Generate the lists */
|
|
|
|
void GenerateLists()
|
|
|
|
{
|
|
|
|
EngineID e = this->sel_engine[0];
|
|
|
|
|
2009-10-18 16:31:27 +00:00
|
|
|
if (this->engines[0].NeedRebuild()) {
|
2009-10-11 13:09:44 +00:00
|
|
|
/* We need to rebuild the left engines list */
|
2009-10-17 07:47:59 +00:00
|
|
|
this->GenerateReplaceVehList(true);
|
2010-08-12 08:42:37 +00:00
|
|
|
this->vscroll[0]->SetCount(this->engines[0].Length());
|
2009-10-11 13:09:44 +00:00
|
|
|
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].Length() != 0) {
|
|
|
|
this->sel_engine[0] = this->engines[0][0];
|
2007-02-06 11:11:12 +00:00
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2009-10-18 16:31:27 +00:00
|
|
|
if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
|
2009-10-11 13:09:44 +00:00
|
|
|
/* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
|
2008-05-10 23:44:15 +00:00
|
|
|
if (this->sel_engine[0] == INVALID_ENGINE) {
|
2009-10-11 13:09:44 +00:00
|
|
|
/* Always empty the right engines list when nothing is selected in the left engines list */
|
|
|
|
this->engines[1].Clear();
|
2008-05-10 23:44:15 +00:00
|
|
|
this->sel_engine[1] = INVALID_ENGINE;
|
|
|
|
} else {
|
2013-10-28 10:28:24 +00:00
|
|
|
if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
|
|
|
|
/* Select the current replacement for sel_engine[0]. */
|
|
|
|
const Company *c = Company::Get(_local_company);
|
|
|
|
this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
|
|
|
|
}
|
|
|
|
/* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
|
2009-10-17 07:47:59 +00:00
|
|
|
this->GenerateReplaceVehList(false);
|
2010-08-12 08:42:37 +00:00
|
|
|
this->vscroll[1]->SetCount(this->engines[1].Length());
|
2013-10-28 10:28:24 +00:00
|
|
|
if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
|
|
|
|
int position = 0;
|
|
|
|
for (EngineID *it = this->engines[1].Begin(); it != this->engines[1].End(); ++it) {
|
|
|
|
if (*it == this->sel_engine[1]) break;
|
|
|
|
++position;
|
|
|
|
}
|
|
|
|
this->vscroll[1]->ScrollTowards(position);
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Reset the flags about needed updates */
|
2009-10-18 16:31:27 +00:00
|
|
|
this->engines[0].RebuildDone();
|
|
|
|
this->engines[1].RebuildDone();
|
2009-10-11 12:51:15 +00:00
|
|
|
this->reset_sel_engine = false;
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 19:44:02 +00:00
|
|
|
/**
|
|
|
|
* Handle click on the start replace button.
|
|
|
|
* @param replace_when_old Replace now or only when old?
|
|
|
|
*/
|
|
|
|
void ReplaceClick_StartReplace(bool replace_when_old)
|
|
|
|
{
|
|
|
|
EngineID veh_from = this->sel_engine[0];
|
|
|
|
EngineID veh_to = this->sel_engine[1];
|
|
|
|
DoCommandP(0, (replace_when_old ? 1 : 0) | (this->sel_group << 16), veh_from + (veh_to << 16), CMD_SET_AUTOREPLACE);
|
|
|
|
}
|
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
public:
|
2013-05-26 19:23:42 +00:00
|
|
|
ReplaceVehicleWindow(WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
|
2008-05-10 23:44:15 +00:00
|
|
|
{
|
2009-10-27 20:19:05 +00:00
|
|
|
if (vehicletype == VEH_TRAIN) {
|
|
|
|
/* For rail vehicles find the most used vehicle type, which is usually
|
|
|
|
* better than 'just' the first/previous vehicle type. */
|
|
|
|
uint type_count[RAILTYPE_END];
|
|
|
|
memset(type_count, 0, sizeof(type_count));
|
|
|
|
|
|
|
|
const Engine *e;
|
|
|
|
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
|
|
|
|
if (e->u.rail.railveh_type == RAILVEH_WAGON) continue;
|
|
|
|
type_count[e->u.rail.railtype] += GetGroupNumEngines(_local_company, id_g, e->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->sel_railtype = RAILTYPE_BEGIN;
|
|
|
|
for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
|
|
|
|
if (type_count[this->sel_railtype] < type_count[rt]) this->sel_railtype = rt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-11 12:51:15 +00:00
|
|
|
this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool)
|
2009-10-18 16:31:27 +00:00
|
|
|
this->engines[0].ForceRebuild();
|
|
|
|
this->engines[1].ForceRebuild();
|
2009-10-11 12:51:15 +00:00
|
|
|
this->reset_sel_engine = true;
|
2009-10-17 14:26:40 +00:00
|
|
|
this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
2008-05-10 23:44:15 +00:00
|
|
|
this->sel_engine[0] = INVALID_ENGINE;
|
|
|
|
this->sel_engine[1] = INVALID_ENGINE;
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
|
|
|
|
this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(vehicletype);
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2009-10-17 14:26:40 +00:00
|
|
|
this->owner = _local_company;
|
|
|
|
this->sel_group = id_g;
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-10-17 14:26:40 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_LEFT_MATRIX:
|
|
|
|
case WID_RV_RIGHT_MATRIX:
|
2009-11-16 16:22:14 +00:00
|
|
|
resize->height = GetEngineListHeight((VehicleType)this->window_number);
|
|
|
|
size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
|
2009-10-17 14:26:40 +00:00
|
|
|
break;
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_LEFT_DETAILS:
|
|
|
|
case WID_RV_RIGHT_DETAILS:
|
2009-10-17 14:26:40 +00:00
|
|
|
size->height = this->details_height;
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
2009-10-17 14:26:40 +00:00
|
|
|
StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
|
2009-11-14 12:50:38 +00:00
|
|
|
SetDParam(0, STR_CONFIG_SETTING_ON);
|
2009-10-17 14:26:40 +00:00
|
|
|
Dimension d = GetStringBoundingBox(str);
|
2009-11-14 12:50:38 +00:00
|
|
|
SetDParam(0, STR_CONFIG_SETTING_OFF);
|
2009-10-17 14:26:40 +00:00
|
|
|
d = maxdim(d, GetStringBoundingBox(str));
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_ENGINEWAGON_TOGGLE: {
|
2009-10-17 14:26:40 +00:00
|
|
|
StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
|
2009-11-14 12:50:38 +00:00
|
|
|
SetDParam(0, STR_REPLACE_ENGINES);
|
2009-10-17 14:26:40 +00:00
|
|
|
Dimension d = GetStringBoundingBox(str);
|
2009-11-14 12:50:38 +00:00
|
|
|
SetDParam(0, STR_REPLACE_WAGONS);
|
2009-10-17 14:26:40 +00:00
|
|
|
d = maxdim(d, GetStringBoundingBox(str));
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_INFO_TAB: {
|
2014-06-10 16:37:25 +00:00
|
|
|
Dimension d = GetStringBoundingBox(STR_REPLACE_NOT_REPLACING);
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED));
|
2009-10-17 14:26:40 +00:00
|
|
|
d.width += WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
|
|
|
|
d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
2009-11-22 19:19:11 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_RAILTYPE_DROPDOWN: {
|
2009-11-22 19:19:11 +00:00
|
|
|
Dimension d = {0, 0};
|
|
|
|
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(rt);
|
|
|
|
/* Skip rail type if it has no label */
|
|
|
|
if (rti->label == 0) continue;
|
|
|
|
d = maxdim(d, GetStringBoundingBox(rti->strings.replace_text));
|
|
|
|
}
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-04-17 19:44:02 +00:00
|
|
|
|
|
|
|
case WID_RV_START_REPLACE: {
|
|
|
|
Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
|
|
|
|
for (int i = 0; _start_replace_dropdown[i] != INVALID_STRING_ID; i++) {
|
|
|
|
d = maxdim(d, GetStringBoundingBox(_start_replace_dropdown[i]));
|
|
|
|
}
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2009-10-17 14:26:40 +00:00
|
|
|
}
|
2007-02-06 11:11:12 +00:00
|
|
|
|
2009-10-17 14:26:40 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_CAPTION:
|
2009-10-17 14:26:40 +00:00
|
|
|
SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
|
2012-04-17 19:44:30 +00:00
|
|
|
switch (this->sel_group) {
|
|
|
|
case ALL_GROUP:
|
|
|
|
SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEFAULT_GROUP:
|
|
|
|
SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetDParam(1, STR_GROUP_NAME);
|
|
|
|
SetDParam(2, sel_group);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-17 14:26:40 +00:00
|
|
|
break;
|
2007-02-06 11:11:12 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
2009-10-17 14:26:40 +00:00
|
|
|
const Company *c = Company::Get(_local_company);
|
2009-11-14 12:50:38 +00:00
|
|
|
SetDParam(0, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
2009-10-17 14:26:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_ENGINEWAGON_TOGGLE:
|
2009-11-14 12:50:38 +00:00
|
|
|
SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
|
2009-10-17 14:26:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_INFO_TAB: {
|
2009-10-17 14:26:40 +00:00
|
|
|
const Company *c = Company::Get(_local_company);
|
2014-06-10 16:37:25 +00:00
|
|
|
StringID str;
|
2009-10-17 14:26:40 +00:00
|
|
|
if (this->sel_engine[0] != INVALID_ENGINE) {
|
|
|
|
if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
|
2014-06-10 16:37:25 +00:00
|
|
|
str = STR_REPLACE_NOT_REPLACING;
|
2009-10-17 14:26:40 +00:00
|
|
|
} else {
|
2012-04-17 19:44:02 +00:00
|
|
|
bool when_old = false;
|
|
|
|
EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
|
2014-06-10 16:37:25 +00:00
|
|
|
str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
|
|
|
|
SetDParam(0, e);
|
2009-10-17 14:26:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-06-10 16:37:25 +00:00
|
|
|
str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
|
2009-10-17 14:26:40 +00:00
|
|
|
}
|
2008-05-11 11:41:18 +00:00
|
|
|
|
2014-06-10 16:37:25 +00:00
|
|
|
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_BLACK, SA_HOR_CENTER);
|
2009-10-17 14:26:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_LEFT_MATRIX:
|
|
|
|
case WID_RV_RIGHT_MATRIX: {
|
|
|
|
int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
|
2010-08-12 08:42:37 +00:00
|
|
|
EngineID start = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
|
|
|
|
EngineID end = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].Length());
|
2009-10-17 14:26:40 +00:00
|
|
|
|
|
|
|
/* Do the actual drawing */
|
|
|
|
DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
|
2009-11-16 15:11:54 +00:00
|
|
|
&this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
|
2009-10-17 14:26:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2007-02-06 11:11:12 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2009-10-18 16:31:27 +00:00
|
|
|
if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
Company *c = Company::Get(_local_company);
|
2008-05-10 23:44:15 +00:00
|
|
|
|
|
|
|
/* Disable the "Start Replacing" button if:
|
2009-10-11 13:09:44 +00:00
|
|
|
* Either engines list is empty
|
2012-04-17 19:44:02 +00:00
|
|
|
* or The selected replacement engine has a replacement (to prevent loops). */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_RV_START_REPLACE,
|
2009-10-11 11:47:21 +00:00
|
|
|
this->sel_engine[0] == INVALID_ENGINE ||
|
|
|
|
this->sel_engine[1] == INVALID_ENGINE ||
|
2012-04-17 19:44:02 +00:00
|
|
|
EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE);
|
2008-05-10 23:44:15 +00:00
|
|
|
|
|
|
|
/* Disable the "Stop Replacing" button if:
|
2009-10-11 13:09:44 +00:00
|
|
|
* The left engines list (existing vehicle) is empty
|
2008-05-10 23:44:15 +00:00
|
|
|
* or The selected vehicle has no replacement set up */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_RV_STOP_REPLACE,
|
2009-10-11 11:47:21 +00:00
|
|
|
this->sel_engine[0] == INVALID_ENGINE ||
|
2009-10-17 08:10:46 +00:00
|
|
|
!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
|
2008-05-10 23:44:15 +00:00
|
|
|
|
|
|
|
if (this->window_number == VEH_TRAIN) {
|
|
|
|
/* sets the colour of that art thing */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->GetWidget<NWidgetCore>(WID_RV_TRAIN_FLUFF_LEFT)->colour = _company_colours[_local_company];
|
|
|
|
this->GetWidget<NWidgetCore>(WID_RV_TRAIN_FLUFF_RIGHT)->colour = _company_colours[_local_company];
|
2008-01-17 21:57:20 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
/* Show the selected railtype in the pulldown menu */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->GetWidget<NWidgetCore>(WID_RV_TRAIN_RAILTYPE_DROPDOWN)->widget_data = GetRailTypeInfo(sel_railtype)->strings.replace_text;
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2010-02-21 17:52:43 +00:00
|
|
|
if (!this->IsShaded()) {
|
|
|
|
int needed_height = this->details_height;
|
|
|
|
/* Draw details panels. */
|
|
|
|
for (int side = 0; side < 2; side++) {
|
|
|
|
if (this->sel_engine[side] != INVALID_ENGINE) {
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
|
2010-02-21 17:52:43 +00:00
|
|
|
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
|
|
|
|
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side]);
|
|
|
|
needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
|
|
|
|
this->details_height = needed_height;
|
|
|
|
this->ReInit();
|
|
|
|
return;
|
2007-02-06 11:11:12 +00:00
|
|
|
}
|
2009-10-17 14:26:40 +00:00
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-10 23:44:15 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_ENGINEWAGON_TOGGLE:
|
2009-10-11 12:51:15 +00:00
|
|
|
this->replace_engines = !(this->replace_engines);
|
2009-10-18 16:31:27 +00:00
|
|
|
this->engines[0].ForceRebuild();
|
2009-10-11 12:51:15 +00:00
|
|
|
this->reset_sel_engine = true;
|
2008-05-10 23:44:15 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_RAILTYPE_DROPDOWN: // Railtype selection dropdown menu
|
|
|
|
ShowDropDownList(this, GetRailTypeDropDownList(true), sel_railtype, WID_RV_TRAIN_RAILTYPE_DROPDOWN);
|
2008-05-10 23:44:15 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
|
2009-05-26 13:29:01 +00:00
|
|
|
DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
|
2008-05-10 23:44:15 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_START_REPLACE: { // Start replacing
|
2012-04-17 19:44:02 +00:00
|
|
|
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
|
|
|
|
this->HandleButtonClick(WID_RV_START_REPLACE);
|
|
|
|
ReplaceClick_StartReplace(false);
|
|
|
|
} else {
|
|
|
|
bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
|
|
|
|
ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_STOP_REPLACE: { // Stop replacing
|
2008-05-10 23:44:15 +00:00
|
|
|
EngineID veh_from = this->sel_engine[0];
|
2009-05-26 13:29:01 +00:00
|
|
|
DoCommandP(0, this->sel_group << 16, veh_from + (INVALID_ENGINE << 16), CMD_SET_AUTOREPLACE);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_RV_LEFT_MATRIX:
|
|
|
|
case WID_RV_RIGHT_MATRIX: {
|
2010-07-26 13:08:48 +00:00
|
|
|
byte click_side;
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget == WID_RV_LEFT_MATRIX) {
|
2010-07-26 13:08:48 +00:00
|
|
|
click_side = 0;
|
|
|
|
} else {
|
|
|
|
click_side = 1;
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2010-08-12 08:42:37 +00:00
|
|
|
uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
|
2010-07-26 13:08:48 +00:00
|
|
|
size_t engine_count = this->engines[click_side].Length();
|
|
|
|
|
|
|
|
EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
|
|
|
|
if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
|
|
|
|
this->sel_engine[click_side] = e;
|
|
|
|
if (click_side == 0) {
|
|
|
|
this->engines[1].ForceRebuild();
|
|
|
|
this->reset_sel_engine = true;
|
|
|
|
}
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2008-05-10 23:44:15 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
2012-04-17 19:44:02 +00:00
|
|
|
switch (widget) {
|
|
|
|
case WID_RV_TRAIN_RAILTYPE_DROPDOWN: {
|
|
|
|
RailType temp = (RailType)index;
|
|
|
|
if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
|
|
|
|
sel_railtype = temp;
|
|
|
|
/* Reset scrollbar positions */
|
|
|
|
this->vscroll[0]->SetPosition(0);
|
|
|
|
this->vscroll[1]->SetPosition(0);
|
|
|
|
/* Rebuild the lists */
|
|
|
|
this->engines[0].ForceRebuild();
|
|
|
|
this->engines[1].ForceRebuild();
|
|
|
|
this->reset_sel_engine = true;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_RV_START_REPLACE:
|
|
|
|
this->ReplaceClick_StartReplace(index != 0);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2007-02-06 11:11:12 +00:00
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-10-04 17:10:57 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
|
|
|
|
this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2007-02-06 11:11:12 +00:00
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2008-05-10 23:44:15 +00:00
|
|
|
{
|
|
|
|
if (data != 0) {
|
2011-03-13 21:34:21 +00:00
|
|
|
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
|
2009-10-18 16:31:27 +00:00
|
|
|
this->engines[0].ForceRebuild();
|
2008-05-10 23:44:15 +00:00
|
|
|
} else {
|
2009-10-18 16:31:27 +00:00
|
|
|
this->engines[1].ForceRebuild();
|
2008-05-10 23:44:15 +00:00
|
|
|
}
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|
2008-05-10 23:44:15 +00:00
|
|
|
};
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2009-03-28 04:26:43 +00:00
|
|
|
static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
2009-10-17 14:26:40 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2013-06-30 14:32:31 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
|
2013-06-30 14:32:31 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
2009-10-17 14:26:40 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2012-05-05 19:27:32 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2012-04-17 19:44:02 +00:00
|
|
|
NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_ENGINEWAGON_TOGGLE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_TRAIN_FLUFF_LEFT), SetMinimalSize(15, 12), EndContainer(),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_RAILTYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_TRAIN_FLUFF_RIGHT), SetMinimalSize(16, 12), EndContainer(),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_WAGONREMOVE_TOGGLE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _replace_rail_vehicle_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "replace_vehicle_train", 500, 140,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_REPLACE_VEHICLE, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_replace_rail_vehicle_widgets, lengthof(_nested_replace_rail_vehicle_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2009-03-28 04:26:43 +00:00
|
|
|
static const NWidgetPart _nested_replace_vehicle_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
2009-10-17 14:26:40 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2013-06-30 14:32:31 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
|
2013-06-30 14:32:31 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
2009-10-17 14:26:40 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2012-04-17 19:44:02 +00:00
|
|
|
NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2009-03-28 04:26:43 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _replace_vehicle_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "replace_vehicle", 456, 118,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_REPLACE_VEHICLE, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2007-01-23 13:26:12 +00:00
|
|
|
|
2011-05-02 20:59:54 +00:00
|
|
|
/**
|
|
|
|
* Show the autoreplace configuration window for a particular group.
|
|
|
|
* @param id_g The group to replace the vehicles for.
|
|
|
|
* @param vehicletype The type of vehicles in the group.
|
|
|
|
*/
|
2007-05-19 09:40:18 +00:00
|
|
|
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
|
|
|
|
{
|
|
|
|
DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
|
2008-05-10 23:44:15 +00:00
|
|
|
new ReplaceVehicleWindow(vehicletype == VEH_TRAIN ? &_replace_rail_vehicle_desc : &_replace_vehicle_desc, vehicletype, id_g);
|
2007-01-23 13:26:12 +00:00
|
|
|
}
|