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