author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1095 | b59632d9df1b |
child 1891 | 862800791170 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
460
diff
changeset
|
3 |
#include "table/strings.h" |
0 | 4 |
#include "window.h" |
5 |
#include "gui.h" |
|
6 |
#include "viewport.h" |
|
7 |
#include "gfx.h" |
|
8 |
#include "engine.h" |
|
9 |
#include "command.h" |
|
10 |
#include "news.h" |
|
11 |
||
12 |
||
1095 | 13 |
static StringID GetEngineCategoryName(byte engine) |
0 | 14 |
{ |
460
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
15 |
if (engine < NUM_TRAIN_ENGINES) { |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
16 |
switch (_engines[engine].railtype) { |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
17 |
case 0: |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
18 |
return STR_8102_RAILROAD_LOCOMOTIVE; |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
19 |
case 1: |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
20 |
return STR_8106_MONORAIL_LOCOMOTIVE; |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
21 |
case 2: |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
22 |
return STR_8107_MAGLEV_LOCOMOTIVE; |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
23 |
} |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
193
diff
changeset
|
24 |
} |
0 | 25 |
|
26 |
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) |
|
27 |
return STR_8103_ROAD_VEHICLE; |
|
28 |
||
29 |
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) |
|
30 |
return STR_8105_SHIP; |
|
31 |
||
32 |
return STR_8104_AIRCRAFT; |
|
33 |
} |
|
34 |
||
35 |
static const Widget _engine_preview_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
36 |
{ WWT_TEXTBTN, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
37 |
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
38 |
{ WWT_IMGBTN, RESIZE_NONE, 5, 0, 299, 14, 191, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
39 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
40 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 155, 214, 172, 183, STR_00C8_YES, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
41 |
{ WIDGETS_END}, |
0 | 42 |
}; |
43 |
||
44 |
typedef void DrawEngineProc(int x, int y, int engine, uint32 image_ormod); |
|
45 |
typedef void DrawEngineInfoProc(int x, int y, int engine, int maxw); |
|
46 |
||
47 |
typedef struct DrawEngineInfo { |
|
48 |
DrawEngineProc *engine_proc; |
|
49 |
DrawEngineInfoProc *info_proc; |
|
50 |
} DrawEngineInfo; |
|
51 |
||
52 |
static const DrawEngineInfo _draw_engine_list[4] = { |
|
53 |
{DrawTrainEngine,DrawTrainEngineInfo}, |
|
54 |
{DrawRoadVehEngine,DrawRoadVehEngineInfo}, |
|
55 |
{DrawShipEngine,DrawShipEngineInfo}, |
|
56 |
{DrawAircraftEngine,DrawAircraftEngineInfo}, |
|
57 |
}; |
|
58 |
||
59 |
static void EnginePreviewWndProc(Window *w, WindowEvent *e) |
|
60 |
{ |
|
61 |
byte eng; |
|
62 |
int engine; |
|
63 |
const DrawEngineInfo *dei; |
|
64 |
int width; |
|
65 |
||
66 |
switch(e->event) { |
|
67 |
case WE_PAINT: |
|
68 |
DrawWindowWidgets(w); |
|
69 |
engine = w->window_number; |
|
70 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
71 |
SetDParam(0, GetEngineCategoryName(engine)); |
0 | 72 |
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296); |
73 |
||
74 |
DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10); |
|
75 |
||
76 |
eng = (byte)engine; |
|
77 |
(dei = _draw_engine_list,eng < NUM_TRAIN_ENGINES) || |
|
78 |
(dei++,eng < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) || |
|
79 |
(dei++,eng < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) || |
|
80 |
(dei++, true); |
|
81 |
||
82 |
width = w->width; |
|
83 |
dei->engine_proc(width >> 1, 100, engine, 0); |
|
84 |
dei->info_proc(engine, width >> 1, 130, width - 52); |
|
85 |
break; |
|
86 |
||
87 |
case WE_CLICK: |
|
88 |
switch(e->click.widget) { |
|
89 |
case 3: DeleteWindow(w); break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
90 |
case 4: |
0 | 91 |
DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW); |
92 |
DeleteWindow(w); |
|
93 |
break; |
|
94 |
} |
|
95 |
break; |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
static const WindowDesc _engine_preview_desc = { |
|
100 |
WDP_CENTER, WDP_CENTER, 300, 192, |
|
101 |
WC_ENGINE_PREVIEW,0, |
|
102 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
103 |
_engine_preview_widgets, |
|
104 |
EnginePreviewWndProc |
|
105 |
}; |
|
106 |
||
107 |
||
108 |
void ShowEnginePreviewWindow(int engine) |
|
109 |
{ |
|
110 |
Window *w; |
|
111 |
||
112 |
w = AllocateWindowDesc(&_engine_preview_desc); |
|
113 |
w->window_number = engine; |
|
114 |
} |
|
115 |
||
116 |
void DrawNewsNewTrainAvail(Window *w) |
|
117 |
{ |
|
118 |
int engine; |
|
119 |
||
120 |
DrawNewsBorder(w); |
|
121 |
||
122 |
engine = WP(w,news_d).ni->string_id; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
123 |
SetDParam(0, GetEngineCategoryName(engine)); |
0 | 124 |
DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2); |
125 |
||
126 |
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
127 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
128 |
SetDParam(0, GetCustomEngineName(engine)); |
0 | 129 |
DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2); |
130 |
||
131 |
DrawTrainEngine(w->width >> 1, 88, engine, 0); |
|
132 |
GfxFillRect(25, 56, w->width - 56, 112, 0x4323); |
|
133 |
DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52); |
|
134 |
} |
|
135 |
||
136 |
StringID GetNewsStringNewTrainAvail(NewsItem *ni) |
|
137 |
{ |
|
138 |
int engine = ni->string_id; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
139 |
SetDParam(0, STR_8859_NEW_NOW_AVAILABLE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
140 |
SetDParam(1, GetEngineCategoryName(engine)); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
141 |
SetDParam(2, GetCustomEngineName(engine)); |
0 | 142 |
return STR_02B6; |
143 |
} |
|
144 |
||
145 |
void DrawNewsNewAircraftAvail(Window *w) |
|
146 |
{ |
|
147 |
int engine; |
|
148 |
||
149 |
DrawNewsBorder(w); |
|
150 |
||
151 |
engine = WP(w,news_d).ni->string_id; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
152 |
|
0 | 153 |
DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2); |
154 |
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
155 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
156 |
SetDParam(0, GetCustomEngineName(engine)); |
0 | 157 |
DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2); |
158 |
||
159 |
DrawAircraftEngine(w->width >> 1, 93, engine, 0); |
|
160 |
GfxFillRect(25, 56, w->width - 56, 110, 0x4323); |
|
161 |
DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52); |
|
162 |
} |
|
163 |
||
164 |
StringID GetNewsStringNewAircraftAvail(NewsItem *ni) |
|
165 |
{ |
|
166 |
int engine = ni->string_id; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
167 |
SetDParam(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
168 |
SetDParam(1, GetCustomEngineName(engine)); |
0 | 169 |
return STR_02B6; |
170 |
} |
|
171 |
||
172 |
void DrawNewsNewRoadVehAvail(Window *w) |
|
173 |
{ |
|
174 |
int engine; |
|
175 |
||
176 |
DrawNewsBorder(w); |
|
177 |
||
178 |
engine = WP(w,news_d).ni->string_id; |
|
179 |
DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2); |
|
180 |
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
181 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
182 |
SetDParam(0, GetCustomEngineName(engine)); |
0 | 183 |
DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2); |
184 |
||
185 |
DrawRoadVehEngine(w->width >> 1, 88, engine, 0); |
|
186 |
GfxFillRect(25, 56, w->width - 56, 112, 0x4323); |
|
187 |
DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52); |
|
188 |
} |
|
189 |
||
190 |
StringID GetNewsStringNewRoadVehAvail(NewsItem *ni) |
|
191 |
{ |
|
192 |
int engine = ni->string_id; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
193 |
SetDParam(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
194 |
SetDParam(1, GetCustomEngineName(engine)); |
0 | 195 |
return STR_02B6; |
196 |
} |
|
197 |
||
198 |
void DrawNewsNewShipAvail(Window *w) |
|
199 |
{ |
|
200 |
int engine; |
|
201 |
||
202 |
DrawNewsBorder(w); |
|
203 |
||
204 |
engine = WP(w,news_d).ni->string_id; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
205 |
|
0 | 206 |
DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2); |
207 |
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
208 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
209 |
SetDParam(0, GetCustomEngineName(engine)); |
0 | 210 |
DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2); |
211 |
||
212 |
DrawShipEngine(w->width >> 1, 93, engine, 0); |
|
213 |
GfxFillRect(25, 56, w->width - 56, 110, 0x4323); |
|
214 |
DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52); |
|
215 |
} |
|
216 |
||
217 |
StringID GetNewsStringNewShipAvail(NewsItem *ni) |
|
218 |
{ |
|
219 |
int engine = ni->string_id; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
220 |
SetDParam(0, STR_982C_NEW_SHIP_NOW_AVAILABLE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
221 |
SetDParam(1, GetCustomEngineName(engine)); |
0 | 222 |
return STR_02B6; |
223 |
} |