|
1 /* $Id$ */ |
|
2 |
|
3 #include "stdafx.h" |
|
4 #include "openttd.h" |
|
5 #include "table/strings.h" |
|
6 #include "table/sprites.h" |
|
7 #include "functions.h" |
|
8 #include "window.h" |
|
9 #include "gui.h" |
|
10 #include "viewport.h" |
|
11 #include "gfx.h" |
|
12 #include "engine.h" |
|
13 #include "command.h" |
|
14 #include "news.h" |
|
15 #include "variables.h" |
|
16 #include "newgrf_engine.h" |
|
17 |
|
18 |
|
19 static StringID GetEngineCategoryName(EngineID engine) |
|
20 { |
|
21 if (engine < NUM_TRAIN_ENGINES) { |
|
22 switch (GetEngine(engine)->railtype) { |
|
23 case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE; |
|
24 case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE; |
|
25 case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE; |
|
26 case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE; |
|
27 } |
|
28 } |
|
29 |
|
30 if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) |
|
31 return STR_8103_ROAD_VEHICLE; |
|
32 |
|
33 if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) |
|
34 return STR_8105_SHIP; |
|
35 |
|
36 return STR_8104_AIRCRAFT; |
|
37 } |
|
38 |
|
39 static const Widget _engine_preview_widgets[] = { |
|
40 { WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
41 { WWT_CAPTION, RESIZE_NONE, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
42 { WWT_PANEL, RESIZE_NONE, 5, 0, 299, 14, 191, 0x0, STR_NULL}, |
|
43 { WWT_PUSHTXTBTN, RESIZE_NONE, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL}, |
|
44 { WWT_PUSHTXTBTN, RESIZE_NONE, 5, 155, 214, 172, 183, STR_00C8_YES, STR_NULL}, |
|
45 { WIDGETS_END}, |
|
46 }; |
|
47 |
|
48 typedef void DrawEngineProc(int x, int y, EngineID engine, uint32 image_ormod); |
|
49 typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw); |
|
50 |
|
51 typedef struct DrawEngineInfo { |
|
52 DrawEngineProc *engine_proc; |
|
53 DrawEngineInfoProc *info_proc; |
|
54 } DrawEngineInfo; |
|
55 |
|
56 static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw); |
|
57 static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw); |
|
58 static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw); |
|
59 static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw); |
|
60 |
|
61 static const DrawEngineInfo _draw_engine_list[4] = { |
|
62 {DrawTrainEngine,DrawTrainEngineInfo}, |
|
63 {DrawRoadVehEngine,DrawRoadVehEngineInfo}, |
|
64 {DrawShipEngine,DrawShipEngineInfo}, |
|
65 {DrawAircraftEngine,DrawAircraftEngineInfo}, |
|
66 }; |
|
67 |
|
68 static void EnginePreviewWndProc(Window *w, WindowEvent *e) |
|
69 { |
|
70 switch (e->event) { |
|
71 case WE_PAINT: { |
|
72 EngineID engine = w->window_number; |
|
73 const DrawEngineInfo* dei; |
|
74 int width; |
|
75 |
|
76 DrawWindowWidgets(w); |
|
77 |
|
78 SetDParam(0, GetEngineCategoryName(engine)); |
|
79 DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296); |
|
80 |
|
81 DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10); |
|
82 |
|
83 (dei = _draw_engine_list,engine < NUM_TRAIN_ENGINES) || |
|
84 (dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) || |
|
85 (dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) || |
|
86 (dei++, true); |
|
87 |
|
88 width = w->width; |
|
89 dei->engine_proc(width >> 1, 100, engine, 0); |
|
90 dei->info_proc(engine, width >> 1, 130, width - 52); |
|
91 break; |
|
92 } |
|
93 |
|
94 case WE_CLICK: |
|
95 switch (e->we.click.widget) { |
|
96 case 4: |
|
97 DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW); |
|
98 /* Fallthrough */ |
|
99 case 3: |
|
100 DeleteWindow(w); |
|
101 break; |
|
102 } |
|
103 break; |
|
104 } |
|
105 } |
|
106 |
|
107 static const WindowDesc _engine_preview_desc = { |
|
108 WDP_CENTER, WDP_CENTER, 300, 192, |
|
109 WC_ENGINE_PREVIEW,0, |
|
110 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
111 _engine_preview_widgets, |
|
112 EnginePreviewWndProc |
|
113 }; |
|
114 |
|
115 |
|
116 void ShowEnginePreviewWindow(EngineID engine) |
|
117 { |
|
118 AllocateWindowDescFront(&_engine_preview_desc, engine); |
|
119 } |
|
120 |
|
121 static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw) |
|
122 { |
|
123 const RailVehicleInfo *rvi = RailVehInfo(engine); |
|
124 uint multihead = (rvi->flags & RVI_MULTIHEAD) ? 1 : 0; |
|
125 |
|
126 SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5); |
|
127 SetDParam(2, rvi->max_speed); |
|
128 SetDParam(3, rvi->power << multihead); |
|
129 SetDParam(1, rvi->weight << multihead); |
|
130 |
|
131 SetDParam(4, rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8 << multihead); |
|
132 |
|
133 if (rvi->capacity != 0) { |
|
134 SetDParam(5, rvi->cargo_type); |
|
135 SetDParam(6, rvi->capacity << multihead); |
|
136 } else { |
|
137 SetDParam(5, CT_INVALID); |
|
138 } |
|
139 DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw); |
|
140 } |
|
141 |
|
142 void DrawNewsNewTrainAvail(Window *w) |
|
143 { |
|
144 EngineID engine; |
|
145 |
|
146 DrawNewsBorder(w); |
|
147 |
|
148 engine = WP(w,news_d).ni->string_id; |
|
149 SetDParam(0, GetEngineCategoryName(engine)); |
|
150 DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2); |
|
151 |
|
152 GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
153 |
|
154 SetDParam(0, GetCustomEngineName(engine)); |
|
155 DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2); |
|
156 |
|
157 DrawTrainEngine(w->width >> 1, 88, engine, 0); |
|
158 GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE); |
|
159 DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52); |
|
160 } |
|
161 |
|
162 StringID GetNewsStringNewTrainAvail(const NewsItem *ni) |
|
163 { |
|
164 EngineID engine = ni->string_id; |
|
165 SetDParam(0, STR_8859_NEW_NOW_AVAILABLE); |
|
166 SetDParam(1, GetEngineCategoryName(engine)); |
|
167 SetDParam(2, GetCustomEngineName(engine)); |
|
168 return STR_02B6; |
|
169 } |
|
170 |
|
171 static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw) |
|
172 { |
|
173 const AircraftVehicleInfo *avi = AircraftVehInfo(engine); |
|
174 SetDParam(0, (_price.aircraft_base >> 3) * avi->base_cost >> 5); |
|
175 SetDParam(1, avi->max_speed * 128 / 10); |
|
176 SetDParam(2, avi->passenger_capacity); |
|
177 SetDParam(3, avi->mail_capacity); |
|
178 SetDParam(4, avi->running_cost * _price.aircraft_running >> 8); |
|
179 |
|
180 DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw); |
|
181 } |
|
182 |
|
183 void DrawNewsNewAircraftAvail(Window *w) |
|
184 { |
|
185 EngineID engine; |
|
186 |
|
187 DrawNewsBorder(w); |
|
188 |
|
189 engine = WP(w,news_d).ni->string_id; |
|
190 |
|
191 DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2); |
|
192 GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
193 |
|
194 SetDParam(0, GetCustomEngineName(engine)); |
|
195 DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2); |
|
196 |
|
197 DrawAircraftEngine(w->width >> 1, 93, engine, 0); |
|
198 GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE); |
|
199 DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52); |
|
200 } |
|
201 |
|
202 StringID GetNewsStringNewAircraftAvail(const NewsItem *ni) |
|
203 { |
|
204 EngineID engine = ni->string_id; |
|
205 SetDParam(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE); |
|
206 SetDParam(1, GetCustomEngineName(engine)); |
|
207 return STR_02B6; |
|
208 } |
|
209 |
|
210 static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw) |
|
211 { |
|
212 const RoadVehicleInfo *rvi = RoadVehInfo(engine); |
|
213 |
|
214 SetDParam(0, (_price.roadveh_base >> 3) * rvi->base_cost >> 5); |
|
215 SetDParam(1, rvi->max_speed / 2); |
|
216 SetDParam(2, rvi->running_cost * _price.roadveh_running >> 8); |
|
217 SetDParam(3, rvi->cargo_type); |
|
218 SetDParam(4, rvi->capacity); |
|
219 |
|
220 DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw); |
|
221 } |
|
222 |
|
223 void DrawNewsNewRoadVehAvail(Window *w) |
|
224 { |
|
225 EngineID engine; |
|
226 |
|
227 DrawNewsBorder(w); |
|
228 |
|
229 engine = WP(w,news_d).ni->string_id; |
|
230 DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2); |
|
231 GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
232 |
|
233 SetDParam(0, GetCustomEngineName(engine)); |
|
234 DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2); |
|
235 |
|
236 DrawRoadVehEngine(w->width >> 1, 88, engine, 0); |
|
237 GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE); |
|
238 DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52); |
|
239 } |
|
240 |
|
241 StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni) |
|
242 { |
|
243 EngineID engine = ni->string_id; |
|
244 SetDParam(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE); |
|
245 SetDParam(1, GetCustomEngineName(engine)); |
|
246 return STR_02B6; |
|
247 } |
|
248 |
|
249 static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw) |
|
250 { |
|
251 const ShipVehicleInfo *svi = ShipVehInfo(engine); |
|
252 SetDParam(0, svi->base_cost * (_price.ship_base >> 3) >> 5); |
|
253 SetDParam(1, svi->max_speed / 2); |
|
254 SetDParam(2, svi->cargo_type); |
|
255 SetDParam(3, svi->capacity); |
|
256 SetDParam(4, svi->running_cost * _price.ship_running >> 8); |
|
257 DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw); |
|
258 } |
|
259 |
|
260 void DrawNewsNewShipAvail(Window *w) |
|
261 { |
|
262 EngineID engine; |
|
263 |
|
264 DrawNewsBorder(w); |
|
265 |
|
266 engine = WP(w,news_d).ni->string_id; |
|
267 |
|
268 DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2); |
|
269 GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); |
|
270 |
|
271 SetDParam(0, GetCustomEngineName(engine)); |
|
272 DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2); |
|
273 |
|
274 DrawShipEngine(w->width >> 1, 93, engine, 0); |
|
275 GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE); |
|
276 DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52); |
|
277 } |
|
278 |
|
279 StringID GetNewsStringNewShipAvail(const NewsItem *ni) |
|
280 { |
|
281 EngineID engine = ni->string_id; |
|
282 SetDParam(0, STR_982C_NEW_SHIP_NOW_AVAILABLE); |
|
283 SetDParam(1, GetCustomEngineName(engine)); |
|
284 return STR_02B6; |
|
285 } |