author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9751 | 9e9c726170cc |
child 9889 | 1aaf71e958cc |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9070
diff
changeset
|
3 |
/** @file autoreplace_gui.cpp GUI for autoreplace handling. */ |
6117
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
5955
diff
changeset
|
4 |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1859
diff
changeset
|
6 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
7 |
#include "debug.h" |
842 | 8 |
#include "gui.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
9 |
#include "command_func.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
10 |
#include "variables.h" |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
11 |
#include "vehicle_gui.h" |
2962
f0a49b646c48
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2951
diff
changeset
|
12 |
#include "newgrf_engine.h" |
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6638
diff
changeset
|
13 |
#include "group.h" |
8103
cf92483a0abf
(svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents:
8082
diff
changeset
|
14 |
#include "rail.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8106
diff
changeset
|
15 |
#include "strings_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8116
diff
changeset
|
16 |
#include "window_func.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8131
diff
changeset
|
17 |
#include "vehicle_func.h" |
8212
cf3fce5c7464
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8174
diff
changeset
|
18 |
#include "autoreplace_func.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8212
diff
changeset
|
19 |
#include "gfx_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
20 |
#include "player_func.h" |
8284
ebdc5ba08874
(svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
8264
diff
changeset
|
21 |
#include "widgets/dropdown_func.h" |
8786
1823ff88a054
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents:
8770
diff
changeset
|
22 |
#include "engine_func.h" |
9070
dd0121143eba
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
9065
diff
changeset
|
23 |
#include "engine_base.h" |
9274
42b67e65f1c2
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium
parents:
9273
diff
changeset
|
24 |
#include "window_gui.h" |
9380
62dabf4a5b7e
(svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents:
9317
diff
changeset
|
25 |
#include "engine_gui.h" |
9725
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
26 |
#include "articulated_vehicles.h" |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
27 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
28 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
29 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
30 |
|
9679
9a09ba6c56cf
(svn r13784) -Codechange: Truncate vehicle names in purchase list to width of window.
peter1138
parents:
9671
diff
changeset
|
31 |
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group); |
505
1d5e770d2ce4
(svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents:
243
diff
changeset
|
32 |
|
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
33 |
static const StringID _rail_types_list[] = { |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
34 |
STR_RAIL_VEHICLES, |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
35 |
STR_ELRAIL_VEHICLES, |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
36 |
STR_MONORAIL_VEHICLES, |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
37 |
STR_MAGLEV_VEHICLES, |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
38 |
INVALID_STRING_ID |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
39 |
}; |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
40 |
|
8345
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
41 |
enum ReplaceVehicleWindowWidgets { |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
42 |
RVW_WIDGET_LEFT_MATRIX = 3, |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
43 |
RVW_WIDGET_LEFT_SCROLLBAR, |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
44 |
RVW_WIDGET_RIGHT_MATRIX, |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
45 |
RVW_WIDGET_RIGHT_SCROLLBAR, |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
46 |
RVW_WIDGET_LEFT_DETAILS, |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
47 |
RVW_WIDGET_RIGHT_DETAILS, |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
48 |
|
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
49 |
/* Button row */ |
8345
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
50 |
RVW_WIDGET_START_REPLACE, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
51 |
RVW_WIDGET_INFO_TAB, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
52 |
RVW_WIDGET_STOP_REPLACE, |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
53 |
RVW_WIDGET_RESIZE, |
8345
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
54 |
|
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
55 |
/* Train only widgets */ |
8345
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
56 |
RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
57 |
RVW_WIDGET_TRAIN_FLUFF_LEFT, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
58 |
RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
59 |
RVW_WIDGET_TRAIN_FLUFF_RIGHT, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
60 |
RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE, |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
61 |
}; |
228a97078526
(svn r11911) -Codechange: use enum for autoreplace window widgets
peter1138
parents:
8333
diff
changeset
|
62 |
|
9671
6f92245afcf1
(svn r13760) -Codechange: With multiple NewGRF engine sets, engine IDs may not be allocated in the order expected by GRF authors, so sort by 'list position' instead of engine ID for all vehicle types.
peter1138
parents:
9403
diff
changeset
|
63 |
static int CDECL EngineNumberSorter(const void *a, const void *b) |
8174
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
64 |
{ |
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
65 |
const EngineID va = *(const EngineID*)a; |
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
66 |
const EngineID vb = *(const EngineID*)b; |
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
67 |
int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb); |
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
68 |
|
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
69 |
return r; |
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
70 |
} |
cef48ed63584
(svn r11737) -Fix: Reinstate NewGRF-specified engine list order in autoreplace window.
peter1138
parents:
8144
diff
changeset
|
71 |
|
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
72 |
/** Rebuild the left autoreplace list if an engine is removed or added |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
73 |
* @param e Engine to check if it is removed or added |
7096
9b231813f232
(svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents:
7059
diff
changeset
|
74 |
* @param id_g The group the engine belongs to |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
75 |
* Note: this function only works if it is called either |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
76 |
* - when a new vehicle is build, but before it's counted in num_engines |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
77 |
* - when a vehicle is deleted and after it's substracted from num_engines |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
78 |
* - when not changing the count (used when changing replace orders) |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
79 |
*/ |
7096
9b231813f232
(svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents:
7059
diff
changeset
|
80 |
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g) |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
81 |
{ |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
82 |
Player *p = GetPlayer(_local_player); |
7481
7d8d1dd8da4c
(svn r10992) -Fix [FS#1132]: huge amount of vehicles in the "ungrouped" group. Patch by frosch.
rubidium
parents:
7341
diff
changeset
|
83 |
uint num_engines = GetGroupNumEngines(_local_player, id_g, e); |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
84 |
|
7096
9b231813f232
(svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents:
7059
diff
changeset
|
85 |
if (num_engines == 0 || p->num_engines[e] == 0) { |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
86 |
/* We don't have any of this engine type. |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
87 |
* Either we just sold the last one, we build a new one or we stopped replacing it. |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
88 |
* In all cases, we need to update the left list */ |
9172
4488ce29544f
(svn r13035) -Codechange: remove two needless global-ish variables.
rubidium
parents:
9156
diff
changeset
|
89 |
InvalidateWindowData(WC_REPLACE_VEHICLE, GetEngine(e)->type, true); |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
90 |
} |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
91 |
} |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
92 |
|
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
93 |
/** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
94 |
* @param type The type of engine |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
95 |
*/ |
6638
09c5d7bf69a5
(svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents:
6398
diff
changeset
|
96 |
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type) |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
97 |
{ |
9172
4488ce29544f
(svn r13035) -Codechange: remove two needless global-ish variables.
rubidium
parents:
9156
diff
changeset
|
98 |
InvalidateWindowData(WC_REPLACE_VEHICLE, type, false); // Update the autoreplace window |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
99 |
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
100 |
} |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
101 |
|
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
102 |
/** Figure out if two engines got at least one type of cargo in common (refitting if needed) |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
103 |
* @param engine_a one of the EngineIDs |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
104 |
* @param engine_b the other EngineID |
9725
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
105 |
* @param type the type of the engines |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
106 |
* @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all) |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
107 |
*/ |
9725
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
108 |
static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b, VehicleType type) |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
109 |
{ |
9725
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
110 |
uint32 available_cargos_a = GetUnionOfArticulatedRefitMasks(engine_a, type, true); |
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
111 |
uint32 available_cargos_b = GetUnionOfArticulatedRefitMasks(engine_b, type, true); |
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
112 |
return (available_cargos_a == 0 || available_cargos_b == 0 || (available_cargos_a & available_cargos_b) != 0); |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
113 |
} |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
114 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
115 |
/** |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
116 |
* Window for the autoreplacing of vehicles. |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
117 |
*/ |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
118 |
class ReplaceVehicleWindow : public Window { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
119 |
byte sel_index[2]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
120 |
EngineID sel_engine[2]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
121 |
uint16 count[2]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
122 |
bool wagon_btnstate; ///< true means engine is selected |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
123 |
GUIEngineList list[2]; |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
124 |
bool update_left; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
125 |
bool update_right; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
126 |
bool init_lists; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
127 |
GroupID sel_group; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
128 |
static RailType sel_railtype; |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
129 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
130 |
/** Figure out if an engine should be added to a list |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
131 |
* @param e The EngineID |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
132 |
* @param draw_left If true, then the left list is drawn (the engines specific to the railtype you selected) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
133 |
* @param show_engines if truem then locomotives are drawn, else wagons (never both) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
134 |
* @return true if the engine should be in the list (based on this check) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
135 |
*/ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
136 |
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
137 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
138 |
const RailVehicleInfo *rvi = RailVehInfo(e); |
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6638
diff
changeset
|
139 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
140 |
/* Ensure that the wagon/engine selection fits the engine. */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
141 |
if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
142 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
143 |
if (draw_left && show_engines) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
144 |
/* Ensure that the railtype is specific to the selected one */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
145 |
if (rvi->railtype != this->sel_railtype) return false; |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
146 |
} else { |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
147 |
/* Ensure that it's a compatible railtype to the selected one (like electric <-> diesel) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
148 |
* The vehicle do not have to have power on the railtype in question, only able to drive (pulled if needed) */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
149 |
if (!IsCompatibleRail(rvi->railtype, this->sel_railtype)) return false; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
150 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
151 |
return true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
152 |
} |
6687
c7b92f03d33f
(svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents:
6643
diff
changeset
|
153 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
154 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
155 |
/** Generate a list |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
156 |
* @param w Window, that contains the list |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
157 |
* @param draw_left true if generating the left list, otherwise false |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
158 |
*/ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
159 |
void GenerateReplaceVehList(Window *w, bool draw_left) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
160 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
161 |
EngineID selected_engine = INVALID_ENGINE; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
162 |
VehicleType type = (VehicleType)this->window_number; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
163 |
byte i = draw_left ? 0 : 1; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
164 |
|
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
165 |
GUIEngineList *list = &this->list[i]; |
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
166 |
list->Clear(); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
167 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
168 |
const Engine *e; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
169 |
FOR_ALL_ENGINES_OF_TYPE(e, type) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
170 |
EngineID eid = e->index; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
171 |
if (type == VEH_TRAIN && !GenerateReplaceRailList(eid, draw_left, this->wagon_btnstate)) continue; // special rules for trains |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
172 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
173 |
if (draw_left) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
174 |
const GroupID selected_group = this->sel_group; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
175 |
const uint num_engines = GetGroupNumEngines(_local_player, selected_group, eid); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
176 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
177 |
/* Skip drawing the engines we don't have any of and haven't set for replacement */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
178 |
if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), eid, selected_group) == INVALID_ENGINE) continue; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
179 |
} else { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
180 |
/* This is for engines we can replace to and they should depend on what we selected to replace from */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
181 |
if (!IsEngineBuildable(eid, type, _local_player)) continue; // we need to be able to build the engine |
9725
982452c3357e
(svn r13850) -Fix [FS#2146]: Fix resp. implement refitting of articulated vehicles during autoreplace.
frosch
parents:
9719
diff
changeset
|
182 |
if (!EnginesGotCargoInCommon(eid, this->sel_engine[0], type)) continue; // the engines needs to be able to carry the same cargo |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
183 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
184 |
/* Road vehicles can't be replaced by trams and vice-versa */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
185 |
if (type == VEH_ROAD && HasBit(EngInfo(this->sel_engine[0])->misc_flags, EF_ROAD_TRAM) != HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
186 |
if (eid == this->sel_engine[0]) continue; // we can't replace an engine into itself (that would be autorenew) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
187 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
188 |
|
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
189 |
*list->Append() = eid; |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
190 |
if (eid == this->sel_engine[i]) selected_engine = eid; // The selected engine is still in the list |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
191 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
192 |
this->sel_engine[i] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore) |
9671
6f92245afcf1
(svn r13760) -Codechange: With multiple NewGRF engine sets, engine IDs may not be allocated in the order expected by GRF authors, so sort by 'list position' instead of engine ID for all vehicle types.
peter1138
parents:
9403
diff
changeset
|
193 |
EngList_Sort(list, &EngineNumberSorter); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
194 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
195 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
196 |
/** Generate the lists */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
197 |
void GenerateLists() |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
198 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
199 |
EngineID e = this->sel_engine[0]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
200 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
201 |
if (this->update_left == true) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
202 |
/* We need to rebuild the left list */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
203 |
GenerateReplaceVehList(this, true); |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
204 |
SetVScrollCount(this, this->list[0].Length()); |
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
205 |
if (this->init_lists && this->sel_engine[0] == INVALID_ENGINE && this->list[0].Length() != 0) { |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
206 |
this->sel_engine[0] = this->list[0][0]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
207 |
} |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
208 |
} |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
209 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
210 |
if (this->update_right || e != this->sel_engine[0]) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
211 |
/* Either we got a request to rebuild the right list or the left list selected a different engine */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
212 |
if (this->sel_engine[0] == INVALID_ENGINE) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
213 |
/* Always empty the right list when nothing is selected in the left list */ |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
214 |
this->list[1].Clear(); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
215 |
this->sel_engine[1] = INVALID_ENGINE; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
216 |
} else { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
217 |
GenerateReplaceVehList(this, false); |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
218 |
SetVScroll2Count(this, this->list[1].Length()); |
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
219 |
if (this->init_lists && this->sel_engine[1] == INVALID_ENGINE && this->list[1].Length() != 0) { |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
220 |
this->sel_engine[1] = this->list[1][0]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
221 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
222 |
} |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
223 |
} |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
224 |
/* Reset the flags about needed updates */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
225 |
this->update_left = false; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
226 |
this->update_right = false; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
227 |
this->init_lists = false; |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
228 |
} |
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
229 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
230 |
public: |
9210
98da60f3e086
(svn r13076) -Fix [FS#2012]: the wrong autoreplace window would be shown if the vehicle isn't a train.
rubidium
parents:
9203
diff
changeset
|
231 |
ReplaceVehicleWindow(const WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc, vehicletype) |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
232 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
233 |
this->wagon_btnstate = true; // start with locomotives (all other vehicles will not read this bool) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
234 |
this->update_left = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
235 |
this->update_right = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
236 |
this->init_lists = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
237 |
this->sel_engine[0] = INVALID_ENGINE; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
238 |
this->sel_engine[1] = INVALID_ENGINE; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
239 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
240 |
this->resize.step_height = GetVehicleListHeight(vehicletype); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
241 |
this->vscroll.cap = this->resize.step_height == 14 ? 8 : 4; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
242 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
243 |
Widget *widget = this->widget; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
244 |
widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.cap << 8) + 1; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
245 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
246 |
if (vehicletype == VEH_TRAIN) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
247 |
this->wagon_btnstate = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
248 |
/* The train window is bigger so we will move some of the widgets to fit the new size. |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
249 |
* We will start by moving the resize button to the lower right corner. */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
250 |
widget[RVW_WIDGET_RESIZE].top = widget[RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE].top; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
251 |
widget[RVW_WIDGET_RESIZE].bottom = widget[RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE].bottom; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
252 |
widget[RVW_WIDGET_STOP_REPLACE].right = widget[RVW_WIDGET_RESIZE].right; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
253 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
254 |
/* The detail panel is one line taller for trains so we will move some of the widgets one line (10 pixels) down. */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
255 |
widget[RVW_WIDGET_LEFT_DETAILS].bottom += 10; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
256 |
widget[RVW_WIDGET_RIGHT_DETAILS].bottom += 10; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
257 |
for (int i = RVW_WIDGET_START_REPLACE; i < RVW_WIDGET_RESIZE; i++) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
258 |
widget[i].top += 10; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
259 |
widget[i].bottom += 10; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
260 |
} |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
261 |
} else { |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
262 |
/* Since it's not a train we will hide the train only widgets. */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
263 |
this->SetWidgetsHiddenState(true, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
264 |
RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
265 |
RVW_WIDGET_TRAIN_FLUFF_LEFT, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
266 |
RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
267 |
RVW_WIDGET_TRAIN_FLUFF_RIGHT, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
268 |
RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
269 |
WIDGET_LIST_END); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
270 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
271 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
272 |
ResizeWindow(this, 0, this->resize.step_height * this->vscroll.cap); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
273 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
274 |
/* Set the minimum window size to the current window size */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
275 |
this->resize.width = this->width; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
276 |
this->resize.height = this->height; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
277 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
278 |
this->caption_color = _local_player; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
279 |
this->sel_group = id_g; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
280 |
this->vscroll2.cap = this->vscroll.cap; // these two are always the same |
9178
3235f895bf12
(svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents:
9174
diff
changeset
|
281 |
|
3235f895bf12
(svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents:
9174
diff
changeset
|
282 |
this->FindWindowPlacementAndResize(desc); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
283 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
284 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
285 |
virtual void OnPaint() |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
286 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
287 |
static const StringID _vehicle_type_names[] = { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
288 |
STR_019F_TRAIN, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
289 |
STR_019C_ROAD_VEHICLE, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
290 |
STR_019E_SHIP, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
291 |
STR_019D_AIRCRAFT |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
292 |
}; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
293 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
294 |
if (this->update_left || this->update_right) this->GenerateLists(); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
295 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
296 |
Player *p = GetPlayer(_local_player); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
297 |
EngineID selected_id[2]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
298 |
const GroupID selected_group = this->sel_group; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
299 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
300 |
selected_id[0] = this->sel_engine[0]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
301 |
selected_id[1] = this->sel_engine[1]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
302 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
303 |
/* Disable the "Start Replacing" button if: |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
304 |
* Either list is empty |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
305 |
* or The selected replacement engine has a replacement (to prevent loops) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
306 |
* or The right list (new replacement) has the existing replacement vehicle selected */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
307 |
this->SetWidgetDisabledState(RVW_WIDGET_START_REPLACE, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
308 |
selected_id[0] == INVALID_ENGINE || |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
309 |
selected_id[1] == INVALID_ENGINE || |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
310 |
EngineReplacementForPlayer(p, selected_id[1], selected_group) != INVALID_ENGINE || |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
311 |
EngineReplacementForPlayer(p, selected_id[0], selected_group) == selected_id[1]); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
312 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
313 |
/* Disable the "Stop Replacing" button if: |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
314 |
* The left list (existing vehicle) is empty |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
315 |
* or The selected vehicle has no replacement set up */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
316 |
this->SetWidgetDisabledState(RVW_WIDGET_STOP_REPLACE, |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
317 |
selected_id[0] == INVALID_ENGINE || |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
318 |
!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
319 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
320 |
/* now the actual drawing of the window itself takes place */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
321 |
SetDParam(0, _vehicle_type_names[this->window_number]); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
322 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
323 |
if (this->window_number == VEH_TRAIN) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
324 |
/* set on/off for renew_keep_length */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
325 |
SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
326 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
327 |
/* set wagon/engine button */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
328 |
SetDParam(2, this->wagon_btnstate ? STR_ENGINES : STR_WAGONS); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
329 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
330 |
/* sets the colour of that art thing */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
331 |
this->widget[RVW_WIDGET_TRAIN_FLUFF_LEFT].color = _player_colors[_local_player]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
332 |
this->widget[RVW_WIDGET_TRAIN_FLUFF_RIGHT].color = _player_colors[_local_player]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
333 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
334 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
335 |
if (this->window_number == VEH_TRAIN) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
336 |
/* Show the selected railtype in the pulldown menu */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
337 |
this->widget[RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN].data = _rail_types_list[sel_railtype]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
338 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
339 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9210
diff
changeset
|
340 |
this->DrawWidgets(); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
341 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
342 |
/* sets up the string for the vehicle that is being replaced to */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
343 |
if (selected_id[0] != INVALID_ENGINE) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
344 |
if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
345 |
SetDParam(0, STR_NOT_REPLACING); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
346 |
} else { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
347 |
SetDParam(0, STR_ENGINE_NAME); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
348 |
SetDParam(1, EngineReplacementForPlayer(p, selected_id[0], selected_group)); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
349 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
350 |
} else { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
351 |
SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
352 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
353 |
|
9719
15e207edea1a
(svn r13840) -Fix: Some glitches in the autoreplace GUI.
frosch
parents:
9679
diff
changeset
|
354 |
DrawStringTruncated(this->widget[RVW_WIDGET_INFO_TAB].left + 6, this->widget[RVW_WIDGET_INFO_TAB].top + 1, STR_02BD, TC_BLACK, this->GetWidgetWidth(RVW_WIDGET_INFO_TAB) - 12); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
355 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
356 |
/* Draw the lists */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
357 |
for (byte i = 0; i < 2; i++) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
358 |
uint widget = (i == 0) ? RVW_WIDGET_LEFT_MATRIX : RVW_WIDGET_RIGHT_MATRIX; |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
359 |
GUIEngineList *list = &this->list[i]; // which list to draw |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
360 |
EngineID start = i == 0 ? this->vscroll.pos : this->vscroll2.pos; // what is the offset for the start (scrolling) |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
361 |
EngineID end = min((i == 0 ? this->vscroll.cap : this->vscroll2.cap) + start, list->Length()); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
362 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
363 |
/* Do the actual drawing */ |
9679
9a09ba6c56cf
(svn r13784) -Codechange: Truncate vehicle names in purchase list to width of window.
peter1138
parents:
9671
diff
changeset
|
364 |
DrawEngineList((VehicleType)this->window_number, this->widget[widget].left + 2, this->widget[widget].right, this->widget[widget].top + 1, list, start, end, this->sel_engine[i], i == 0 ? this->widget[RVW_WIDGET_LEFT_MATRIX].right - 2 : 0, selected_group); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
365 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
366 |
/* Also draw the details if an engine is selected */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
367 |
if (this->sel_engine[i] != INVALID_ENGINE) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
368 |
const Widget *wi = &this->widget[i == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
369 |
int text_end = DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, this->sel_engine[i]); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
370 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
371 |
if (text_end > wi->bottom) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
372 |
this->SetDirty(); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
373 |
ResizeWindowForWidget(this, i == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS, 0, text_end - wi->bottom); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
374 |
this->SetDirty(); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
375 |
} |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
376 |
} |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
377 |
} |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
378 |
} |
8419
64d84dfad2a1
(svn r11989) -Fix: Resize autoreplace window to fit purchase information text if it is too large.
peter1138
parents:
8352
diff
changeset
|
379 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
380 |
virtual void OnClick(Point pt, int widget) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
381 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
382 |
switch (widget) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
383 |
case RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE: |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
384 |
this->wagon_btnstate = !(this->wagon_btnstate); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
385 |
this->update_left = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
386 |
this->init_lists = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
387 |
this->SetDirty(); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
388 |
break; |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
389 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
390 |
case RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: /* Railtype selection dropdown menu */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
391 |
ShowDropDownMenu(this, _rail_types_list, sel_railtype, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN, 0, ~GetPlayer(_local_player)->avail_railtypes); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
392 |
break; |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
393 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
394 |
case RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE: /* toggle renew_keep_length */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
395 |
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
396 |
break; |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
397 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
398 |
case RVW_WIDGET_START_REPLACE: { /* Start replacing */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
399 |
EngineID veh_from = this->sel_engine[0]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
400 |
EngineID veh_to = this->sel_engine[1]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
401 |
DoCommandP(0, 3 + (this->sel_group << 16) , veh_from + (veh_to << 16), NULL, CMD_SET_AUTOREPLACE); |
9719
15e207edea1a
(svn r13840) -Fix: Some glitches in the autoreplace GUI.
frosch
parents:
9679
diff
changeset
|
402 |
this->SetDirty(); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
403 |
} break; |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
404 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
405 |
case RVW_WIDGET_STOP_REPLACE: { /* Stop replacing */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
406 |
EngineID veh_from = this->sel_engine[0]; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
407 |
DoCommandP(0, 3 + (this->sel_group << 16), veh_from + (INVALID_ENGINE << 16), NULL, CMD_SET_AUTOREPLACE); |
9719
15e207edea1a
(svn r13840) -Fix: Some glitches in the autoreplace GUI.
frosch
parents:
9679
diff
changeset
|
408 |
this->SetDirty(); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
409 |
} break; |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5893
diff
changeset
|
410 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
411 |
case RVW_WIDGET_LEFT_MATRIX: |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
412 |
case RVW_WIDGET_RIGHT_MATRIX: { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
413 |
uint i = (pt.y - 14) / this->resize.step_height; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
414 |
uint16 click_scroll_pos = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.pos : this->vscroll2.pos; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
415 |
uint16 click_scroll_cap = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.cap : this->vscroll2.cap; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
416 |
byte click_side = widget == RVW_WIDGET_LEFT_MATRIX ? 0 : 1; |
9403
8cfca59c11f1
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents:
9402
diff
changeset
|
417 |
size_t engine_count = this->list[click_side].Length(); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
418 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
419 |
if (i < click_scroll_cap) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
420 |
i += click_scroll_pos; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
421 |
EngineID e = engine_count > i ? this->list[click_side][i] : INVALID_ENGINE; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
422 |
if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
423 |
this->sel_engine[click_side] = e; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
424 |
if (click_side == 0) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
425 |
this->update_right = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
426 |
this->init_lists = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
427 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
428 |
this->SetDirty(); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
429 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
430 |
break; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
431 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
432 |
} |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
433 |
} |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
434 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
435 |
virtual void OnDropdownSelect(int widget, int index) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
436 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
437 |
RailType temp = (RailType)index; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
438 |
if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
439 |
sel_railtype = temp; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
440 |
/* Reset scrollbar positions */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
441 |
this->vscroll.pos = 0; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
442 |
this->vscroll2.pos = 0; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
443 |
/* Rebuild the lists */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
444 |
this->update_left = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
445 |
this->update_right = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
446 |
this->init_lists = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
447 |
this->SetDirty(); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
448 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
449 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
450 |
virtual void OnResize(Point new_size, Point delta) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
451 |
this->vscroll.cap += delta.y / (int)this->resize.step_height; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
452 |
this->vscroll2.cap += delta.y / (int)this->resize.step_height; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
453 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
454 |
Widget *widget = this->widget; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
455 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
456 |
widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll2.cap << 8) + 1; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
457 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
458 |
if (delta.x != 0) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
459 |
/* We changed the width of the window so we have to resize the lists. |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
460 |
* Because ResizeButtons() makes each widget the same size it can't be used on the lists |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
461 |
* because then the lists would have the same size as the scrollbars. |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
462 |
* Instead we use it on the detail panels. |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
463 |
* Afterwards we use the new location of the detail panels (the middle of the window) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
464 |
* to place the lists. |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
465 |
* This way the lists will have equal size while keeping the width of the scrollbars unchanged. */ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
466 |
ResizeButtons(this, RVW_WIDGET_LEFT_DETAILS, RVW_WIDGET_RIGHT_DETAILS); |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
467 |
widget[RVW_WIDGET_RIGHT_MATRIX].left = widget[RVW_WIDGET_RIGHT_DETAILS].left; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
468 |
widget[RVW_WIDGET_LEFT_SCROLLBAR].right = widget[RVW_WIDGET_LEFT_DETAILS].right; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
469 |
widget[RVW_WIDGET_LEFT_SCROLLBAR].left = widget[RVW_WIDGET_LEFT_SCROLLBAR].right - 11; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
470 |
widget[RVW_WIDGET_LEFT_MATRIX].right = widget[RVW_WIDGET_LEFT_SCROLLBAR].left - 1; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
471 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
472 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
473 |
|
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
474 |
virtual void OnInvalidateData(int data) |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
475 |
{ |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
476 |
if (data != 0) { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
477 |
this->update_left = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
478 |
} else { |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
479 |
this->update_right = true; |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
480 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
481 |
} |
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
482 |
}; |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
483 |
|
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
484 |
static const Widget _replace_vehicle_widgets[] = { |
9751
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
485 |
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
486 |
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
487 |
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
488 |
|
9751
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
489 |
{ WWT_MATRIX, RESIZE_BOTTOM, COLOUR_GREY, 0, 215, 14, 13, 0x1, STR_REPLACE_HELP_LEFT_ARRAY}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
490 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, COLOUR_GREY, 216, 227, 14, 13, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
491 |
{ WWT_MATRIX, RESIZE_LRB, COLOUR_GREY, 228, 443, 14, 13, 0x1, STR_REPLACE_HELP_RIGHT_ARRAY}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
492 |
{ WWT_SCROLL2BAR, RESIZE_LRB, COLOUR_GREY, 444, 455, 14, 13, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
493 |
{ WWT_PANEL, RESIZE_TB, COLOUR_GREY, 0, 227, 14, 105, 0x0, STR_NULL}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
494 |
{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 228, 455, 14, 105, 0x0, STR_NULL}, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
495 |
|
9751
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
496 |
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 138, 106, 117, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
497 |
{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 139, 305, 106, 117, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
498 |
{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 306, 443, 106, 117, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
499 |
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 444, 455, 106, 117, STR_NULL, STR_RESIZE_BUTTON}, |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
500 |
|
9751
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
501 |
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 138, 128, 139, STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
502 |
{ WWT_PANEL, RESIZE_TB, COLOUR_GREY, 139, 153, 128, 139, 0x0, STR_NULL}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
503 |
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 154, 289, 128, 139, 0x0, STR_REPLACE_HELP_RAILTYPE}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
504 |
{ WWT_PANEL, RESIZE_LRTB, COLOUR_GREY, 290, 305, 128, 139, 0x0, STR_NULL}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9725
diff
changeset
|
505 |
{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 306, 443, 128, 139, STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP}, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
506 |
{ WIDGETS_END}, |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
507 |
}; |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
508 |
|
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
509 |
static const WindowDesc _replace_rail_vehicle_desc = { |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
510 |
WDP_AUTO, WDP_AUTO, 456, 140, 456, 140, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5868
diff
changeset
|
511 |
WC_REPLACE_VEHICLE, WC_NONE, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
512 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
513 |
_replace_vehicle_widgets, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
514 |
}; |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
515 |
|
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
516 |
static const WindowDesc _replace_vehicle_desc = { |
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
517 |
WDP_AUTO, WDP_AUTO, 456, 118, 456, 118, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5868
diff
changeset
|
518 |
WC_REPLACE_VEHICLE, WC_NONE, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
519 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
9027
b28d0b8809ad
(svn r12843) -Feature [FS#1945]: The autoreplace window is now resizable in both directions
bjarni
parents:
9024
diff
changeset
|
520 |
_replace_vehicle_widgets, |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
521 |
}; |
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
522 |
|
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
523 |
RailType ReplaceVehicleWindow::sel_railtype = RAILTYPE_RAIL; |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
524 |
|
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6638
diff
changeset
|
525 |
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype) |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6638
diff
changeset
|
526 |
{ |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6638
diff
changeset
|
527 |
DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype); |
9174
5d1ba8c43503
(svn r13037) -Codechange: make a class of the ReplaceVehicle window.
rubidium
parents:
9172
diff
changeset
|
528 |
new ReplaceVehicleWindow(vehicletype == VEH_TRAIN ? &_replace_rail_vehicle_desc : &_replace_vehicle_desc, vehicletype, id_g); |
5808
c34443483ed3
(svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents:
5801
diff
changeset
|
529 |
} |