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