author | matthijs |
Wed, 22 Mar 2006 22:26:16 +0000 | |
branch | 0.4.5 |
changeset 9958 | bed516c67d61 |
parent 2725 | 5c632bc5be28 |
child 3554 | c16eadc2d060 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
4 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1272
diff
changeset
|
5 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
7 |
#include "strings.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
487
diff
changeset
|
8 |
#include "table/strings.h" |
0 | 9 |
#include "window.h" |
10 |
#include "gui.h" |
|
11 |
#include "station.h" |
|
12 |
#include "gfx.h" |
|
13 |
#include "player.h" |
|
14 |
#include "town.h" |
|
15 |
#include "command.h" |
|
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2084
diff
changeset
|
16 |
#include "variables.h" |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2084
diff
changeset
|
17 |
#include "vehicle_gui.h" |
0 | 18 |
|
19 |
static void StationsWndShowStationRating(int x, int y, int type, uint acceptance, int rating) |
|
20 |
{ |
|
21 |
static const byte _rating_colors[NUM_CARGO] = {152,32,15,174,208,194,191,55,184,10,191,48}; |
|
22 |
int color = _rating_colors[type]; |
|
23 |
uint w; |
|
24 |
||
2639 | 25 |
if (acceptance > 575) acceptance = 575; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
26 |
|
2639 | 27 |
acceptance = (acceptance + 7) / 8; |
0 | 28 |
|
29 |
/* draw cargo */ |
|
2639 | 30 |
w = acceptance / 8; |
31 |
if (w != 0) { |
|
32 |
GfxFillRect(x, y, x + w - 1, y + 6, color); |
|
0 | 33 |
x += w; |
34 |
} |
|
35 |
||
2639 | 36 |
w = acceptance % 8; |
37 |
if (w != 0) { |
|
38 |
if (w == 7) w--; |
|
39 |
GfxFillRect(x, y + (w - 1), x, y + 6, color); |
|
0 | 40 |
} |
41 |
||
2639 | 42 |
x -= acceptance / 8; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
43 |
|
2639 | 44 |
DrawString(x + 1, y, _cargoc.names_short[type], 0x10); |
0 | 45 |
|
46 |
/* draw green/red ratings bar */ |
|
2639 | 47 |
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
|
48 |
|
2639 | 49 |
rating >>= 5; |
0 | 50 |
|
2639 | 51 |
if (rating != 0) GfxFillRect(x + 1, y + 8, x + rating, y + 8, 0xD0); |
0 | 52 |
} |
53 |
||
54 |
static uint16 _num_station_sort[MAX_PLAYERS]; |
|
55 |
||
56 |
static char _bufcache[64]; |
|
57 |
static uint16 _last_station_idx; |
|
58 |
||
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
|
59 |
static int CDECL StationNameSorter(const void *a, const void *b) |
0 | 60 |
{ |
61 |
char buf1[64]; |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
62 |
int32 argv[1]; |
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
|
63 |
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
|
64 |
const SortStruct *cmp2 = (const SortStruct*)b; |
0 | 65 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
66 |
argv[0] = cmp1->index; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
67 |
GetStringWithArgs(buf1, STR_STATION, argv); |
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
|
68 |
|
2639 | 69 |
if (cmp2->index != _last_station_idx) { |
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
|
70 |
_last_station_idx = cmp2->index; |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
71 |
argv[0] = cmp2->index; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
72 |
GetStringWithArgs(_bufcache, STR_STATION, argv); |
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
|
73 |
} |
0 | 74 |
|
2026 | 75 |
return strcmp(buf1, _bufcache); // sort by name |
0 | 76 |
} |
77 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
919
diff
changeset
|
78 |
static void GlobalSortStationList(void) |
0 | 79 |
{ |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
80 |
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
|
81 |
uint32 n = 0; |
0 | 82 |
uint16 *i; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
83 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
84 |
// reset #-of stations to 0 because ++ is used for value-assignment |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1341
diff
changeset
|
85 |
memset(_num_station_sort, 0, sizeof(_num_station_sort)); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
86 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
87 |
/* Create array for sorting */ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
88 |
_station_sort = realloc(_station_sort, GetStationPoolSize() * sizeof(_station_sort[0])); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
89 |
if (_station_sort == NULL) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
90 |
error("Could not allocate memory for the station-sorting-list"); |
0 | 91 |
|
92 |
FOR_ALL_STATIONS(st) { |
|
2639 | 93 |
if (st->xy != 0 && st->owner != OWNER_NONE) { |
0 | 94 |
_station_sort[n].index = st->index; |
95 |
_station_sort[n++].owner = st->owner; |
|
2026 | 96 |
_num_station_sort[st->owner]++; // add number of stations of player |
0 | 97 |
} |
98 |
} |
|
99 |
||
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
100 |
// create cumulative station-ownership |
0 | 101 |
// stations are stored as a cummulative index, eg 25, 41, 43. This means |
102 |
// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 |
|
2639 | 103 |
for (i = &_num_station_sort[1]; i != endof(_num_station_sort); i++) { |
104 |
*i += *(i - 1); |
|
105 |
} |
|
0 | 106 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
107 |
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
|
108 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
109 |
// 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
|
110 |
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
|
111 |
_global_station_sort_dirty = false; |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
112 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
113 |
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
|
114 |
} |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
115 |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
116 |
static void MakeSortedStationList(PlayerID owner) |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
117 |
{ |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
118 |
SortStruct *firstelement; |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
119 |
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
|
120 |
|
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 |
if (owner == 0) { // first element starts at 0th element and has n elements as described above |
2026 | 122 |
firstelement = &_station_sort[0]; |
123 |
n = _num_station_sort[0]; |
|
124 |
} else { // nth element starts at the end of the previous one, and has n elements as described above |
|
125 |
firstelement = &_station_sort[_num_station_sort[owner - 1]]; |
|
126 |
n = _num_station_sort[owner] - _num_station_sort[owner - 1]; |
|
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
|
127 |
} |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
128 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
129 |
_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
|
130 |
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
|
131 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
132 |
_station_sort_dirty[owner] = false; |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
133 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
134 |
DEBUG(misc, 1) ("Resorting Stations list player %d...", owner+1); |
0 | 135 |
} |
136 |
||
137 |
static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
|
138 |
{ |
|
2639 | 139 |
switch (e->event) { |
0 | 140 |
case WE_PAINT: { |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
141 |
const PlayerID owner = w->window_number; |
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
|
142 |
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
|
143 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
144 |
// resort station window if stations have been added/removed |
2639 | 145 |
if (_global_station_sort_dirty) GlobalSortStationList(); |
146 |
if (_station_sort_dirty[owner]) MakeSortedStationList(owner); |
|
0 | 147 |
|
148 |
// stations are stored as a cummulative index, eg 25, 41, 43. This means |
|
149 |
// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 stations |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
150 |
i = (owner == 0) ? 0 : _num_station_sort[owner - 1]; |
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
151 |
SetVScrollCount(w, _num_station_sort[owner] - i); |
0 | 152 |
|
153 |
/* draw widgets, with player's name in the caption */ |
|
154 |
{ |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
155 |
const Player* p = GetPlayer(owner); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
156 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
157 |
SetDParam(1, p->name_2); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
158 |
SetDParam(2, w->vscroll.count); |
0 | 159 |
DrawWindowWidgets(w); |
160 |
} |
|
161 |
||
162 |
{ |
|
163 |
byte p = 0; |
|
2630 | 164 |
int xb = 2; |
2026 | 165 |
int y = 16; // offset from top of widget |
0 | 166 |
|
2026 | 167 |
if (w->vscroll.count == 0) { // player has no stations |
0 | 168 |
DrawString(xb, y, STR_304A_NONE, 0); |
169 |
return; |
|
170 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
171 |
|
2026 | 172 |
i += w->vscroll.pos; // offset from sorted station list of current player |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
173 |
assert(i < _num_station_sort[owner]); // at least one station must exist |
0 | 174 |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
175 |
while (i < _num_station_sort[owner]) { // do until max number of stations of owner |
2630 | 176 |
const Station* st = GetStation(_station_sort[i].index); |
177 |
uint j; |
|
178 |
int x; |
|
0 | 179 |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
180 |
assert(st->xy && st->owner == owner); |
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
|
181 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
182 |
SetDParam(0, st->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
183 |
SetDParam(1, st->facilities); |
0 | 184 |
x = DrawString(xb, y, STR_3049_0, 0) + 5; |
185 |
||
186 |
// show cargo waiting and station ratings |
|
2639 | 187 |
for (j = 0; j != NUM_CARGO; j++) { |
188 |
uint acc = GB(st->goods[j].waiting_acceptance, 0, 12); |
|
189 |
||
0 | 190 |
if (acc != 0) { |
191 |
StationsWndShowStationRating(x, y, j, acc, st->goods[j].rating); |
|
192 |
x += 10; |
|
193 |
} |
|
194 |
} |
|
195 |
y += 10; |
|
2026 | 196 |
i++; // next station |
2639 | 197 |
if (++p == w->vscroll.cap) break; // max number of stations in 1 window |
0 | 198 |
} |
199 |
} |
|
200 |
} break; |
|
201 |
case WE_CLICK: { |
|
2639 | 202 |
switch (e->click.widget) { |
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
203 |
case 3: { |
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
|
204 |
uint32 id_v = (e->click.pt.y - 15) / 10; |
0 | 205 |
|
2639 | 206 |
if (id_v >= w->vscroll.cap) return; // click out of bounds |
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
|
207 |
|
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 += 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
|
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 |
{ |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
211 |
const PlayerID owner = w->window_number; |
2630 | 212 |
const Station* st; |
213 |
||
2026 | 214 |
id_v += (owner == 0) ? 0 : _num_station_sort[owner - 1]; // first element in list |
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
|
215 |
|
2639 | 216 |
if (id_v >= _num_station_sort[owner]) return; // click out of station bound |
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
|
217 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
218 |
st = GetStation(_station_sort[id_v].index); |
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
|
219 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
220 |
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
|
221 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
222 |
ScrollMainWindowToTile(st->xy); |
0 | 223 |
} |
224 |
} break; |
|
225 |
} |
|
226 |
} break; |
|
227 |
||
228 |
case WE_4: |
|
229 |
WP(w,plstations_d).refresh_counter++; |
|
2639 | 230 |
if (WP(w,plstations_d).refresh_counter == 5) { |
0 | 231 |
WP(w,plstations_d).refresh_counter = 0; |
232 |
SetWindowDirty(w); |
|
233 |
} |
|
234 |
break; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
235 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
236 |
case WE_RESIZE: |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
237 |
w->vscroll.cap += e->sizing.diff.y / 10; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
238 |
break; |
0 | 239 |
} |
240 |
} |
|
241 |
||
242 |
static const Widget _player_stations_widgets[] = { |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
243 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
244 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 345, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
245 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON}, |
893
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
246 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 345, 14, 137, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, |
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
247 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 346, 357, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
248 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 346, 357, 126, 137, 0x0, STR_RESIZE_BUTTON}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
249 |
{ WIDGETS_END}, |
0 | 250 |
}; |
251 |
||
252 |
static const WindowDesc _player_stations_desc = { |
|
253 |
-1, -1, 358, 138, |
|
254 |
WC_STATION_LIST,0, |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
255 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 256 |
_player_stations_widgets, |
257 |
PlayerStationsWndProc |
|
258 |
}; |
|
259 |
||
260 |
||
2475 | 261 |
void ShowPlayerStations(PlayerID player) |
0 | 262 |
{ |
263 |
Window *w; |
|
264 |
||
265 |
w = AllocateWindowDescFront(&_player_stations_desc, player); |
|
2549 | 266 |
if (w != NULL) { |
0 | 267 |
w->caption_color = (byte)w->window_number; |
268 |
w->vscroll.cap = 12; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
269 |
w->resize.step_height = 10; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
270 |
w->resize.height = w->height - 10 * 7; // minimum if 5 in the list |
0 | 271 |
} |
272 |
} |
|
273 |
||
274 |
static const Widget _station_view_expanded_widgets[] = { |
|
2725
5c632bc5be28
(svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents:
2639
diff
changeset
|
275 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
276 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
277 |
{ WWT_STICKYBOX, RESIZE_NONE, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON}, |
893
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
278 |
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, |
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
279 |
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
280 |
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
281 |
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 248, 66, 197, 0x0, STR_NULL}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
282 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 63, 198, 209, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
283 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 64, 128, 198, 209, STR_3033_ACCEPTS, STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
284 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 129, 192, 198, 209, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
285 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 193, 206, 198, 209, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
286 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 207, 220, 198, 209, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP }, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
287 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 221, 234, 198, 209, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP }, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
288 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 198, 209, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
289 |
{ WIDGETS_END}, |
0 | 290 |
}; |
291 |
||
292 |
static const Widget _station_view_widgets[] = { |
|
2725
5c632bc5be28
(svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents:
2639
diff
changeset
|
293 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
294 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
295 |
{ WWT_STICKYBOX, RESIZE_NONE, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON}, |
893
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
296 |
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, |
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
297 |
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
298 |
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 248, 66, 97, 0x0, STR_NULL}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
299 |
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
300 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 63, 98, 109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
301 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 64, 128, 98, 109, STR_3032_RATINGS, STR_3054_SHOW_STATION_RATINGS}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
302 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 129, 192, 98, 109, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
303 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 193, 206, 98, 109, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
304 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 207, 220, 98, 109, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP }, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
305 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 221, 234, 98, 109, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP }, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
306 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 98, 109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
307 |
{ WIDGETS_END}, |
0 | 308 |
}; |
309 |
||
310 |
static void DrawStationViewWindow(Window *w) |
|
311 |
{ |
|
2630 | 312 |
StationID station_id = w->window_number; |
313 |
const Station* st = GetStation(station_id); |
|
314 |
uint i; |
|
315 |
uint num; |
|
0 | 316 |
int x,y; |
317 |
int pos; |
|
318 |
StringID str; |
|
319 |
||
320 |
num = 1; |
|
2639 | 321 |
for (i = 0; i != NUM_CARGO; i++) { |
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2498
diff
changeset
|
322 |
if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) { |
0 | 323 |
num++; |
2639 | 324 |
if (st->goods[i].enroute_from != station_id) num++; |
0 | 325 |
} |
326 |
} |
|
327 |
SetVScrollCount(w, num); |
|
328 |
||
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
329 |
w->disabled_state = st->owner == _local_player ? 0 : (1 << 9); |
588 | 330 |
|
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
331 |
if (!(st->facilities & FACIL_TRAIN)) SETBIT(w->disabled_state, 10); |
588 | 332 |
if (!(st->facilities & FACIL_TRUCK_STOP) && |
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
333 |
!(st->facilities & FACIL_BUS_STOP)) SETBIT(w->disabled_state, 11); |
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
334 |
if (!(st->facilities & FACIL_AIRPORT)) SETBIT(w->disabled_state, 12); |
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
335 |
if (!(st->facilities & FACIL_DOCK)) SETBIT(w->disabled_state, 13); |
588 | 336 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
337 |
SetDParam(0, st->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
338 |
SetDParam(1, st->facilities); |
0 | 339 |
DrawWindowWidgets(w); |
340 |
||
341 |
x = 2; |
|
342 |
y = 15; |
|
343 |
pos = w->vscroll.pos; |
|
344 |
||
345 |
if (--pos < 0) { |
|
346 |
str = STR_00D0_NOTHING; |
|
2639 | 347 |
for (i = 0; i != NUM_CARGO; i++) { |
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2498
diff
changeset
|
348 |
if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY; |
2639 | 349 |
} |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
350 |
SetDParam(0, str); |
0 | 351 |
DrawString(x, y, STR_0008_WAITING, 0); |
352 |
y += 10; |
|
353 |
} |
|
354 |
||
355 |
i = 0; |
|
356 |
do { |
|
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2498
diff
changeset
|
357 |
uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12); |
2639 | 358 |
if (waiting == 0) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
359 |
|
0 | 360 |
num = (waiting + 5) / 10; |
361 |
if (num != 0) { |
|
362 |
int cur_x = x; |
|
363 |
num = min(num, 23); |
|
364 |
do { |
|
365 |
DrawSprite(_cargoc.sprites[i], cur_x, y); |
|
366 |
cur_x += 10; |
|
367 |
} while (--num); |
|
368 |
} |
|
369 |
||
370 |
if ( st->goods[i].enroute_from == station_id) { |
|
371 |
if (--pos < 0) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
372 |
SetDParam(1, waiting); |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2070
diff
changeset
|
373 |
SetDParam(0, _cargoc.names_long[i]); |
0 | 374 |
DrawStringRightAligned(x + 234, y, STR_0009, 0); |
375 |
y += 10; |
|
376 |
} |
|
377 |
} else { |
|
378 |
/* enroute */ |
|
379 |
if (--pos < 0) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
380 |
SetDParam(1, waiting); |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2070
diff
changeset
|
381 |
SetDParam(0, _cargoc.names_long[i]); |
0 | 382 |
DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0); |
383 |
y += 10; |
|
384 |
} |
|
385 |
||
386 |
if (pos > -5 && --pos < 0) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
387 |
SetDParam(0, st->goods[i].enroute_from); |
0 | 388 |
DrawStringRightAligned(x + 234, y, STR_000B, 0); |
389 |
y += 10; |
|
390 |
} |
|
391 |
} |
|
2638
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2630
diff
changeset
|
392 |
} while (pos > -5 && ++i != NUM_CARGO); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
393 |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
394 |
if (IsWindowOfPrototype(w, _station_view_widgets)) { |
1556
4fd2c95e6bc4
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
395 |
char *b = _userstring; |
1329 | 396 |
|
1553
4976359e2bf9
(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
tron
parents:
1474
diff
changeset
|
397 |
b = InlineString(b, STR_000C_ACCEPTS); |
0 | 398 |
|
1556
4fd2c95e6bc4
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
399 |
for (i = 0; i != NUM_CARGO; i++) { |
4fd2c95e6bc4
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
400 |
if (b >= endof(_userstring) - 5 - 1) break; |
0 | 401 |
if (st->goods[i].waiting_acceptance & 0x8000) { |
1553
4976359e2bf9
(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
tron
parents:
1474
diff
changeset
|
402 |
b = InlineString(b, _cargoc.names_s[i]); |
1556
4fd2c95e6bc4
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
403 |
*b++ = ','; |
4fd2c95e6bc4
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
404 |
*b++ = ' '; |
0 | 405 |
} |
406 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
407 |
|
1329 | 408 |
if (b == &_userstring[3]) { |
1553
4976359e2bf9
(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
tron
parents:
1474
diff
changeset
|
409 |
b = InlineString(b, STR_00D0_NOTHING); |
4976359e2bf9
(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
tron
parents:
1474
diff
changeset
|
410 |
*b++ = '\0'; |
0 | 411 |
} else { |
1556
4fd2c95e6bc4
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
412 |
b[-2] = '\0'; |
0 | 413 |
} |
414 |
||
415 |
DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245); |
|
416 |
} else { |
|
417 |
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0); |
|
418 |
||
419 |
y = 77; |
|
2639 | 420 |
for (i = 0; i != NUM_CARGO; i++) { |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1093
diff
changeset
|
421 |
if (st->goods[i].enroute_from != INVALID_STATION) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
422 |
SetDParam(0, _cargoc.names_s[i]); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
423 |
SetDParam(2, st->goods[i].rating * 101 >> 8); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
424 |
SetDParam(1, STR_3035_APPALLING + (st->goods[i].rating >> 5)); |
0 | 425 |
DrawString(8, y, STR_303D, 0); |
426 |
y += 10; |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
||
433 |
static void StationViewWndProc(Window *w, WindowEvent *e) |
|
434 |
{ |
|
2639 | 435 |
switch (e->event) { |
0 | 436 |
case WE_PAINT: |
437 |
DrawStationViewWindow(w); |
|
438 |
break; |
|
439 |
||
440 |
case WE_CLICK: |
|
2639 | 441 |
switch (e->click.widget) { |
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
442 |
case 7: |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
443 |
ScrollMainWindowToTile(GetStation(w->window_number)->xy); |
0 | 444 |
break; |
445 |
||
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
446 |
case 8: |
0 | 447 |
SetWindowDirty(w); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
448 |
|
0 | 449 |
/* toggle height/widget set */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
450 |
if (IsWindowOfPrototype(w, _station_view_expanded_widgets)) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
451 |
AssignWidgetToWindow(w, _station_view_widgets); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
452 |
w->height = 110; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
453 |
} else { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
454 |
AssignWidgetToWindow(w, _station_view_expanded_widgets); |
893
d9e69e5060ba
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
867
diff
changeset
|
455 |
w->height = 210; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
817
diff
changeset
|
456 |
} |
0 | 457 |
|
458 |
SetWindowDirty(w); |
|
459 |
break; |
|
460 |
||
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
461 |
case 9: { |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
462 |
SetDParam(0, w->window_number); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
463 |
ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w->window_class, w->window_number); |
2026 | 464 |
} break; |
588 | 465 |
|
1809
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
466 |
case 10: { /* Show a list of scheduled trains to this station */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
467 |
const Station *st = GetStation(w->window_number); |
588 | 468 |
ShowPlayerTrains(st->owner, w->window_number); |
469 |
break; |
|
470 |
} |
|
471 |
||
1809
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
472 |
case 11: { /* Show a list of scheduled road-vehicles to this station */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
473 |
const Station *st = GetStation(w->window_number); |
588 | 474 |
ShowPlayerRoadVehicles(st->owner, w->window_number); |
475 |
break; |
|
476 |
} |
|
477 |
||
1809
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
478 |
case 12: { /* Show a list of scheduled aircraft to this station */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
479 |
const Station *st = GetStation(w->window_number); |
1809
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
480 |
/* Since oilrigs have no owners, show the scheduled aircraft of current player */ |
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
481 |
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner; |
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
482 |
ShowPlayerAircraft(owner, w->window_number); |
588 | 483 |
break; |
484 |
} |
|
485 |
||
1809
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
486 |
case 13: { /* Show a list of scheduled ships to this station */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
487 |
const Station *st = GetStation(w->window_number); |
1809
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
488 |
/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */ |
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
489 |
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner; |
f644ae658ec9
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
Darkvater
parents:
1556
diff
changeset
|
490 |
ShowPlayerShips(owner, w->window_number); |
588 | 491 |
break; |
492 |
} |
|
0 | 493 |
} |
494 |
break; |
|
495 |
||
2549 | 496 |
case WE_ON_EDIT_TEXT: |
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1809
diff
changeset
|
497 |
if (e->edittext.str[0] != '\0') { |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1809
diff
changeset
|
498 |
_cmd_text = e->edittext.str; |
2543
a6344040f735
(svn r3072) CMD_RENAME_STATION isn't interested in the tile coordinates, so don't pass them
tron
parents:
2504
diff
changeset
|
499 |
DoCommandP(0, w->window_number, 0, NULL, |
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1809
diff
changeset
|
500 |
CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1809
diff
changeset
|
501 |
} |
2549 | 502 |
break; |
588 | 503 |
|
504 |
case WE_DESTROY: { |
|
505 |
WindowNumber wno = |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
506 |
(w->window_number << 16) | GetStation(w->window_number)->owner; |
588 | 507 |
|
508 |
DeleteWindowById(WC_TRAINS_LIST, wno); |
|
509 |
DeleteWindowById(WC_ROADVEH_LIST, wno); |
|
510 |
DeleteWindowById(WC_SHIPS_LIST, wno); |
|
511 |
DeleteWindowById(WC_AIRCRAFT_LIST, wno); |
|
512 |
break; |
|
513 |
} |
|
0 | 514 |
} |
515 |
} |
|
516 |
||
517 |
||
518 |
static const WindowDesc _station_view_desc = { |
|
519 |
-1, -1, 249, 110, |
|
520 |
WC_STATION_VIEW,0, |
|
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
603
diff
changeset
|
521 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 522 |
_station_view_widgets, |
523 |
StationViewWndProc |
|
524 |
}; |
|
525 |
||
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
526 |
void ShowStationViewWindow(StationID station) |
0 | 527 |
{ |
528 |
Window *w; |
|
529 |
||
530 |
w = AllocateWindowDescFront(&_station_view_desc, station); |
|
2549 | 531 |
if (w != NULL) { |
2544 | 532 |
PlayerID owner = GetStation(w->window_number)->owner; |
533 |
if (owner != OWNER_NONE) w->caption_color = owner; |
|
0 | 534 |
w->vscroll.cap = 5; |
535 |
} |
|
536 |
} |