4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file autoreplace_gui.cpp GUI for autoreplace handling. */
13 #include "command_func.h"
14 #include "vehicle_gui.h"
15 #include "newgrf_engine.h"
17 #include "strings_func.h"
18 #include "window_func.h"
19 #include "autoreplace_func.h"
20 #include "company_func.h"
21 #include "engine_base.h"
22 #include "window_gui.h"
23 #include "engine_gui.h"
24 #include "settings_func.h"
25 #include "core/geometry_func.hpp"
27 #include "widgets/dropdown_func.h"
29 #include "widgets/autoreplace_widget.h"
32 uint
GetEngineListHeight(VehicleType type
);
33 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
);
35 static int CDECL
EngineNumberSorter(const EngineID
*a
, const EngineID
*b
)
37 int r
= Engine::Get(*a
)->list_position
- Engine::Get(*b
)->list_position
;
43 * Rebuild the left autoreplace list if an engine is removed or added
44 * @param e Engine to check if it is removed or added
45 * @param id_g The group the engine belongs to
46 * Note: this function only works if it is called either
47 * - when a new vehicle is build, but before it's counted in num_engines
48 * - when a vehicle is deleted and after it's subtracted from num_engines
49 * - when not changing the count (used when changing replace orders)
51 void InvalidateAutoreplaceWindow(EngineID e
, GroupID id_g
)
53 if (GetGroupNumEngines(_local_company
, id_g
, e
) == 0 || GetGroupNumEngines(_local_company
, ALL_GROUP
, e
) == 0) {
54 /* We don't have any of this engine type.
55 * Either we just sold the last one, we build a new one or we stopped replacing it.
56 * In all cases, we need to update the left list */
57 InvalidateWindowData(WC_REPLACE_VEHICLE
, Engine::Get(e
)->type
, 1);
62 * When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
63 * @param type The type of engine
65 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type
)
67 InvalidateWindowData(WC_REPLACE_VEHICLE
, type
, 0); // Update the autoreplace window
68 InvalidateWindowClassesData(WC_BUILD_VEHICLE
); // The build windows needs updating as well
71 static const StringID _start_replace_dropdown
[] = {
72 STR_REPLACE_VEHICLES_NOW
,
73 STR_REPLACE_VEHICLES_WHEN_OLD
,
78 * Window for the autoreplacing of vehicles.
80 class ReplaceVehicleWindow
: public Window
{
81 EngineID sel_engine
[2]; ///< Selected engine left and right.
82 GUIEngineList engines
[2]; ///< Left and right list of engines.
83 bool replace_engines
; ///< If \c true, engines are replaced, if \c false, wagons are replaced (only for trains).
84 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.
85 GroupID sel_group
; ///< Group selected to replace.
86 int details_height
; ///< Minimal needed height of the details panels (found so far).
87 RailType sel_railtype
; ///< Type of rail tracks selected.
88 Scrollbar
*vscroll
[2];
91 * Figure out if an engine should be added to a list.
92 * @param e The EngineID.
93 * @param draw_left If \c true, the left list is drawn (the engines specific to the railtype you selected).
94 * @param show_engines If \c true, the locomotives are drawn, else the wagons are drawn (never both).
95 * @return \c true if the engine should be in the list (based on this check), else \c false.
97 bool GenerateReplaceRailList(EngineID e
, bool draw_left
, bool show_engines
)
99 const RailVehicleInfo
*rvi
= RailVehInfo(e
);
101 /* Ensure that the wagon/engine selection fits the engine. */
102 if ((rvi
->railveh_type
== RAILVEH_WAGON
) == show_engines
) return false;
104 if (draw_left
&& show_engines
) {
105 /* Ensure that the railtype is specific to the selected one */
106 if (rvi
->railtype
!= this->sel_railtype
) return false;
113 * Generate an engines list
114 * @param draw_left true if generating the left list, otherwise false
116 void GenerateReplaceVehList(bool draw_left
)
118 EngineID selected_engine
= INVALID_ENGINE
;
119 VehicleType type
= (VehicleType
)this->window_number
;
120 byte side
= draw_left
? 0 : 1;
122 GUIEngineList
*list
= &this->engines
[side
];
126 FOR_ALL_ENGINES_OF_TYPE(e
, type
) {
127 EngineID eid
= e
->index
;
128 if (type
== VEH_TRAIN
&& !this->GenerateReplaceRailList(eid
, draw_left
, this->replace_engines
)) continue; // special rules for trains
131 const uint num_engines
= GetGroupNumEngines(_local_company
, this->sel_group
, eid
);
133 /* Skip drawing the engines we don't have any of and haven't set for replacement */
134 if (num_engines
== 0 && EngineReplacementForCompany(Company::Get(_local_company
), eid
, this->sel_group
) == INVALID_ENGINE
) continue;
136 if (!CheckAutoreplaceValidity(this->sel_engine
[0], eid
, _local_company
)) continue;
139 *list
->Append() = eid
;
140 if (eid
== this->sel_engine
[side
]) selected_engine
= eid
; // The selected engine is still in the list
142 this->sel_engine
[side
] = selected_engine
; // update which engine we selected (the same or none, if it's not in the list anymore)
143 EngList_Sort(list
, &EngineNumberSorter
);
146 /** Generate the lists */
149 EngineID e
= this->sel_engine
[0];
151 if (this->engines
[0].NeedRebuild()) {
152 /* We need to rebuild the left engines list */
153 this->GenerateReplaceVehList(true);
154 this->vscroll
[0]->SetCount(this->engines
[0].Length());
155 if (this->reset_sel_engine
&& this->sel_engine
[0] == INVALID_ENGINE
&& this->engines
[0].Length() != 0) {
156 this->sel_engine
[0] = this->engines
[0][0];
160 if (this->engines
[1].NeedRebuild() || e
!= this->sel_engine
[0]) {
161 /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
162 if (this->sel_engine
[0] == INVALID_ENGINE
) {
163 /* Always empty the right engines list when nothing is selected in the left engines list */
164 this->engines
[1].Clear();
165 this->sel_engine
[1] = INVALID_ENGINE
;
167 if (this->reset_sel_engine
&& this->sel_engine
[0] != INVALID_ENGINE
) {
168 /* Select the current replacement for sel_engine[0]. */
169 const Company
*c
= Company::Get(_local_company
);
170 this->sel_engine
[1] = EngineReplacementForCompany(c
, this->sel_engine
[0], this->sel_group
);
172 /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
173 this->GenerateReplaceVehList(false);
174 this->vscroll
[1]->SetCount(this->engines
[1].Length());
175 if (this->reset_sel_engine
&& this->sel_engine
[1] != INVALID_ENGINE
) {
177 for (EngineID
*it
= this->engines
[1].Begin(); it
!= this->engines
[1].End(); ++it
) {
178 if (*it
== this->sel_engine
[1]) break;
181 this->vscroll
[1]->ScrollTowards(position
);
185 /* Reset the flags about needed updates */
186 this->engines
[0].RebuildDone();
187 this->engines
[1].RebuildDone();
188 this->reset_sel_engine
= false;
192 * Handle click on the start replace button.
193 * @param replace_when_old Replace now or only when old?
195 void ReplaceClick_StartReplace(bool replace_when_old
)
197 EngineID veh_from
= this->sel_engine
[0];
198 EngineID veh_to
= this->sel_engine
[1];
199 DoCommandP(0, (replace_when_old
? 1 : 0) | (this->sel_group
<< 16), veh_from
+ (veh_to
<< 16), CMD_SET_AUTOREPLACE
);
203 ReplaceVehicleWindow(WindowDesc
*desc
, VehicleType vehicletype
, GroupID id_g
) : Window(desc
)
205 if (vehicletype
== VEH_TRAIN
) {
206 /* For rail vehicles find the most used vehicle type, which is usually
207 * better than 'just' the first/previous vehicle type. */
208 uint type_count
[RAILTYPE_END
];
209 memset(type_count
, 0, sizeof(type_count
));
212 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_TRAIN
) {
213 if (e
->u
.rail
.railveh_type
== RAILVEH_WAGON
) continue;
214 type_count
[e
->u
.rail
.railtype
] += GetGroupNumEngines(_local_company
, id_g
, e
->index
);
217 this->sel_railtype
= RAILTYPE_BEGIN
;
218 for (RailType rt
= RAILTYPE_BEGIN
; rt
< RAILTYPE_END
; rt
++) {
219 if (type_count
[this->sel_railtype
] < type_count
[rt
]) this->sel_railtype
= rt
;
223 this->replace_engines
= true; // start with locomotives (all other vehicles will not read this bool)
224 this->engines
[0].ForceRebuild();
225 this->engines
[1].ForceRebuild();
226 this->reset_sel_engine
= true;
227 this->details_height
= ((vehicletype
== VEH_TRAIN
) ? 10 : 9) * FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
228 this->sel_engine
[0] = INVALID_ENGINE
;
229 this->sel_engine
[1] = INVALID_ENGINE
;
231 this->CreateNestedTree();
232 this->vscroll
[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR
);
233 this->vscroll
[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR
);
234 this->FinishInitNested(vehicletype
);
236 this->owner
= _local_company
;
237 this->sel_group
= id_g
;
240 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
243 case WID_RV_LEFT_MATRIX
:
244 case WID_RV_RIGHT_MATRIX
:
245 resize
->height
= GetEngineListHeight((VehicleType
)this->window_number
);
246 size
->height
= (this->window_number
<= VEH_ROAD
? 8 : 4) * resize
->height
;
249 case WID_RV_LEFT_DETAILS
:
250 case WID_RV_RIGHT_DETAILS
:
251 size
->height
= this->details_height
;
254 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE
: {
255 StringID str
= this->GetWidget
<NWidgetCore
>(widget
)->widget_data
;
256 SetDParam(0, STR_CONFIG_SETTING_ON
);
257 Dimension d
= GetStringBoundingBox(str
);
258 SetDParam(0, STR_CONFIG_SETTING_OFF
);
259 d
= maxdim(d
, GetStringBoundingBox(str
));
260 d
.width
+= padding
.width
;
261 d
.height
+= padding
.height
;
262 *size
= maxdim(*size
, d
);
266 case WID_RV_TRAIN_ENGINEWAGON_TOGGLE
: {
267 StringID str
= this->GetWidget
<NWidgetCore
>(widget
)->widget_data
;
268 SetDParam(0, STR_REPLACE_ENGINES
);
269 Dimension d
= GetStringBoundingBox(str
);
270 SetDParam(0, STR_REPLACE_WAGONS
);
271 d
= maxdim(d
, GetStringBoundingBox(str
));
272 d
.width
+= padding
.width
;
273 d
.height
+= padding
.height
;
274 *size
= maxdim(*size
, d
);
278 case WID_RV_INFO_TAB
: {
279 SetDParam(0, STR_REPLACE_NOT_REPLACING
);
280 Dimension d
= GetStringBoundingBox(STR_BLACK_STRING
);
281 SetDParam(0, STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED
);
282 d
= maxdim(d
, GetStringBoundingBox(STR_BLACK_STRING
));
283 d
.width
+= WD_FRAMETEXT_LEFT
+ WD_FRAMETEXT_RIGHT
;
284 d
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
285 *size
= maxdim(*size
, d
);
289 case WID_RV_TRAIN_RAILTYPE_DROPDOWN
: {
290 Dimension d
= {0, 0};
291 for (RailType rt
= RAILTYPE_BEGIN
; rt
!= RAILTYPE_END
; rt
++) {
292 const RailtypeInfo
*rti
= GetRailTypeInfo(rt
);
293 /* Skip rail type if it has no label */
294 if (rti
->label
== 0) continue;
295 d
= maxdim(d
, GetStringBoundingBox(rti
->strings
.replace_text
));
297 d
.width
+= padding
.width
;
298 d
.height
+= padding
.height
;
299 *size
= maxdim(*size
, d
);
303 case WID_RV_START_REPLACE
: {
304 Dimension d
= GetStringBoundingBox(STR_REPLACE_VEHICLES_START
);
305 for (int i
= 0; _start_replace_dropdown
[i
] != INVALID_STRING_ID
; i
++) {
306 d
= maxdim(d
, GetStringBoundingBox(_start_replace_dropdown
[i
]));
308 d
.width
+= padding
.width
;
309 d
.height
+= padding
.height
;
310 *size
= maxdim(*size
, d
);
316 virtual void SetStringParameters(int widget
) const
320 SetDParam(0, STR_REPLACE_VEHICLE_TRAIN
+ this->window_number
);
321 switch (this->sel_group
) {
323 SetDParam(1, STR_GROUP_ALL_TRAINS
+ this->window_number
);
327 SetDParam(1, STR_GROUP_DEFAULT_TRAINS
+ this->window_number
);
331 SetDParam(1, STR_GROUP_NAME
);
332 SetDParam(2, sel_group
);
337 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE
: {
338 const Company
*c
= Company::Get(_local_company
);
339 SetDParam(0, c
->settings
.renew_keep_length
? STR_CONFIG_SETTING_ON
: STR_CONFIG_SETTING_OFF
);
343 case WID_RV_TRAIN_ENGINEWAGON_TOGGLE
:
344 SetDParam(0, this->replace_engines
? STR_REPLACE_ENGINES
: STR_REPLACE_WAGONS
);
349 virtual void DrawWidget(const Rect
&r
, int widget
) const
352 case WID_RV_INFO_TAB
: {
353 const Company
*c
= Company::Get(_local_company
);
354 if (this->sel_engine
[0] != INVALID_ENGINE
) {
355 if (!EngineHasReplacementForCompany(c
, this->sel_engine
[0], this->sel_group
)) {
356 SetDParam(0, STR_REPLACE_NOT_REPLACING
);
358 bool when_old
= false;
359 EngineID e
= EngineReplacementForCompany(c
, this->sel_engine
[0], this->sel_group
, &when_old
);
360 SetDParam(0, when_old
? STR_REPLACE_REPLACING_WHEN_OLD
: STR_ENGINE_NAME
);
364 SetDParam(0, STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED
);
367 DrawString(r
.left
+ WD_FRAMETEXT_LEFT
, r
.right
- WD_FRAMETEXT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, STR_BLACK_STRING
, TC_FROMSTRING
, SA_HOR_CENTER
);
371 case WID_RV_LEFT_MATRIX
:
372 case WID_RV_RIGHT_MATRIX
: {
373 int side
= (widget
== WID_RV_LEFT_MATRIX
) ? 0 : 1;
374 EngineID start
= this->vscroll
[side
]->GetPosition(); // what is the offset for the start (scrolling)
375 EngineID end
= min(this->vscroll
[side
]->GetCapacity() + start
, this->engines
[side
].Length());
377 /* Do the actual drawing */
378 DrawEngineList((VehicleType
)this->window_number
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
,
379 &this->engines
[side
], start
, end
, this->sel_engine
[side
], side
== 0, this->sel_group
);
385 virtual void OnPaint()
387 if (this->engines
[0].NeedRebuild() || this->engines
[1].NeedRebuild()) this->GenerateLists();
389 Company
*c
= Company::Get(_local_company
);
391 /* Disable the "Start Replacing" button if:
392 * Either engines list is empty
393 * or The selected replacement engine has a replacement (to prevent loops). */
394 this->SetWidgetDisabledState(WID_RV_START_REPLACE
,
395 this->sel_engine
[0] == INVALID_ENGINE
||
396 this->sel_engine
[1] == INVALID_ENGINE
||
397 EngineReplacementForCompany(c
, this->sel_engine
[1], this->sel_group
) != INVALID_ENGINE
);
399 /* Disable the "Stop Replacing" button if:
400 * The left engines list (existing vehicle) is empty
401 * or The selected vehicle has no replacement set up */
402 this->SetWidgetDisabledState(WID_RV_STOP_REPLACE
,
403 this->sel_engine
[0] == INVALID_ENGINE
||
404 !EngineHasReplacementForCompany(c
, this->sel_engine
[0], this->sel_group
));
406 if (this->window_number
== VEH_TRAIN
) {
407 /* sets the colour of that art thing */
408 this->GetWidget
<NWidgetCore
>(WID_RV_TRAIN_FLUFF_LEFT
)->colour
= _company_colours
[_local_company
];
409 this->GetWidget
<NWidgetCore
>(WID_RV_TRAIN_FLUFF_RIGHT
)->colour
= _company_colours
[_local_company
];
411 /* Show the selected railtype in the pulldown menu */
412 this->GetWidget
<NWidgetCore
>(WID_RV_TRAIN_RAILTYPE_DROPDOWN
)->widget_data
= GetRailTypeInfo(sel_railtype
)->strings
.replace_text
;
417 if (!this->IsShaded()) {
418 int needed_height
= this->details_height
;
419 /* Draw details panels. */
420 for (int side
= 0; side
< 2; side
++) {
421 if (this->sel_engine
[side
] != INVALID_ENGINE
) {
422 NWidgetBase
*nwi
= this->GetWidget
<NWidgetBase
>(side
== 0 ? WID_RV_LEFT_DETAILS
: WID_RV_RIGHT_DETAILS
);
423 int text_end
= DrawVehiclePurchaseInfo(nwi
->pos_x
+ WD_FRAMETEXT_LEFT
, nwi
->pos_x
+ nwi
->current_x
- WD_FRAMETEXT_RIGHT
,
424 nwi
->pos_y
+ WD_FRAMERECT_TOP
, this->sel_engine
[side
]);
425 needed_height
= max(needed_height
, text_end
- (int)nwi
->pos_y
+ WD_FRAMERECT_BOTTOM
);
428 if (needed_height
!= this->details_height
) { // Details window are not high enough, enlarge them.
429 this->details_height
= needed_height
;
436 virtual void OnClick(Point pt
, int widget
, int click_count
)
439 case WID_RV_TRAIN_ENGINEWAGON_TOGGLE
:
440 this->replace_engines
= !(this->replace_engines
);
441 this->engines
[0].ForceRebuild();
442 this->reset_sel_engine
= true;
446 case WID_RV_TRAIN_RAILTYPE_DROPDOWN
: // Railtype selection dropdown menu
447 ShowDropDownList(this, GetRailTypeDropDownList(true), sel_railtype
, WID_RV_TRAIN_RAILTYPE_DROPDOWN
);
450 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE
: // toggle renew_keep_length
451 DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company
)->settings
.renew_keep_length
? 0 : 1, CMD_CHANGE_COMPANY_SETTING
);
454 case WID_RV_START_REPLACE
: { // Start replacing
455 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
456 this->HandleButtonClick(WID_RV_START_REPLACE
);
457 ReplaceClick_StartReplace(false);
459 bool replacment_when_old
= EngineHasReplacementWhenOldForCompany(Company::Get(_local_company
), this->sel_engine
[0], this->sel_group
);
460 ShowDropDownMenu(this, _start_replace_dropdown
, replacment_when_old
? 1 : 0, WID_RV_START_REPLACE
, !this->replace_engines
? 1 << 1 : 0, 0);
465 case WID_RV_STOP_REPLACE
: { // Stop replacing
466 EngineID veh_from
= this->sel_engine
[0];
467 DoCommandP(0, this->sel_group
<< 16, veh_from
+ (INVALID_ENGINE
<< 16), CMD_SET_AUTOREPLACE
);
471 case WID_RV_LEFT_MATRIX
:
472 case WID_RV_RIGHT_MATRIX
: {
474 if (widget
== WID_RV_LEFT_MATRIX
) {
479 uint i
= this->vscroll
[click_side
]->GetScrolledRowFromWidget(pt
.y
, this, widget
);
480 size_t engine_count
= this->engines
[click_side
].Length();
482 EngineID e
= engine_count
> i
? this->engines
[click_side
][i
] : INVALID_ENGINE
;
483 if (e
== this->sel_engine
[click_side
]) break; // we clicked the one we already selected
484 this->sel_engine
[click_side
] = e
;
485 if (click_side
== 0) {
486 this->engines
[1].ForceRebuild();
487 this->reset_sel_engine
= true;
495 virtual void OnDropdownSelect(int widget
, int index
)
498 case WID_RV_TRAIN_RAILTYPE_DROPDOWN
: {
499 RailType temp
= (RailType
)index
;
500 if (temp
== sel_railtype
) return; // we didn't select a new one. No need to change anything
502 /* Reset scrollbar positions */
503 this->vscroll
[0]->SetPosition(0);
504 this->vscroll
[1]->SetPosition(0);
505 /* Rebuild the lists */
506 this->engines
[0].ForceRebuild();
507 this->engines
[1].ForceRebuild();
508 this->reset_sel_engine
= true;
513 case WID_RV_START_REPLACE
:
514 this->ReplaceClick_StartReplace(index
!= 0);
519 virtual void OnResize()
521 this->vscroll
[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX
);
522 this->vscroll
[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX
);
526 * Some data on this window has become invalid.
527 * @param data Information about the changed data.
528 * @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.
530 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
533 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
534 this->engines
[0].ForceRebuild();
536 this->engines
[1].ForceRebuild();
541 static const NWidgetPart _nested_replace_rail_vehicle_widgets
[] = {
542 NWidget(NWID_HORIZONTAL
),
543 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
544 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_RV_CAPTION
), SetDataTip(STR_REPLACE_VEHICLES_WHITE
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
545 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
546 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
547 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
549 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
550 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
),
551 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_RV_LEFT_SCROLLBAR
),
552 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
),
553 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_RV_RIGHT_SCROLLBAR
),
555 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
556 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_LEFT_DETAILS
), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
557 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_RIGHT_DETAILS
), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
559 NWidget(NWID_HORIZONTAL
),
560 NWidget(NWID_PUSHBUTTON_DROPDOWN
, COLOUR_GREY
, WID_RV_START_REPLACE
), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START
, STR_REPLACE_HELP_START_BUTTON
),
561 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_INFO_TAB
), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB
), SetResize(1, 0),
563 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_RV_STOP_REPLACE
), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP
, STR_REPLACE_HELP_STOP_BUTTON
),
565 NWidget(NWID_HORIZONTAL
),
566 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
),
567 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_TRAIN_FLUFF_LEFT
), SetMinimalSize(15, 12), EndContainer(),
568 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_RV_TRAIN_RAILTYPE_DROPDOWN
), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE
), SetResize(1, 0),
569 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_TRAIN_FLUFF_RIGHT
), SetMinimalSize(16, 12), EndContainer(),
570 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_RV_TRAIN_WAGONREMOVE_TOGGLE
), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_REMOVE_WAGON
, STR_REPLACE_REMOVE_WAGON_HELP
),
571 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
575 static WindowDesc
_replace_rail_vehicle_desc(
576 WDP_AUTO
, "replace_vehicle_train", 500, 140,
577 WC_REPLACE_VEHICLE
, WC_NONE
,
579 _nested_replace_rail_vehicle_widgets
, lengthof(_nested_replace_rail_vehicle_widgets
)
582 static const NWidgetPart _nested_replace_vehicle_widgets
[] = {
583 NWidget(NWID_HORIZONTAL
),
584 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
585 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_RV_CAPTION
), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
586 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
587 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
588 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
590 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
591 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
),
592 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_RV_LEFT_SCROLLBAR
),
593 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
),
594 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_RV_RIGHT_SCROLLBAR
),
596 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
597 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_LEFT_DETAILS
), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
598 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_RIGHT_DETAILS
), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
600 NWidget(NWID_HORIZONTAL
),
601 NWidget(NWID_PUSHBUTTON_DROPDOWN
, COLOUR_GREY
, WID_RV_START_REPLACE
), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START
, STR_REPLACE_HELP_START_BUTTON
),
602 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_RV_INFO_TAB
), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB
), SetResize(1, 0), EndContainer(),
603 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_RV_STOP_REPLACE
), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP
, STR_REPLACE_HELP_STOP_BUTTON
),
604 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
608 static WindowDesc
_replace_vehicle_desc(
609 WDP_AUTO
, "replace_vehicle", 456, 118,
610 WC_REPLACE_VEHICLE
, WC_NONE
,
612 _nested_replace_vehicle_widgets
, lengthof(_nested_replace_vehicle_widgets
)
616 * Show the autoreplace configuration window for a particular group.
617 * @param id_g The group to replace the vehicles for.
618 * @param vehicletype The type of vehicles in the group.
620 void ShowReplaceGroupVehicleWindow(GroupID id_g
, VehicleType vehicletype
)
622 DeleteWindowById(WC_REPLACE_VEHICLE
, vehicletype
);
623 new ReplaceVehicleWindow(vehicletype
== VEH_TRAIN
? &_replace_rail_vehicle_desc
: &_replace_vehicle_desc
, vehicletype
, id_g
);