author | tron |
Thu, 25 Nov 2004 10:47:30 +0000 | |
changeset 507 | 8aa8100b0b22 |
parent 487 | 03a9f4ffe58b |
child 534 | 17ab2f22ff74 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
487
diff
changeset
|
3 |
#include "table/strings.h" |
0 | 4 |
#include "window.h" |
5 |
#include "gui.h" |
|
6 |
#include "station.h" |
|
7 |
#include "gfx.h" |
|
8 |
#include "player.h" |
|
9 |
#include "town.h" |
|
10 |
#include "command.h" |
|
11 |
||
12 |
static void StationsWndShowStationRating(int x, int y, int type, uint acceptance, int rating) |
|
13 |
{ |
|
14 |
static const byte _rating_colors[NUM_CARGO] = {152,32,15,174,208,194,191,55,184,10,191,48}; |
|
15 |
int color = _rating_colors[type]; |
|
16 |
uint w; |
|
17 |
||
18 |
if (acceptance > 575) |
|
19 |
acceptance = 575; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
20 |
|
0 | 21 |
acceptance = (acceptance + 7) >> 3; |
22 |
||
23 |
/* draw cargo */ |
|
24 |
if ( (w=acceptance>>3) != 0) { |
|
25 |
GfxFillRect(x, y, x+w-1, y+6, color); |
|
26 |
x += w; |
|
27 |
} |
|
28 |
||
29 |
if ( (w=acceptance&7) != 0) { |
|
30 |
if (w==7) w--; |
|
31 |
GfxFillRect(x, y+(w-1), x, y+6, color); |
|
32 |
} |
|
33 |
||
34 |
x -= (acceptance>>3); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
35 |
|
0 | 36 |
DrawString(x+1, y, _cargoc.names_short[type], 0x10); |
37 |
||
38 |
/* draw green/red ratings bar */ |
|
39 |
GfxFillRect(x+1, y+8, x+7, y+8, 0xB8); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
40 |
|
0 | 41 |
rating = (rating >> 5); |
42 |
||
43 |
if (rating != 0) { |
|
44 |
GfxFillRect(x+1, y+8, x+rating, y+8, 0xD0); |
|
45 |
} |
|
46 |
} |
|
47 |
||
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
|
48 |
static SortStruct _station_sort[lengthof(_stations)]; |
0 | 49 |
static uint16 _num_station_sort[MAX_PLAYERS]; |
50 |
||
51 |
static char _bufcache[64]; |
|
52 |
static uint16 _last_station_idx; |
|
53 |
||
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
|
54 |
static int CDECL StationNameSorter(const void *a, const void *b) |
0 | 55 |
{ |
56 |
char buf1[64]; |
|
57 |
Station *st; |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
193
diff
changeset
|
58 |
const SortStruct *cmp1 = (const SortStruct*)a; |
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
193
diff
changeset
|
59 |
const SortStruct *cmp2 = (const 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 |
||
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
77 |
static void GlobalSortStationList() |
0 | 78 |
{ |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
79 |
const 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
|
80 |
uint32 n = 0; |
0 | 81 |
uint16 *i; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
82 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
83 |
// reset #-of stations to 0 because ++ is used for value-assignment |
0 | 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 |
||
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
94 |
// create cumulative station-ownership |
0 | 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 |
||
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
99 |
qsort(_station_sort, n, sizeof(_station_sort[0]), GeneralOwnerSorter); // sort by owner |
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 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
101 |
// since indexes are messed up after adding/removing a station, mark all lists dirty |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
102 |
memset(_station_sort_dirty, true, sizeof(_station_sort_dirty)); |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
103 |
_global_station_sort_dirty = false; |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
104 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
105 |
DEBUG(misc, 1) ("Resorting global station list..."); |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
106 |
} |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
107 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
108 |
static void MakeSortedStationList(byte owner) |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
109 |
{ |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
110 |
SortStruct *firstelement; |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
111 |
uint32 n = 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:
69
diff
changeset
|
112 |
|
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
} 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
|
117 |
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
|
118 |
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
|
119 |
} |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
120 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
121 |
_last_station_idx = 0; // used for "cache" in namesorting |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
122 |
qsort(firstelement, n, sizeof(_station_sort[0]), StationNameSorter); // sort by name |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
123 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
124 |
_station_sort_dirty[owner] = false; |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
125 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
126 |
DEBUG(misc, 1) ("Resorting Stations list player %d...", owner+1); |
0 | 127 |
} |
128 |
||
129 |
static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
|
130 |
{ |
|
131 |
switch(e->event) { |
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
136 |
// resort station window if stations have been added/removed |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
137 |
if (_global_station_sort_dirty) |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
138 |
GlobalSortStationList(); |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
139 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
140 |
if (_station_sort_dirty[window_number]) { // resort in case of a station rename. |
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
|
141 |
MakeSortedStationList(window_number); |
0 | 142 |
} |
143 |
||
144 |
// stations are stored as a cummulative index, eg 25, 41, 43. This means |
|
145 |
// 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
|
146 |
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
|
147 |
SetVScrollCount(w, _num_station_sort[window_number] - i); |
0 | 148 |
|
149 |
/* draw widgets, with player's name in the caption */ |
|
150 |
{ |
|
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
|
151 |
Player *p = DEREF_PLAYER(window_number); |
0 | 152 |
SET_DPARAM16(0, p->name_1); |
153 |
SET_DPARAM32(1, p->name_2); |
|
154 |
SET_DPARAM16(2, w->vscroll.count); |
|
155 |
DrawWindowWidgets(w); |
|
156 |
} |
|
157 |
||
158 |
{ |
|
159 |
byte p = 0; |
|
160 |
Station *st; |
|
161 |
int x,xb = 2; |
|
162 |
int y = 16; // offset from top of widget |
|
163 |
int j; |
|
164 |
||
165 |
if (w->vscroll.count == 0) { // player has no stations |
|
166 |
DrawString(xb, y, STR_304A_NONE, 0); |
|
167 |
return; |
|
168 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
169 |
|
0 | 170 |
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
|
171 |
assert(i < _num_station_sort[window_number]); // at least one station must exist |
0 | 172 |
|
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
|
173 |
while (i < _num_station_sort[window_number]) { // do until max number of stations of owner |
0 | 174 |
st = DEREF_STATION(_station_sort[i].index); |
175 |
||
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
|
176 |
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
|
177 |
|
0 | 178 |
SET_DPARAM16(0, st->index); |
179 |
SET_DPARAM8(1, st->facilities); |
|
180 |
x = DrawString(xb, y, STR_3049_0, 0) + 5; |
|
181 |
||
182 |
// show cargo waiting and station ratings |
|
183 |
for(j=0; j!=NUM_CARGO; j++) { |
|
184 |
int acc = (st->goods[j].waiting_acceptance & 0xFFF); |
|
185 |
if (acc != 0) { |
|
186 |
StationsWndShowStationRating(x, y, j, acc, st->goods[j].rating); |
|
187 |
x += 10; |
|
188 |
} |
|
189 |
} |
|
190 |
y += 10; |
|
191 |
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
|
192 |
if (++p == w->vscroll.cap) { break;} // max number of stations in 1 window |
0 | 193 |
} |
194 |
} |
|
195 |
} break; |
|
196 |
case WE_CLICK: { |
|
197 |
switch(e->click.widget) { |
|
198 |
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
|
199 |
uint32 id_v = (e->click.pt.y - 15) / 10; |
0 | 200 |
|
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
|
201 |
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
|
202 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
203 |
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
|
204 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
205 |
{ |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
210 |
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
|
211 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
212 |
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
|
213 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
214 |
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
|
215 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
216 |
ScrollMainWindowToTile(st->xy); |
0 | 217 |
} |
218 |
} break; |
|
219 |
} |
|
220 |
} break; |
|
221 |
||
222 |
case WE_4: |
|
223 |
WP(w,plstations_d).refresh_counter++; |
|
224 |
if (WP(w,plstations_d).refresh_counter==5) { |
|
225 |
WP(w,plstations_d).refresh_counter = 0; |
|
226 |
SetWindowDirty(w); |
|
227 |
} |
|
228 |
break; |
|
229 |
} |
|
230 |
} |
|
231 |
||
232 |
static const Widget _player_stations_widgets[] = { |
|
233 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
234 |
{ WWT_CAPTION, 14, 11, 357, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
235 |
{ WWT_PANEL, 14, 0, 346, 14, 137, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, |
|
236 |
{ 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
|
237 |
{ WIDGETS_END}, |
0 | 238 |
}; |
239 |
||
240 |
static const WindowDesc _player_stations_desc = { |
|
241 |
-1, -1, 358, 138, |
|
242 |
WC_STATION_LIST,0, |
|
243 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
244 |
_player_stations_widgets, |
|
245 |
PlayerStationsWndProc |
|
246 |
}; |
|
247 |
||
248 |
||
249 |
void ShowPlayerStations(int player) |
|
250 |
{ |
|
251 |
Window *w; |
|
252 |
||
253 |
w = AllocateWindowDescFront(&_player_stations_desc, player); |
|
254 |
if (w) { |
|
255 |
w->caption_color = (byte)w->window_number; |
|
256 |
w->vscroll.cap = 12; |
|
257 |
} |
|
258 |
} |
|
259 |
||
260 |
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
|
261 |
{ 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
|
262 |
{ 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
|
263 |
{ 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
|
264 |
{ 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
|
265 |
{ 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
|
266 |
{ 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
|
267 |
{ 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
|
268 |
{ 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
|
269 |
{ 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
|
270 |
{ WIDGETS_END}, |
0 | 271 |
}; |
272 |
||
273 |
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
|
274 |
{ 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
|
275 |
{ 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
|
276 |
{ 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
|
277 |
{ 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
|
278 |
{ 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
|
279 |
{ 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
|
280 |
{ 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
|
281 |
{ 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
|
282 |
{ 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
|
283 |
{ WIDGETS_END}, |
0 | 284 |
}; |
285 |
||
286 |
static void DrawStationViewWindow(Window *w) |
|
287 |
{ |
|
288 |
Station *st; |
|
289 |
int i; |
|
290 |
int num; |
|
291 |
int x,y; |
|
292 |
int pos; |
|
293 |
StringID str; |
|
294 |
byte station_id; |
|
295 |
byte *b; |
|
296 |
||
297 |
||
298 |
station_id = (byte)w->window_number; |
|
299 |
||
300 |
st = DEREF_STATION(w->window_number); |
|
301 |
||
302 |
num = 1; |
|
303 |
for(i=0; i!=NUM_CARGO; i++) { |
|
304 |
if ((st->goods[i].waiting_acceptance & 0xFFF) != 0) { |
|
305 |
num++; |
|
306 |
if (st->goods[i].enroute_from != station_id) |
|
307 |
num++; |
|
308 |
} |
|
309 |
} |
|
310 |
SetVScrollCount(w, num); |
|
311 |
||
312 |
w->disabled_state = st->owner == _local_player ? 0 : (1 << 8); |
|
313 |
SET_DPARAM16(0, st->index); |
|
314 |
SET_DPARAM8(1, st->facilities); |
|
315 |
DrawWindowWidgets(w); |
|
316 |
||
317 |
x = 2; |
|
318 |
y = 15; |
|
319 |
pos = w->vscroll.pos; |
|
320 |
||
321 |
if (--pos < 0) { |
|
322 |
str = STR_00D0_NOTHING; |
|
323 |
for(i=0; i!=NUM_CARGO; i++) |
|
324 |
if (st->goods[i].waiting_acceptance & 0xFFF) |
|
325 |
str = STR_EMPTY; |
|
326 |
SET_DPARAM16(0, str); |
|
327 |
DrawString(x, y, STR_0008_WAITING, 0); |
|
328 |
y += 10; |
|
329 |
} |
|
330 |
||
331 |
i = 0; |
|
332 |
do { |
|
333 |
uint waiting = (st->goods[i].waiting_acceptance & 0xFFF); |
|
334 |
if (waiting == 0) |
|
335 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
336 |
|
0 | 337 |
num = (waiting + 5) / 10; |
338 |
if (num != 0) { |
|
339 |
int cur_x = x; |
|
340 |
num = min(num, 23); |
|
341 |
do { |
|
342 |
DrawSprite(_cargoc.sprites[i], cur_x, y); |
|
343 |
cur_x += 10; |
|
344 |
} while (--num); |
|
345 |
} |
|
346 |
||
347 |
if ( st->goods[i].enroute_from == station_id) { |
|
348 |
if (--pos < 0) { |
|
349 |
SET_DPARAM16(1, waiting); |
|
350 |
SET_DPARAM16(0, _cargoc.names_long_s[i] + (waiting==1 ? 0 : 32)); |
|
351 |
DrawStringRightAligned(x + 234, y, STR_0009, 0); |
|
352 |
y += 10; |
|
353 |
} |
|
354 |
} else { |
|
355 |
/* enroute */ |
|
356 |
if (--pos < 0) { |
|
357 |
SET_DPARAM16(1, waiting); |
|
358 |
SET_DPARAM16(0, _cargoc.names_long_s[i] + (waiting==1 ? 0 : 32)); |
|
359 |
DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0); |
|
360 |
y += 10; |
|
361 |
} |
|
362 |
||
363 |
if (pos > -5 && --pos < 0) { |
|
364 |
SET_DPARAM16(0, st->goods[i].enroute_from); |
|
365 |
DrawStringRightAligned(x + 234, y, STR_000B, 0); |
|
366 |
y += 10; |
|
367 |
} |
|
368 |
} |
|
369 |
} while (pos > -5 && ++i != 12); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
370 |
|
0 | 371 |
if (w->widget == _station_view_widgets) { |
372 |
b = _userstring; |
|
373 |
b[0] = 0x81; |
|
374 |
b[1] = STR_000C_ACCEPTS; |
|
375 |
b[2] = STR_000C_ACCEPTS >> 8; |
|
376 |
b += 3; |
|
377 |
||
378 |
for(i=0; i!=NUM_CARGO; i++) { |
|
487
03a9f4ffe58b
(svn r769) Fixed a tiny mistake in the _userstring boundary check. Let's hope I got it right this time.
pasky
parents:
485
diff
changeset
|
379 |
if ((b - (byte *) &_userstring) + 5 > USERSTRING_LEN - 1) |
485
453c096beb1b
(svn r767) Introduce USERSTRING_LEN (128) and try to make sure we don't overflow it anywhere (as long as we keep USERSTRING_LEN above 7 or so).
pasky
parents:
243
diff
changeset
|
380 |
break; |
0 | 381 |
if (st->goods[i].waiting_acceptance & 0x8000) { |
382 |
b[0] = 0x81; |
|
383 |
WRITE_LE_UINT16(b+1, _cargoc.names_s[i]); |
|
384 |
WRITE_LE_UINT16(b+3, 0x202C); |
|
385 |
b += 5; |
|
386 |
} |
|
387 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
388 |
|
0 | 389 |
if (b == (byte*)&_userstring[3]) { |
390 |
b[0] = 0x81; |
|
391 |
b[1] = STR_00D0_NOTHING; |
|
392 |
b[2] = STR_00D0_NOTHING >> 8; |
|
393 |
b[3] = 0; |
|
394 |
} else { |
|
395 |
b[-2] = 0; |
|
396 |
} |
|
397 |
||
398 |
DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245); |
|
399 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
400 |
|
0 | 401 |
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0); |
402 |
||
403 |
y = 77; |
|
404 |
for(i=0; i!=NUM_CARGO; i++) { |
|
405 |
if (st->goods[i].enroute_from != 0xFF) { |
|
406 |
SET_DPARAM16(0, _cargoc.names_s[i]); |
|
407 |
SET_DPARAM8(2, st->goods[i].rating * 101 >> 8); |
|
408 |
SET_DPARAM16(1, STR_3035_APPALLING + (st->goods[i].rating >> 5)); |
|
409 |
DrawString(8, y, STR_303D, 0); |
|
410 |
y += 10; |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
||
417 |
static void StationViewWndProc(Window *w, WindowEvent *e) |
|
418 |
{ |
|
419 |
switch(e->event) { |
|
420 |
case WE_PAINT: |
|
421 |
DrawStationViewWindow(w); |
|
422 |
break; |
|
423 |
||
424 |
case WE_CLICK: |
|
425 |
switch(e->click.widget) { |
|
426 |
case 6: |
|
427 |
ScrollMainWindowToTile(DEREF_STATION(w->window_number)->xy); |
|
428 |
break; |
|
429 |
||
430 |
case 7: |
|
431 |
SetWindowDirty(w); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
432 |
|
0 | 433 |
/* toggle height/widget set */ |
434 |
w->height ^= (210 ^ 110); |
|
435 |
*(uint32*)&w->widget ^= (uint32)_station_view_expanded_widgets ^ (uint32)_station_view_widgets; |
|
436 |
||
437 |
SetWindowDirty(w); |
|
438 |
break; |
|
439 |
||
440 |
case 8: { |
|
441 |
Station *st = DEREF_STATION(w->window_number); |
|
442 |
SET_DPARAM16(0, st->town->townnametype); |
|
443 |
SET_DPARAM32(1, st->town->townnameparts); |
|
444 |
ShowQueryString(st->string_id, STR_3030_RENAME_STATION_LOADING, 31, 180, w->window_class, w->window_number); |
|
445 |
} break; |
|
446 |
} |
|
447 |
break; |
|
448 |
||
449 |
case WE_ON_EDIT_TEXT: { |
|
450 |
Station *st; |
|
451 |
byte *b = e->edittext.str; |
|
452 |
if (*b == 0) |
|
453 |
return; |
|
454 |
memcpy(_decode_parameters, b, 32); |
|
455 |
||
456 |
st = DEREF_STATION(w->window_number); |
|
457 |
DoCommandP(st->xy, w->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
458 |
} break; |
0 | 459 |
} |
460 |
} |
|
461 |
||
462 |
||
463 |
static const WindowDesc _station_view_desc = { |
|
464 |
-1, -1, 249, 110, |
|
465 |
WC_STATION_VIEW,0, |
|
466 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
467 |
_station_view_widgets, |
|
468 |
StationViewWndProc |
|
469 |
}; |
|
470 |
||
471 |
void ShowStationViewWindow(int station) |
|
472 |
{ |
|
473 |
Window *w; |
|
474 |
byte color; |
|
475 |
||
476 |
w = AllocateWindowDescFront(&_station_view_desc, station); |
|
477 |
if (w) { |
|
478 |
color = DEREF_STATION(w->window_number)->owner; |
|
479 |
if (color != 0x10) |
|
480 |
w->caption_color = color; |
|
481 |
w->vscroll.cap = 5; |
|
482 |
} |
|
483 |
} |