author | dominik |
Sun, 19 Dec 2004 22:23:32 +0000 | |
changeset 727 | f2737e7461ef |
parent 679 | 04ca2cd69420 |
child 755 | 80091de50044 |
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:
243
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
588
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "window.h" |
6 |
#include "gui.h" |
|
7 |
#include "gfx.h" |
|
8 |
#include "vehicle.h" |
|
9 |
#include "viewport.h" |
|
10 |
#include "station.h" |
|
11 |
#include "command.h" |
|
12 |
#include "player.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: { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
30 |
Vehicle *v = &_vehicles[w->window_number]; |
0 | 31 |
const byte *b; |
32 |
int sel; |
|
33 |
int x,y; |
|
34 |
byte color; |
|
35 |
int cargo; |
|
36 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
37 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
38 |
SetDParam(1, v->unitnumber); |
0 | 39 |
DrawWindowWidgets(w); |
40 |
||
41 |
DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
42 |
|
0 | 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) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
86 |
SetDParam(2, cost); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
87 |
SetDParam(0, _cargoc.names_long_p[cargo]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
88 |
SetDParam(1, v->cargo_cap); |
0 | 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) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
107 |
Vehicle *v = &_vehicles[w->window_number]; |
0 | 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[] = { |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
119 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
120 |
{ WWT_CAPTION, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
121 |
{ WWT_IMGBTN, 14, 0, 239, 14, 135, 0x0, STR_983D_SELECT_TYPE_OF_CARGO_FOR}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
122 |
{ WWT_IMGBTN, 14, 0, 239, 136, 157, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
123 |
{ WWT_PUSHTXTBTN, 14, 0, 239, 158, 169, STR_983C_REFIT_SHIP, STR_983E_REFIT_SHIP_TO_CARRY_HIGHLIGHTED}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
124 |
{ WIDGETS_END}, |
0 | 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); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
140 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
141 |
_alloc_wnd_parent_num = v->index; |
0 | 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); |
|
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:
10
diff
changeset
|
157 |
if (!_patches.servint_ships) // disable service-scroller when interval is set to disabled |
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:
10
diff
changeset
|
158 |
w->disabled_state |= (1 << 5) | (1 << 6); |
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:
10
diff
changeset
|
159 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
160 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
161 |
SetDParam(1, v->unitnumber); |
0 | 162 |
DrawWindowWidgets(w); |
163 |
||
164 |
/* Draw running cost */ |
|
165 |
{ |
|
166 |
int year = v->age / 366; |
|
167 |
StringID str; |
|
168 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
169 |
SetDParam(1, year); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
170 |
|
0 | 171 |
str = STR_0199_YEAR; |
172 |
if (year != 1) { |
|
173 |
str++; |
|
174 |
if (v->max_age - 366 < v->age) |
|
175 |
str++; |
|
176 |
} |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
177 |
SetDParam(0, str); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
178 |
SetDParam(2, v->max_age / 366); |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
179 |
SetDParam(3, ShipVehInfo(v->engine_type)->running_cost * _price.ship_running >> 8); |
0 | 180 |
DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0); |
181 |
} |
|
182 |
||
183 |
/* Draw max speed */ |
|
184 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
185 |
SetDParam(0, v->max_speed * 10 >> 5); |
0 | 186 |
DrawString(2, 25, STR_9813_MAX_SPEED, 0); |
187 |
} |
|
188 |
||
189 |
/* Draw profit */ |
|
190 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
191 |
SetDParam(0, v->profit_this_year); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
192 |
SetDParam(1, v->profit_last_year); |
0 | 193 |
DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
194 |
} |
|
195 |
||
196 |
/* Draw breakdown & reliability */ |
|
197 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
198 |
SetDParam(0, v->reliability * 100 >> 16); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
199 |
SetDParam(1, v->breakdowns_since_last_service); |
0 | 200 |
DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0); |
201 |
} |
|
202 |
||
203 |
/* Draw service interval text */ |
|
204 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
205 |
SetDParam(0, v->service_interval); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
206 |
SetDParam(1, v->date_of_last_service); |
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:
10
diff
changeset
|
207 |
DrawString(13, 90, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); |
0 | 208 |
} |
209 |
||
210 |
DrawShipImage(v, 3, 57, INVALID_VEHICLE); |
|
211 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
212 |
SetDParam(1, 1920 + v->build_year); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
213 |
SetDParam(0, GetCustomEngineName(v->engine_type)); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
214 |
SetDParam(2, v->value); |
0 | 215 |
DrawString(74, 57, STR_9816_BUILT_VALUE, 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
216 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
217 |
SetDParam(0, _cargoc.names_long_p[v->cargo_type]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
218 |
SetDParam(1, v->cargo_cap); |
0 | 219 |
DrawString(74, 67, STR_9817_CAPACITY, 0); |
220 |
||
221 |
str = STR_8812_EMPTY; |
|
222 |
if (v->cargo_count != 0) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
223 |
SetDParam(0, v->cargo_type); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
224 |
SetDParam(1, v->cargo_count); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
225 |
SetDParam(2, v->cargo_source); |
0 | 226 |
str = STR_8813_FROM; |
227 |
} |
|
228 |
DrawString(74, 78, str, 0); |
|
229 |
break; |
|
230 |
||
231 |
case WE_CLICK: |
|
232 |
switch(e->click.widget) { |
|
233 |
case 2: /* rename */ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
234 |
SetDParam(0, v->unitnumber); |
0 | 235 |
ShowQueryString(v->string_id, STR_9831_NAME_SHIP, 31, 150, w->window_class, w->window_number); |
236 |
break; |
|
237 |
case 5: /* increase int */ |
|
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:
10
diff
changeset
|
238 |
mod = _ctrl_pressed? 5 : 10; |
0 | 239 |
goto change_int; |
240 |
case 6: /* decrease int */ |
|
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:
10
diff
changeset
|
241 |
mod = _ctrl_pressed?- 5 : -10; |
0 | 242 |
change_int: |
243 |
mod += v->service_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:
10
diff
changeset
|
244 |
|
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:
10
diff
changeset
|
245 |
/* %-based service interval max 5%-90% |
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:
10
diff
changeset
|
246 |
day-based service interval max 30-800 days */ |
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:
10
diff
changeset
|
247 |
mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1); |
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:
10
diff
changeset
|
248 |
if (mod == v->service_interval) |
0 | 249 |
return; |
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:
10
diff
changeset
|
250 |
|
0 | 251 |
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SHIP_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); |
252 |
break; |
|
253 |
} |
|
254 |
break; |
|
255 |
||
256 |
case WE_4: |
|
257 |
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) |
|
258 |
DeleteWindow(w); |
|
259 |
break; |
|
260 |
||
261 |
case WE_ON_EDIT_TEXT: { |
|
262 |
byte *b = e->edittext.str; |
|
263 |
if (*b == 0) |
|
264 |
return; |
|
265 |
memcpy(_decode_parameters, b, 32); |
|
266 |
DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP)); |
|
267 |
} break; |
|
268 |
||
269 |
} |
|
270 |
} |
|
271 |
||
272 |
||
273 |
static const Widget _ship_details_widgets[] = { |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
274 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
0 | 275 |
{ WWT_CAPTION, 14, 11, 364, 0, 13, STR_9811_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
276 |
{ WWT_PUSHTXTBTN, 14, 365, 404, 0, 13, STR_01AA_NAME, STR_982F_NAME_SHIP}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
277 |
{ WWT_IMGBTN, 14, 0, 404, 14, 55, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
278 |
{ WWT_IMGBTN, 14, 0, 404, 56, 88, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
279 |
{ WWT_PUSHTXTBTN, 14, 0, 10, 89, 94, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
280 |
{ WWT_PUSHTXTBTN, 14, 0, 10, 95, 100, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
281 |
{ WWT_IMGBTN, 14, 11, 404, 89, 100, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
282 |
{ WIDGETS_END}, |
0 | 283 |
}; |
284 |
||
285 |
static const WindowDesc _ship_details_desc = { |
|
286 |
-1,-1, 405, 101, |
|
287 |
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, |
|
288 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
289 |
_ship_details_widgets, |
|
290 |
ShipDetailsWndProc |
|
291 |
}; |
|
292 |
||
293 |
static void ShowShipDetailsWindow(Vehicle *v) |
|
294 |
{ |
|
295 |
Window *w; |
|
296 |
VehicleID veh = v->index; |
|
297 |
DeleteWindowById(WC_VEHICLE_ORDERS, veh); |
|
298 |
DeleteWindowById(WC_VEHICLE_DETAILS, veh); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
299 |
_alloc_wnd_parent_num = veh; |
0 | 300 |
w = AllocateWindowDesc(&_ship_details_desc); |
301 |
w->window_number = veh; |
|
302 |
w->caption_color = v->owner; |
|
303 |
} |
|
304 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
538
diff
changeset
|
305 |
void CcBuildShip(bool success, uint tile, uint32 p1, uint32 p2) |
0 | 306 |
{ |
307 |
Vehicle *v; |
|
308 |
if (!success) return; |
|
309 |
||
310 |
v = &_vehicles[_new_ship_id]; |
|
311 |
if (v->tile == _backup_orders_tile) { |
|
312 |
_backup_orders_tile = 0; |
|
313 |
RestoreVehicleOrders(v, _backup_orders_data); |
|
314 |
} |
|
315 |
ShowShipViewWindow(v); |
|
316 |
} |
|
317 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
318 |
static void NewShipWndProc(Window *w, WindowEvent *e) |
0 | 319 |
{ |
320 |
YearMonthDay ymd; |
|
321 |
switch(e->event) { |
|
322 |
case WE_PAINT: |
|
323 |
if (w->window_number == 0) |
|
324 |
w->disabled_state = 1 << 5; |
|
325 |
||
326 |
// Setup scroll count |
|
327 |
{ |
|
328 |
int count = 0; |
|
329 |
int num = NUM_SHIP_ENGINES; |
|
330 |
Engine *e = &_engines[SHIP_ENGINES_INDEX]; |
|
331 |
do { |
|
332 |
if (HASBIT(e->player_avail, _local_player)) |
|
333 |
count++; |
|
334 |
} while (++e,--num); |
|
335 |
SetVScrollCount(w, count); |
|
336 |
} |
|
337 |
||
338 |
DrawWindowWidgets(w); |
|
339 |
||
340 |
{ |
|
341 |
int num = NUM_SHIP_ENGINES; |
|
342 |
Engine *e = &_engines[SHIP_ENGINES_INDEX]; |
|
343 |
int x = 2; |
|
344 |
int y = 15; |
|
345 |
int sel = WP(w,buildtrain_d).sel_index; |
|
346 |
int pos = w->vscroll.pos; |
|
347 |
int engine_id = SHIP_ENGINES_INDEX; |
|
348 |
int selected_id = -1; |
|
349 |
||
350 |
do { |
|
351 |
if (HASBIT(e->player_avail, _local_player)) { |
|
352 |
if (sel==0) selected_id = engine_id; |
|
353 |
if (IS_INT_INSIDE(--pos, -4, 0)) { |
|
354 |
DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10); |
|
355 |
DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
356 |
y += 24; |
|
357 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
358 |
sel--; |
0 | 359 |
} |
360 |
} while (++engine_id, ++e,--num); |
|
361 |
||
362 |
WP(w,buildtrain_d).sel_engine = selected_id; |
|
363 |
||
364 |
if (selected_id != -1) { |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
365 |
const ShipVehicleInfo *svi = ShipVehInfo(selected_id); |
0 | 366 |
Engine *e; |
367 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
368 |
SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
369 |
SetDParam(1, svi->max_speed * 10 >> 5); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
370 |
SetDParam(2, _cargoc.names_long_p[svi->cargo_type]); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
371 |
SetDParam(3, svi->capacity); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
372 |
SetDParam(4, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
373 |
SetDParam(5, svi->running_cost * _price.ship_running >> 8); |
0 | 374 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
375 |
e = &_engines[selected_id]; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
376 |
SetDParam(7, e->lifelength); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
377 |
SetDParam(8, e->reliability * 100 >> 16); |
0 | 378 |
ConvertDayToYMD(&ymd, e->intro_date); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
379 |
SetDParam(6, ymd.year + 1920); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
380 |
|
0 | 381 |
DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0); |
382 |
} |
|
383 |
} |
|
384 |
break; |
|
385 |
||
386 |
case WE_CLICK: |
|
387 |
switch(e->click.widget) { |
|
388 |
case 2: { /* listbox */ |
|
389 |
uint i = (e->click.pt.y - 14) / 24; |
|
390 |
if (i < 4) { |
|
391 |
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; |
|
392 |
SetWindowDirty(w); |
|
393 |
} |
|
394 |
} break; |
|
395 |
case 5: { /* build */ |
|
396 |
int sel_eng = WP(w,buildtrain_d).sel_engine; |
|
397 |
if (sel_eng != -1) |
|
398 |
DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)); |
|
399 |
} break; |
|
400 |
||
401 |
case 6: /* rename */ |
|
402 |
WP(w,buildtrain_d).rename_engine = WP(w,buildtrain_d).sel_engine; |
|
403 |
ShowQueryString( |
|
404 |
GetCustomEngineName(WP(w,buildtrain_d).sel_engine), |
|
405 |
STR_9838_RENAME_SHIP_TYPE, |
|
406 |
31, |
|
407 |
160, |
|
408 |
w->window_class, |
|
409 |
w->window_number); |
|
410 |
break; |
|
411 |
||
412 |
} |
|
413 |
break; |
|
414 |
||
415 |
case WE_4: |
|
416 |
if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) { |
|
417 |
DeleteWindow(w); |
|
418 |
} |
|
419 |
break; |
|
420 |
||
421 |
case WE_ON_EDIT_TEXT: { |
|
422 |
byte *b = e->edittext.str; |
|
423 |
if (*b == 0) |
|
424 |
return; |
|
425 |
memcpy(_decode_parameters, b, 32); |
|
426 |
DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_9839_CAN_T_RENAME_SHIP_TYPE)); |
|
427 |
} break; |
|
428 |
||
429 |
} |
|
430 |
} |
|
431 |
||
432 |
static const Widget _new_ship_widgets[] = { |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
433 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
434 |
{ WWT_CAPTION, 14, 11, 254, 0, 13, STR_9808_NEW_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
435 |
{ WWT_MATRIX, 14, 0, 243, 14, 109, 0x401, STR_9825_SHIP_SELECTION_LIST_CLICK}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
436 |
{ WWT_SCROLLBAR, 14, 244, 254, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
437 |
{ WWT_IMGBTN, 14, 0, 254, 110, 161, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
438 |
{ WWT_PUSHTXTBTN, 14, 0, 126, 162, 173, STR_9809_BUILD_SHIP, STR_9826_BUILD_THE_HIGHLIGHTED_SHIP}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
439 |
{ WWT_PUSHTXTBTN, 14, 127, 254, 162, 173, STR_9836_RENAME, STR_9837_RENAME_SHIP_TYPE}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
440 |
{ WIDGETS_END}, |
0 | 441 |
}; |
442 |
||
443 |
static const WindowDesc _new_ship_desc = { |
|
444 |
-1, -1, 255, 174, |
|
445 |
WC_BUILD_VEHICLE,0, |
|
446 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
447 |
_new_ship_widgets, |
|
448 |
NewShipWndProc |
|
449 |
}; |
|
450 |
||
451 |
||
452 |
static void ShowBuildShipWindow(TileIndex tile) |
|
453 |
{ |
|
454 |
Window *w; |
|
455 |
||
456 |
DeleteWindowById(WC_BUILD_VEHICLE, tile); |
|
457 |
||
458 |
w = AllocateWindowDesc(&_new_ship_desc); |
|
459 |
w->window_number = tile; |
|
460 |
w->vscroll.cap = 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
461 |
|
0 | 462 |
if (tile != 0) { |
463 |
w->caption_color = _map_owner[tile]; |
|
464 |
} else { |
|
465 |
w->caption_color = _local_player; |
|
466 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
467 |
|
0 | 468 |
} |
469 |
||
470 |
||
471 |
static void ShipViewWndProc(Window *w, WindowEvent *e) { |
|
472 |
switch(e->event) { |
|
473 |
case WE_PAINT: { |
|
474 |
Vehicle *v = &_vehicles[w->window_number]; |
|
475 |
uint32 disabled = 1<<7; |
|
476 |
StringID str; |
|
477 |
||
478 |
// Possible to refit? |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
479 |
if (ShipVehInfo(v->engine_type)->refittable && |
0 | 480 |
v->vehstatus&VS_STOPPED && |
481 |
v->u.ship.state == 0x80 && |
|
482 |
IsShipDepotTile(v->tile)) |
|
483 |
disabled = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
484 |
|
0 | 485 |
if (v->owner != _local_player) |
486 |
disabled |= 1<<7 | 1<<6; |
|
487 |
w->disabled_state = disabled; |
|
488 |
||
489 |
/* draw widgets & caption */ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
490 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
491 |
SetDParam(1, v->unitnumber); |
0 | 492 |
DrawWindowWidgets(w); |
493 |
||
494 |
/* draw the flag */ |
|
495 |
DrawSprite((v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, 2, 105); |
|
496 |
||
497 |
if (v->breakdown_ctr == 1) { |
|
498 |
str = STR_885C_BROKEN_DOWN; |
|
499 |
} else if (v->vehstatus & VS_STOPPED) { |
|
500 |
str = STR_8861_STOPPED; |
|
501 |
} else { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
502 |
switch (v->current_order.type) { |
0 | 503 |
case OT_GOTO_STATION: { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
504 |
SetDParam(0, v->current_order.station); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
505 |
SetDParam(1, v->cur_speed * 10 >> 5); |
0 | 506 |
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; |
507 |
} break; |
|
508 |
||
509 |
case OT_GOTO_DEPOT: { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
510 |
Depot *dep = &_depots[v->current_order.station]; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
511 |
SetDParam(0, dep->town_index); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
512 |
SetDParam(1, v->cur_speed * 10 >> 5); |
0 | 513 |
str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed; |
514 |
} break; |
|
515 |
||
516 |
case OT_LOADING: |
|
517 |
case OT_LEAVESTATION: |
|
518 |
str = STR_882F_LOADING_UNLOADING; |
|
519 |
break; |
|
520 |
||
521 |
default: |
|
522 |
if (v->num_orders == 0) { |
|
523 |
str = STR_NO_ORDERS + _patches.vehicle_speed; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
524 |
SetDParam(0, v->cur_speed * 10 >> 5); |
0 | 525 |
} else |
526 |
str = STR_EMPTY; |
|
527 |
break; |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
DrawStringCentered(125, 105, str, 0); |
|
532 |
DrawWindowViewport(w); |
|
533 |
} break; |
|
534 |
||
535 |
case WE_CLICK: { |
|
536 |
Vehicle *v = &_vehicles[w->window_number]; |
|
537 |
||
538 |
switch(e->click.widget) { |
|
539 |
case 4: /* start stop */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
540 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP)); |
0 | 541 |
break; |
542 |
case 5: /* center main view */ |
|
543 |
ScrollMainWindowTo(v->x_pos, v->y_pos); |
|
544 |
break; |
|
545 |
case 6: /* goto hangar */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
546 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT)); |
0 | 547 |
break; |
548 |
case 7: /* refit */ |
|
549 |
ShowShipRefitWindow(v); |
|
550 |
break; |
|
551 |
case 8: /* show orders */ |
|
552 |
ShowOrdersWindow(v); |
|
553 |
break; |
|
554 |
case 9: /* show details */ |
|
555 |
ShowShipDetailsWindow(v); |
|
556 |
break; |
|
557 |
} |
|
558 |
} break; |
|
559 |
||
560 |
case WE_DESTROY: |
|
561 |
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
562 |
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number); |
0 | 563 |
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); |
564 |
break; |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
static const Widget _ship_view_widgets[] = { |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
569 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
570 |
{ WWT_CAPTION, 14, 11, 249, 0, 13, STR_980F, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
571 |
{ WWT_IMGBTN, 14, 0, 231, 14, 103, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
572 |
{ WWT_6, 14, 2, 229, 16, 101, 0x0, STR_NULL}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
573 |
{ WWT_PUSHIMGBTN, 14, 0, 249, 104, 115, 0x0, STR_9827_CURRENT_SHIP_ACTION_CLICK}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
574 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 14, 31, 0x2AB, STR_9829_CENTER_MAIN_VIEW_ON_SHIP}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
575 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 32, 49, 0x2B0, STR_982A_SEND_SHIP_TO_DEPOT}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
576 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 50, 67, 0x2B4, STR_983A_REFIT_CARGO_SHIP_TO_CARRY}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
577 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 68, 85, 0x2B2, STR_9828_SHOW_SHIP_S_ORDERS}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
578 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 86, 103, 0x2B3, STR_982B_SHOW_SHIP_DETAILS}, |
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
579 |
{ WIDGETS_END}, |
0 | 580 |
}; |
581 |
||
582 |
static const WindowDesc _ship_view_desc = { |
|
583 |
-1,-1, 250, 116, |
|
584 |
WC_VEHICLE_VIEW,0, |
|
585 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
586 |
_ship_view_widgets, |
|
587 |
ShipViewWndProc |
|
588 |
}; |
|
589 |
||
590 |
void ShowShipViewWindow(Vehicle *v) |
|
591 |
{ |
|
592 |
Window *w; |
|
593 |
||
594 |
w = AllocateWindowDescFront(&_ship_view_desc, v->index); |
|
595 |
if (w) { |
|
596 |
w->caption_color = v->owner; |
|
597 |
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0); |
|
598 |
} |
|
599 |
} |
|
600 |
||
601 |
||
602 |
static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection) |
|
603 |
{ |
|
604 |
int image = GetShipImage(v, 6); |
|
605 |
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); |
|
606 |
DrawSprite(image | ormod, x+32, y+10); |
|
607 |
||
608 |
if (v->index == selection) { |
|
609 |
DrawFrameRect(x-5, y-1, x+67, y+21, 15, 0x10); |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
static void DrawShipDepotWindow(Window *w) |
|
614 |
{ |
|
615 |
uint tile; |
|
616 |
Vehicle *v; |
|
617 |
int num,x,y; |
|
618 |
Depot *d; |
|
619 |
||
620 |
tile = w->window_number; |
|
621 |
||
622 |
/* setup disabled buttons */ |
|
623 |
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<3)|(1<<5)); |
|
624 |
||
625 |
/* determine amount of items for scroller */ |
|
626 |
num = 0; |
|
627 |
FOR_ALL_VEHICLES(v) { |
|
628 |
if (v->type == VEH_Ship && v->u.ship.state == 0x80 && |
|
629 |
v->tile == (TileIndex)tile) |
|
630 |
num++; |
|
631 |
} |
|
632 |
SetVScrollCount(w, (num+2) / 3); |
|
633 |
||
634 |
/* locate the depot struct */ |
|
635 |
for(d=_depots; d->xy != (TileIndex)tile; d++) {} |
|
636 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
637 |
SetDParam(0, d->town_index); |
0 | 638 |
DrawWindowWidgets(w); |
639 |
||
640 |
x = 2; |
|
641 |
y = 15; |
|
642 |
num = w->vscroll.pos * 3; |
|
643 |
||
644 |
FOR_ALL_VEHICLES(v) { |
|
645 |
if (v->type == VEH_Ship && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
646 |
v->u.ship.state == 0x80 && |
0 | 647 |
v->tile == (TileIndex)tile && |
648 |
--num < 0 && num >= -6) { |
|
649 |
||
650 |
DrawShipImage(v, x+19, y, WP(w,traindepot_d).sel); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
651 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
652 |
SetDParam(0, v->unitnumber); |
0 | 653 |
DrawString(x, y, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0); |
654 |
||
655 |
DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x, y + 9); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
656 |
|
0 | 657 |
if ((x+=90) == 2+90*3) { |
658 |
x = 2; |
|
659 |
y += 24; |
|
660 |
} |
|
661 |
} |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
static int GetVehicleFromShipDepotWndPt(Window *w, int x, int y, Vehicle **veh) |
|
666 |
{ |
|
667 |
uint xt,yt,xm,ym; |
|
668 |
TileIndex tile; |
|
669 |
Vehicle *v; |
|
670 |
int pos; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
671 |
|
0 | 672 |
xt = x / 90; |
673 |
xm = x % 90; |
|
674 |
if (xt >= 5) |
|
675 |
return 1; |
|
676 |
||
677 |
yt = (y - 14) / 24; |
|
678 |
ym = (y - 14) % 24; |
|
679 |
if (yt >= 2) |
|
680 |
return 1; |
|
681 |
||
682 |
pos = (yt + w->vscroll.pos) * 3 + xt; |
|
683 |
||
684 |
tile = w->window_number; |
|
685 |
FOR_ALL_VEHICLES(v) { |
|
686 |
if (v->type == VEH_Ship && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
687 |
v->vehstatus&VS_HIDDEN && |
0 | 688 |
v->tile == (TileIndex)tile && |
689 |
--pos < 0) { |
|
690 |
*veh = v; |
|
691 |
if (xm >= 19) |
|
692 |
return 0; |
|
693 |
if (ym <= 10) |
|
694 |
return -1; /* show window */ |
|
695 |
return -2; /* start stop */ |
|
696 |
} |
|
697 |
} |
|
698 |
||
699 |
return 1; /* outside */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
700 |
|
0 | 701 |
} |
702 |
||
703 |
static void ShipDepotClick(Window *w, int x, int y) |
|
704 |
{ |
|
705 |
Vehicle *v; |
|
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
706 |
int mode = GetVehicleFromShipDepotWndPt(w, x, y, &v); |
0 | 707 |
|
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
708 |
// share / copy orders |
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
709 |
if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = v; return; } |
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
710 |
|
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
711 |
switch (mode) { |
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
712 |
case 1: // invalid |
0 | 713 |
return; |
714 |
||
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
715 |
case 0: // start dragging of vehicle |
0 | 716 |
if (v != NULL) { |
717 |
WP(w,traindepot_d).sel = v->index; |
|
718 |
SetWindowDirty(w); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
719 |
SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + |
0 | 720 |
GetShipImage(v, 6), 4, w); |
721 |
} |
|
722 |
break; |
|
723 |
||
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
724 |
case -1: // show info window |
0 | 725 |
ShowShipViewWindow(v); |
726 |
break; |
|
727 |
||
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
728 |
case -2: // click start/stop flag |
0 | 729 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP)); |
730 |
break; |
|
731 |
||
732 |
default: |
|
733 |
NOT_REACHED(); |
|
734 |
} |
|
735 |
} |
|
736 |
||
737 |
static void ShipDepotWndProc(Window *w, WindowEvent *e) { |
|
738 |
switch(e->event) { |
|
739 |
case WE_PAINT: |
|
740 |
DrawShipDepotWindow(w); |
|
741 |
break; |
|
742 |
||
743 |
case WE_CLICK: |
|
744 |
switch(e->click.widget) { |
|
745 |
case 2: |
|
746 |
ShipDepotClick(w, e->click.pt.x, e->click.pt.y); |
|
747 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
748 |
|
0 | 749 |
case 5: |
750 |
ShowBuildShipWindow(w->window_number); |
|
751 |
break; |
|
752 |
||
753 |
case 6: /* scroll to tile */ |
|
754 |
ScrollMainWindowToTile(w->window_number); |
|
755 |
break; |
|
756 |
} |
|
757 |
break; |
|
758 |
||
759 |
case WE_DESTROY: |
|
760 |
DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); |
|
761 |
break; |
|
762 |
||
763 |
case WE_DRAGDROP: { |
|
764 |
switch(e->click.widget) { |
|
765 |
case 2: { |
|
766 |
Vehicle *v; |
|
767 |
VehicleID sel = WP(w,traindepot_d).sel; |
|
768 |
||
769 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
770 |
SetWindowDirty(w); |
|
771 |
||
772 |
if (GetVehicleFromShipDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &v) == 0 && |
|
773 |
v != NULL && |
|
774 |
sel == v->index) { |
|
775 |
ShowShipViewWindow(v); |
|
776 |
} |
|
777 |
} break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
778 |
|
0 | 779 |
case 3: |
780 |
if (!HASBIT(w->disabled_state, 3) && |
|
781 |
WP(w,traindepot_d).sel != INVALID_VEHICLE) { |
|
782 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
783 |
|
0 | 784 |
HandleButtonClick(w, 3); |
785 |
||
786 |
v = &_vehicles[WP(w,traindepot_d).sel]; |
|
787 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
788 |
||
789 |
_backup_orders_tile = v->tile; |
|
790 |
BackupVehicleOrders(v, _backup_orders_data); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
791 |
|
0 | 792 |
if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP))) |
793 |
_backup_orders_tile = 0; |
|
794 |
} |
|
795 |
break; |
|
796 |
default: |
|
797 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
798 |
SetWindowDirty(w); |
|
799 |
} |
|
800 |
break; |
|
801 |
} |
|
802 |
break; |
|
803 |
} |
|
804 |
} |
|
805 |
||
806 |
static const Widget _ship_depot_widgets[] = { |
|
807 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
808 |
{ WWT_CAPTION, 14, 11, 304, 0, 13, STR_9803_SHIP_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
809 |
{ WWT_MATRIX, 14, 0, 269, 14, 61, 0x203, STR_981F_SHIPS_CLICK_ON_SHIP_FOR}, |
|
810 |
{ WWT_IMGBTN, 14, 270, 293, 14, 61, 0x2A9, STR_9821_DRAG_SHIP_TO_HERE_TO_SELL}, |
|
811 |
{ WWT_SCROLLBAR, 14, 294, 304, 14, 61, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
812 |
{ WWT_PUSHTXTBTN, 14, 0, 151, 62, 73, STR_9804_NEW_SHIPS, STR_9820_BUILD_NEW_SHIP}, |
|
813 |
{ WWT_PUSHTXTBTN, 14, 152, 304, 62, 73, STR_00E4_LOCATION, STR_9822_CENTER_MAIN_VIEW_ON_SHIP}, |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
814 |
{ WIDGETS_END}, |
0 | 815 |
}; |
816 |
||
817 |
static const WindowDesc _ship_depot_desc = { |
|
818 |
-1, -1, 305, 74, |
|
819 |
WC_VEHICLE_DEPOT,0, |
|
820 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
821 |
_ship_depot_widgets, |
|
822 |
ShipDepotWndProc |
|
823 |
}; |
|
824 |
||
825 |
void ShowShipDepotWindow(uint tile) |
|
826 |
{ |
|
827 |
Window *w; |
|
828 |
||
829 |
w = AllocateWindowDescFront(&_ship_depot_desc,tile); |
|
830 |
if (w) { |
|
831 |
w->caption_color = _map_owner[w->window_number]; |
|
832 |
w->vscroll.cap = 2; |
|
833 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
834 |
_backup_orders_tile = 0; |
|
835 |
} |
|
836 |
} |
|
837 |
||
838 |
||
839 |
static void DrawSmallShipSchedule(Vehicle *v, int x, int y) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
840 |
Order *sched; |
0 | 841 |
int sel; |
842 |
Station *st; |
|
843 |
int i = 0; |
|
844 |
||
845 |
sel = v->cur_order_index; |
|
846 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
847 |
for (sched = v->schedule_ptr; sched->type != OT_NOTHING; ++sched) { |
0 | 848 |
if (sel == 0) { |
849 |
_stringwidth_base = 0xE0; |
|
850 |
DoDrawString( "\xAF", x-6, y, 16); |
|
851 |
_stringwidth_base = 0; |
|
852 |
} |
|
853 |
sel--; |
|
854 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
855 |
if (sched->type == OT_GOTO_STATION) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
856 |
st = DEREF_STATION(sched->station); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
857 |
|
0 | 858 |
if (!(st->had_vehicle_of_type & HVOT_BUOY)) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
859 |
SetDParam(0, sched->station); |
0 | 860 |
DrawString(x, y, STR_A036, 0); |
861 |
||
862 |
y += 6; |
|
863 |
if (++i == 4) |
|
864 |
break; |
|
865 |
} |
|
866 |
} |
|
867 |
} |
|
868 |
} |
|
869 |
||
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
193
diff
changeset
|
870 |
|
588 | 871 |
static Widget _player_ships_widgets[] = { |
872 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
873 |
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
727 | 874 |
{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP}, |
875 |
{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, |
|
876 |
{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, |
|
588 | 877 |
{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, STR_NULL}, |
878 |
{ WWT_MATRIX, 14, 0, 248, 26, 169, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR}, |
|
879 |
{ WWT_SCROLLBAR, 14, 249, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
880 |
{ WWT_PUSHTXTBTN, 14, 0, 129, 170, 181, STR_9804_NEW_SHIPS, STR_9824_BUILD_NEW_SHIPS_REQUIRES}, |
|
881 |
{ WWT_PANEL, 14, 130, 259, 170, 181, 0x0, STR_NULL}, |
|
882 |
{ WIDGETS_END}, |
|
883 |
}; |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
884 |
|
588 | 885 |
static Widget _other_player_ships_widgets[] = { |
886 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
887 |
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
727 | 888 |
{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP}, |
889 |
{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, |
|
890 |
{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, |
|
588 | 891 |
{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, STR_NULL}, |
892 |
{ WWT_MATRIX, 14, 0, 248, 26, 169, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR}, |
|
893 |
{ WWT_SCROLLBAR, 14, 249, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
894 |
{ WIDGETS_END}, |
|
895 |
}; |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
896 |
|
0 | 897 |
static void PlayerShipsWndProc(Window *w, WindowEvent *e) |
898 |
{ |
|
588 | 899 |
int station = (int)w->window_number >> 16; |
900 |
int owner = w->window_number & 0xff; |
|
901 |
vehiclelist_d *vl = &WP(w, vehiclelist_d); |
|
902 |
||
0 | 903 |
switch(e->event) { |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
904 |
case WE_PAINT: { |
588 | 905 |
int x = 2; |
906 |
int y = PLY_WND_PRC__OFFSET_TOP_WIDGET; |
|
907 |
int max; |
|
908 |
int i; |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
193
diff
changeset
|
909 |
|
588 | 910 |
BuildVehicleList(vl, VEH_Ship, owner, station); |
911 |
SortVehicleList(vl); |
|
0 | 912 |
|
588 | 913 |
SetVScrollCount(w, vl->list_length); |
914 |
||
915 |
// disable 'Sort By' tooltip on Unsorted sorting criteria |
|
916 |
if (vl->sort_type == SORT_BY_UNSORTED) |
|
917 |
w->disabled_state |= (1 << 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
918 |
|
0 | 919 |
/* draw the widgets */ |
920 |
{ |
|
588 | 921 |
const Player *p = DEREF_PLAYER(owner); |
922 |
/* XXX hack */ |
|
923 |
if (station == -1) { |
|
924 |
/* Company Name -- (###) Trains */ |
|
925 |
SetDParam(0, p->name_1); |
|
926 |
SetDParam(1, p->name_2); |
|
927 |
SetDParam(2, w->vscroll.count); |
|
928 |
_player_ships_widgets[1].unkA = STR_9805_SHIPS; |
|
929 |
_other_player_ships_widgets[1].unkA = STR_9805_SHIPS; |
|
930 |
} else { |
|
931 |
/* Station Name -- (###) Trains */ |
|
932 |
SetDParam(0, DEREF_STATION(station)->index); |
|
933 |
SetDParam(1, w->vscroll.count); |
|
934 |
_player_ships_widgets[1].unkA = STR_SCHEDULED_SHIPS; |
|
935 |
_other_player_ships_widgets[1].unkA = STR_SCHEDULED_SHIPS; |
|
936 |
} |
|
0 | 937 |
DrawWindowWidgets(w); |
938 |
} |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
939 |
/* draw sorting criteria string */ |
588 | 940 |
DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10); |
941 |
/* draw arrow pointing up/down for ascending/descending sorting */ |
|
942 |
DoDrawString( |
|
943 |
vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10); |
|
0 | 944 |
|
588 | 945 |
max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length); |
946 |
for (i = w->vscroll.pos; i < max; ++i) { |
|
947 |
Vehicle *v = DEREF_VEHICLE(vl->sort_list[i].index); |
|
948 |
StringID str; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
949 |
|
588 | 950 |
assert(v->type == VEH_Ship); |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
951 |
|
588 | 952 |
DrawShipImage(v, x + 19, y + 6, INVALID_VEHICLE); |
953 |
DrawVehicleProfitButton(v, x, y + 13); |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
954 |
|
588 | 955 |
SetDParam(0, v->unitnumber); |
956 |
if (IsShipDepotTile(v->tile)) |
|
957 |
str = STR_021F; |
|
958 |
else |
|
959 |
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; |
|
960 |
DrawString(x, y + 2, str, 0); |
|
961 |
||
962 |
SetDParam(0, v->profit_this_year); |
|
963 |
SetDParam(1, v->profit_last_year); |
|
964 |
DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
|
965 |
||
966 |
if (v->string_id != STR_SV_SHIP_NAME) { |
|
967 |
SetDParam(0, v->string_id); |
|
968 |
DrawString(x + 12, y, STR_01AB, 0); |
|
0 | 969 |
} |
588 | 970 |
|
971 |
DrawSmallShipSchedule(v, x + 138, y); |
|
972 |
||
973 |
y += PLY_WND_PRC__SIZE_OF_ROW_BIG; |
|
0 | 974 |
} |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
975 |
} break; |
0 | 976 |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
977 |
case WE_CLICK: { |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
978 |
switch(e->click.widget) { |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
979 |
case 2: /* Flip sorting method ascending/descending */ |
588 | 980 |
vl->flags ^= VL_DESC; |
981 |
vl->flags |= VL_RESORT; |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
982 |
SetWindowDirty(w); |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
983 |
break; |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
984 |
case 3: case 4:/* Select sorting criteria dropdown menu */ |
588 | 985 |
ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 4, 0); |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
986 |
return; |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
987 |
case 6: { /* Matrix to show vehicles */ |
174
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
168
diff
changeset
|
988 |
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
989 |
|
174
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
168
diff
changeset
|
990 |
if (id_v >= w->vscroll.cap) { return;} // click out of bounds |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
991 |
|
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
992 |
id_v += w->vscroll.pos; |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
993 |
|
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
994 |
{ |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
995 |
Vehicle *v; |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
996 |
|
588 | 997 |
if (id_v >= vl->list_length) return; // click out of list bound |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
998 |
|
588 | 999 |
v = DEREF_VEHICLE(vl->sort_list[id_v].index); |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1000 |
|
588 | 1001 |
assert(v->type == VEH_Ship); |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1002 |
|
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1003 |
ShowShipViewWindow(v); |
0 | 1004 |
} |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1005 |
} break; |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1006 |
|
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1007 |
case 8: { /* Build new Vehicle */ |
0 | 1008 |
uint tile; |
1009 |
||
1010 |
tile = _last_built_ship_depot_tile; |
|
1011 |
do { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1012 |
if (_map_owner[tile] == _local_player && IsShipDepotTile(tile)) { |
0 | 1013 |
ShowShipDepotWindow(tile); |
1014 |
ShowBuildShipWindow(tile); |
|
1015 |
return; |
|
1016 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1017 |
|
0 | 1018 |
tile = TILE_MASK(tile + 1); |
1019 |
} while(tile != _last_built_ship_depot_tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1020 |
|
0 | 1021 |
ShowBuildShipWindow(0); |
1022 |
} break; |
|
1023 |
} |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1024 |
} break; |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1025 |
|
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1026 |
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ |
588 | 1027 |
if (vl->sort_type != e->dropdown.index) { |
1028 |
// value has changed -> resort |
|
1029 |
vl->flags |= VL_RESORT; |
|
1030 |
vl->sort_type = e->dropdown.index; |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1031 |
|
588 | 1032 |
// enable 'Sort By' if a sorter criteria is chosen |
1033 |
if (vl->sort_type != SORT_BY_UNSORTED) |
|
1034 |
w->disabled_state &= ~(1 << 2); |
|
1035 |
} |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1036 |
SetWindowDirty(w); |
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1037 |
break; |
588 | 1038 |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1039 |
case WE_CREATE: /* set up resort timer */ |
588 | 1040 |
vl->sort_list = NULL; |
1041 |
vl->flags = VL_REBUILD; |
|
1042 |
vl->sort_type = SORT_BY_UNSORTED; |
|
1043 |
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1044 |
break; |
588 | 1045 |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1046 |
case WE_TICK: /* resort the list every 20 seconds orso (10 days) */ |
588 | 1047 |
if (--vl->resort_timer == 0) { |
1048 |
DEBUG(misc, 1) ("Periodic resort ships list player %d station %d", |
|
1049 |
owner, station); |
|
1050 |
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
|
1051 |
vl->flags |= VL_RESORT; |
|
1052 |
SetWindowDirty(w); |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1053 |
} |
0 | 1054 |
break; |
1055 |
} |
|
1056 |
} |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
1057 |
|
0 | 1058 |
static const WindowDesc _player_ships_desc = { |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1059 |
-1, -1, 260, 182, |
0 | 1060 |
WC_SHIPS_LIST,0, |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
1061 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
0 | 1062 |
_player_ships_widgets, |
1063 |
PlayerShipsWndProc |
|
1064 |
}; |
|
1065 |
||
1066 |
static const WindowDesc _other_player_ships_desc = { |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
1067 |
-1, -1, 260, 170, |
0 | 1068 |
WC_SHIPS_LIST,0, |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
1069 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
0 | 1070 |
_other_player_ships_widgets, |
1071 |
PlayerShipsWndProc |
|
1072 |
}; |
|
1073 |
||
1074 |
||
588 | 1075 |
void ShowPlayerShips(int player, int station) |
0 | 1076 |
{ |
1077 |
Window *w; |
|
1078 |
||
1079 |
if ( player == _local_player) { |
|
588 | 1080 |
w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | player); |
0 | 1081 |
} else { |
588 | 1082 |
w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | player); |
0 | 1083 |
} |
1084 |
if (w) { |
|
1085 |
w->caption_color = w->window_number; |
|
1086 |
w->vscroll.cap = 4; |
|
1087 |
} |
|
1088 |
} |