author | darkvater |
Mon, 06 Sep 2004 18:15:13 +0000 | |
changeset 164 | 0cbdf3c9bde1 |
parent 69 | f8c29cdb388e |
child 174 | bd79fb899824 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "window.h" |
|
4 |
#include "gui.h" |
|
5 |
#include "station.h" |
|
6 |
#include "gfx.h" |
|
7 |
#include "player.h" |
|
8 |
#include "town.h" |
|
9 |
#include "command.h" |
|
10 |
||
11 |
static void StationsWndShowStationRating(int x, int y, int type, uint acceptance, int rating) |
|
12 |
{ |
|
13 |
static const byte _rating_colors[NUM_CARGO] = {152,32,15,174,208,194,191,55,184,10,191,48}; |
|
14 |
int color = _rating_colors[type]; |
|
15 |
uint w; |
|
16 |
||
17 |
if (acceptance > 575) |
|
18 |
acceptance = 575; |
|
19 |
||
20 |
acceptance = (acceptance + 7) >> 3; |
|
21 |
||
22 |
/* draw cargo */ |
|
23 |
if ( (w=acceptance>>3) != 0) { |
|
24 |
GfxFillRect(x, y, x+w-1, y+6, color); |
|
25 |
x += w; |
|
26 |
} |
|
27 |
||
28 |
if ( (w=acceptance&7) != 0) { |
|
29 |
if (w==7) w--; |
|
30 |
GfxFillRect(x, y+(w-1), x, y+6, color); |
|
31 |
} |
|
32 |
||
33 |
x -= (acceptance>>3); |
|
34 |
||
35 |
DrawString(x+1, y, _cargoc.names_short[type], 0x10); |
|
36 |
||
37 |
/* draw green/red ratings bar */ |
|
38 |
GfxFillRect(x+1, y+8, x+7, y+8, 0xB8); |
|
39 |
||
40 |
rating = (rating >> 5); |
|
41 |
||
42 |
if (rating != 0) { |
|
43 |
GfxFillRect(x+1, y+8, x+rating, y+8, 0xD0); |
|
44 |
} |
|
45 |
} |
|
46 |
||
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:
69
diff
changeset
|
47 |
static SortStruct _station_sort[lengthof(_stations)]; |
0 | 48 |
static uint16 _num_station_sort[MAX_PLAYERS]; |
49 |
||
50 |
static char _bufcache[64]; |
|
51 |
static uint16 _last_station_idx; |
|
52 |
||
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:
69
diff
changeset
|
53 |
static int CDECL StationNameSorter(const void *a, const void *b) |
0 | 54 |
{ |
55 |
char buf1[64]; |
|
56 |
Station *st; |
|
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:
69
diff
changeset
|
57 |
SortStruct *cmp1, *cmp2; |
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:
69
diff
changeset
|
58 |
cmp1 = (SortStruct*)a; |
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:
69
diff
changeset
|
59 |
cmp2 = (SortStruct*)b; |
0 | 60 |
|
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:
69
diff
changeset
|
61 |
st = DEREF_STATION(cmp1->index); |
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:
69
diff
changeset
|
62 |
SET_DPARAM16(0, st->town->townnametype); |
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:
69
diff
changeset
|
63 |
SET_DPARAM32(1, st->town->townnameparts); |
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:
69
diff
changeset
|
64 |
GetString(buf1, st->string_id); |
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:
69
diff
changeset
|
65 |
|
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:
69
diff
changeset
|
66 |
if ( cmp2->index != _last_station_idx) { |
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:
69
diff
changeset
|
67 |
_last_station_idx = cmp2->index; |
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:
69
diff
changeset
|
68 |
st = DEREF_STATION(cmp2->index); |
0 | 69 |
SET_DPARAM16(0, st->town->townnametype); |
70 |
SET_DPARAM32(1, st->town->townnameparts); |
|
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:
69
diff
changeset
|
71 |
GetString(_bufcache, st->string_id); |
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:
69
diff
changeset
|
72 |
} |
0 | 73 |
|
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:
69
diff
changeset
|
74 |
return strcmp(buf1, _bufcache); // sort by name |
0 | 75 |
} |
76 |
||
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:
69
diff
changeset
|
77 |
static void MakeSortedStationList() |
0 | 78 |
{ |
79 |
Station *st; |
|
80 |
uint16 n = 0; |
|
81 |
uint16 *i; |
|
82 |
// reset to 0 just to be sure |
|
83 |
for (i = _num_station_sort; i != endof(_num_station_sort); i++) {*i = 0;} |
|
84 |
||
85 |
FOR_ALL_STATIONS(st) { |
|
86 |
if(st->xy && st->owner != OWNER_NONE) { |
|
87 |
_station_sort[n].index = st->index; |
|
88 |
_station_sort[n++].owner = st->owner; |
|
89 |
_num_station_sort[st->owner]++; // add number of stations of player |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
// create cumulative station-ownage |
|
94 |
// stations are stored as a cummulative index, eg 25, 41, 43. This means |
|
95 |
// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 |
|
96 |
for (i = &_num_station_sort[1]; i != endof(_num_station_sort); i++) {*i += *(i-1);} |
|
97 |
||
98 |
_last_station_idx = 255; // used for "cache" |
|
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:
69
diff
changeset
|
99 |
|
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:
69
diff
changeset
|
100 |
// sort by owner, then only subsort the requested owner-vehicles |
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:
69
diff
changeset
|
101 |
qsort(_station_sort, n, sizeof(_station_sort[0]), GeneralOwnerSorter); |
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:
69
diff
changeset
|
102 |
|
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:
69
diff
changeset
|
103 |
qsort(_station_sort, n, sizeof(_station_sort[0]), StationNameSorter); |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
0
diff
changeset
|
104 |
|
69 | 105 |
DEBUG(misc, 1) ("Resorting Stations list..."); |
0 | 106 |
} |
107 |
||
108 |
static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
|
109 |
{ |
|
110 |
switch(e->event) { |
|
111 |
case WE_PAINT: { |
|
112 |
byte i; |
|
113 |
if (_station_sort_dirty) { |
|
114 |
_station_sort_dirty = false; |
|
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:
69
diff
changeset
|
115 |
MakeSortedStationList(); |
0 | 116 |
} |
117 |
||
118 |
// stations are stored as a cummulative index, eg 25, 41, 43. This means |
|
119 |
// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 stations |
|
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:
69
diff
changeset
|
120 |
i = (byte)(w->window_number == 0) ? 0 : _num_station_sort[w->window_number-1]; |
0 | 121 |
SetVScrollCount(w, _num_station_sort[w->window_number] - i); |
122 |
||
123 |
/* draw widgets, with player's name in the caption */ |
|
124 |
{ |
|
125 |
Player *p = DEREF_PLAYER(w->window_number); |
|
126 |
SET_DPARAM16(0, p->name_1); |
|
127 |
SET_DPARAM32(1, p->name_2); |
|
128 |
SET_DPARAM16(2, w->vscroll.count); |
|
129 |
DrawWindowWidgets(w); |
|
130 |
} |
|
131 |
||
132 |
{ |
|
133 |
byte p = 0; |
|
134 |
Station *st; |
|
135 |
int x,xb = 2; |
|
136 |
int y = 16; // offset from top of widget |
|
137 |
int j; |
|
138 |
||
139 |
if (w->vscroll.count == 0) { // player has no stations |
|
140 |
DrawString(xb, y, STR_304A_NONE, 0); |
|
141 |
return; |
|
142 |
} |
|
143 |
||
144 |
i += w->vscroll.pos; // offset from sorted station list of current player |
|
145 |
assert(i < _num_station_sort[w->window_number]); // at least one station must exist |
|
146 |
||
147 |
while (i < _num_station_sort[w->window_number]) { // do until max number of stations of owner |
|
148 |
st = DEREF_STATION(_station_sort[i].index); |
|
149 |
||
150 |
SET_DPARAM16(0, st->index); |
|
151 |
SET_DPARAM8(1, st->facilities); |
|
152 |
x = DrawString(xb, y, STR_3049_0, 0) + 5; |
|
153 |
||
154 |
// show cargo waiting and station ratings |
|
155 |
for(j=0; j!=NUM_CARGO; j++) { |
|
156 |
int acc = (st->goods[j].waiting_acceptance & 0xFFF); |
|
157 |
if (acc != 0) { |
|
158 |
StationsWndShowStationRating(x, y, j, acc, st->goods[j].rating); |
|
159 |
x += 10; |
|
160 |
} |
|
161 |
} |
|
162 |
y += 10; |
|
163 |
i++; // next station |
|
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:
69
diff
changeset
|
164 |
if (++p == w->vscroll.cap) { break;} // max number of stations in 1 window |
0 | 165 |
} |
166 |
} |
|
167 |
} break; |
|
168 |
case WE_CLICK: { |
|
169 |
switch(e->click.widget) { |
|
170 |
case 2: { |
|
171 |
uint y = (e->click.pt.y - 15) / 10; |
|
172 |
uint16 p; |
|
173 |
||
174 |
if (!IS_INT_INSIDE(y, 0, 12)) { return;} |
|
175 |
||
176 |
// get the p-th OUR station from globally sorted list |
|
177 |
p = y + w->vscroll.pos; |
|
178 |
p += (w->window_number == 0) ? 0 : _num_station_sort[w->window_number-1]; // get offset of first station in list |
|
179 |
if (p < _num_station_sort[w->window_number]) { |
|
180 |
ScrollMainWindowToTile(DEREF_STATION(_station_sort[p].index)->xy); |
|
181 |
} |
|
182 |
} break; |
|
183 |
} |
|
184 |
} break; |
|
185 |
||
186 |
case WE_4: |
|
187 |
WP(w,plstations_d).refresh_counter++; |
|
188 |
if (WP(w,plstations_d).refresh_counter==5) { |
|
189 |
WP(w,plstations_d).refresh_counter = 0; |
|
190 |
SetWindowDirty(w); |
|
191 |
} |
|
192 |
break; |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
static const Widget _player_stations_widgets[] = { |
|
197 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
198 |
{ WWT_CAPTION, 14, 11, 357, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
199 |
{ WWT_PANEL, 14, 0, 346, 14, 137, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, |
|
200 |
{ WWT_SCROLLBAR, 14, 347, 357, 14, 137, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
201 |
{ WWT_LAST}, |
|
202 |
}; |
|
203 |
||
204 |
static const WindowDesc _player_stations_desc = { |
|
205 |
-1, -1, 358, 138, |
|
206 |
WC_STATION_LIST,0, |
|
207 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
208 |
_player_stations_widgets, |
|
209 |
PlayerStationsWndProc |
|
210 |
}; |
|
211 |
||
212 |
||
213 |
void ShowPlayerStations(int player) |
|
214 |
{ |
|
215 |
Window *w; |
|
216 |
||
217 |
w = AllocateWindowDescFront(&_player_stations_desc, player); |
|
218 |
if (w) { |
|
219 |
w->caption_color = (byte)w->window_number; |
|
220 |
w->vscroll.cap = 12; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
static const Widget _station_view_expanded_widgets[] = { |
|
225 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
226 |
{ WWT_CAPTION, 14, 11, 248, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
227 |
{ WWT_IMGBTN, 14, 0, 237, 14, 65, 0x0, 0}, |
|
228 |
{ WWT_SCROLLBAR, 14, 238, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
229 |
{ WWT_EMPTY, 0, 0, 0, 0, 0, 0x0, 0}, |
|
230 |
{ WWT_IMGBTN, 14, 0, 248, 66, 197, 0x0, 0}, |
|
231 |
{ WWT_PUSHTXTBTN, 14, 0, 82, 198, 209, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, |
|
232 |
{ WWT_PUSHTXTBTN, 14, 83, 165, 198, 209, STR_3033_ACCEPTS, STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO}, |
|
233 |
{ WWT_PUSHTXTBTN, 14, 166, 248, 198, 209, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, |
|
234 |
{ WWT_LAST}, |
|
235 |
}; |
|
236 |
||
237 |
static const Widget _station_view_widgets[] = { |
|
238 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
239 |
{ WWT_CAPTION, 14, 11, 248, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
240 |
{ WWT_IMGBTN, 14, 0, 237, 14, 65, 0x0, 0}, |
|
241 |
{ WWT_SCROLLBAR, 14, 238, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
242 |
{ WWT_IMGBTN, 14, 0, 248, 66, 97, 0x0, 0}, |
|
243 |
{ WWT_EMPTY, 0, 0, 0, 0, 0, 0x0, 0}, |
|
244 |
{ WWT_PUSHTXTBTN, 14, 0, 82, 98, 109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, |
|
245 |
{ WWT_PUSHTXTBTN, 14, 83, 165, 98, 109, STR_3032_RATINGS, STR_3054_SHOW_STATION_RATINGS}, |
|
246 |
{ WWT_PUSHTXTBTN, 14, 166, 248, 98, 109, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, |
|
247 |
{ WWT_LAST}, |
|
248 |
}; |
|
249 |
||
250 |
static void DrawStationViewWindow(Window *w) |
|
251 |
{ |
|
252 |
Station *st; |
|
253 |
int i; |
|
254 |
int num; |
|
255 |
int x,y; |
|
256 |
int pos; |
|
257 |
StringID str; |
|
258 |
byte station_id; |
|
259 |
byte *b; |
|
260 |
||
261 |
||
262 |
station_id = (byte)w->window_number; |
|
263 |
||
264 |
st = DEREF_STATION(w->window_number); |
|
265 |
||
266 |
num = 1; |
|
267 |
for(i=0; i!=NUM_CARGO; i++) { |
|
268 |
if ((st->goods[i].waiting_acceptance & 0xFFF) != 0) { |
|
269 |
num++; |
|
270 |
if (st->goods[i].enroute_from != station_id) |
|
271 |
num++; |
|
272 |
} |
|
273 |
} |
|
274 |
SetVScrollCount(w, num); |
|
275 |
||
276 |
w->disabled_state = st->owner == _local_player ? 0 : (1 << 8); |
|
277 |
SET_DPARAM16(0, st->index); |
|
278 |
SET_DPARAM8(1, st->facilities); |
|
279 |
DrawWindowWidgets(w); |
|
280 |
||
281 |
x = 2; |
|
282 |
y = 15; |
|
283 |
pos = w->vscroll.pos; |
|
284 |
||
285 |
if (--pos < 0) { |
|
286 |
str = STR_00D0_NOTHING; |
|
287 |
for(i=0; i!=NUM_CARGO; i++) |
|
288 |
if (st->goods[i].waiting_acceptance & 0xFFF) |
|
289 |
str = STR_EMPTY; |
|
290 |
SET_DPARAM16(0, str); |
|
291 |
DrawString(x, y, STR_0008_WAITING, 0); |
|
292 |
y += 10; |
|
293 |
} |
|
294 |
||
295 |
i = 0; |
|
296 |
do { |
|
297 |
uint waiting = (st->goods[i].waiting_acceptance & 0xFFF); |
|
298 |
if (waiting == 0) |
|
299 |
continue; |
|
300 |
||
301 |
num = (waiting + 5) / 10; |
|
302 |
if (num != 0) { |
|
303 |
int cur_x = x; |
|
304 |
num = min(num, 23); |
|
305 |
do { |
|
306 |
DrawSprite(_cargoc.sprites[i], cur_x, y); |
|
307 |
cur_x += 10; |
|
308 |
} while (--num); |
|
309 |
} |
|
310 |
||
311 |
if ( st->goods[i].enroute_from == station_id) { |
|
312 |
if (--pos < 0) { |
|
313 |
SET_DPARAM16(1, waiting); |
|
314 |
SET_DPARAM16(0, _cargoc.names_long_s[i] + (waiting==1 ? 0 : 32)); |
|
315 |
DrawStringRightAligned(x + 234, y, STR_0009, 0); |
|
316 |
y += 10; |
|
317 |
} |
|
318 |
} else { |
|
319 |
/* enroute */ |
|
320 |
if (--pos < 0) { |
|
321 |
SET_DPARAM16(1, waiting); |
|
322 |
SET_DPARAM16(0, _cargoc.names_long_s[i] + (waiting==1 ? 0 : 32)); |
|
323 |
DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0); |
|
324 |
y += 10; |
|
325 |
} |
|
326 |
||
327 |
if (pos > -5 && --pos < 0) { |
|
328 |
SET_DPARAM16(0, st->goods[i].enroute_from); |
|
329 |
DrawStringRightAligned(x + 234, y, STR_000B, 0); |
|
330 |
y += 10; |
|
331 |
} |
|
332 |
} |
|
333 |
} while (pos > -5 && ++i != 12); |
|
334 |
||
335 |
if (w->widget == _station_view_widgets) { |
|
336 |
b = _userstring; |
|
337 |
b[0] = 0x81; |
|
338 |
b[1] = STR_000C_ACCEPTS; |
|
339 |
b[2] = STR_000C_ACCEPTS >> 8; |
|
340 |
b += 3; |
|
341 |
||
342 |
for(i=0; i!=NUM_CARGO; i++) { |
|
343 |
if (st->goods[i].waiting_acceptance & 0x8000) { |
|
344 |
b[0] = 0x81; |
|
345 |
WRITE_LE_UINT16(b+1, _cargoc.names_s[i]); |
|
346 |
WRITE_LE_UINT16(b+3, 0x202C); |
|
347 |
b += 5; |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
if (b == (byte*)&_userstring[3]) { |
|
352 |
b[0] = 0x81; |
|
353 |
b[1] = STR_00D0_NOTHING; |
|
354 |
b[2] = STR_00D0_NOTHING >> 8; |
|
355 |
b[3] = 0; |
|
356 |
} else { |
|
357 |
b[-2] = 0; |
|
358 |
} |
|
359 |
||
360 |
DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245); |
|
361 |
} else { |
|
362 |
||
363 |
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0); |
|
364 |
||
365 |
y = 77; |
|
366 |
for(i=0; i!=NUM_CARGO; i++) { |
|
367 |
if (st->goods[i].enroute_from != 0xFF) { |
|
368 |
SET_DPARAM16(0, _cargoc.names_s[i]); |
|
369 |
SET_DPARAM8(2, st->goods[i].rating * 101 >> 8); |
|
370 |
SET_DPARAM16(1, STR_3035_APPALLING + (st->goods[i].rating >> 5)); |
|
371 |
DrawString(8, y, STR_303D, 0); |
|
372 |
y += 10; |
|
373 |
} |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
||
379 |
static void StationViewWndProc(Window *w, WindowEvent *e) |
|
380 |
{ |
|
381 |
switch(e->event) { |
|
382 |
case WE_PAINT: |
|
383 |
DrawStationViewWindow(w); |
|
384 |
break; |
|
385 |
||
386 |
case WE_CLICK: |
|
387 |
switch(e->click.widget) { |
|
388 |
case 6: |
|
389 |
ScrollMainWindowToTile(DEREF_STATION(w->window_number)->xy); |
|
390 |
break; |
|
391 |
||
392 |
case 7: |
|
393 |
SetWindowDirty(w); |
|
394 |
||
395 |
/* toggle height/widget set */ |
|
396 |
w->height ^= (210 ^ 110); |
|
397 |
*(uint32*)&w->widget ^= (uint32)_station_view_expanded_widgets ^ (uint32)_station_view_widgets; |
|
398 |
||
399 |
SetWindowDirty(w); |
|
400 |
break; |
|
401 |
||
402 |
case 8: { |
|
403 |
Station *st = DEREF_STATION(w->window_number); |
|
404 |
SET_DPARAM16(0, st->town->townnametype); |
|
405 |
SET_DPARAM32(1, st->town->townnameparts); |
|
406 |
ShowQueryString(st->string_id, STR_3030_RENAME_STATION_LOADING, 31, 180, w->window_class, w->window_number); |
|
407 |
} break; |
|
408 |
} |
|
409 |
break; |
|
410 |
||
411 |
case WE_ON_EDIT_TEXT: { |
|
412 |
Station *st; |
|
413 |
byte *b = e->edittext.str; |
|
414 |
if (*b == 0) |
|
415 |
return; |
|
416 |
memcpy(_decode_parameters, b, 32); |
|
417 |
||
418 |
st = DEREF_STATION(w->window_number); |
|
419 |
DoCommandP(st->xy, w->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); |
|
420 |
} break; |
|
421 |
} |
|
422 |
} |
|
423 |
||
424 |
||
425 |
static const WindowDesc _station_view_desc = { |
|
426 |
-1, -1, 249, 110, |
|
427 |
WC_STATION_VIEW,0, |
|
428 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
429 |
_station_view_widgets, |
|
430 |
StationViewWndProc |
|
431 |
}; |
|
432 |
||
433 |
void ShowStationViewWindow(int station) |
|
434 |
{ |
|
435 |
Window *w; |
|
436 |
byte color; |
|
437 |
||
438 |
w = AllocateWindowDescFront(&_station_view_desc, station); |
|
439 |
if (w) { |
|
440 |
color = DEREF_STATION(w->window_number)->owner; |
|
441 |
if (color != 0x10) |
|
442 |
w->caption_color = color; |
|
443 |
w->vscroll.cap = 5; |
|
444 |
} |
|
445 |
} |