0
|
1 |
#include "stdafx.h"
|
|
2 |
#include "ttd.h"
|
|
3 |
|
|
4 |
#include "window.h"
|
|
5 |
#include "gui.h"
|
|
6 |
#include "gfx.h"
|
|
7 |
#include "vehicle.h"
|
|
8 |
#include "viewport.h"
|
|
9 |
#include "station.h"
|
|
10 |
#include "command.h"
|
|
11 |
#include "player.h"
|
|
12 |
//#include "town.h"
|
|
13 |
#include "engine.h"
|
|
14 |
|
|
15 |
|
|
16 |
static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection);
|
|
17 |
|
|
18 |
|
|
19 |
const byte _ship_refit_types[4][16] = {
|
|
20 |
{CT_MAIL, CT_COAL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, CT_IRON_ORE, CT_STEEL, CT_VALUABLES, 255},
|
|
21 |
{CT_MAIL, CT_COAL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, CT_PAPER, CT_FOOD, CT_VALUABLES, 255},
|
|
22 |
{CT_MAIL, CT_FRUIT, CT_GOODS, CT_COPPER_ORE, CT_GRAIN, CT_WOOD, CT_WATER, CT_VALUABLES, 255},
|
|
23 |
{CT_MAIL, CT_SUGAR, CT_TOYS, CT_CANDY, CT_COLA, CT_COTTON_CANDY, CT_BUBBLES, CT_TOFFEE, CT_BATTERIES, CT_PLASTIC, CT_FIZZY_DRINKS, 255},
|
|
24 |
};
|
|
25 |
|
|
26 |
static void ShipRefitWndProc(Window *w, WindowEvent *e)
|
|
27 |
{
|
|
28 |
switch(e->event) {
|
|
29 |
case WE_PAINT: {
|
|
30 |
Vehicle *v = &_vehicles[w->window_number];
|
|
31 |
const byte *b;
|
|
32 |
int sel;
|
|
33 |
int x,y;
|
|
34 |
byte color;
|
|
35 |
int cargo;
|
|
36 |
|
|
37 |
SET_DPARAM16(0, v->string_id);
|
|
38 |
SET_DPARAM16(1, v->unitnumber);
|
|
39 |
DrawWindowWidgets(w);
|
|
40 |
|
|
41 |
DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0);
|
|
42 |
|
|
43 |
cargo = -1;
|
|
44 |
x = 6;
|
|
45 |
y = 25;
|
|
46 |
sel = WP(w,refit_d).sel;
|
|
47 |
|
|
48 |
#define show_cargo(ctype) { \
|
|
49 |
color = 16; \
|
|
50 |
if (sel == 0) { \
|
|
51 |
cargo = ctype; \
|
|
52 |
color = 12; \
|
|
53 |
} \
|
|
54 |
sel--; \
|
|
55 |
DrawString(x, y, _cargoc.names_s[ctype], color); \
|
|
56 |
y += 10; \
|
|
57 |
}
|
|
58 |
|
|
59 |
if (_engine_refit_masks[v->engine_type]) {
|
|
60 |
uint32 mask = _engine_refit_masks[v->engine_type];
|
|
61 |
int cid = 0;
|
|
62 |
|
|
63 |
for (; mask; mask >>= 1, cid++) {
|
|
64 |
if (!(mask & 1)) // not this cid
|
|
65 |
continue;
|
|
66 |
if (!(_local_cargo_id_landscape[cid] & (1 << _opt.landscape))) // not in this landscape
|
|
67 |
continue;
|
|
68 |
|
|
69 |
show_cargo(_local_cargo_id_ctype[cid]);
|
|
70 |
}
|
|
71 |
|
|
72 |
} else { // generic refit list
|
|
73 |
b = _ship_refit_types[_opt.landscape];
|
|
74 |
do {
|
|
75 |
show_cargo(*b);
|
|
76 |
} while (*++b != 255);
|
|
77 |
}
|
|
78 |
|
|
79 |
#undef show_cargo
|
|
80 |
|
|
81 |
WP(w,refit_d).cargo = cargo;
|
|
82 |
|
|
83 |
if (cargo != -1) {
|
|
84 |
int32 cost = DoCommandByTile(v->tile, v->index, cargo, 0, CMD_REFIT_SHIP);
|
|
85 |
if (cost != CMD_ERROR) {
|
|
86 |
SET_DPARAM32(2, cost);
|
|
87 |
SET_DPARAM16(0, _cargoc.names_long_p[cargo]);
|
|
88 |
SET_DPARAM16(1, v->cargo_cap);
|
|
89 |
DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0);
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
break;
|
|
94 |
}
|
|
95 |
|
|
96 |
case WE_CLICK:
|
|
97 |
switch(e->click.widget) {
|
|
98 |
case 2: { /* listbox */
|
|
99 |
int y = e->click.pt.y - 25;
|
|
100 |
if (y >= 0) {
|
|
101 |
WP(w,refit_d).sel = y / 10;
|
|
102 |
SetWindowDirty(w);
|
|
103 |
}
|
|
104 |
} break;
|
|
105 |
case 4: /* refit button */
|
|
106 |
if (WP(w,refit_d).cargo != 0xFF) {
|
|
107 |
Vehicle *v = &_vehicles[w->window_number];
|
|
108 |
if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP)))
|
|
109 |
DeleteWindow(w);
|
|
110 |
}
|
|
111 |
break;
|
|
112 |
}
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
static const Widget _ship_refit_widgets[] = {
|
|
119 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
120 |
{ WWT_CAPTION, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
121 |
{ WWT_IMGBTN, 14, 0, 239, 14, 135, 0x0, STR_983D_SELECT_TYPE_OF_CARGO_FOR},
|
|
122 |
{ WWT_IMGBTN, 14, 0, 239, 136, 157, 0x0},
|
|
123 |
{ WWT_PUSHTXTBTN, 14, 0, 239, 158, 169, STR_983C_REFIT_SHIP, STR_983E_REFIT_SHIP_TO_CARRY_HIGHLIGHTED},
|
|
124 |
{ WWT_LAST},
|
|
125 |
};
|
|
126 |
|
|
127 |
static const WindowDesc _ship_refit_desc = {
|
|
128 |
-1,-1, 240, 170,
|
|
129 |
WC_VEHICLE_REFIT,WC_VEHICLE_VIEW,
|
|
130 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
131 |
_ship_refit_widgets,
|
|
132 |
ShipRefitWndProc,
|
|
133 |
};
|
|
134 |
|
|
135 |
static void ShowShipRefitWindow(Vehicle *v)
|
|
136 |
{
|
|
137 |
Window *w;
|
|
138 |
|
|
139 |
DeleteWindowById(WC_VEHICLE_REFIT, v->index);
|
|
140 |
|
|
141 |
_alloc_wnd_parent_num = v->index;
|
|
142 |
w = AllocateWindowDesc(&_ship_refit_desc);
|
|
143 |
w->window_number = v->index;
|
|
144 |
w->caption_color = v->owner;
|
|
145 |
WP(w,refit_d).sel = -1;
|
|
146 |
}
|
|
147 |
|
|
148 |
static void ShipDetailsWndProc(Window *w, WindowEvent *e)
|
|
149 |
{
|
|
150 |
Vehicle *v = &_vehicles[w->window_number];
|
|
151 |
StringID str;
|
|
152 |
int mod;
|
|
153 |
|
|
154 |
switch(e->event) {
|
|
155 |
case WE_PAINT:
|
|
156 |
w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
|
|
157 |
SET_DPARAM16(0, v->string_id);
|
|
158 |
SET_DPARAM16(1, v->unitnumber);
|
|
159 |
DrawWindowWidgets(w);
|
|
160 |
|
|
161 |
/* Draw running cost */
|
|
162 |
{
|
|
163 |
int year = v->age / 366;
|
|
164 |
StringID str;
|
|
165 |
|
|
166 |
SET_DPARAM16(1, year);
|
|
167 |
|
|
168 |
str = STR_0199_YEAR;
|
|
169 |
if (year != 1) {
|
|
170 |
str++;
|
|
171 |
if (v->max_age - 366 < v->age)
|
|
172 |
str++;
|
|
173 |
}
|
|
174 |
SET_DPARAM16(0, str);
|
|
175 |
SET_DPARAM16(2, v->max_age / 366);
|
|
176 |
SET_DPARAM32(3, ship_vehicle_info(v->engine_type).running_cost * _price.ship_running >> 8);
|
|
177 |
DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0);
|
|
178 |
}
|
|
179 |
|
|
180 |
/* Draw max speed */
|
|
181 |
{
|
|
182 |
SET_DPARAM16(0, v->max_speed * 10 >> 5);
|
|
183 |
DrawString(2, 25, STR_9813_MAX_SPEED, 0);
|
|
184 |
}
|
|
185 |
|
|
186 |
/* Draw profit */
|
|
187 |
{
|
|
188 |
SET_DPARAM32(0, v->profit_this_year);
|
|
189 |
SET_DPARAM32(1, v->profit_last_year);
|
|
190 |
DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
|
191 |
}
|
|
192 |
|
|
193 |
/* Draw breakdown & reliability */
|
|
194 |
{
|
|
195 |
SET_DPARAM8(0, v->reliability * 100 >> 16);
|
|
196 |
SET_DPARAM16(1, v->breakdowns_since_last_service);
|
|
197 |
DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0);
|
|
198 |
}
|
|
199 |
|
|
200 |
/* Draw service interval text */
|
|
201 |
{
|
|
202 |
SET_DPARAM16(0, v->service_interval);
|
|
203 |
SET_DPARAM16(1, v->date_of_last_service);
|
|
204 |
DrawString(13, 90, STR_883C_SERVICING_INTERVAL_DAYS, 0);
|
|
205 |
}
|
|
206 |
|
|
207 |
DrawShipImage(v, 3, 57, INVALID_VEHICLE);
|
|
208 |
|
|
209 |
SET_DPARAM16(1, 1920 + v->build_year);
|
|
210 |
SET_DPARAM16(0, GetCustomEngineName(v->engine_type));
|
|
211 |
SET_DPARAM32(2, v->value);
|
|
212 |
DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
|
|
213 |
|
|
214 |
SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]);
|
|
215 |
SET_DPARAM16(1, v->cargo_cap);
|
|
216 |
DrawString(74, 67, STR_9817_CAPACITY, 0);
|
|
217 |
|
|
218 |
str = STR_8812_EMPTY;
|
|
219 |
if (v->cargo_count != 0) {
|
|
220 |
SET_DPARAM8(0, v->cargo_type);
|
|
221 |
SET_DPARAM16(1, v->cargo_count);
|
|
222 |
SET_DPARAM16(2, v->cargo_source);
|
|
223 |
str = STR_8813_FROM;
|
|
224 |
}
|
|
225 |
DrawString(74, 78, str, 0);
|
|
226 |
break;
|
|
227 |
|
|
228 |
case WE_CLICK:
|
|
229 |
switch(e->click.widget) {
|
|
230 |
case 2: /* rename */
|
|
231 |
SET_DPARAM16(0, v->unitnumber);
|
|
232 |
ShowQueryString(v->string_id, STR_9831_NAME_SHIP, 31, 150, w->window_class, w->window_number);
|
|
233 |
break;
|
|
234 |
case 5: /* increase int */
|
|
235 |
mod = 10;
|
|
236 |
goto change_int;
|
|
237 |
case 6: /* decrease int */
|
|
238 |
mod = -10;
|
|
239 |
change_int:
|
|
240 |
mod += v->service_interval;
|
|
241 |
if (!IS_INT_INSIDE(mod, 30, 800+1))
|
|
242 |
return;
|
|
243 |
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SHIP_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
|
|
244 |
break;
|
|
245 |
}
|
|
246 |
break;
|
|
247 |
|
|
248 |
case WE_4:
|
|
249 |
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)
|
|
250 |
DeleteWindow(w);
|
|
251 |
break;
|
|
252 |
|
|
253 |
case WE_ON_EDIT_TEXT: {
|
|
254 |
byte *b = e->edittext.str;
|
|
255 |
if (*b == 0)
|
|
256 |
return;
|
|
257 |
memcpy(_decode_parameters, b, 32);
|
|
258 |
DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP));
|
|
259 |
} break;
|
|
260 |
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
|
264 |
|
|
265 |
static const Widget _ship_details_widgets[] = {
|
|
266 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
267 |
{ WWT_CAPTION, 14, 11, 364, 0, 13, STR_9811_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
268 |
{ WWT_PUSHTXTBTN, 14, 365, 404, 0, 13, STR_01AA_NAME, STR_982F_NAME_SHIP},
|
|
269 |
{ WWT_IMGBTN, 14, 0, 404, 14, 55, 0x0},
|
|
270 |
{ WWT_IMGBTN, 14, 0, 404, 56, 88, 0x0},
|
|
271 |
{ WWT_PUSHTXTBTN, 14, 0, 10, 89, 94, STR_0188,STR_884D_INCREASE_SERVICING_INTERVAL},
|
|
272 |
{ WWT_PUSHTXTBTN, 14, 0, 10, 95, 100, STR_0189,STR_884E_DECREASE_SERVICING_INTERVAL},
|
|
273 |
{ WWT_IMGBTN, 14, 11, 404, 89, 100, 0x0},
|
|
274 |
{ WWT_LAST},
|
|
275 |
};
|
|
276 |
|
|
277 |
static const WindowDesc _ship_details_desc = {
|
|
278 |
-1,-1, 405, 101,
|
|
279 |
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
|
|
280 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
281 |
_ship_details_widgets,
|
|
282 |
ShipDetailsWndProc
|
|
283 |
};
|
|
284 |
|
|
285 |
static void ShowShipDetailsWindow(Vehicle *v)
|
|
286 |
{
|
|
287 |
Window *w;
|
|
288 |
VehicleID veh = v->index;
|
|
289 |
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
|
290 |
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
|
291 |
_alloc_wnd_parent_num = veh;
|
|
292 |
w = AllocateWindowDesc(&_ship_details_desc);
|
|
293 |
w->window_number = veh;
|
|
294 |
w->caption_color = v->owner;
|
|
295 |
}
|
|
296 |
|
|
297 |
static void CcBuildShip(bool success, uint tile, uint32 p1, uint32 p2)
|
|
298 |
{
|
|
299 |
Vehicle *v;
|
|
300 |
if (!success) return;
|
|
301 |
|
|
302 |
v = &_vehicles[_new_ship_id];
|
|
303 |
if (v->tile == _backup_orders_tile) {
|
|
304 |
_backup_orders_tile = 0;
|
|
305 |
RestoreVehicleOrders(v, _backup_orders_data);
|
|
306 |
}
|
|
307 |
ShowShipViewWindow(v);
|
|
308 |
}
|
|
309 |
|
|
310 |
static void NewShipWndProc(Window *w, WindowEvent *e)
|
|
311 |
{
|
|
312 |
YearMonthDay ymd;
|
|
313 |
switch(e->event) {
|
|
314 |
case WE_PAINT:
|
|
315 |
if (w->window_number == 0)
|
|
316 |
w->disabled_state = 1 << 5;
|
|
317 |
|
|
318 |
// Setup scroll count
|
|
319 |
{
|
|
320 |
int count = 0;
|
|
321 |
int num = NUM_SHIP_ENGINES;
|
|
322 |
Engine *e = &_engines[SHIP_ENGINES_INDEX];
|
|
323 |
do {
|
|
324 |
if (HASBIT(e->player_avail, _local_player))
|
|
325 |
count++;
|
|
326 |
} while (++e,--num);
|
|
327 |
SetVScrollCount(w, count);
|
|
328 |
}
|
|
329 |
|
|
330 |
DrawWindowWidgets(w);
|
|
331 |
|
|
332 |
{
|
|
333 |
int num = NUM_SHIP_ENGINES;
|
|
334 |
Engine *e = &_engines[SHIP_ENGINES_INDEX];
|
|
335 |
int x = 2;
|
|
336 |
int y = 15;
|
|
337 |
int sel = WP(w,buildtrain_d).sel_index;
|
|
338 |
int pos = w->vscroll.pos;
|
|
339 |
int engine_id = SHIP_ENGINES_INDEX;
|
|
340 |
int selected_id = -1;
|
|
341 |
|
|
342 |
do {
|
|
343 |
if (HASBIT(e->player_avail, _local_player)) {
|
|
344 |
if (sel==0) selected_id = engine_id;
|
|
345 |
if (IS_INT_INSIDE(--pos, -4, 0)) {
|
|
346 |
DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
|
|
347 |
DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
|
348 |
y += 24;
|
|
349 |
}
|
|
350 |
sel--;
|
|
351 |
}
|
|
352 |
} while (++engine_id, ++e,--num);
|
|
353 |
|
|
354 |
WP(w,buildtrain_d).sel_engine = selected_id;
|
|
355 |
|
|
356 |
if (selected_id != -1) {
|
|
357 |
Engine *e;
|
|
358 |
|
|
359 |
SET_DPARAM32(0, ship_vehicle_info(selected_id).base_cost * (_price.ship_base>>3)>>5);
|
|
360 |
SET_DPARAM16(1, ship_vehicle_info(selected_id).max_speed * 10 >> 5);
|
|
361 |
SET_DPARAM16(2, _cargoc.names_long_p[ship_vehicle_info(selected_id).cargo_type]);
|
|
362 |
SET_DPARAM16(3, ship_vehicle_info(selected_id).capacity);
|
|
363 |
SET_DPARAM16(4, ship_vehicle_info(selected_id).refittable ? STR_9842_REFITTABLE : STR_EMPTY);
|
|
364 |
SET_DPARAM32(5, ship_vehicle_info(selected_id).running_cost * _price.ship_running >> 8);
|
|
365 |
|
|
366 |
e = &_engines[selected_id];
|
|
367 |
SET_DPARAM16(7, e->lifelength);
|
|
368 |
SET_DPARAM8(8, e->reliability * 100 >> 16);
|
|
369 |
ConvertDayToYMD(&ymd, e->intro_date);
|
|
370 |
SET_DPARAM16(6, ymd.year + 1920);
|
|
371 |
|
|
372 |
DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0);
|
|
373 |
}
|
|
374 |
}
|
|
375 |
break;
|
|
376 |
|
|
377 |
case WE_CLICK:
|
|
378 |
switch(e->click.widget) {
|
|
379 |
case 2: { /* listbox */
|
|
380 |
uint i = (e->click.pt.y - 14) / 24;
|
|
381 |
if (i < 4) {
|
|
382 |
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
|
|
383 |
SetWindowDirty(w);
|
|
384 |
}
|
|
385 |
} break;
|
|
386 |
case 5: { /* build */
|
|
387 |
int sel_eng = WP(w,buildtrain_d).sel_engine;
|
|
388 |
if (sel_eng != -1)
|
|
389 |
DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
|
|
390 |
} break;
|
|
391 |
|
|
392 |
case 6: /* rename */
|
|
393 |
WP(w,buildtrain_d).rename_engine = WP(w,buildtrain_d).sel_engine;
|
|
394 |
ShowQueryString(
|
|
395 |
GetCustomEngineName(WP(w,buildtrain_d).sel_engine),
|
|
396 |
STR_9838_RENAME_SHIP_TYPE,
|
|
397 |
31,
|
|
398 |
160,
|
|
399 |
w->window_class,
|
|
400 |
w->window_number);
|
|
401 |
break;
|
|
402 |
|
|
403 |
}
|
|
404 |
break;
|
|
405 |
|
|
406 |
case WE_4:
|
|
407 |
if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
|
|
408 |
DeleteWindow(w);
|
|
409 |
}
|
|
410 |
break;
|
|
411 |
|
|
412 |
case WE_ON_EDIT_TEXT: {
|
|
413 |
byte *b = e->edittext.str;
|
|
414 |
if (*b == 0)
|
|
415 |
return;
|
|
416 |
memcpy(_decode_parameters, b, 32);
|
|
417 |
DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_9839_CAN_T_RENAME_SHIP_TYPE));
|
|
418 |
} break;
|
|
419 |
|
|
420 |
}
|
|
421 |
}
|
|
422 |
|
|
423 |
static const Widget _new_ship_widgets[] = {
|
|
424 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
425 |
{ WWT_CAPTION, 14, 11, 254, 0, 13, STR_9808_NEW_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
426 |
{ WWT_MATRIX, 14, 0, 243, 14, 109, 0x401, STR_9825_SHIP_SELECTION_LIST_CLICK},
|
|
427 |
{ WWT_SCROLLBAR, 14, 244, 254, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
428 |
{ WWT_IMGBTN, 14, 0, 254, 110, 161, 0x0},
|
|
429 |
{ WWT_PUSHTXTBTN, 14, 0, 126, 162, 173, STR_9809_BUILD_SHIP, STR_9826_BUILD_THE_HIGHLIGHTED_SHIP},
|
|
430 |
{ WWT_PUSHTXTBTN, 14, 127, 254, 162, 173, STR_9836_RENAME, STR_9837_RENAME_SHIP_TYPE},
|
|
431 |
{ WWT_LAST},
|
|
432 |
};
|
|
433 |
|
|
434 |
static const WindowDesc _new_ship_desc = {
|
|
435 |
-1, -1, 255, 174,
|
|
436 |
WC_BUILD_VEHICLE,0,
|
|
437 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
438 |
_new_ship_widgets,
|
|
439 |
NewShipWndProc
|
|
440 |
};
|
|
441 |
|
|
442 |
|
|
443 |
static void ShowBuildShipWindow(TileIndex tile)
|
|
444 |
{
|
|
445 |
Window *w;
|
|
446 |
|
|
447 |
DeleteWindowById(WC_BUILD_VEHICLE, tile);
|
|
448 |
|
|
449 |
w = AllocateWindowDesc(&_new_ship_desc);
|
|
450 |
w->window_number = tile;
|
|
451 |
w->vscroll.cap = 4;
|
|
452 |
|
|
453 |
if (tile != 0) {
|
|
454 |
w->caption_color = _map_owner[tile];
|
|
455 |
} else {
|
|
456 |
w->caption_color = _local_player;
|
|
457 |
}
|
|
458 |
|
|
459 |
}
|
|
460 |
|
|
461 |
|
|
462 |
static void ShipViewWndProc(Window *w, WindowEvent *e) {
|
|
463 |
switch(e->event) {
|
|
464 |
case WE_PAINT: {
|
|
465 |
Vehicle *v = &_vehicles[w->window_number];
|
|
466 |
uint32 disabled = 1<<7;
|
|
467 |
StringID str;
|
|
468 |
|
|
469 |
// Possible to refit?
|
|
470 |
if (ship_vehicle_info(v->engine_type).refittable &&
|
|
471 |
v->vehstatus&VS_STOPPED &&
|
|
472 |
v->u.ship.state == 0x80 &&
|
|
473 |
IsShipDepotTile(v->tile))
|
|
474 |
disabled = 0;
|
|
475 |
|
|
476 |
if (v->owner != _local_player)
|
|
477 |
disabled |= 1<<7 | 1<<6;
|
|
478 |
w->disabled_state = disabled;
|
|
479 |
|
|
480 |
/* draw widgets & caption */
|
|
481 |
SET_DPARAM16(0, v->string_id);
|
|
482 |
SET_DPARAM16(1, v->unitnumber);
|
|
483 |
DrawWindowWidgets(w);
|
|
484 |
|
|
485 |
/* draw the flag */
|
|
486 |
DrawSprite((v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, 2, 105);
|
|
487 |
|
|
488 |
if (v->breakdown_ctr == 1) {
|
|
489 |
str = STR_885C_BROKEN_DOWN;
|
|
490 |
} else if (v->vehstatus & VS_STOPPED) {
|
|
491 |
str = STR_8861_STOPPED;
|
|
492 |
} else {
|
|
493 |
switch(v->next_order & OT_MASK) {
|
|
494 |
case OT_GOTO_STATION: {
|
|
495 |
SET_DPARAM16(0, v->next_order_param);
|
|
496 |
SET_DPARAM16(1, v->cur_speed * 10 >> 5);
|
|
497 |
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
|
498 |
} break;
|
|
499 |
|
|
500 |
case OT_GOTO_DEPOT: {
|
|
501 |
Depot *dep = &_depots[v->next_order_param];
|
|
502 |
SET_DPARAM16(0, dep->town_index);
|
|
503 |
SET_DPARAM16(1, v->cur_speed * 10 >> 5);
|
|
504 |
str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed;
|
|
505 |
} break;
|
|
506 |
|
|
507 |
case OT_LOADING:
|
|
508 |
case OT_LEAVESTATION:
|
|
509 |
str = STR_882F_LOADING_UNLOADING;
|
|
510 |
break;
|
|
511 |
|
|
512 |
default:
|
|
513 |
if (v->num_orders == 0) {
|
|
514 |
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
|
515 |
SET_DPARAM16(0, v->cur_speed * 10 >> 5);
|
|
516 |
} else
|
|
517 |
str = STR_EMPTY;
|
|
518 |
break;
|
|
519 |
}
|
|
520 |
}
|
|
521 |
|
|
522 |
DrawStringCentered(125, 105, str, 0);
|
|
523 |
DrawWindowViewport(w);
|
|
524 |
} break;
|
|
525 |
|
|
526 |
case WE_CLICK: {
|
|
527 |
Vehicle *v = &_vehicles[w->window_number];
|
|
528 |
|
|
529 |
switch(e->click.widget) {
|
|
530 |
case 4: /* start stop */
|
|
531 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
|
|
532 |
break;
|
|
533 |
case 5: /* center main view */
|
|
534 |
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
535 |
break;
|
|
536 |
case 6: /* goto hangar */
|
|
537 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT));
|
|
538 |
break;
|
|
539 |
case 7: /* refit */
|
|
540 |
ShowShipRefitWindow(v);
|
|
541 |
break;
|
|
542 |
case 8: /* show orders */
|
|
543 |
ShowOrdersWindow(v);
|
|
544 |
break;
|
|
545 |
case 9: /* show details */
|
|
546 |
ShowShipDetailsWindow(v);
|
|
547 |
break;
|
|
548 |
}
|
|
549 |
} break;
|
|
550 |
|
|
551 |
case WE_DESTROY:
|
|
552 |
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
|
|
553 |
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
|
|
554 |
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
|
|
555 |
break;
|
|
556 |
}
|
|
557 |
}
|
|
558 |
|
|
559 |
static const Widget _ship_view_widgets[] = {
|
|
560 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
561 |
{ WWT_CAPTION, 14, 11, 249, 0, 13, STR_980F, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
562 |
{ WWT_IMGBTN, 14, 0, 231, 14, 103, 0x0},
|
|
563 |
{ WWT_6, 14, 2, 229, 16, 101, 0},
|
|
564 |
{ WWT_PUSHIMGBTN, 14, 0, 249, 104, 115, 0x0, STR_9827_CURRENT_SHIP_ACTION_CLICK},
|
|
565 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 14, 31, 0x2AB, STR_9829_CENTER_MAIN_VIEW_ON_SHIP},
|
|
566 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 32, 49, 0x2B0, STR_982A_SEND_SHIP_TO_DEPOT},
|
|
567 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 50, 67, 0x2B4, STR_983A_REFIT_CARGO_SHIP_TO_CARRY},
|
|
568 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 68, 85, 0x2B2, STR_9828_SHOW_SHIP_S_ORDERS},
|
|
569 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 86, 103, 0x2B3, STR_982B_SHOW_SHIP_DETAILS},
|
|
570 |
{ WWT_LAST},
|
|
571 |
};
|
|
572 |
|
|
573 |
static const WindowDesc _ship_view_desc = {
|
|
574 |
-1,-1, 250, 116,
|
|
575 |
WC_VEHICLE_VIEW,0,
|
|
576 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
577 |
_ship_view_widgets,
|
|
578 |
ShipViewWndProc
|
|
579 |
};
|
|
580 |
|
|
581 |
void ShowShipViewWindow(Vehicle *v)
|
|
582 |
{
|
|
583 |
Window *w;
|
|
584 |
|
|
585 |
w = AllocateWindowDescFront(&_ship_view_desc, v->index);
|
|
586 |
if (w) {
|
|
587 |
w->caption_color = v->owner;
|
|
588 |
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
|
|
589 |
}
|
|
590 |
}
|
|
591 |
|
|
592 |
|
|
593 |
static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection)
|
|
594 |
{
|
|
595 |
int image = GetShipImage(v, 6);
|
|
596 |
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
|
|
597 |
DrawSprite(image | ormod, x+32, y+10);
|
|
598 |
|
|
599 |
if (v->index == selection) {
|
|
600 |
DrawFrameRect(x-5, y-1, x+67, y+21, 15, 0x10);
|
|
601 |
}
|
|
602 |
}
|
|
603 |
|
|
604 |
static void DrawShipDepotWindow(Window *w)
|
|
605 |
{
|
|
606 |
uint tile;
|
|
607 |
Vehicle *v;
|
|
608 |
int num,x,y;
|
|
609 |
Depot *d;
|
|
610 |
|
|
611 |
tile = w->window_number;
|
|
612 |
|
|
613 |
/* setup disabled buttons */
|
|
614 |
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<3)|(1<<5));
|
|
615 |
|
|
616 |
/* determine amount of items for scroller */
|
|
617 |
num = 0;
|
|
618 |
FOR_ALL_VEHICLES(v) {
|
|
619 |
if (v->type == VEH_Ship && v->u.ship.state == 0x80 &&
|
|
620 |
v->tile == (TileIndex)tile)
|
|
621 |
num++;
|
|
622 |
}
|
|
623 |
SetVScrollCount(w, (num+2) / 3);
|
|
624 |
|
|
625 |
/* locate the depot struct */
|
|
626 |
for(d=_depots; d->xy != (TileIndex)tile; d++) {}
|
|
627 |
|
|
628 |
SET_DPARAM16(0, d->town_index);
|
|
629 |
DrawWindowWidgets(w);
|
|
630 |
|
|
631 |
x = 2;
|
|
632 |
y = 15;
|
|
633 |
num = w->vscroll.pos * 3;
|
|
634 |
|
|
635 |
FOR_ALL_VEHICLES(v) {
|
|
636 |
if (v->type == VEH_Ship &&
|
|
637 |
v->u.ship.state == 0x80 &&
|
|
638 |
v->tile == (TileIndex)tile &&
|
|
639 |
--num < 0 && num >= -6) {
|
|
640 |
|
|
641 |
DrawShipImage(v, x+19, y, WP(w,traindepot_d).sel);
|
|
642 |
|
|
643 |
SET_DPARAM16(0, v->unitnumber);
|
|
644 |
DrawString(x, y, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
|
|
645 |
|
|
646 |
DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x, y + 9);
|
|
647 |
|
|
648 |
if ((x+=90) == 2+90*3) {
|
|
649 |
x = 2;
|
|
650 |
y += 24;
|
|
651 |
}
|
|
652 |
}
|
|
653 |
}
|
|
654 |
}
|
|
655 |
|
|
656 |
static int GetVehicleFromShipDepotWndPt(Window *w, int x, int y, Vehicle **veh)
|
|
657 |
{
|
|
658 |
uint xt,yt,xm,ym;
|
|
659 |
TileIndex tile;
|
|
660 |
Vehicle *v;
|
|
661 |
int pos;
|
|
662 |
|
|
663 |
xt = x / 90;
|
|
664 |
xm = x % 90;
|
|
665 |
if (xt >= 5)
|
|
666 |
return 1;
|
|
667 |
|
|
668 |
yt = (y - 14) / 24;
|
|
669 |
ym = (y - 14) % 24;
|
|
670 |
if (yt >= 2)
|
|
671 |
return 1;
|
|
672 |
|
|
673 |
pos = (yt + w->vscroll.pos) * 3 + xt;
|
|
674 |
|
|
675 |
tile = w->window_number;
|
|
676 |
FOR_ALL_VEHICLES(v) {
|
|
677 |
if (v->type == VEH_Ship &&
|
|
678 |
v->vehstatus&VS_HIDDEN &&
|
|
679 |
v->tile == (TileIndex)tile &&
|
|
680 |
--pos < 0) {
|
|
681 |
*veh = v;
|
|
682 |
if (xm >= 19)
|
|
683 |
return 0;
|
|
684 |
if (ym <= 10)
|
|
685 |
return -1; /* show window */
|
|
686 |
return -2; /* start stop */
|
|
687 |
}
|
|
688 |
}
|
|
689 |
|
|
690 |
return 1; /* outside */
|
|
691 |
|
|
692 |
}
|
|
693 |
|
|
694 |
static void ShipDepotClick(Window *w, int x, int y)
|
|
695 |
{
|
|
696 |
Vehicle *v;
|
|
697 |
|
|
698 |
switch (GetVehicleFromShipDepotWndPt(w, x, y, &v)) {
|
|
699 |
case 1:
|
|
700 |
return;
|
|
701 |
|
|
702 |
case 0:
|
|
703 |
if (v != NULL) {
|
|
704 |
WP(w,traindepot_d).sel = v->index;
|
|
705 |
SetWindowDirty(w);
|
|
706 |
SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) +
|
|
707 |
GetShipImage(v, 6), 4, w);
|
|
708 |
}
|
|
709 |
break;
|
|
710 |
|
|
711 |
case -1:
|
|
712 |
ShowShipViewWindow(v);
|
|
713 |
break;
|
|
714 |
|
|
715 |
case -2:
|
|
716 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
|
|
717 |
break;
|
|
718 |
|
|
719 |
default:
|
|
720 |
NOT_REACHED();
|
|
721 |
}
|
|
722 |
}
|
|
723 |
|
|
724 |
static void ShipDepotWndProc(Window *w, WindowEvent *e) {
|
|
725 |
switch(e->event) {
|
|
726 |
case WE_PAINT:
|
|
727 |
DrawShipDepotWindow(w);
|
|
728 |
break;
|
|
729 |
|
|
730 |
case WE_CLICK:
|
|
731 |
switch(e->click.widget) {
|
|
732 |
case 2:
|
|
733 |
ShipDepotClick(w, e->click.pt.x, e->click.pt.y);
|
|
734 |
break;
|
|
735 |
|
|
736 |
case 5:
|
|
737 |
ShowBuildShipWindow(w->window_number);
|
|
738 |
break;
|
|
739 |
|
|
740 |
case 6: /* scroll to tile */
|
|
741 |
ScrollMainWindowToTile(w->window_number);
|
|
742 |
break;
|
|
743 |
}
|
|
744 |
break;
|
|
745 |
|
|
746 |
case WE_DESTROY:
|
|
747 |
DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
|
|
748 |
break;
|
|
749 |
|
|
750 |
case WE_DRAGDROP: {
|
|
751 |
switch(e->click.widget) {
|
|
752 |
case 2: {
|
|
753 |
Vehicle *v;
|
|
754 |
VehicleID sel = WP(w,traindepot_d).sel;
|
|
755 |
|
|
756 |
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
757 |
SetWindowDirty(w);
|
|
758 |
|
|
759 |
if (GetVehicleFromShipDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &v) == 0 &&
|
|
760 |
v != NULL &&
|
|
761 |
sel == v->index) {
|
|
762 |
ShowShipViewWindow(v);
|
|
763 |
}
|
|
764 |
} break;
|
|
765 |
|
|
766 |
case 3:
|
|
767 |
if (!HASBIT(w->disabled_state, 3) &&
|
|
768 |
WP(w,traindepot_d).sel != INVALID_VEHICLE) {
|
|
769 |
Vehicle *v;
|
|
770 |
|
|
771 |
HandleButtonClick(w, 3);
|
|
772 |
|
|
773 |
v = &_vehicles[WP(w,traindepot_d).sel];
|
|
774 |
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
775 |
|
|
776 |
_backup_orders_tile = v->tile;
|
|
777 |
BackupVehicleOrders(v, _backup_orders_data);
|
|
778 |
|
|
779 |
if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP)))
|
|
780 |
_backup_orders_tile = 0;
|
|
781 |
}
|
|
782 |
break;
|
|
783 |
default:
|
|
784 |
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
785 |
SetWindowDirty(w);
|
|
786 |
}
|
|
787 |
break;
|
|
788 |
}
|
|
789 |
break;
|
|
790 |
}
|
|
791 |
}
|
|
792 |
|
|
793 |
static const Widget _ship_depot_widgets[] = {
|
|
794 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
795 |
{ WWT_CAPTION, 14, 11, 304, 0, 13, STR_9803_SHIP_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
796 |
{ WWT_MATRIX, 14, 0, 269, 14, 61, 0x203, STR_981F_SHIPS_CLICK_ON_SHIP_FOR},
|
|
797 |
{ WWT_IMGBTN, 14, 270, 293, 14, 61, 0x2A9, STR_9821_DRAG_SHIP_TO_HERE_TO_SELL},
|
|
798 |
{ WWT_SCROLLBAR, 14, 294, 304, 14, 61, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
799 |
{ WWT_PUSHTXTBTN, 14, 0, 151, 62, 73, STR_9804_NEW_SHIPS, STR_9820_BUILD_NEW_SHIP},
|
|
800 |
{ WWT_PUSHTXTBTN, 14, 152, 304, 62, 73, STR_00E4_LOCATION, STR_9822_CENTER_MAIN_VIEW_ON_SHIP},
|
|
801 |
{ WWT_LAST},
|
|
802 |
};
|
|
803 |
|
|
804 |
static const WindowDesc _ship_depot_desc = {
|
|
805 |
-1, -1, 305, 74,
|
|
806 |
WC_VEHICLE_DEPOT,0,
|
|
807 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
808 |
_ship_depot_widgets,
|
|
809 |
ShipDepotWndProc
|
|
810 |
};
|
|
811 |
|
|
812 |
void ShowShipDepotWindow(uint tile)
|
|
813 |
{
|
|
814 |
Window *w;
|
|
815 |
|
|
816 |
w = AllocateWindowDescFront(&_ship_depot_desc,tile);
|
|
817 |
if (w) {
|
|
818 |
w->caption_color = _map_owner[w->window_number];
|
|
819 |
w->vscroll.cap = 2;
|
|
820 |
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
821 |
_backup_orders_tile = 0;
|
|
822 |
}
|
|
823 |
}
|
|
824 |
|
|
825 |
|
|
826 |
static void DrawSmallShipSchedule(Vehicle *v, int x, int y) {
|
|
827 |
uint16 *sched;
|
|
828 |
int sel;
|
|
829 |
uint ord;
|
|
830 |
Station *st;
|
|
831 |
int i = 0;
|
|
832 |
|
|
833 |
sched = v->schedule_ptr;
|
|
834 |
sel = v->cur_order_index;
|
|
835 |
|
|
836 |
while ((ord=*sched++) != 0) {
|
|
837 |
if (sel == 0) {
|
|
838 |
_stringwidth_base = 0xE0;
|
|
839 |
DoDrawString( "\xAF", x-6, y, 16);
|
|
840 |
_stringwidth_base = 0;
|
|
841 |
}
|
|
842 |
sel--;
|
|
843 |
|
|
844 |
if ((ord & OT_MASK) == OT_GOTO_STATION) {
|
|
845 |
st = DEREF_STATION(ord >> 8);
|
|
846 |
|
|
847 |
if (!(st->had_vehicle_of_type & HVOT_BUOY)) {
|
|
848 |
SET_DPARAM16(0, ord >> 8);
|
|
849 |
DrawString(x, y, STR_A036, 0);
|
|
850 |
|
|
851 |
y += 6;
|
|
852 |
if (++i == 4)
|
|
853 |
break;
|
|
854 |
}
|
|
855 |
}
|
|
856 |
}
|
|
857 |
}
|
|
858 |
|
|
859 |
static void PlayerShipsWndProc(Window *w, WindowEvent *e)
|
|
860 |
{
|
|
861 |
switch(e->event) {
|
|
862 |
case WE_PAINT:
|
|
863 |
/* determine amount of items for scroller */
|
|
864 |
{
|
|
865 |
Vehicle *v;
|
|
866 |
int num = 0;
|
|
867 |
byte owner = (byte)w->window_number;
|
|
868 |
|
|
869 |
FOR_ALL_VEHICLES(v) {
|
|
870 |
if (v->type == VEH_Ship && v->owner == owner)
|
|
871 |
num++;
|
|
872 |
}
|
|
873 |
SetVScrollCount(w, num);
|
|
874 |
}
|
|
875 |
|
|
876 |
/* draw the widgets */
|
|
877 |
{
|
|
878 |
Player *p = DEREF_PLAYER(w->window_number);
|
|
879 |
SET_DPARAM16(0, p->name_1);
|
|
880 |
SET_DPARAM32(1, p->name_2);
|
|
881 |
DrawWindowWidgets(w);
|
|
882 |
}
|
|
883 |
|
|
884 |
/* draw the ships vehicles */
|
|
885 |
{
|
|
886 |
Vehicle *v;
|
|
887 |
int pos = w->vscroll.pos;
|
|
888 |
byte owner = (byte)w->window_number;
|
|
889 |
int x = 2;
|
|
890 |
int y = 15;
|
|
891 |
|
|
892 |
FOR_ALL_VEHICLES(v) {
|
|
893 |
if (v->type == VEH_Ship && v->owner == owner &&
|
|
894 |
--pos < 0 && pos >= -4) {
|
|
895 |
StringID str;
|
|
896 |
|
|
897 |
DrawShipImage(v, x + 19, y + 6, INVALID_VEHICLE);
|
|
898 |
DrawVehicleProfitButton(v, x, y+13);
|
|
899 |
|
|
900 |
SET_DPARAM16(0, v->unitnumber);
|
|
901 |
if (IsShipDepotTile(v->tile)) {
|
|
902 |
str = STR_021F;
|
|
903 |
} else {
|
|
904 |
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
|
|
905 |
}
|
|
906 |
DrawString(x, y+2, str, 0);
|
|
907 |
|
|
908 |
SET_DPARAM32(0, v->profit_this_year);
|
|
909 |
SET_DPARAM32(1, v->profit_last_year);
|
|
910 |
DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
|
911 |
|
|
912 |
if (v->string_id != STR_SV_SHIP_NAME) {
|
|
913 |
SET_DPARAM16(0, v->string_id);
|
|
914 |
DrawString(x+12, y, STR_01AB, 0);
|
|
915 |
}
|
|
916 |
|
|
917 |
DrawSmallShipSchedule(v, x+138, y);
|
|
918 |
|
|
919 |
y += 36;
|
|
920 |
}
|
|
921 |
}
|
|
922 |
}
|
|
923 |
break;
|
|
924 |
case WE_CLICK:
|
|
925 |
switch(e->click.widget) {
|
|
926 |
case 2: { /* click ship */
|
|
927 |
int sel;
|
|
928 |
Vehicle *v;
|
|
929 |
byte owner;
|
|
930 |
|
|
931 |
sel = (e->click.pt.y - 14) / 36;
|
|
932 |
|
|
933 |
if ((uint)sel >= 4)
|
|
934 |
break;
|
|
935 |
sel += w->vscroll.pos;
|
|
936 |
owner = (byte)w->window_number;
|
|
937 |
FOR_ALL_VEHICLES(v) {
|
|
938 |
if (v->type == VEH_Ship && v->owner == owner && --sel < 0) {
|
|
939 |
ShowShipViewWindow(v);
|
|
940 |
break;
|
|
941 |
}
|
|
942 |
}
|
|
943 |
break;
|
|
944 |
}
|
|
945 |
case 4: {/* click buy */
|
|
946 |
uint tile;
|
|
947 |
|
|
948 |
tile = _last_built_ship_depot_tile;
|
|
949 |
do {
|
|
950 |
if (_map_owner[tile] == _local_player &&
|
|
951 |
IsShipDepotTile(tile)) {
|
|
952 |
|
|
953 |
ShowShipDepotWindow(tile);
|
|
954 |
ShowBuildShipWindow(tile);
|
|
955 |
return;
|
|
956 |
}
|
|
957 |
|
|
958 |
tile = TILE_MASK(tile + 1);
|
|
959 |
} while(tile != _last_built_ship_depot_tile);
|
|
960 |
|
|
961 |
ShowBuildShipWindow(0);
|
|
962 |
} break;
|
|
963 |
}
|
|
964 |
break;
|
|
965 |
}
|
|
966 |
}
|
|
967 |
|
|
968 |
static const Widget _player_ships_widgets[] = {
|
|
969 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
970 |
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
971 |
{ WWT_MATRIX, 14, 0, 248, 14, 157, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
|
|
972 |
{ WWT_SCROLLBAR, 14, 249, 259, 14, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
973 |
{ WWT_PUSHTXTBTN, 14, 0, 129, 158, 169, STR_9804_NEW_SHIPS, STR_9824_BUILD_NEW_SHIPS_REQUIRES},
|
|
974 |
{ WWT_IMGBTN, 14, 130, 259, 158, 169, 0x0},
|
|
975 |
{ WWT_LAST},
|
|
976 |
};
|
|
977 |
static const WindowDesc _player_ships_desc = {
|
|
978 |
-1, -1, 260, 170,
|
|
979 |
WC_SHIPS_LIST,0,
|
|
980 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
981 |
_player_ships_widgets,
|
|
982 |
PlayerShipsWndProc
|
|
983 |
};
|
|
984 |
|
|
985 |
static const Widget _other_player_ships_widgets[] = {
|
|
986 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
987 |
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
988 |
{ WWT_MATRIX, 14, 0, 248, 14, 157, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
|
|
989 |
{ WWT_SCROLLBAR, 14, 249, 259, 14, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
990 |
{ WWT_LAST},
|
|
991 |
};
|
|
992 |
static const WindowDesc _other_player_ships_desc = {
|
|
993 |
-1, -1, 260, 158,
|
|
994 |
WC_SHIPS_LIST,0,
|
|
995 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
996 |
_other_player_ships_widgets,
|
|
997 |
PlayerShipsWndProc
|
|
998 |
};
|
|
999 |
|
|
1000 |
|
|
1001 |
void ShowPlayerShips(int player)
|
|
1002 |
{
|
|
1003 |
Window *w;
|
|
1004 |
|
|
1005 |
if ( player == _local_player) {
|
|
1006 |
w = AllocateWindowDescFront(&_player_ships_desc, player);
|
|
1007 |
} else {
|
|
1008 |
w = AllocateWindowDescFront(&_other_player_ships_desc, player);
|
|
1009 |
}
|
|
1010 |
if (w) {
|
|
1011 |
w->caption_color = w->window_number;
|
|
1012 |
w->vscroll.cap = 4;
|
|
1013 |
}
|
|
1014 |
}
|