author | celestar |
Fri, 29 Dec 2006 11:03:39 +0000 | |
branch | custombridgeheads |
changeset 5593 | 3e0dd1f014ca |
parent 5588 | 1bcb6b4c01d8 |
child 5623 | ef2a8a524a95 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
4 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
5 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2147
diff
changeset
|
6 |
#include "functions.h" |
4041
caf4fcb4e05b
(svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents:
4012
diff
changeset
|
7 |
#include "rail_map.h" |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
8 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
460
diff
changeset
|
9 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
601
diff
changeset
|
10 |
#include "map.h" |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
11 |
#include "engine.h" |
0 | 12 |
#include "window.h" |
13 |
#include "gui.h" |
|
14 |
#include "gfx.h" |
|
15 |
#include "vehicle.h" |
|
16 |
#include "viewport.h" |
|
17 |
#include "station.h" |
|
18 |
#include "command.h" |
|
19 |
#include "player.h" |
|
588 | 20 |
#include "vehicle_gui.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
21 |
#include "depot.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2639
diff
changeset
|
22 |
#include "train.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2959
diff
changeset
|
23 |
#include "newgrf_engine.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4251
diff
changeset
|
24 |
#include "date.h" |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
25 |
#include "strings.h" |
420
d3a089648ec3
(svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents:
395
diff
changeset
|
26 |
|
5273
5fde4b8c94c4
(svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents:
5215
diff
changeset
|
27 |
enum BuildTrainWidgets { |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
28 |
BUILD_TRAIN_WIDGET_CLOSEBOX = 0, |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
29 |
BUILD_TRAIN_WIDGET_CAPTION, |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
30 |
BUILD_TRAIN_WIDGET_SORT_ASCENDING_DESCENDING, |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
31 |
BUILD_TRAIN_WIDGET_SORT_TEXT, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
32 |
BUILD_TRAIN_WIDGET_SORT_DROPDOWN, |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
33 |
BUILD_TRAIN_WIDGET_LIST, |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
34 |
BUILD_TRAIN_WIDGET_SCROLLBAR, |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
35 |
BUILD_TRAIN_WIDGET_PANEL, |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
36 |
BUILD_TRAIN_WIDGET_BUILD, |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
37 |
BUILD_TRAIN_WIDGET_RENAME, |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
38 |
BUILD_TRAIN_WIDGET_RESIZE, |
5273
5fde4b8c94c4
(svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents:
5215
diff
changeset
|
39 |
}; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
40 |
|
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
41 |
static const Widget _new_rail_vehicle_widgets[] = { |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
42 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
43 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 227, 0, 13, STR_JUST_STRING, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
44 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP}, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
45 |
{ WWT_PANEL, RESIZE_NONE, 14, 81, 215, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
46 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 216, 227, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
47 |
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 26, 137, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION}, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
48 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 26, 137, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
4931
6e09e884257d
(svn r6911) - Codechange: Add extra space to all purchase windows (and the replace window) to allow room for more text. (mart3p)
peter1138
parents:
4930
diff
changeset
|
49 |
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 138, 239, 0x0, STR_NULL}, |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
50 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 107, 240, 251, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN}, |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
51 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 108, 215, 240, 251, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE}, |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
52 |
{ WWT_RESIZEBOX, RESIZE_TB, 14, 216, 227, 240, 251, 0x0, STR_RESIZE_BUTTON}, |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
53 |
{ WIDGETS_END}, |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
54 |
}; |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
55 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
56 |
static bool _internal_sort_order; // false = ascending, true = descending |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
57 |
static byte _last_sort_criteria = 0; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
58 |
static bool _last_sort_order = false; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
59 |
|
5195
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
60 |
static int CDECL TrainEngineNumberSorter(const void *a, const void *b) |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
61 |
{ |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
62 |
const EngineID va = *(const EngineID*)a; |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
63 |
const EngineID vb = *(const EngineID*)b; |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
64 |
int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb); |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
65 |
|
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
66 |
return _internal_sort_order ? -r : r; |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
67 |
} |
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
68 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
69 |
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b) |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
70 |
{ |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
71 |
EngineID va = *(const EngineID*)a; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
72 |
EngineID vb = *(const EngineID*)b; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
73 |
int val_a = ((RailVehInfo(va)->flags & RVI_WAGON) != 0) ? 1 : 0; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
74 |
int val_b = ((RailVehInfo(vb)->flags & RVI_WAGON) != 0) ? 1 : 0; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
75 |
int r = val_a - val_b; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
76 |
|
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
77 |
/* Use EngineID to sort instead since we want consistent sorting */ |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
78 |
if (r == 0) return TrainEngineNumberSorter(a, b); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
79 |
|
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
80 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
81 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
82 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
83 |
static int CDECL TrainEngineCostSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
84 |
{ |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
85 |
int va = RailVehInfo(*(const EngineID*)a)->base_cost; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
86 |
int vb = RailVehInfo(*(const EngineID*)b)->base_cost; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
87 |
int r = va - vb; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
88 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
89 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
90 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
91 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
92 |
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
93 |
{ |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
94 |
int va = RailVehInfo(*(const EngineID*)a)->max_speed; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
95 |
int vb = RailVehInfo(*(const EngineID*)b)->max_speed; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
96 |
int r = va - vb; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
97 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
98 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
99 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
100 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
101 |
static int CDECL TrainEnginePowerSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
102 |
{ |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
103 |
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
104 |
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
105 |
|
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
106 |
int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
107 |
int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
108 |
int r = va - vb; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
109 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
110 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
111 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
112 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
113 |
static int CDECL TrainEngineIntroDateSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
114 |
{ |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
115 |
int va = GetEngine(*(const EngineID*)a)->intro_date; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
116 |
int vb = GetEngine(*(const EngineID*)b)->intro_date; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
117 |
int r = va - vb; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
118 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
119 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
120 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
121 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
122 |
static EngineID _last_engine; // cached vehicle to hopefully speed up name-sorting |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
123 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
124 |
static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
125 |
static int CDECL TrainEngineNameSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
126 |
{ |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
127 |
const EngineID va = *(const EngineID*)a; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
128 |
const EngineID vb = *(const EngineID*)b; |
4835
22d6a5811aee
(svn r6759) -Codechange: Remove the brainheaded usage of STR_JUST_STRING to pass a StringID
Darkvater
parents:
4813
diff
changeset
|
129 |
char buf1[64]; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
130 |
int r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
131 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
132 |
GetString(buf1, GetCustomEngineName(va), lastof(buf1)); |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
133 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
134 |
if (vb != _last_engine) { |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
135 |
_last_engine = vb; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
136 |
_bufcache[0] = '\0'; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
137 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
138 |
GetString(_bufcache, GetCustomEngineName(vb), lastof(_bufcache)); |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
139 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
140 |
|
4836
03d2f66ffe6c
(svn r6760) -Codechange: Do a case insensitive sort of train engine names and just normally
Darkvater
parents:
4835
diff
changeset
|
141 |
r = strcasecmp(buf1, _bufcache); // sort by name |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
142 |
|
4836
03d2f66ffe6c
(svn r6760) -Codechange: Do a case insensitive sort of train engine names and just normally
Darkvater
parents:
4835
diff
changeset
|
143 |
return _internal_sort_order ? -r : r; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
144 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
145 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
146 |
static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
147 |
{ |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
148 |
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
149 |
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
150 |
|
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
151 |
int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
152 |
int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
153 |
int r = va - vb; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
154 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
155 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
156 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
157 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
158 |
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
159 |
{ |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
160 |
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
161 |
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
162 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
163 |
/* Here we are using a few tricks to get the right sort. |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
164 |
* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
165 |
* we will actually calculate cunning cost/power (to make it more than 1). |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
166 |
* Because of this, the return value have to be reversed as well and we return b - a instead of a - b. |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
167 |
* Another thing is that both power and running costs should be doubled for multiheaded engines. |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
168 |
* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */ |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
169 |
int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1, rvi_a->power); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
170 |
int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1, rvi_b->power); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
171 |
int r = vb - va; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
172 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
173 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
174 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
175 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
176 |
static int CDECL TrainEngineReliabilitySorter(const void *a, const void *b) |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
177 |
{ |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
178 |
int va = GetEngine(*(const EngineID*)a)->reliability; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
179 |
int vb = GetEngine(*(const EngineID*)b)->reliability; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
180 |
int r = va - vb; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
181 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
182 |
return _internal_sort_order ? -r : r; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
183 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
184 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
185 |
static EngList_SortTypeFunction * const _engine_sorter[] = { |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
186 |
&TrainEngineNumberSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
187 |
&TrainEngineCostSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
188 |
&TrainEngineSpeedSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
189 |
&TrainEnginePowerSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
190 |
&TrainEngineIntroDateSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
191 |
&TrainEngineNameSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
192 |
&TrainEngineRunningCostSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
193 |
&TrainEnginePowerVsRunningCostSorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
194 |
&TrainEngineReliabilitySorter, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
195 |
}; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
196 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
197 |
static const StringID _engine_sort_listing[] = { |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
198 |
STR_ENGINE_SORT_ENGINE_ID, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
199 |
STR_ENGINE_SORT_COST, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
200 |
STR_SORT_BY_MAX_SPEED, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
201 |
STR_ENGINE_SORT_POWER, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
202 |
STR_ENGINE_SORT_INTRO_DATE, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
203 |
STR_SORT_BY_DROPDOWN_NAME, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
204 |
STR_ENGINE_SORT_RUNNING_COST, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
205 |
STR_ENGINE_SORT_POWER_VS_RUNNING_COST, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
206 |
STR_SORT_BY_RELIABILITY, |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
207 |
INVALID_STRING_ID |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
208 |
}; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
209 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
210 |
/** |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
211 |
* Draw the purchase info details of train engine at a given location. |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
212 |
* @param x,y location where to draw the info |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
213 |
* @param engine_number the engine of which to draw the info of |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
214 |
*/ |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
215 |
void DrawTrainEnginePurchaseInfo(int x, int y, uint w, EngineID engine_number) |
842 | 216 |
{ |
217 |
const RailVehicleInfo *rvi = RailVehInfo(engine_number); |
|
4171 | 218 |
const Engine *e = GetEngine(engine_number); |
842 | 219 |
int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); |
220 |
YearMonthDay ymd; |
|
4288
60398d0e64ee
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4286
diff
changeset
|
221 |
ConvertDateToYMD(e->intro_date, &ymd); |
842 | 222 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
223 |
/* Purchase Cost - Engine weight */ |
842 | 224 |
SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5); |
225 |
SetDParam(1, rvi->weight << multihead); |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
226 |
DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
227 |
y += 10; |
842 | 228 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
229 |
/* Max speed - Engine power */ |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
230 |
SetDParam(0, rvi->max_speed); |
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
231 |
SetDParam(1, rvi->power << multihead); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
232 |
DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
233 |
y += 10; |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
234 |
|
5588
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
235 |
/* Max tractive effort - not applicable if old acceleration or maglev */ |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
236 |
if (_patches.realistic_acceleration && e->railtype != RAILTYPE_MAGLEV) { |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
237 |
SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256); |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
238 |
DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0); |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
239 |
y += 10; |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
240 |
} |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
241 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
242 |
/* Running cost */ |
2840
d68a605b2087
(svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents:
2822
diff
changeset
|
243 |
SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead); |
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
244 |
DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
245 |
y += 10; |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
246 |
|
1908
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
247 |
/* Powered wagons power - Powered wagons extra weight */ |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
248 |
if (rvi->pow_wag_power != 0) { |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
249 |
SetDParam(0, rvi->pow_wag_power); |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
250 |
SetDParam(1, rvi->pow_wag_weight); |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
251 |
DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0); |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
252 |
y += 10; |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
253 |
}; |
bc48a30aba72
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
254 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
255 |
/* Cargo type + capacity, or N/A */ |
4898
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
256 |
if (rvi->capacity == 0) { |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
257 |
SetDParam(0, CT_INVALID); |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
258 |
SetDParam(2, STR_EMPTY); |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
259 |
} else { |
4896
72d7a8614580
(svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents:
4871
diff
changeset
|
260 |
SetDParam(0, rvi->cargo_type); |
4737
e38af7736681
(svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents:
4712
diff
changeset
|
261 |
SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead); |
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
262 |
SetDParam(2, STR_9842_REFITTABLE); |
842 | 263 |
} |
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
264 |
DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
265 |
y += 10; |
842 | 266 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
267 |
/* Design date - Life length */ |
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4288
diff
changeset
|
268 |
SetDParam(0, ymd.year); |
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
269 |
SetDParam(1, e->lifelength); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
270 |
DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
271 |
y += 10; |
842 | 272 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
273 |
/* Reliability */ |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
274 |
SetDParam(0, e->reliability * 100 >> 16); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
275 |
DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
276 |
y += 10; |
3651
688936ccf1d2
(svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents:
3491
diff
changeset
|
277 |
|
688936ccf1d2
(svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents:
3491
diff
changeset
|
278 |
/* Additional text from NewGRF */ |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
279 |
y += ShowAdditionalText(x, y, w, engine_number); |
4933
106e2a14ab3c
(svn r6920) - Codechange: Ignore refit options of an engine if it has no capacity.
peter1138
parents:
4932
diff
changeset
|
280 |
if (rvi->capacity > 0) y += ShowRefitOptionsList(x, y, w, engine_number); |
842 | 281 |
} |
282 |
||
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
283 |
/** |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
284 |
* Draw the purchase info details of a train wagon at a given location. |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
285 |
* @param x,y location where to draw the info |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
286 |
* @param engine_number the engine of which to draw the info of |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
287 |
*/ |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
288 |
void DrawTrainWagonPurchaseInfo(int x, int y, uint w, EngineID engine_number) |
842 | 289 |
{ |
290 |
const RailVehicleInfo *rvi = RailVehInfo(engine_number); |
|
3393
48ce4c723a76
(svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents:
3384
diff
changeset
|
291 |
bool refittable = (EngInfo(engine_number)->refit_mask != 0); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
292 |
|
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
293 |
/* Purchase cost */ |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
294 |
SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
295 |
DrawString(x, y, STR_PURCHASE_INFO_COST, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
296 |
y += 10; |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
297 |
|
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
298 |
/* Wagon weight - (including cargo) */ |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
299 |
SetDParam(0, rvi->weight); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
300 |
SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
301 |
DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
302 |
y += 10; |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
303 |
|
3685
7d2d1fee14d7
(svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents:
3651
diff
changeset
|
304 |
/* Cargo type + capacity, or N/A */ |
4898
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
305 |
if (rvi->capacity == 0) { |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
306 |
SetDParam(0, CT_INVALID); |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
307 |
SetDParam(2, STR_EMPTY); |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4896
diff
changeset
|
308 |
} else { |
4896
72d7a8614580
(svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents:
4871
diff
changeset
|
309 |
SetDParam(0, rvi->cargo_type); |
4737
e38af7736681
(svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents:
4712
diff
changeset
|
310 |
SetDParam(1, rvi->capacity * (CountArticulatedParts(engine_number) + 1)); |
3685
7d2d1fee14d7
(svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents:
3651
diff
changeset
|
311 |
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); |
7d2d1fee14d7
(svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents:
3651
diff
changeset
|
312 |
} |
1907
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
313 |
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); |
cebdef7a1c8a
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
314 |
y += 10; |
2443
62ff46a3f530
(svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents:
2436
diff
changeset
|
315 |
|
62ff46a3f530
(svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents:
2436
diff
changeset
|
316 |
/* Wagon speed limit, displayed if above zero */ |
2456
93041d70867b
(svn r2982) Newgrf: Added patch option for wagon speed limits. This is enabled by default.
peter1138
parents:
2443
diff
changeset
|
317 |
if (rvi->max_speed > 0 && _patches.wagon_speed_limits) { |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
318 |
SetDParam(0, rvi->max_speed); |
2443
62ff46a3f530
(svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents:
2436
diff
changeset
|
319 |
DrawString(x,y, STR_PURCHASE_INFO_SPEED, 0); |
62ff46a3f530
(svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents:
2436
diff
changeset
|
320 |
y += 10; |
62ff46a3f530
(svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents:
2436
diff
changeset
|
321 |
} |
3651
688936ccf1d2
(svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents:
3491
diff
changeset
|
322 |
|
688936ccf1d2
(svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents:
3491
diff
changeset
|
323 |
/* Additional text from NewGRF */ |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
324 |
y += ShowAdditionalText(x, y, w, engine_number); |
4932
3567a3ec9d80
(svn r6912) - Feature: Show a list of cargo types that a vehicle is refittable to in the purchase information window. (mart3p)
peter1138
parents:
4931
diff
changeset
|
325 |
y += ShowRefitOptionsList(x, y, w, engine_number); |
842 | 326 |
} |
0 | 327 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
328 |
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 329 |
{ |
4171 | 330 |
Vehicle *v, *found; |
0 | 331 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4049
diff
changeset
|
332 |
if (!success) return; |
0 | 333 |
|
334 |
// find a locomotive in the depot. |
|
335 |
found = NULL; |
|
336 |
FOR_ALL_VEHICLES(v) { |
|
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2639
diff
changeset
|
337 |
if (v->type == VEH_Train && IsFrontEngine(v) && |
0 | 338 |
v->tile == tile && |
339 |
v->u.rail.track == 0x80) { |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4049
diff
changeset
|
340 |
if (found != NULL) return; // must be exactly one. |
0 | 341 |
found = v; |
342 |
} |
|
343 |
} |
|
344 |
||
345 |
// if we found a loco, |
|
346 |
if (found != NULL) { |
|
347 |
found = GetLastVehicleInChain(found); |
|
348 |
// put the new wagon at the end of the loco. |
|
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3919
diff
changeset
|
349 |
DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); |
588 | 350 |
RebuildVehicleLists(); |
0 | 351 |
} |
352 |
} |
|
353 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
354 |
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 355 |
{ |
4171 | 356 |
const Vehicle *v; |
0 | 357 |
|
2639 | 358 |
if (!success) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
359 |
|
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3919
diff
changeset
|
360 |
v = GetVehicle(_new_vehicle_id); |
0 | 361 |
if (tile == _backup_orders_tile) { |
362 |
_backup_orders_tile = 0; |
|
363 |
RestoreVehicleOrders(v, _backup_orders_data); |
|
364 |
} |
|
365 |
ShowTrainViewWindow(v); |
|
366 |
} |
|
367 |
||
3887
3e44ae3b1e7c
(svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents:
3884
diff
changeset
|
368 |
void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2) |
2244 | 369 |
{ |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3919
diff
changeset
|
370 |
if (success) ShowTrainViewWindow(GetVehicle(_new_vehicle_id)); |
2244 | 371 |
} |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
372 |
|
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
373 |
static void engine_drawing_loop(const EngineList *engines, int x, int *y, EngineID sel, EngineID position, int16 show_max) |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
374 |
{ |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
375 |
int count = min(EngList_Count(engines), show_max); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
376 |
for (; position < count; *y += 14, position++) { |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
377 |
EngineID id = (*engines)[position]; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
378 |
DrawString(x + 59, *y + 2, GetCustomEngineName(id), sel == id ? 0xC : 0x10); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
379 |
DrawTrainEngine(x + 29, *y + 6, id, GetEnginePalette(id, _local_player)); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
380 |
} |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
381 |
} |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
382 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
383 |
static void GenerateBuildList(Window *w) |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
384 |
{ |
5200
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
385 |
EngineID eid, sel_id; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
386 |
int num_engines = 0; |
5190
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
387 |
int num_wagons = 0; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
388 |
buildvehicle_d *bv = &WP(w, buildvehicle_d); |
524
6ed367906581
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
389 |
|
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
390 |
bv->filter.railtype = (w->window_number == 0) ? RAILTYPE_END : GetRailType(w->window_number); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
391 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
392 |
EngList_RemoveAll(&bv->eng_list); |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
393 |
|
5200
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
394 |
/* Make list of all available train engines and wagons. |
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
395 |
* Also check to see if the previously selected engine is still available, |
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
396 |
* and if not, reset selection to INVALID_ENGINE. This could be the case |
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
397 |
* when engines become obsolete and are removed */ |
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
398 |
for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) { |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
399 |
const Engine *e = GetEngine(eid); |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
400 |
const RailVehicleInfo *rvi = RailVehInfo(eid); |
524
6ed367906581
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
401 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
402 |
if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue; |
5215
439d5ca71311
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5202
diff
changeset
|
403 |
if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue; |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
404 |
|
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
405 |
EngList_Add(&bv->eng_list, eid); |
5190
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
406 |
if ((rvi->flags & RVI_WAGON) == 0) { |
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
407 |
num_engines++; |
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
408 |
} else { |
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
409 |
num_wagons++; |
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
410 |
} |
5200
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
411 |
|
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
412 |
if (eid == bv->sel_engine) sel_id = eid; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
413 |
} |
5190
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
414 |
|
5200
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
415 |
bv->sel_engine = sel_id; |
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
416 |
|
5195
fa04ba5d3465
(svn r7309) -Codechange: sort train engines/wagons by number first and then by custom rule
KUDr
parents:
5191
diff
changeset
|
417 |
// make engines first, and then wagons, sorted by ListPositionOfEngine() |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
418 |
_internal_sort_order = false; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
419 |
EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter); |
5190
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
420 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
421 |
// and then sort engines |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
422 |
_internal_sort_order = bv->descending_sort_order; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
423 |
EngList_SortPartial(&bv->eng_list, _engine_sorter[bv->sort_criteria], 0, num_engines); |
5190
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
424 |
|
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
425 |
// and finally sort wagons |
dd49d0abb049
(svn r7303) -Codechange: Sort wagon list as well as engine list.
peter1138
parents:
5187
diff
changeset
|
426 |
EngList_SortPartial(&bv->eng_list, _engine_sorter[bv->sort_criteria], num_engines, num_wagons); |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
427 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
428 |
|
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
429 |
static void DrawTrainBuildWindow(Window *w) |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
430 |
{ |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
431 |
const buildvehicle_d *bv = &WP(w, buildvehicle_d); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
432 |
int x = 1; |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
433 |
int y = 27; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
434 |
EngineID selected_id = bv->sel_engine; |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
435 |
int max = w->vscroll.pos + w->vscroll.cap; |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
436 |
|
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
437 |
SetWindowWidgetDisabledState(w, BUILD_TRAIN_WIDGET_BUILD, w->window_number == 0); // Disable unless we got a depot to build in |
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
438 |
|
5200
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
439 |
SetVScrollCount(w, EngList_Count(&bv->eng_list)); |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
440 |
SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
441 |
DrawWindowWidgets(w); |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
442 |
|
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
443 |
/* Draw the engines */ |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
444 |
engine_drawing_loop(&bv->eng_list, x, &y, selected_id, w->vscroll.pos, max); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
445 |
|
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
446 |
if (selected_id != INVALID_ENGINE) { |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
447 |
const RailVehicleInfo *rvi = RailVehInfo(selected_id); |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
448 |
const Widget *wi = &w->widget[BUILD_TRAIN_WIDGET_PANEL]; |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
449 |
|
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
450 |
if (rvi->flags & RVI_WAGON) { |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
451 |
DrawTrainWagonPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
452 |
} else { |
4930
fd91a88d6ef6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4912
diff
changeset
|
453 |
DrawTrainEnginePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
454 |
} |
524
6ed367906581
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
455 |
} |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
456 |
DrawString(85, 15, _engine_sort_listing[bv->sort_criteria], 0x10); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
457 |
DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10); |
524
6ed367906581
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
458 |
} |
6ed367906581
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
459 |
|
0 | 460 |
static void NewRailVehicleWndProc(Window *w, WindowEvent *e) |
461 |
{ |
|
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
462 |
buildvehicle_d *bv = &WP(w, buildvehicle_d); |
2952 | 463 |
switch (e->event) { |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
464 |
case WE_CREATE: |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
465 |
EngList_Create(&bv->eng_list); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
466 |
bv->sel_engine = INVALID_ENGINE; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
467 |
bv->sort_criteria = _last_sort_criteria; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
468 |
bv->descending_sort_order = _last_sort_order; |
5191
d79fef6eeb76
(svn r7304) -Codechange: Reinstate caching of sorted purchase list. Dropping from 9m to 1.5m cycles for a redraw of a full list is not frivolous.
peter1138
parents:
5190
diff
changeset
|
469 |
GenerateBuildList(w); |
5200
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
470 |
/* Select the first engine in the list as default when opening the window */ |
603e30641448
(svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents:
5199
diff
changeset
|
471 |
if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0]; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4765
diff
changeset
|
472 |
break; |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4765
diff
changeset
|
473 |
|
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4765
diff
changeset
|
474 |
case WE_INVALIDATE_DATA: |
5191
d79fef6eeb76
(svn r7304) -Codechange: Reinstate caching of sorted purchase list. Dropping from 9m to 1.5m cycles for a redraw of a full list is not frivolous.
peter1138
parents:
5190
diff
changeset
|
475 |
GenerateBuildList(w); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
476 |
break; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
477 |
|
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
478 |
case WE_DESTROY: |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
479 |
EngList_Destroy(&bv->eng_list); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
480 |
break; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
481 |
|
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
482 |
case WE_PAINT: |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
483 |
DrawTrainBuildWindow(w); |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
484 |
break; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
485 |
|
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
486 |
case WE_CLICK: { |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
487 |
switch (e->we.click.widget) { |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
488 |
case BUILD_TRAIN_WIDGET_SORT_ASCENDING_DESCENDING: |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
489 |
bv->descending_sort_order ^= true; |
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
490 |
_last_sort_order = bv->descending_sort_order; |
5191
d79fef6eeb76
(svn r7304) -Codechange: Reinstate caching of sorted purchase list. Dropping from 9m to 1.5m cycles for a redraw of a full list is not frivolous.
peter1138
parents:
5190
diff
changeset
|
491 |
GenerateBuildList(w); |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
492 |
SetWindowDirty(w); |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
493 |
break; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
494 |
|
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
495 |
case BUILD_TRAIN_WIDGET_SORT_TEXT: case BUILD_TRAIN_WIDGET_SORT_DROPDOWN:/* Select sorting criteria dropdown menu */ |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
496 |
ShowDropDownMenu(w, _engine_sort_listing, bv->sort_criteria, BUILD_TRAIN_WIDGET_SORT_DROPDOWN, 0, 0); |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
497 |
return; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
498 |
|
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
499 |
case BUILD_TRAIN_WIDGET_LIST: { |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
500 |
uint i = ((e->we.click.pt.y - 26) / 14) + w->vscroll.pos; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
501 |
uint num_items = EngList_Count(&bv->eng_list); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
502 |
bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
503 |
SetWindowDirty(w); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
504 |
break; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
505 |
} |
0 | 506 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
507 |
case BUILD_TRAIN_WIDGET_BUILD: { |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
508 |
EngineID sel_eng = bv->sel_engine; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
509 |
if (sel_eng != INVALID_ENGINE) |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
510 |
DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
511 |
break; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
512 |
} |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
513 |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
514 |
case BUILD_TRAIN_WIDGET_RENAME: { |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
515 |
EngineID sel_eng = bv->sel_engine; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
516 |
if (sel_eng != INVALID_ENGINE) { |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
517 |
bv->rename_engine = sel_eng; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
518 |
ShowQueryString(GetCustomEngineName(sel_eng), STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL); |
4765
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
519 |
} |
18cc31fe97a8
(svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents:
4764
diff
changeset
|
520 |
break; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
521 |
} |
0 | 522 |
} |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
523 |
} |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
524 |
break; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
525 |
|
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
526 |
case WE_ON_EDIT_TEXT: { |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
527 |
if (e->we.edittext.str[0] != '\0') { |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
528 |
_cmd_text = e->we.edittext.str; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
529 |
DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE)); |
968
9c47631d62dc
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
530 |
} |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
531 |
break; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
532 |
} |
0 | 533 |
|
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
534 |
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
535 |
if (bv->sort_criteria != e->we.dropdown.index) { |
5199
523e7025d979
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents:
5198
diff
changeset
|
536 |
bv->sort_criteria = _last_sort_criteria = e->we.dropdown.index; |
5191
d79fef6eeb76
(svn r7304) -Codechange: Reinstate caching of sorted purchase list. Dropping from 9m to 1.5m cycles for a redraw of a full list is not frivolous.
peter1138
parents:
5190
diff
changeset
|
537 |
GenerateBuildList(w); |
d79fef6eeb76
(svn r7304) -Codechange: Reinstate caching of sorted purchase list. Dropping from 9m to 1.5m cycles for a redraw of a full list is not frivolous.
peter1138
parents:
5190
diff
changeset
|
538 |
SetWindowDirty(w); |
4770
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
539 |
} |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
540 |
break; |
987ef30e5b45
(svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents:
4769
diff
changeset
|
541 |
|
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
542 |
case WE_RESIZE: { |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
543 |
if (e->we.sizing.diff.y == 0) break; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
544 |
|
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
545 |
w->vscroll.cap += e->we.sizing.diff.y / 14; |
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
546 |
w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1; |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
547 |
break; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
548 |
} |
0 | 549 |
} |
550 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
551 |
|
0 | 552 |
static const WindowDesc _new_rail_vehicle_desc = { |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
553 |
WDP_AUTO, WDP_AUTO, 228, 252, |
0 | 554 |
WC_BUILD_VEHICLE,0, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
555 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
0 | 556 |
_new_rail_vehicle_widgets, |
557 |
NewRailVehicleWndProc |
|
558 |
}; |
|
559 |
||
4442
8d8d0c2df7cb
(svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents:
4434
diff
changeset
|
560 |
void ShowBuildTrainWindow(TileIndex tile) |
0 | 561 |
{ |
562 |
Window *w; |
|
563 |
||
564 |
DeleteWindowById(WC_BUILD_VEHICLE, tile); |
|
565 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5106
diff
changeset
|
566 |
w = AllocateWindowDescFront(&_new_rail_vehicle_desc, tile); |
0 | 567 |
w->vscroll.cap = 8; |
4764
3793c26ec137
(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents:
4737
diff
changeset
|
568 |
w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
569 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
570 |
w->resize.step_height = 14; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3948
diff
changeset
|
571 |
w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
572 |
|
0 | 573 |
if (tile != 0) { |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
574 |
w->caption_color = GetTileOwner(tile); |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
575 |
WP(w,buildvehicle_d).filter.railtype = GetRailType(tile); |
0 | 576 |
} else { |
577 |
w->caption_color = _local_player; |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
578 |
WP(w,buildvehicle_d).filter.railtype = RAILTYPE_END; |
0 | 579 |
} |
580 |
} |
|
581 |
||
2593
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
582 |
/** |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
583 |
* Get the number of pixels for the given wagon length. |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
584 |
* @param len Length measured in 1/8ths of a standard wagon. |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
585 |
* @return Number of pixels across. |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
586 |
*/ |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
4635
diff
changeset
|
587 |
int WagonLengthToPixels(int len) { |
3845
c3cd4b825c2f
(svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents:
3844
diff
changeset
|
588 |
return (len * _traininfo_vehicle_width) / 8; |
2593
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
589 |
} |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
590 |
|
4442
8d8d0c2df7cb
(svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents:
4434
diff
changeset
|
591 |
void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection) |
0 | 592 |
{ |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
593 |
DrawPixelInfo tmp_dpi, *old_dpi; |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
594 |
int dx = -(skip * 8) / _traininfo_vehicle_width; |
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
595 |
/* Position of highlight box */ |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
596 |
int highlight_l = 0; |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
597 |
int highlight_r = 0; |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
598 |
|
4429
1bb01569940c
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4426
diff
changeset
|
599 |
if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, count + 1, 14)) return; |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
600 |
|
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
601 |
count = (count * 8) / _traininfo_vehicle_width; |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
602 |
|
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
603 |
old_dpi = _cur_dpi; |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
604 |
_cur_dpi = &tmp_dpi; |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
605 |
|
0 | 606 |
do { |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
607 |
int width = v->u.rail.cached_veh_length; |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
608 |
|
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
609 |
if (dx + width > 0) { |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
610 |
if (dx <= count) { |
3049
b797ca543c13
(svn r3631) - 2cc: Remove use of some temporary variables and perform minor optimization in the form of the ternary operator.
peter1138
parents:
3040
diff
changeset
|
611 |
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
612 |
DrawSprite(GetTrainImage(v, DIR_W) | pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
613 |
if (v->index == selection) { |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
614 |
/* Set the highlight position */ |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
615 |
highlight_l = WagonLengthToPixels(dx) + 1; |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
616 |
highlight_r = WagonLengthToPixels(dx + width) + 1; |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
617 |
} |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
618 |
} |
0 | 619 |
} |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
620 |
dx += width; |
0 | 621 |
|
2593
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
622 |
v = v->next; |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
623 |
} while (dx < count && v != NULL); |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
624 |
|
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
625 |
if (highlight_l != highlight_r) { |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
626 |
/* Draw the highlight. Now done after drawing all the engines, as |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
627 |
* the next engine after the highlight could overlap it. */ |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
628 |
DrawFrameRect(highlight_l, 0, highlight_r, 13, 15, FR_BORDERONLY); |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
629 |
} |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
630 |
|
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
631 |
_cur_dpi = old_dpi; |
0 | 632 |
} |
633 |
||
2275
cbaeb07740b1
(svn r2799) Make the only two non-const widget lists const
tron
parents:
2261
diff
changeset
|
634 |
static const Widget _train_view_widgets[] = { |
4937
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
635 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
636 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
637 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
638 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 121, 0x0, STR_NULL }, |
4939
ede0f6777b3c
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
639 |
{ WWT_INSET, RESIZE_RB, 14, 2, 229, 16, 119, 0x0, STR_NULL }, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4937
diff
changeset
|
640 |
{ WWT_PUSHBTN, RESIZE_RTB, 14, 0, 237, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK }, |
4937
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
641 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, SPR_CENTRE_VIEW_VEHICLE, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
642 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_SEND_TRAIN_TODEPOT, STR_8849_SEND_TRAIN_TO_DEPOT }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
643 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_IGNORE_SIGNALS, STR_884A_FORCE_TRAIN_TO_PROCEED }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
644 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_FORCE_VEHICLE_TURN, STR_884B_REVERSE_DIRECTION_OF_TRAIN }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
645 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, SPR_SHOW_ORDERS, STR_8847_SHOW_TRAIN_S_ORDERS }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
646 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 104, 121, SPR_SHOW_VEHICLE_DETAILS,STR_884C_SHOW_TRAIN_DETAILS }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
647 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_REFIT_VEHICLE, STR_RAIL_REFIT_VEHICLE_TO_CARRY }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
648 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_CLONE_TRAIN, STR_CLONE_TRAIN_INFO }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
649 |
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 122, 121, 0x0, STR_NULL }, |
a525d56a8d40
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4933
diff
changeset
|
650 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0, STR_NULL }, |
1485
a2f36708c260
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
651 |
{ WIDGETS_END } |
0 | 652 |
}; |
653 |
||
4171 | 654 |
static void ShowTrainDetailsWindow(const Vehicle *v); |
2561
c78c3d248897
(svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents:
2549
diff
changeset
|
655 |
|
0 | 656 |
static void TrainViewWndProc(Window *w, WindowEvent *e) |
657 |
{ |
|
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
658 |
switch (e->event) { |
0 | 659 |
case WE_PAINT: { |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
660 |
const Vehicle *v, *u; |
0 | 661 |
StringID str; |
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
662 |
bool is_localplayer; |
0 | 663 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
664 |
v = GetVehicle(w->window_number); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
665 |
|
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
666 |
is_localplayer = v->owner == _local_player; |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
667 |
SetWindowWidgetDisabledState(w, 7, !is_localplayer); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
668 |
SetWindowWidgetDisabledState(w, 8, !is_localplayer); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
669 |
SetWindowWidgetDisabledState(w, 9, !is_localplayer); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
670 |
SetWindowWidgetDisabledState(w, 13, !is_localplayer); |
1387
eff794048d92
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
671 |
|
4871
f79dbad27b47
(svn r6801) - Fix (r6619): Always disable the train refit button. It will be enabled later if refitting is possible.
peter1138
parents:
4868
diff
changeset
|
672 |
/* Disable cargo refit button, until we know we can enable it below. */ |
f79dbad27b47
(svn r6801) - Fix (r6619): Always disable the train refit button. It will be enabled later if refitting is possible.
peter1138
parents:
4868
diff
changeset
|
673 |
DisableWindowWidget(w, 12); |
f79dbad27b47
(svn r6801) - Fix (r6619): Always disable the train refit button. It will be enabled later if refitting is possible.
peter1138
parents:
4868
diff
changeset
|
674 |
|
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
675 |
if (is_localplayer) { |
2867
66a9c4e27e34
(svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents:
2840
diff
changeset
|
676 |
/* See if any vehicle can be refitted */ |
66a9c4e27e34
(svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents:
2840
diff
changeset
|
677 |
for (u = v; u != NULL; u = u->next) { |
3393
48ce4c723a76
(svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents:
3384
diff
changeset
|
678 |
if (EngInfo(u->engine_type)->refit_mask != 0 || |
2867
66a9c4e27e34
(svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents:
2840
diff
changeset
|
679 |
(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) { |
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
680 |
EnableWindowWidget(w, 12); |
2867
66a9c4e27e34
(svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents:
2840
diff
changeset
|
681 |
/* We have a refittable carriage, bail out */ |
66a9c4e27e34
(svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents:
2840
diff
changeset
|
682 |
break; |
66a9c4e27e34
(svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents:
2840
diff
changeset
|
683 |
} |
1387
eff794048d92
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
684 |
} |
eff794048d92
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
685 |
} |
eff794048d92
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
686 |
|
0 | 687 |
/* draw widgets & caption */ |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
688 |
SetDParam(0, v->string_id); |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2252
diff
changeset
|
689 |
SetDParam(1, v->unitnumber); |
0 | 690 |
DrawWindowWidgets(w); |
691 |
||
692 |
if (v->u.rail.crash_anim_pos != 0) { |
|
693 |
str = STR_8863_CRASHED; |
|
694 |
} else if (v->breakdown_ctr == 1) { |
|
695 |
str = STR_885C_BROKEN_DOWN; |
|
696 |
} else if (v->vehstatus & VS_STOPPED) { |
|
697 |
if (v->u.rail.last_speed == 0) { |
|
4251
85befcd5f435
(svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents:
4171
diff
changeset
|
698 |
if (v->u.rail.cached_power == 0) { |
85befcd5f435
(svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents:
4171
diff
changeset
|
699 |
str = STR_TRAIN_NO_POWER; |
85befcd5f435
(svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents:
4171
diff
changeset
|
700 |
} else { |
85befcd5f435
(svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents:
4171
diff
changeset
|
701 |
str = STR_8861_STOPPED; |
85befcd5f435
(svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents:
4171
diff
changeset
|
702 |
} |
0 | 703 |
} else { |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
704 |
SetDParam(0, v->u.rail.last_speed); |
0 | 705 |
str = STR_TRAIN_STOPPING + _patches.vehicle_speed; |
706 |
} |
|
707 |
} else { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
708 |
switch (v->current_order.type) { |
0 | 709 |
case OT_GOTO_STATION: { |
710 |
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4524
diff
changeset
|
711 |
SetDParam(0, v->current_order.dest); |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
712 |
SetDParam(1, v->u.rail.last_speed); |
0 | 713 |
} break; |
714 |
||
715 |
case OT_GOTO_DEPOT: { |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4524
diff
changeset
|
716 |
Depot *dep = GetDepot(v->current_order.dest); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
717 |
SetDParam(0, dep->town_index); |
4633
fae5d85ef53d
(svn r6497) -Fix r6165: Vehicles heading for depots when their orders contained "service in depot" displayed the stopping in depot string
bjarni
parents:
4547
diff
changeset
|
718 |
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) { |
4412
945e8a9bb89a
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
719 |
str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed; |
945e8a9bb89a
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
720 |
} else { |
945e8a9bb89a
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
721 |
str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed; |
945e8a9bb89a
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
722 |
} |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
723 |
SetDParam(1, v->u.rail.last_speed); |
0 | 724 |
} break; |
725 |
||
726 |
case OT_LOADING: |
|
727 |
case OT_LEAVESTATION: |
|
728 |
str = STR_882F_LOADING_UNLOADING; |
|
729 |
break; |
|
730 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
382
diff
changeset
|
731 |
case OT_GOTO_WAYPOINT: { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4524
diff
changeset
|
732 |
SetDParam(0, v->current_order.dest); |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
382
diff
changeset
|
733 |
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed; |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
734 |
SetDParam(1, v->u.rail.last_speed); |
0 | 735 |
break; |
736 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
737 |
|
0 | 738 |
default: |
739 |
if (v->num_orders == 0) { |
|
740 |
str = STR_NO_ORDERS + _patches.vehicle_speed; |
|
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
741 |
SetDParam(0, v->u.rail.last_speed); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4049
diff
changeset
|
742 |
} else { |
0 | 743 |
str = STR_EMPTY; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4049
diff
changeset
|
744 |
} |
0 | 745 |
break; |
746 |
} |
|
747 |
} |
|
748 |
||
2103
9266bb2ac29d
(svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents:
2084
diff
changeset
|
749 |
/* draw the flag plus orders */ |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2498
diff
changeset
|
750 |
DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1); |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
751 |
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0); |
0 | 752 |
DrawWindowViewport(w); |
753 |
} break; |
|
754 |
||
755 |
case WE_CLICK: { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
756 |
int wid = e->we.click.widget; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
757 |
Vehicle *v = GetVehicle(w->window_number); |
0 | 758 |
|
2952 | 759 |
switch (wid) { |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
760 |
case 5: /* start/stop train */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
761 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); |
0 | 762 |
break; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
763 |
case 6: /* center main view */ |
0 | 764 |
ScrollMainWindowTo(v->x_pos, v->y_pos); |
765 |
break; |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
766 |
case 7: /* goto depot */ |
601
952c0295f79a
(svn r1025) -Fix: [Network] [ 1083687 ] Sending to depot caused desync because the
truelight
parents:
588
diff
changeset
|
767 |
/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */ |
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4495
diff
changeset
|
768 |
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_TRAIN_TO_DEPOT | CMD_NO_TEST_IF_IN_NETWORK | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT)); |
0 | 769 |
break; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
770 |
case 8: /* force proceed */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
771 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL)); |
0 | 772 |
break; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
773 |
case 9: /* reverse direction */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
774 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION)); |
0 | 775 |
break; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
776 |
case 10: /* show train orders */ |
0 | 777 |
ShowOrdersWindow(v); |
778 |
break; |
|
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
779 |
case 11: /* show train details */ |
0 | 780 |
ShowTrainDetailsWindow(v); |
781 |
break; |
|
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
782 |
case 12: |
4712
273ec3b182bf
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4709
diff
changeset
|
783 |
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID); |
0 | 784 |
break; |
2244 | 785 |
case 13: |
786 |
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); |
|
787 |
break; |
|
0 | 788 |
} |
789 |
} break; |
|
790 |
||
1485
a2f36708c260
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
791 |
case WE_RESIZE: |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
792 |
w->viewport->width += e->we.sizing.diff.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
793 |
w->viewport->height += e->we.sizing.diff.y; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
794 |
w->viewport->virtual_width += e->we.sizing.diff.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
795 |
w->viewport->virtual_height += e->we.sizing.diff.y; |
1485
a2f36708c260
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
796 |
break; |
a2f36708c260
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
797 |
|
0 | 798 |
case WE_DESTROY: |
338
04ad3e897bf8
(svn r514) -Fix: [1053397] Refit Train Window Stays Open
tron
parents:
243
diff
changeset
|
799 |
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number); |
0 | 800 |
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); |
801 |
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); |
|
802 |
break; |
|
803 |
||
804 |
case WE_MOUSELOOP: { |
|
4171 | 805 |
const Vehicle *v = GetVehicle(w->window_number); |
4702
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
806 |
bool train_stopped = CheckTrainStoppedInDepot(v) >= 0; |
0 | 807 |
|
4702
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
808 |
/* Widget 7 (send to depot) must be hidden if the train is already stopped in hangar. |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
809 |
* Widget 13 (clone) should then be shown, since cloning is allowed only while in depot and stopped. |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
810 |
* This sytem allows to have two buttons, on top of each other. |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
811 |
* The same system applies to widget 9 and 12, reverse direction and refit*/ |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
812 |
if (train_stopped != IsWindowWidgetHidden(w, 7) || train_stopped == IsWindowWidgetHidden(w, 13)) { |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
813 |
SetWindowWidgetHiddenState(w, 7, train_stopped); // send to depot |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
814 |
SetWindowWidgetHiddenState(w, 9, train_stopped); // reverse direction |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
815 |
SetWindowWidgetHiddenState(w, 12, !train_stopped); // refit |
5179f9adc5b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
816 |
SetWindowWidgetHiddenState(w, 13, !train_stopped); // clone |
0 | 817 |
SetWindowDirty(w); |
818 |
} |
|
819 |
break; |
|
820 |
} |
|
821 |
||
822 |
} |
|
823 |
} |
|
824 |
||
825 |
static const WindowDesc _train_view_desc = { |
|
5070
0bbf5264bfb7
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
826 |
WDP_AUTO, WDP_AUTO, 250, 134, |
0 | 827 |
WC_VEHICLE_VIEW,0, |
1485
a2f36708c260
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
828 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 829 |
_train_view_widgets, |
830 |
TrainViewWndProc |
|
831 |
}; |
|
832 |
||
4171 | 833 |
void ShowTrainViewWindow(const Vehicle *v) |
0 | 834 |
{ |
4171 | 835 |
Window *w = AllocateWindowDescFront(&_train_view_desc,v->index); |
0 | 836 |
|
2561
c78c3d248897
(svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents:
2549
diff
changeset
|
837 |
if (w != NULL) { |
0 | 838 |
w->caption_color = v->owner; |
839 |
AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0); |
|
840 |
} |
|
841 |
} |
|
842 |
||
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
843 |
static void TrainDetailsCargoTab(const Vehicle *v, int x, int y) |
0 | 844 |
{ |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
845 |
if (v->cargo_cap != 0) { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
846 |
uint num = v->cargo_count; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
847 |
StringID str = STR_8812_EMPTY; |
0 | 848 |
|
849 |
if (num != 0) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
850 |
SetDParam(0, v->cargo_type); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
851 |
SetDParam(1, num); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
852 |
SetDParam(2, v->cargo_source); |
5163
83acad83bbdd
(svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents:
5124
diff
changeset
|
853 |
SetDParam(3, _patches.freight_trains); |
5316
b04421921eae
(svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents:
5273
diff
changeset
|
854 |
str = FreightWagonMult(v->cargo_type) > 1 ? STR_FROM_MULT : STR_8813_FROM; |
0 | 855 |
} |
856 |
DrawString(x, y, str, 0); |
|
857 |
} |
|
858 |
} |
|
859 |
||
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
860 |
static void TrainDetailsInfoTab(const Vehicle *v, int x, int y) |
0 | 861 |
{ |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
862 |
if (RailVehInfo(v->engine_type)->flags & RVI_WAGON) { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
863 |
SetDParam(0, GetCustomEngineName(v->engine_type)); |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
864 |
SetDParam(1, v->value); |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
865 |
DrawString(x, y, STR_882D_VALUE, 0x10); |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
866 |
} else { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
867 |
SetDParam(0, GetCustomEngineName(v->engine_type)); |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4299
diff
changeset
|
868 |
SetDParam(1, v->build_year); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
869 |
SetDParam(2, v->value); |
0 | 870 |
DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
871 |
} |
0 | 872 |
} |
873 |
||
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
874 |
static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y) |
0 | 875 |
{ |
876 |
if (v->cargo_cap != 0) { |
|
4896
72d7a8614580
(svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents:
4871
diff
changeset
|
877 |
SetDParam(0, v->cargo_type); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
878 |
SetDParam(1, v->cargo_cap); |
5163
83acad83bbdd
(svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents:
5124
diff
changeset
|
879 |
SetDParam(2, _patches.freight_trains); |
5316
b04421921eae
(svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents:
5273
diff
changeset
|
880 |
DrawString(x, y, FreightWagonMult(v->cargo_type) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, 0); |
0 | 881 |
} |
882 |
} |
|
883 |
||
884 |
||
885 |
static void DrawTrainDetailsWindow(Window *w) |
|
886 |
{ |
|
887 |
byte det_tab = WP(w, traindetails_d).tab; |
|
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
888 |
const Vehicle *v; |
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
889 |
const Vehicle *u; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
890 |
AcceptedCargo act_cargo; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
891 |
AcceptedCargo max_cargo; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
892 |
uint i; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
893 |
int num; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
894 |
int x; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
895 |
int y; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
896 |
int sel; |
0 | 897 |
|
898 |
num = 0; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
899 |
u = v = GetVehicle(w->window_number); |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
900 |
if (det_tab == 3) { // Total cargo tab |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
901 |
for (i = 0; i < lengthof(act_cargo); i++) { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
902 |
act_cargo[i] = 0; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
903 |
max_cargo[i] = 0; |
0 | 904 |
} |
905 |
||
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
906 |
do { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
907 |
act_cargo[u->cargo_type] += u->cargo_count; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
908 |
max_cargo[u->cargo_type] += u->cargo_cap; |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
909 |
} while ((u = u->next) != NULL); |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
910 |
|
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
911 |
/* Set scroll-amount seperately from counting, as to not compute num double |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
912 |
* for more carriages of the same type |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
913 |
*/ |
0 | 914 |
for (i = 0; i != NUM_CARGO; i++) { |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
915 |
if (max_cargo[i] > 0) num++; // only count carriages that the train has |
0 | 916 |
} |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
917 |
num++; // needs one more because first line is description string |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
918 |
} else { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
919 |
do { |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
920 |
if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++; |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
921 |
} while ((u = u->next) != NULL); |
0 | 922 |
} |
923 |
||
924 |
SetVScrollCount(w, num); |
|
925 |
||
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
926 |
DisableWindowWidget(w, det_tab + 9); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
927 |
SetWindowWidgetDisabledState(w, 2, v->owner != _local_player); |
0 | 928 |
|
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
929 |
/* disable service-scroller when interval is set to disabled */ |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
930 |
SetWindowWidgetDisabledState(w, 6, !_patches.servint_trains); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
931 |
SetWindowWidgetDisabledState(w, 7, !_patches.servint_trains); |
156
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
932 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
933 |
SetDParam(0, v->string_id); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
934 |
SetDParam(1, v->unitnumber); |
0 | 935 |
DrawWindowWidgets(w); |
936 |
||
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
937 |
SetDParam(1, v->age / 366); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
938 |
|
0 | 939 |
x = 2; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
940 |
|
2252
37e3ca7014e0
(svn r2772) Simplify the age notice in the vehicle details window
tron
parents:
2244
diff
changeset
|
941 |
SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
942 |
SetDParam(2, v->max_age / 366); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
943 |
SetDParam(3, GetTrainRunningCost(v) >> 8); |
0 | 944 |
DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0); |
945 |
||
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3401
diff
changeset
|
946 |
SetDParam(2, v->u.rail.cached_max_speed); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
947 |
SetDParam(1, v->u.rail.cached_power); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
948 |
SetDParam(0, v->u.rail.cached_weight); |
5588
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
949 |
SetDParam(3, v->u.rail.cached_max_te / 1000); |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
950 |
DrawString(x, 25, (_patches.realistic_acceleration && v->u.rail.railtype != RAILTYPE_MAGLEV) ? |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
951 |
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE : |
1bcb6b4c01d8
(svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents:
5316
diff
changeset
|
952 |
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0); |
0 | 953 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
954 |
SetDParam(0, v->profit_this_year); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
955 |
SetDParam(1, v->profit_last_year); |
0 | 956 |
DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
957 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
958 |
SetDParam(0, 100 * (v->reliability>>8) >> 8); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
959 |
SetDParam(1, v->breakdowns_since_last_service); |
0 | 960 |
DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0); |
961 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
962 |
SetDParam(0, v->service_interval); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
963 |
SetDParam(1, v->date_of_last_service); |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
964 |
DrawString(x + 11, 57 + (w->vscroll.cap * 14), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0); |
0 | 965 |
|
966 |
y = 57; |
|
967 |
sel = w->vscroll.pos; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
968 |
|
0 | 969 |
// draw the first 3 details tabs |
970 |
if (det_tab != 3) { |
|
2822
ff15d6f947ed
(svn r3370) Improve alignment of text within total cargo tab of train view window
peter1138
parents:
2819
diff
changeset
|
971 |
x = 1; |
2952 | 972 |
for (;;) { |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
973 |
if (--sel < 0 && sel >= -w->vscroll.cap) { |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
974 |
int dx = 0; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
975 |
int px; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
976 |
int py; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
977 |
|
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
978 |
u = v; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
979 |
do { |
3844
bed426de30ea
(svn r4868) - Codechange: in the train detail window, don't call DrawTrainImage() for each row, as we already loop to find the vehicles to
peter1138
parents:
3785
diff
changeset
|
980 |
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
bed426de30ea
(svn r4868) - Codechange: in the train detail window, don't call DrawTrainImage() for each row, as we already loop to find the vehicles to
peter1138
parents:
3785
diff
changeset
|
981 |
DrawSprite(GetTrainImage(u, DIR_W) | pal, x + 14 + WagonLengthToPixels(dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
982 |
dx += u->u.rail.cached_veh_length; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
983 |
u = u->next; |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
984 |
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0); |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
985 |
|
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
986 |
px = x + WagonLengthToPixels(dx) + 2; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
987 |
py = y + 2; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
988 |
switch (det_tab) { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
989 |
default: NOT_REACHED(); |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
990 |
case 0: TrainDetailsCargoTab( v, px, py); break; |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
991 |
case 1: |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
992 |
// Only show name and value for the 'real' part |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
993 |
if (!IsArticulatedPart(v)) { |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
994 |
TrainDetailsInfoTab(v, px, py); |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
995 |
} |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
996 |
break; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
997 |
case 2: TrainDetailsCapacityTab(v, px, py); break; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
998 |
} |
0 | 999 |
y += 14; |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1000 |
|
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1001 |
v = u; |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1002 |
} else { |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1003 |
// Move to the next line |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1004 |
do { |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1005 |
v = v->next; |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
1006 |
} while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0); |
0 | 1007 |
} |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
1008 |
if (v == NULL) return; |
0 | 1009 |
} |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1010 |
} else { |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1011 |
// draw total cargo tab |
0 | 1012 |
DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0); |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1013 |
for (i = 0; i != NUM_CARGO; i++) { |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
1014 |
if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) { |
0 | 1015 |
y += 14; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
1016 |
SetDParam(0, i); // {CARGO} #1 |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
1017 |
SetDParam(1, act_cargo[i]); // {CARGO} #2 |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
1018 |
SetDParam(2, i); // {SHORTCARGO} #1 |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
1019 |
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 |
5163
83acad83bbdd
(svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents:
5124
diff
changeset
|
1020 |
SetDParam(4, _patches.freight_trains); |
5316
b04421921eae
(svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents:
5273
diff
changeset
|
1021 |
DrawString(x, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_013F_TOTAL_CAPACITY, 0); |
0 | 1022 |
} |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1023 |
} |
0 | 1024 |
} |
1025 |
} |
|
1026 |
||
1027 |
static void TrainDetailsWndProc(Window *w, WindowEvent *e) |
|
1028 |
{ |
|
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1029 |
switch (e->event) { |
0 | 1030 |
case WE_PAINT: |
1031 |
DrawTrainDetailsWindow(w); |
|
1032 |
break; |
|
1033 |
case WE_CLICK: { |
|
1034 |
int mod; |
|
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1035 |
const Vehicle *v; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
1036 |
switch (e->we.click.widget) { |
0 | 1037 |
case 2: /* name train */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1038 |
v = GetVehicle(w->window_number); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1039 |
SetDParam(0, v->unitnumber); |
4299
b86602eaaff1
(svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents:
4293
diff
changeset
|
1040 |
ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL); |
0 | 1041 |
break; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
1042 |
case 6: /* inc serv interval */ |
156
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
1043 |
mod = _ctrl_pressed? 5 : 10; |
0 | 1044 |
goto do_change_service_int; |
1045 |
||
1046 |
case 7: /* dec serv interval */ |
|
156
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
1047 |
mod = _ctrl_pressed? -5 : -10; |
0 | 1048 |
do_change_service_int: |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1049 |
v = GetVehicle(w->window_number); |
156
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
1050 |
|
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1051 |
mod = GetServiceIntervalClamped(mod + v->service_interval); |
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1052 |
if (mod == v->service_interval) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1053 |
|
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2806
diff
changeset
|
1054 |
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); |
0 | 1055 |
break; |
1056 |
/* details buttons*/ |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
1057 |
case 9: // Cargo |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
1058 |
case 10: // Information |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
1059 |
case 11: // Capacities |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
1060 |
case 12: // Total cargo |
4709
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
1061 |
EnableWindowWidget(w, 9); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
1062 |
EnableWindowWidget(w, 10); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
1063 |
EnableWindowWidget(w, 11); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
1064 |
EnableWindowWidget(w, 12); |
eff35edfb653
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
1065 |
EnableWindowWidget(w, e->we.click.widget); |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
1066 |
WP(w,traindetails_d).tab = e->we.click.widget - 9; |
0 | 1067 |
SetWindowDirty(w); |
1068 |
break; |
|
1069 |
} |
|
1070 |
} break; |
|
1071 |
||
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2520
diff
changeset
|
1072 |
case WE_ON_EDIT_TEXT: |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
1073 |
if (e->we.edittext.str[0] != '\0') { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
1074 |
_cmd_text = e->we.edittext.str; |
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1075 |
DoCommandP(0, w->window_number, 0, NULL, |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1076 |
CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN)); |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1077 |
} |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2520
diff
changeset
|
1078 |
break; |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1079 |
|
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1080 |
case WE_RESIZE: |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
1081 |
if (e->we.sizing.diff.y == 0) break; |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1082 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
1083 |
w->vscroll.cap += e->we.sizing.diff.y / 14; |
4547
9786a24c4102
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4541
diff
changeset
|
1084 |
w->widget[4].data = (w->vscroll.cap << 8) + 1; |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1085 |
break; |
0 | 1086 |
} |
1087 |
} |
|
1088 |
||
1089 |
static const Widget _train_details_widgets[] = { |
|
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1090 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1091 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1092 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1093 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 55, 0x0, STR_NULL}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1094 |
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 357, 56, 139, 0x601, STR_NULL}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1095 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1096 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1097 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1098 |
{ WWT_PANEL, RESIZE_TB, 14, 11, 369, 140, 151, 0x0, STR_NULL}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1099 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 89, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1100 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 90, 178, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1101 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 179, 268, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1102 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 269, 357, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO}, |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1103 |
{ WWT_RESIZEBOX, RESIZE_TB, 14, 358, 369, 152, 163, 0x0, STR_RESIZE_BUTTON}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
1104 |
{ WIDGETS_END}, |
0 | 1105 |
}; |
1106 |
||
1107 |
||
1108 |
static const WindowDesc _train_details_desc = { |
|
5070
0bbf5264bfb7
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
1109 |
WDP_AUTO, WDP_AUTO, 370, 164, |
0 | 1110 |
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1111 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
0 | 1112 |
_train_details_widgets, |
1113 |
TrainDetailsWndProc |
|
1114 |
}; |
|
1115 |
||
1116 |
||
4171 | 1117 |
static void ShowTrainDetailsWindow(const Vehicle *v) |
0 | 1118 |
{ |
1119 |
Window *w; |
|
1120 |
VehicleID veh = v->index; |
|
1121 |
||
1122 |
DeleteWindowById(WC_VEHICLE_ORDERS, veh); |
|
1123 |
DeleteWindowById(WC_VEHICLE_DETAILS, veh); |
|
1124 |
||
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5070
diff
changeset
|
1125 |
w = AllocateWindowDescFront(&_train_details_desc, veh); |
0 | 1126 |
|
1127 |
w->caption_color = v->owner; |
|
1128 |
w->vscroll.cap = 6; |
|
4547
9786a24c4102
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4541
diff
changeset
|
1129 |
w->widget[4].data = (w->vscroll.cap << 8) + 1; |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1130 |
|
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1131 |
w->resize.step_height = 14; |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1132 |
w->resize.height = w->height - 14 * 2; /* Minimum of 4 wagons in the display */ |
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
1133 |
|
0 | 1134 |
WP(w,traindetails_d).tab = 0; |
1135 |
} |