author | rubidium |
Fri, 20 Apr 2007 08:00:30 +0000 | |
changeset 6500 | f12678890222 |
parent 6422 | 6679df1c05ba |
child 6624 | 880e29b1f25e |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
3 |
/** @file town_gui.cpp */ |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
6 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1260
diff
changeset
|
7 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
1309
4403a69da4f8
(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
|
9 |
#include "strings.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1323
diff
changeset
|
10 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
410
diff
changeset
|
11 |
#include "table/strings.h" |
0 | 12 |
#include "town.h" |
13 |
#include "window.h" |
|
14 |
#include "gfx.h" |
|
15 |
#include "viewport.h" |
|
16 |
#include "gui.h" |
|
17 |
#include "command.h" |
|
18 |
#include "player.h" |
|
5469
7edfc643abbc
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5431
diff
changeset
|
19 |
#include "network/network.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2070
diff
changeset
|
20 |
#include "variables.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
21 |
#include "helpers.hpp" |
0 | 22 |
|
23 |
static const Widget _town_authority_widgets[] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
24 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
25 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
26 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 14, 105, 0x0, STR_NULL}, |
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
27 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 304, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
28 |
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 305, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
29 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 158, 209, 0x0, STR_NULL}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
30 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 316, 210, 221, STR_2042_DO_IT, STR_2044_CARRY_OUT_THE_HIGHLIGHTED}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
31 |
{ WIDGETS_END}, |
0 | 32 |
}; |
33 |
||
34 |
extern const byte _town_action_costs[8]; |
|
35 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
36 |
/** Get a list of available actions to do at a town. |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
37 |
* @param nump if not NULL add put the number of available actions in it |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
38 |
* @param pid the player that is querying the town |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
39 |
* @param t the town that is queried |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
40 |
* @return bitmasked value of enabled actions |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
41 |
*/ |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
42 |
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t) |
0 | 43 |
{ |
44 |
int32 avail, ref; |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
45 |
int num = 0; |
0 | 46 |
uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled. |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
47 |
uint buttons = 0; |
0 | 48 |
|
4848
45f848b46222
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4709
diff
changeset
|
49 |
if (pid != PLAYER_SPECTATOR) { |
2639 | 50 |
uint i; |
51 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
52 |
/* bribe option enabled? */ |
0 | 53 |
if (_patches.bribe) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
54 |
/* if unwanted, disable everything. */ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
55 |
if (t->unwanted[pid]) { |
0 | 56 |
avail_buttons = 0; |
2659
12f179a71b81
(svn r3201) -Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early
tron
parents:
2639
diff
changeset
|
57 |
} else if (t->ratings[pid] < RATING_BRIBE_MAXIMUM) { |
12f179a71b81
(svn r3201) -Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early
tron
parents:
2639
diff
changeset
|
58 |
SETBIT(avail_buttons, 7); // Allow bribing |
12f179a71b81
(svn r3201) -Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early
tron
parents:
2639
diff
changeset
|
59 |
} |
0 | 60 |
} |
61 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
62 |
/* Things worth more than this are not shown */ |
1962
8254df1b359b
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1891
diff
changeset
|
63 |
avail = GetPlayer(pid)->player_money + _price.station_value * 200; |
0 | 64 |
ref = _price.build_industry >> 8; |
65 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
66 |
for (i = 0; i != lengthof(_town_action_costs); i++, avail_buttons >>= 1) { |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
67 |
if (HASBIT(avail_buttons, 0) && avail >= _town_action_costs[i] * ref) { |
0 | 68 |
SETBIT(buttons, i); |
69 |
num++; |
|
70 |
} |
|
71 |
} |
|
72 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
73 |
/* Disable build statue if already built */ |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
74 |
if (HASBIT(t->statues, pid)) { |
0 | 75 |
CLRBIT(buttons, 4); |
76 |
num--; |
|
77 |
} |
|
78 |
||
79 |
} |
|
80 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
81 |
if (nump != NULL) *nump = num; |
0 | 82 |
return buttons; |
83 |
} |
|
84 |
||
85 |
static int GetNthSetBit(uint32 bits, int n) |
|
86 |
{ |
|
87 |
int i = 0; |
|
2639 | 88 |
|
0 | 89 |
if (n >= 0) { |
90 |
do { |
|
2639 | 91 |
if (bits & 1 && --n < 0) return i; |
0 | 92 |
i++; |
2639 | 93 |
} while (bits >>= 1); |
0 | 94 |
} |
95 |
return -1; |
|
96 |
} |
|
97 |
||
98 |
static void TownAuthorityWndProc(Window *w, WindowEvent *e) |
|
99 |
{ |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
100 |
switch (e->event) { |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
101 |
case WE_PAINT: { |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
102 |
const Town *t = GetTown(w->window_number); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
103 |
int numact; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
104 |
uint buttons = GetMaskOfTownActions(&numact, _local_player, t); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
105 |
|
0 | 106 |
SetVScrollCount(w, numact + 1); |
107 |
||
108 |
if (WP(w,def_d).data_1 != -1 && !HASBIT(buttons, WP(w,def_d).data_1)) |
|
109 |
WP(w,def_d).data_1 = -1; |
|
110 |
||
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4634
diff
changeset
|
111 |
SetWindowWidgetDisabledState(w, 6, WP(w, def_d).data_1 == -1); |
0 | 112 |
|
113 |
{ |
|
114 |
int y; |
|
4171 | 115 |
const Player *p; |
0 | 116 |
int r; |
117 |
StringID str; |
|
118 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
119 |
SetDParam(0, w->window_number); |
0 | 120 |
DrawWindowWidgets(w); |
121 |
||
122 |
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
|
123 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
124 |
/* Draw list of players */ |
0 | 125 |
y = 25; |
126 |
FOR_ALL_PLAYERS(p) { |
|
2639 | 127 |
if (p->is_active && (HASBIT(t->have_ratings, p->index) || t->exclusivity == p->index)) { |
125 | 128 |
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
|
129 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
130 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
131 |
SetDParam(1, p->name_2); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
132 |
SetDParam(2, GetPlayerNameString(p->index, 3)); |
0 | 133 |
|
134 |
r = t->ratings[p->index]; |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
135 |
(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
136 |
(str++, r <= RATING_VERYPOOR) || // Very Poor |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
137 |
(str++, r <= RATING_POOR) || // Poor |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
138 |
(str++, r <= RATING_MEDIOCRE) || // Mediocore |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
139 |
(str++, r <= RATING_GOOD) || // Good |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
140 |
(str++, r <= RATING_VERYGOOD) || // Very Good |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
141 |
(str++, r <= RATING_EXCELLENT) || // Excellent |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
142 |
(str++, true); // Outstanding |
0 | 143 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
1962
diff
changeset
|
144 |
SetDParam(4, str); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5609
diff
changeset
|
145 |
if (t->exclusivity == p->index) { // red icon for player with exclusive rights |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5609
diff
changeset
|
146 |
DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y); |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5609
diff
changeset
|
147 |
} |
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
|
148 |
|
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
|
149 |
DrawString(28, y, STR_2024, 0); |
2639 | 150 |
y += 10; |
0 | 151 |
} |
152 |
} |
|
153 |
} |
|
154 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
155 |
/* Draw actions list */ |
0 | 156 |
{ |
157 |
int y = 107, i; |
|
158 |
int pos = w->vscroll.pos; |
|
159 |
||
160 |
if (--pos < 0) { |
|
161 |
DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, 0); |
|
2639 | 162 |
y += 10; |
0 | 163 |
} |
2639 | 164 |
for (i = 0; buttons; i++, buttons >>= 1) { |
165 |
if (pos <= -5) break; |
|
0 | 166 |
|
167 |
if (buttons&1 && --pos < 0) { |
|
168 |
DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, 6); |
|
169 |
y += 10; |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
122
6e56237f536c
(svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents:
121
diff
changeset
|
173 |
|
0 | 174 |
{ |
2639 | 175 |
int i = WP(w,def_d).data_1; |
176 |
||
177 |
if (i != -1) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
178 |
SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[i]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
179 |
SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i); |
0 | 180 |
DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + i, 313); |
181 |
} |
|
182 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
183 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
184 |
} break; |
0 | 185 |
|
186 |
case WE_CLICK: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
187 |
switch (e->we.click.widget) { |
0 | 188 |
case 3: { /* listbox */ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
189 |
const Town *t = GetTown(w->window_number); |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
190 |
int y = (e->we.click.pt.y - 0x6B) / 10; |
2639 | 191 |
|
192 |
if (!IS_INT_INSIDE(y, 0, 5)) return; |
|
0 | 193 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
194 |
y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1); |
0 | 195 |
if (y >= 0) { |
196 |
WP(w,def_d).data_1 = y; |
|
197 |
SetWindowDirty(w); |
|
198 |
} |
|
199 |
break; |
|
200 |
} |
|
201 |
||
202 |
case 6: { /* carry out the action */ |
|
1803
8fd9dca6d2c6
(svn r2307) - Fix (regression): it was not possible to change the drive-side in the intro-game.
Darkvater
parents:
1793
diff
changeset
|
203 |
DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w,def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); |
0 | 204 |
break; |
205 |
} |
|
206 |
} |
|
207 |
break; |
|
208 |
||
209 |
case WE_4: |
|
210 |
SetWindowDirty(w); |
|
211 |
break; |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
static const WindowDesc _town_authority_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
216 |
WDP_AUTO, WDP_AUTO, 317, 222, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
217 |
WC_TOWN_AUTHORITY, WC_NONE, |
0 | 218 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
219 |
_town_authority_widgets, |
|
220 |
TownAuthorityWndProc |
|
221 |
}; |
|
222 |
||
410 | 223 |
static void ShowTownAuthorityWindow(uint town) |
0 | 224 |
{ |
4171 | 225 |
Window *w = AllocateWindowDescFront(&_town_authority_desc, town); |
0 | 226 |
|
2639 | 227 |
if (w != NULL) { |
0 | 228 |
w->vscroll.cap = 5; |
229 |
WP(w,def_d).data_1 = -1; |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
static void TownViewWndProc(Window *w, WindowEvent *e) |
|
234 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
235 |
Town *t = GetTown(w->window_number); |
0 | 236 |
|
2639 | 237 |
switch (e->event) { |
0 | 238 |
case WE_PAINT: |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
239 |
/* disable renaming town in network games if you are not the server */ |
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4634
diff
changeset
|
240 |
SetWindowWidgetDisabledState(w, 8, _networking && !_network_server); |
891
8f020b87e3c6
(svn r1377) -Fix: only a server can rename a town in a MP game
darkvater
parents:
867
diff
changeset
|
241 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
242 |
SetDParam(0, t->index); |
0 | 243 |
DrawWindowWidgets(w); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
244 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
245 |
SetDParam(0, t->population); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
246 |
SetDParam(1, t->num_houses); |
2639 | 247 |
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
|
248 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
249 |
SetDParam(0, t->act_pass); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
250 |
SetDParam(1, t->max_pass); |
2639 | 251 |
DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, 0); |
0 | 252 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
253 |
SetDParam(0, t->act_mail); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
254 |
SetDParam(1, t->max_mail); |
2639 | 255 |
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
|
256 |
|
0 | 257 |
DrawWindowViewport(w); |
258 |
break; |
|
259 |
||
260 |
case WE_CLICK: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
261 |
switch (e->we.click.widget) { |
2639 | 262 |
case 6: /* scroll to location */ |
263 |
ScrollMainWindowToTile(t->xy); |
|
264 |
break; |
|
265 |
||
266 |
case 7: /* town authority */ |
|
267 |
ShowTownAuthorityWindow(w->window_number); |
|
268 |
break; |
|
269 |
||
270 |
case 8: /* rename */ |
|
271 |
SetDParam(0, w->window_number); |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5380
diff
changeset
|
272 |
ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL); |
2639 | 273 |
break; |
274 |
||
275 |
case 9: /* expand town */ |
|
276 |
ExpandTown(t); |
|
277 |
break; |
|
278 |
||
279 |
case 10: /* delete town */ |
|
280 |
DeleteTown(t); |
|
281 |
break; |
|
0 | 282 |
} |
283 |
break; |
|
284 |
||
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2406
diff
changeset
|
285 |
case WE_ON_EDIT_TEXT: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
286 |
if (e->we.edittext.str[0] != '\0') { |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
287 |
_cmd_text = e->we.edittext.str; |
1820
d03c56850dc2
(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:
1803
diff
changeset
|
288 |
DoCommandP(0, w->window_number, 0, NULL, |
d03c56850dc2
(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:
1803
diff
changeset
|
289 |
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); |
d03c56850dc2
(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:
1803
diff
changeset
|
290 |
} |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2406
diff
changeset
|
291 |
break; |
0 | 292 |
} |
293 |
} |
|
294 |
||
295 |
||
296 |
static const Widget _town_view_widgets[] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
297 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
298 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 247, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
299 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
300 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL}, |
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
301 |
{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
302 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
303 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
304 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
305 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
306 |
{ WIDGETS_END}, |
0 | 307 |
}; |
308 |
||
309 |
static const WindowDesc _town_view_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
310 |
WDP_AUTO, WDP_AUTO, 260, 150, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
311 |
WC_TOWN_VIEW, WC_NONE, |
758
423ae0bcba07
(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:
727
diff
changeset
|
312 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 313 |
_town_view_widgets, |
314 |
TownViewWndProc |
|
315 |
}; |
|
316 |
||
317 |
static const Widget _town_view_scen_widgets[] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
318 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
319 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 172, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
320 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
321 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL}, |
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
322 |
{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
323 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
324 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
325 |
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
326 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 173, 247, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
327 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
328 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0290_DELETE, STR_0291_DELETE_THIS_TOWN_COMPLETELY}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
329 |
{ WIDGETS_END}, |
0 | 330 |
}; |
331 |
||
332 |
static const WindowDesc _town_view_scen_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
333 |
WDP_AUTO, WDP_AUTO, 260, 150, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
334 |
WC_TOWN_VIEW, WC_NONE, |
758
423ae0bcba07
(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:
727
diff
changeset
|
335 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 336 |
_town_view_scen_widgets, |
337 |
TownViewWndProc |
|
338 |
}; |
|
339 |
||
3349
716104d39983
(svn r4133) - Some miscellaneous changes (unconverted TownID in function definition, Owner instead of byte, remove obsolete member and compare waypoint index with 0 not STR_NULL)
Darkvater
parents:
2952
diff
changeset
|
340 |
void ShowTownViewWindow(TownID town) |
0 | 341 |
{ |
342 |
Window *w; |
|
343 |
||
344 |
if (_game_mode != GM_EDITOR) { |
|
345 |
w = AllocateWindowDescFront(&_town_view_desc, town); |
|
346 |
} else { |
|
347 |
w = AllocateWindowDescFront(&_town_view_scen_desc, town); |
|
348 |
} |
|
349 |
||
2639 | 350 |
if (w != NULL) { |
0 | 351 |
w->flags4 |= WF_DISABLE_VP_SCROLL; |
2639 | 352 |
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, 1); |
0 | 353 |
} |
354 |
} |
|
355 |
||
356 |
static const Widget _town_directory_widgets[] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
357 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
358 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 195, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
359 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 196, 207, 0, 13, 0x0, STR_STICKY_BUTTON}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
360 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 98, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
361 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 99, 195, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
362 |
{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 195, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
363 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 196, 207, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
364 |
{ WWT_PANEL, RESIZE_TB, 13, 0, 195, 190, 201, 0x0, STR_NULL}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
365 |
{ WWT_RESIZEBOX, RESIZE_TB, 13, 196, 207, 190, 201, 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
|
366 |
{ WIDGETS_END}, |
0 | 367 |
}; |
368 |
||
369 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
370 |
/* used to get a sorted list of the towns */ |
0 | 371 |
static uint _num_town_sort; |
372 |
||
373 |
static char _bufcache[64]; |
|
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
374 |
static const Town* _last_town; |
0 | 375 |
|
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
|
376 |
static int CDECL TownNameSorter(const void *a, const void *b) |
0 | 377 |
{ |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
378 |
const Town* ta = *(const Town**)a; |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
379 |
const Town* tb = *(const Town**)b; |
0 | 380 |
char buf1[64]; |
381 |
int r; |
|
382 |
||
4416
442b18840569
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4354
diff
changeset
|
383 |
SetDParam(0, ta->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
384 |
GetString(buf1, STR_TOWN, lastof(buf1)); |
0 | 385 |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1093
diff
changeset
|
386 |
/* If 'b' is the same town as in the last round, use the cached value |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1093
diff
changeset
|
387 |
* We do this to speed stuff up ('b' is called with the same value a lot of |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
388 |
* times after eachother) */ |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
389 |
if (tb != _last_town) { |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
390 |
_last_town = tb; |
4416
442b18840569
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4354
diff
changeset
|
391 |
SetDParam(0, tb->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
392 |
GetString(_bufcache, STR_TOWN, lastof(_bufcache)); |
0 | 393 |
} |
394 |
||
395 |
r = strcmp(buf1, _bufcache); |
|
396 |
if (_town_sort_order & 1) r = -r; |
|
397 |
return r; |
|
398 |
} |
|
399 |
||
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
|
400 |
static int CDECL TownPopSorter(const void *a, const void *b) |
0 | 401 |
{ |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
402 |
const Town* ta = *(const Town**)a; |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
403 |
const Town* tb = *(const Town**)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
|
404 |
int r = ta->population - tb->population; |
0 | 405 |
if (_town_sort_order & 1) r = -r; |
406 |
return r; |
|
407 |
} |
|
408 |
||
6247 | 409 |
static void MakeSortedTownList() |
0 | 410 |
{ |
2630 | 411 |
const Town* t; |
2639 | 412 |
uint n = 0; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
413 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
414 |
/* Create array for sorting */ |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
415 |
_town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1); |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
416 |
if (_town_sort == NULL) error("Could not allocate memory for the town-sorting-list"); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
417 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
418 |
FOR_ALL_TOWNS(t) _town_sort[n++] = t; |
821
60524daa442c
(svn r1292) -Codechange: also updated the town/industry sort-list to be uint16 compatible
truelight
parents:
758
diff
changeset
|
419 |
|
0 | 420 |
_num_town_sort = n; |
421 |
||
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
422 |
_last_town = NULL; // used for "cache" |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
423 |
qsort((void*)_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
|
424 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
425 |
DEBUG(misc, 3, "Resorting towns list"); |
0 | 426 |
} |
427 |
||
428 |
||
429 |
static void TownDirectoryWndProc(Window *w, WindowEvent *e) |
|
430 |
{ |
|
2639 | 431 |
switch (e->event) { |
0 | 432 |
case WE_PAINT: { |
433 |
if (_town_sort_dirty) { |
|
434 |
_town_sort_dirty = false; |
|
435 |
MakeSortedTownList(); |
|
436 |
} |
|
437 |
||
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
|
438 |
SetVScrollCount(w, _num_town_sort); |
0 | 439 |
|
440 |
DrawWindowWidgets(w); |
|
2406
8c873205483a
(svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents:
2187
diff
changeset
|
441 |
DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_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
|
442 |
|
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 |
{ |
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 |
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
|
445 |
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
|
446 |
int y = 28; |
0 | 447 |
|
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
|
448 |
while (i < _num_town_sort) { |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
449 |
const Town* t = _town_sort[i]; |
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
|
450 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
451 |
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
|
452 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
453 |
SetDParam(0, t->index); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
454 |
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
|
455 |
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
|
456 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
457 |
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
|
458 |
i++; |
2549 | 459 |
if (++n == w->vscroll.cap) break; // max number of towns in 1 window |
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
|
460 |
} |
1080
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1005
diff
changeset
|
461 |
SetDParam(0, GetWorldPopulation()); |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1005
diff
changeset
|
462 |
DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, 0); |
0 | 463 |
} |
464 |
} break; |
|
465 |
||
466 |
case WE_CLICK: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
467 |
switch (e->we.click.widget) { |
758
423ae0bcba07
(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:
727
diff
changeset
|
468 |
case 3: { /* Sort by Name ascending/descending */ |
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
|
469 |
_town_sort_order = (_town_sort_order == 0) ? 1 : 0; |
0 | 470 |
_town_sort_dirty = true; |
471 |
SetWindowDirty(w); |
|
472 |
} break; |
|
473 |
||
758
423ae0bcba07
(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:
727
diff
changeset
|
474 |
case 4: { /* Sort by Population ascending/descending */ |
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
|
475 |
_town_sort_order = (_town_sort_order == 2) ? 3 : 2; |
0 | 476 |
_town_sort_dirty = true; |
477 |
SetWindowDirty(w); |
|
478 |
} break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
479 |
|
758
423ae0bcba07
(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:
727
diff
changeset
|
480 |
case 5: { /* Click on Town Matrix */ |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
481 |
const Town* t; |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
482 |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
483 |
uint16 id_v = (e->we.click.pt.y - 28) / 10; |
0 | 484 |
|
2549 | 485 |
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
|
486 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
487 |
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
|
488 |
|
2549 | 489 |
if (id_v >= _num_town_sort) return; // click out of town 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
|
490 |
|
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
491 |
t = _town_sort[id_v]; |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
492 |
assert(t->xy); |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
493 |
ScrollMainWindowToTile(t->xy); |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
494 |
break; |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4171
diff
changeset
|
495 |
} |
0 | 496 |
} |
497 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
498 |
|
0 | 499 |
case WE_4: |
500 |
SetWindowDirty(w); |
|
501 |
break; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
502 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
503 |
case WE_RESIZE: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
504 |
w->vscroll.cap += e->we.sizing.diff.y / 10; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
505 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
506 |
} |
0 | 507 |
} |
508 |
||
509 |
static const WindowDesc _town_directory_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
510 |
WDP_AUTO, WDP_AUTO, 208, 202, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
511 |
WC_TOWN_DIRECTORY, WC_NONE, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
512 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 513 |
_town_directory_widgets, |
514 |
TownDirectoryWndProc |
|
515 |
}; |
|
516 |
||
517 |
||
6247 | 518 |
void ShowTownDirectory() |
0 | 519 |
{ |
4171 | 520 |
Window *w = AllocateWindowDescFront(&_town_directory_desc, 0); |
0 | 521 |
|
2639 | 522 |
if (w != NULL) { |
0 | 523 |
w->vscroll.cap = 16; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
524 |
w->resize.step_height = 10; |
1080
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1005
diff
changeset
|
525 |
w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high |
0 | 526 |
} |
527 |
} |