author | darkvater |
Mon, 06 Sep 2004 18:15:13 +0000 | |
changeset 164 | 0cbdf3c9bde1 |
parent 125 | 3716c3a69f4f |
child 174 | bd79fb899824 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "town.h" |
|
4 |
#include "window.h" |
|
5 |
#include "gfx.h" |
|
6 |
#include "viewport.h" |
|
7 |
#include "gui.h" |
|
8 |
#include "command.h" |
|
9 |
#include "player.h" |
|
10 |
||
11 |
static const Widget _town_authority_widgets[] = { |
|
12 |
{ WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
13 |
{ WWT_CAPTION, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
14 |
{ WWT_IMGBTN, 13, 0, 316, 14, 105, 0x0, 0}, |
|
15 |
{ WWT_IMGBTN, 13, 0, 305, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT}, |
|
16 |
{ WWT_SCROLLBAR, 13, 306, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
17 |
{ WWT_IMGBTN, 13, 0, 316, 158, 209, 0x0, 0}, |
|
18 |
{ WWT_PUSHTXTBTN, 13, 0, 316, 210, 221, STR_2042_DO_IT, STR_2044_CARRY_OUT_THE_HIGHLIGHTED}, |
|
19 |
{ WWT_LAST}, |
|
20 |
}; |
|
21 |
||
22 |
extern const byte _town_action_costs[8]; |
|
23 |
extern void DrawPlayerIcon(int p, int x, int y); |
|
24 |
||
25 |
static uint GetMaskOfTownActions(int *nump, Town *t) |
|
26 |
{ |
|
27 |
int32 avail, ref; |
|
28 |
int i, num; |
|
29 |
uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled. |
|
30 |
uint buttons; |
|
31 |
||
1 | 32 |
if (_local_player != OWNER_SPECTATOR) { |
0 | 33 |
// bribe option enabled? |
34 |
if (_patches.bribe) { |
|
35 |
// if unwanted, disable everything. |
|
36 |
if (t->unwanted[_local_player]) { |
|
37 |
avail_buttons = 0; |
|
38 |
} else if (t->ratings[_local_player] < 600) |
|
39 |
avail_buttons |= (1 << 7); // only bribe if less than excellent |
|
40 |
} |
|
41 |
||
42 |
// Things worth more than this are not shown |
|
43 |
avail = DEREF_PLAYER(_local_player)->player_money + _price.station_value * 200; |
|
44 |
ref = _price.build_industry >> 8; |
|
45 |
||
46 |
for(i=0,buttons=0,num=0; i != lengthof(_town_action_costs); i++,avail_buttons>>=1) { |
|
47 |
if (avail_buttons&1 && avail >= _town_action_costs[i] * ref) { |
|
48 |
SETBIT(buttons, i); |
|
49 |
num++; |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
// Disable build statue if already built |
|
54 |
if(HASBIT(t->statues, _local_player)) |
|
55 |
{ |
|
56 |
CLRBIT(buttons, 4); |
|
57 |
num--; |
|
58 |
} |
|
59 |
||
60 |
} else { |
|
61 |
// no actions available for spectator |
|
62 |
buttons = 0; |
|
63 |
num = 0; |
|
64 |
} |
|
65 |
||
66 |
if (nump) *nump = num; |
|
67 |
return buttons; |
|
68 |
} |
|
69 |
||
70 |
static int GetNthSetBit(uint32 bits, int n) |
|
71 |
{ |
|
72 |
int i = 0; |
|
73 |
if (n >= 0) { |
|
74 |
do { |
|
75 |
if (bits&1 && --n < 0) return i; |
|
76 |
i++; |
|
77 |
} while (bits>>=1); |
|
78 |
} |
|
79 |
return -1; |
|
80 |
} |
|
81 |
||
82 |
static void TownAuthorityWndProc(Window *w, WindowEvent *e) |
|
83 |
{ |
|
84 |
uint buttons; |
|
85 |
int numact; |
|
86 |
Town *t = DEREF_TOWN(w->window_number); |
|
87 |
||
88 |
switch(e->event) { |
|
89 |
case WE_PAINT: |
|
90 |
buttons = GetMaskOfTownActions(&numact, t); |
|
91 |
SetVScrollCount(w, numact + 1); |
|
92 |
||
93 |
if (WP(w,def_d).data_1 != -1 && !HASBIT(buttons, WP(w,def_d).data_1)) |
|
94 |
WP(w,def_d).data_1 = -1; |
|
95 |
||
96 |
w->disabled_state = (WP(w,def_d).data_1 == -1) ? (1 << 6) : 0; |
|
97 |
||
98 |
{ |
|
99 |
int y; |
|
100 |
Player *p; |
|
101 |
int r; |
|
102 |
StringID str; |
|
103 |
||
104 |
SET_DPARAM16(0, w->window_number); |
|
105 |
DrawWindowWidgets(w); |
|
106 |
||
107 |
DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, 0); |
|
122
6e56237f536c
(svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents:
121
diff
changeset
|
108 |
|
0 | 109 |
// Draw list of players |
110 |
y = 25; |
|
111 |
FOR_ALL_PLAYERS(p) { |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
69
diff
changeset
|
112 |
if (p->is_active && (HASBIT(t->have_ratings, p->index) || t->exclusivity==p->index)) { |
125 | 113 |
DrawPlayerIcon(p->index, 2, y); |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
69
diff
changeset
|
114 |
|
0 | 115 |
SET_DPARAM16(0, p->name_1); |
116 |
SET_DPARAM32(1, p->name_2); |
|
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
117 |
SET_DPARAM16(2, GetPlayerNameString(p->index, 3)); |
0 | 118 |
|
119 |
r = t->ratings[p->index]; |
|
120 |
(str = STR_3035_APPALLING, r <= -400) || // Apalling |
|
121 |
(str++, r <= -200) || // Very Poor |
|
122 |
(str++, r <= 0) || // Poor |
|
123 |
(str++, r <= 200) || // Mediocore |
|
124 |
(str++, r <= 400) || // Good |
|
125 |
(str++, r <= 600) || // Very Good |
|
126 |
(str++, r <= 800) || // Excellent |
|
127 |
(str++, true); // Outstanding |
|
128 |
||
16
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
129 |
/* WARNING ugly hack! |
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
130 |
GetPlayerNameString sets up (Player #) if the player is human in an extra DPARAM16 |
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
131 |
It seems that if player is non-human, nothing is set up, so param is 0. GetString doesn't like |
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
132 |
that because there is another param after it. |
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
133 |
So we'll just shift the rating one back if player is AI and all is fine |
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
134 |
*/ |
5ee72235b403
(svn r17) -Fix Player window fixes, Getstring id0 fixes, Finances window is now ok
darkvater
parents:
2
diff
changeset
|
135 |
SET_DPARAM16((IS_HUMAN_PLAYER(p->index) ? 4 : 3), str); |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
69
diff
changeset
|
136 |
DrawString(19, y, STR_2024, (t->exclusivity==p->index)?3:0); |
0 | 137 |
y+=10; |
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
// Draw actions list |
|
143 |
{ |
|
144 |
int y = 107, i; |
|
145 |
int pos = w->vscroll.pos; |
|
146 |
||
147 |
if (--pos < 0) { |
|
148 |
DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, 0); |
|
149 |
y+=10; |
|
150 |
} |
|
151 |
for(i=0; buttons; i++,buttons>>=1) { |
|
152 |
if (pos <= -5) |
|
153 |
break; |
|
154 |
||
155 |
if (buttons&1 && --pos < 0) { |
|
156 |
DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, 6); |
|
157 |
y += 10; |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
122
6e56237f536c
(svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents:
121
diff
changeset
|
161 |
|
0 | 162 |
{ |
163 |
int i; |
|
164 |
if ((i=WP(w,def_d).data_1) != -1) { |
|
165 |
SET_DPARAM32(1, (_price.build_industry >> 8) * _town_action_costs[i]); |
|
166 |
SET_DPARAM16(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i); |
|
167 |
DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + i, 313); |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
break; |
|
172 |
||
173 |
case WE_CLICK: |
|
174 |
switch(e->click.widget) { |
|
175 |
case 3: { /* listbox */ |
|
176 |
int y = (e->click.pt.y - 0x6B) / 10; |
|
177 |
if (!IS_INT_INSIDE(y, 0, 5)) |
|
178 |
return; |
|
179 |
||
180 |
y = GetNthSetBit(GetMaskOfTownActions(NULL, t), y + w->vscroll.pos - 1); |
|
181 |
if (y >= 0) { |
|
182 |
WP(w,def_d).data_1 = y; |
|
183 |
SetWindowDirty(w); |
|
184 |
} |
|
185 |
break; |
|
186 |
} |
|
187 |
||
188 |
case 6: { /* carry out the action */ |
|
189 |
DoCommandP(t->xy, w->window_number, WP(w,def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_2054_CAN_T_DO_THIS)); |
|
190 |
break; |
|
191 |
} |
|
192 |
} |
|
193 |
break; |
|
194 |
||
195 |
case WE_4: |
|
196 |
SetWindowDirty(w); |
|
197 |
break; |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
static const WindowDesc _town_authority_desc = { |
|
202 |
-1, -1, 317, 222, |
|
203 |
WC_TOWN_AUTHORITY,0, |
|
204 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
205 |
_town_authority_widgets, |
|
206 |
TownAuthorityWndProc |
|
207 |
}; |
|
208 |
||
209 |
void ShowTownAuthorityWindow(uint town) |
|
210 |
{ |
|
211 |
Window *w; |
|
212 |
||
213 |
w = AllocateWindowDescFront(&_town_authority_desc, town); |
|
214 |
if (w) { |
|
215 |
w->vscroll.cap = 5; |
|
216 |
WP(w,def_d).data_1 = -1; |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
static void TownViewWndProc(Window *w, WindowEvent *e) |
|
221 |
{ |
|
222 |
Town *t = DEREF_TOWN(w->window_number); |
|
223 |
||
224 |
switch(e->event) { |
|
225 |
case WE_PAINT: |
|
226 |
SET_DPARAM16(0, t->index); |
|
227 |
DrawWindowWidgets(w); |
|
228 |
||
229 |
SET_DPARAM32(0, t->population); |
|
230 |
SET_DPARAM32(1, t->num_houses); |
|
231 |
DrawString(2,107,STR_2006_POPULATION,0); |
|
232 |
||
233 |
SET_DPARAM16(0, t->act_pass); |
|
234 |
SET_DPARAM16(1, t->max_pass); |
|
235 |
DrawString(2,117,STR_200D_PASSENGERS_LAST_MONTH_MAX,0); |
|
236 |
||
237 |
SET_DPARAM16(0, t->act_mail); |
|
238 |
SET_DPARAM16(1, t->max_mail); |
|
239 |
DrawString(2,127,STR_200E_MAIL_LAST_MONTH_MAX,0); |
|
240 |
||
241 |
DrawWindowViewport(w); |
|
242 |
break; |
|
243 |
||
244 |
case WE_CLICK: |
|
245 |
switch(e->click.widget) { |
|
246 |
case 5: /* scroll to location */ |
|
247 |
ScrollMainWindowToTile(t->xy); |
|
248 |
break; |
|
249 |
case 6: /* town authority */ |
|
250 |
ShowTownAuthorityWindow(w->window_number); |
|
251 |
break; |
|
252 |
case 7: /* rename */ |
|
253 |
SET_DPARAM32(0, t->townnameparts); |
|
254 |
ShowQueryString(t->townnametype, STR_2007_RENAME_TOWN, 31, 130, w->window_class, w->window_number); |
|
255 |
break; |
|
256 |
case 8: /* expand town */ |
|
257 |
ExpandTown(t); |
|
258 |
break; |
|
259 |
case 9: /* delete town */ |
|
260 |
DeleteTown(t); |
|
261 |
break; |
|
262 |
} |
|
263 |
break; |
|
264 |
||
265 |
case WE_ON_EDIT_TEXT: { |
|
266 |
byte *b = e->edittext.str; |
|
267 |
if (*b == 0) |
|
268 |
return; |
|
269 |
memcpy(_decode_parameters, b, 32); |
|
270 |
DoCommandP(0, w->window_number, 0, NULL, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); |
|
271 |
} break; |
|
272 |
} |
|
273 |
} |
|
274 |
||
275 |
||
276 |
static const Widget _town_view_widgets[] = { |
|
277 |
{ WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
278 |
{ WWT_CAPTION, 13, 11, 259, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
279 |
{ WWT_IMGBTN, 13, 0, 259, 14, 105, 0x0, 0}, |
|
280 |
{ WWT_6, 13, 2, 257, 16, 103, 0x0, 0}, |
|
281 |
{ WWT_IMGBTN, 13, 0, 259, 106, 137, 0x0, 0}, |
|
282 |
{ WWT_PUSHTXTBTN, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON}, |
|
283 |
{ WWT_PUSHTXTBTN, 13, 86, 171, 138, 149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL}, |
|
284 |
{ WWT_PUSHTXTBTN, 13, 172, 259, 138, 149, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
|
285 |
{ WWT_LAST}, |
|
286 |
}; |
|
287 |
||
288 |
static const WindowDesc _town_view_desc = { |
|
289 |
-1, -1, 260, 150, |
|
290 |
WC_TOWN_VIEW,0, |
|
291 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
292 |
_town_view_widgets, |
|
293 |
TownViewWndProc |
|
294 |
}; |
|
295 |
||
296 |
static const Widget _town_view_scen_widgets[] = { |
|
297 |
{ WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
298 |
{ WWT_CAPTION, 13, 11, 184, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
299 |
{ WWT_IMGBTN, 13, 0, 259, 14, 105, 0x0}, |
|
300 |
{ WWT_6, 13, 2, 257, 16, 103, 0x0}, |
|
301 |
{ WWT_IMGBTN, 13, 0, 259, 106, 137, 0x0}, |
|
302 |
{ WWT_PUSHTXTBTN, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON}, |
|
303 |
{ WWT_EMPTY, 0, 0, 0, 0, 0, 0x0}, |
|
304 |
{ WWT_PUSHTXTBTN, 13, 185, 259, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
|
305 |
{ WWT_PUSHTXTBTN, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN}, |
|
306 |
{ WWT_PUSHTXTBTN, 13, 172, 259, 138, 149, STR_0290_DELETE, STR_0291_DELETE_THIS_TOWN_COMPLETELY}, |
|
307 |
{ WWT_LAST}, |
|
308 |
}; |
|
309 |
||
310 |
static const WindowDesc _town_view_scen_desc = { |
|
311 |
-1, -1, 260, 150, |
|
312 |
WC_TOWN_VIEW,0, |
|
313 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
314 |
_town_view_scen_widgets, |
|
315 |
TownViewWndProc |
|
316 |
}; |
|
317 |
||
318 |
void ShowTownViewWindow(uint town) |
|
319 |
{ |
|
320 |
Window *w; |
|
321 |
Town *t; |
|
322 |
||
323 |
if (_game_mode != GM_EDITOR) { |
|
324 |
w = AllocateWindowDescFront(&_town_view_desc, town); |
|
325 |
} else { |
|
326 |
w = AllocateWindowDescFront(&_town_view_scen_desc, town); |
|
327 |
} |
|
328 |
||
329 |
if (w) { |
|
330 |
w->flags4 |= WF_DISABLE_VP_SCROLL; |
|
331 |
t = DEREF_TOWN(w->window_number); |
|
332 |
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, t->xy, 1); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
static const Widget _town_directory_widgets[] = { |
|
337 |
{ WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
338 |
{ WWT_CAPTION, 13, 11, 207, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
339 |
{ WWT_PUSHTXTBTN, 13, 0, 98, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
340 |
{ WWT_PUSHTXTBTN, 13, 99, 196, 14, 25, STR_SORT_BY_POPULATION,STR_SORT_TIP}, |
|
341 |
{ WWT_IMGBTN, 13, 0, 196, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, |
|
342 |
{ WWT_SCROLLBAR, 13, 197, 207, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
343 |
{ WWT_LAST}, |
|
344 |
}; |
|
345 |
||
346 |
||
347 |
// used to get a sorted list of the towns |
|
348 |
static byte _town_sort[lengthof(_towns)]; |
|
349 |
static uint _num_town_sort; |
|
350 |
||
351 |
static char _bufcache[64]; |
|
352 |
static byte _last_town_idx; |
|
353 |
||
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:
125
diff
changeset
|
354 |
static int CDECL TownNameSorter(const void *a, const void *b) |
0 | 355 |
{ |
356 |
char buf1[64]; |
|
357 |
Town *t; |
|
358 |
byte val; |
|
359 |
int r; |
|
360 |
||
361 |
t = DEREF_TOWN(*(byte*)a); |
|
362 |
SET_DPARAM32(0, t->townnameparts); |
|
363 |
GetString(buf1, t->townnametype); |
|
364 |
||
365 |
if ( (val=*(byte*)b) != _last_town_idx) { |
|
366 |
_last_town_idx = val; |
|
367 |
t = DEREF_TOWN(val); |
|
368 |
SET_DPARAM32(0, t->townnameparts); |
|
369 |
GetString(_bufcache, t->townnametype); |
|
370 |
} |
|
371 |
||
372 |
r = strcmp(buf1, _bufcache); |
|
373 |
if (_town_sort_order & 1) r = -r; |
|
374 |
return r; |
|
375 |
} |
|
376 |
||
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:
125
diff
changeset
|
377 |
static int CDECL TownPopSorter(const void *a, const void *b) |
0 | 378 |
{ |
379 |
Town *ta = DEREF_TOWN(*(byte*)a); |
|
380 |
Town *tb = DEREF_TOWN(*(byte*)b); |
|
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:
125
diff
changeset
|
381 |
int r = ta->population - tb->population; |
0 | 382 |
if (_town_sort_order & 1) r = -r; |
383 |
return r; |
|
384 |
} |
|
385 |
||
386 |
static void MakeSortedTownList() |
|
387 |
{ |
|
388 |
Town *t; |
|
389 |
int n = 0; |
|
390 |
FOR_ALL_TOWNS(t) if(t->xy) _town_sort[n++] = t->index; |
|
391 |
_num_town_sort = n; |
|
392 |
||
393 |
_last_town_idx = 255; // used for "cache" |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
125
diff
changeset
|
394 |
qsort(_town_sort, n, sizeof(_town_sort[0]), _town_sort_order & 2 ? TownPopSorter : TownNameSorter); |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
16
diff
changeset
|
395 |
|
69 | 396 |
DEBUG(misc, 1) ("Resorting Towns list..."); |
0 | 397 |
} |
398 |
||
399 |
||
400 |
static void TownDirectoryWndProc(Window *w, WindowEvent *e) |
|
401 |
{ |
|
402 |
switch(e->event) { |
|
403 |
case WE_PAINT: { |
|
404 |
int n; |
|
405 |
uint p; |
|
406 |
Town *t; |
|
407 |
||
408 |
if (_town_sort_dirty) { |
|
409 |
_town_sort_dirty = false; |
|
410 |
MakeSortedTownList(); |
|
411 |
} |
|
412 |
||
413 |
w->vscroll.count = _num_town_sort; |
|
414 |
||
415 |
DrawWindowWidgets(w); |
|
416 |
DoDrawString(_town_sort_order & 1 ? "\xAA" : "\xA0", _town_sort_order <= 1 ? 88 : 187, 15, 0x10); |
|
417 |
||
418 |
p = w->vscroll.pos; |
|
419 |
n = 0; |
|
420 |
||
421 |
while (p < _num_town_sort) { |
|
422 |
t = DEREF_TOWN(_town_sort[p]); |
|
423 |
SET_DPARAM16(0, t->index); |
|
424 |
SET_DPARAM32(1, t->population); |
|
425 |
DrawString(2, 28+n*10, STR_2057, 0); |
|
426 |
p++; |
|
427 |
if (++n == 16) |
|
428 |
break; |
|
429 |
} |
|
430 |
} break; |
|
431 |
||
432 |
case WE_CLICK: |
|
433 |
switch(e->click.widget) { |
|
434 |
case 2: { |
|
435 |
_town_sort_order = _town_sort_order==0 ? 1 : 0; |
|
436 |
_town_sort_dirty = true; |
|
437 |
SetWindowDirty(w); |
|
438 |
} break; |
|
439 |
||
440 |
case 3: { |
|
441 |
_town_sort_order = _town_sort_order==2 ? 3 : 2; |
|
442 |
_town_sort_dirty = true; |
|
443 |
SetWindowDirty(w); |
|
444 |
} break; |
|
445 |
||
446 |
case 4: { |
|
447 |
int y = (e->click.pt.y - 28) / 10; |
|
448 |
byte p; |
|
449 |
Town *t; |
|
450 |
||
451 |
if (!IS_INT_INSIDE(y, 0, 16)) |
|
452 |
return; |
|
453 |
p = y + w->vscroll.pos; |
|
454 |
if (p < _num_town_sort) { |
|
455 |
t = DEREF_TOWN(_town_sort[p]); |
|
456 |
ScrollMainWindowToTile(t->xy); |
|
457 |
} |
|
458 |
break; |
|
459 |
} |
|
460 |
} |
|
461 |
break; |
|
462 |
||
463 |
||
464 |
case WE_4: |
|
465 |
SetWindowDirty(w); |
|
466 |
break; |
|
467 |
} |
|
468 |
} |
|
469 |
||
470 |
static const WindowDesc _town_directory_desc = { |
|
471 |
-1, -1, 208, 190, |
|
472 |
WC_TOWN_DIRECTORY,0, |
|
473 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
474 |
_town_directory_widgets, |
|
475 |
TownDirectoryWndProc |
|
476 |
}; |
|
477 |
||
478 |
||
479 |
void ShowTownDirectory() |
|
480 |
{ |
|
481 |
Window *w; |
|
482 |
||
483 |
w = AllocateWindowDescFront(&_town_directory_desc, 0); |
|
484 |
if (w) { |
|
485 |
w->vscroll.cap = 16; |
|
486 |
} |
|
487 |
} |
|
488 |
||
489 |