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