author | rubidium |
Mon, 19 May 2008 09:48:47 +0000 | |
changeset 9317 | f14eb8815829 |
parent 9312 | cd2d59f498e5 |
child 9325 | 40c766e7b959 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9094
diff
changeset
|
3 |
/** @file town_gui.cpp GUI for towns. */ |
6422
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" |
0 | 8 |
#include "town.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8131
diff
changeset
|
9 |
#include "viewport_func.h" |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8131
diff
changeset
|
10 |
#include "gfx_func.h" |
0 | 11 |
#include "gui.h" |
8107
bb7deea89175
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8106
diff
changeset
|
12 |
#include "window_gui.h" |
bb7deea89175
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8106
diff
changeset
|
13 |
#include "textbuf_gui.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
14 |
#include "command_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
15 |
#include "player_func.h" |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
16 |
#include "player_base.h" |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
17 |
#include "player_gui.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
|
18 |
#include "network/network.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2070
diff
changeset
|
19 |
#include "variables.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8107
diff
changeset
|
20 |
#include "strings_func.h" |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
21 |
#include "sound_func.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
22 |
#include "economy_func.h" |
8130
d2eb7d04f6e1
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8121
diff
changeset
|
23 |
#include "core/alloc_func.hpp" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
24 |
#include "settings_type.h" |
9127
14f21c5954ee
(svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents:
9116
diff
changeset
|
25 |
#include "tilehighlight_func.h" |
9164
18e971e0b44f
(svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
rubidium
parents:
9161
diff
changeset
|
26 |
#include "string_func.h" |
0 | 27 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
28 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
29 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
30 |
|
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
31 |
extern bool GenerateTowns(); |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
32 |
static int _scengen_town_size = 1; // depress medium-sized towns per default |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
33 |
|
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
34 |
enum TownAuthorityWidget { |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
35 |
TWA_CLOSEBOX = 0, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
36 |
TWA_CAPTION, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
37 |
TWA_RATING_INFO, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
38 |
TWA_COMMAND_LIST, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
39 |
TWA_SCROLLBAR, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
40 |
TWA_ACTION_INFO, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
41 |
TWA_EXECUTE, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
42 |
}; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
43 |
|
0 | 44 |
static const Widget _town_authority_widgets[] = { |
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
45 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // TWA_CLOSEBOX |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
46 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS}, // TWA_CAPTION |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
47 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 14, 105, 0x0, STR_NULL}, // TWA_RATING_INFO |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
48 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 304, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT}, // TWA_COMMAND_LIST |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
49 |
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 305, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // TWA_SCROLLBAR |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
50 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 158, 209, 0x0, STR_NULL}, // TWA_ACTION_INFO |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
51 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 316, 210, 221, STR_2042_DO_IT, STR_2044_CARRY_OUT_THE_HIGHLIGHTED}, // TWA_EXECUTE |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
52 |
{ WIDGETS_END}, |
0 | 53 |
}; |
54 |
||
55 |
extern const byte _town_action_costs[8]; |
|
56 |
||
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
57 |
enum TownActions { |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
58 |
TACT_NONE = 0x00, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
59 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
60 |
TACT_ADVERTISE_SMALL = 0x01, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
61 |
TACT_ADVERTISE_MEDIUM = 0x02, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
62 |
TACT_ADVERTISE_LARGE = 0x04, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
63 |
TACT_ROAD_REBUILD = 0x08, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
64 |
TACT_BUILD_STATUE = 0x10, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
65 |
TACT_FOUND_BUILDINGS = 0x20, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
66 |
TACT_BUY_RIGHTS = 0x40, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
67 |
TACT_BRIBE = 0x80, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
68 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
69 |
TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
70 |
TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
71 |
TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
72 |
TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS, |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
73 |
}; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
74 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
75 |
DECLARE_ENUM_AS_BIT_SET(TownActions); |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
76 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
77 |
/** 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
|
78 |
* @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
|
79 |
* @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
|
80 |
* @param t the town that is queried |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
81 |
* @return bitmasked value of enabled actions |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
82 |
*/ |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
83 |
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t) |
0 | 84 |
{ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
85 |
int num = 0; |
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
86 |
TownActions buttons = TACT_NONE; |
2639 | 87 |
|
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
88 |
/* Spectators and unwanted have no options */ |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
89 |
if (pid != PLAYER_SPECTATOR && !(_patches.bribe && t->unwanted[pid])) { |
0 | 90 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
91 |
/* Things worth more than this are not shown */ |
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
92 |
Money avail = GetPlayer(pid)->player_money + _price.station_value * 200; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
93 |
Money ref = _price.build_industry >> 8; |
0 | 94 |
|
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
95 |
/* Check the action bits for validity and |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
96 |
* if they are valid add them */ |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
97 |
for (uint i = 0; i != lengthof(_town_action_costs); i++) { |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
98 |
const TownActions cur = (TownActions)(1 << i); |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
99 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
100 |
/* Is the player not able to bribe ? */ |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
101 |
if (cur == TACT_BRIBE && (!_patches.bribe || t->ratings[pid] >= RATING_BRIBE_MAXIMUM)) |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
102 |
continue; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
103 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
104 |
/* Is the player not able to buy exclusive rights ? */ |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
105 |
if (cur == TACT_BUY_RIGHTS && !_patches.exclusive_rights) |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
106 |
continue; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
107 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
108 |
/* Is the player not able to build a statue ? */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7824
diff
changeset
|
109 |
if (cur == TACT_BUILD_STATUE && HasBit(t->statues, pid)) |
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
110 |
continue; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
111 |
|
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
112 |
if (avail >= _town_action_costs[i] * ref) { |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7386
diff
changeset
|
113 |
buttons |= cur; |
0 | 114 |
num++; |
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
119 |
if (nump != NULL) *nump = num; |
0 | 120 |
return buttons; |
121 |
} |
|
122 |
||
7982
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
123 |
/** |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
124 |
* Get the position of the Nth set bit. |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
125 |
* |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
126 |
* If there is no Nth bit set return -1 |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
127 |
* |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
128 |
* @param bits The value to search in |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
129 |
* @param n The Nth set bit from which we want to know the position |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
130 |
* @return The position of the Nth set bit |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
131 |
*/ |
0 | 132 |
static int GetNthSetBit(uint32 bits, int n) |
133 |
{ |
|
134 |
if (n >= 0) { |
|
8005
2318a0547719
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
7997
diff
changeset
|
135 |
uint i; |
2318a0547719
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
7997
diff
changeset
|
136 |
FOR_EACH_SET_BIT(i, bits) { |
2318a0547719
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
7997
diff
changeset
|
137 |
n--; |
7982
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
138 |
if (n < 0) return i; |
0d1198a12414
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
7954
diff
changeset
|
139 |
} |
0 | 140 |
} |
141 |
return -1; |
|
142 |
} |
|
143 |
||
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
144 |
struct TownAuthorityWindow : Window { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
145 |
int sel_index; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
146 |
|
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
147 |
TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) : |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
148 |
Window(desc, window_number), sel_index(-1) |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
149 |
{ |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
150 |
this->vscroll.cap = 5; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
151 |
|
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
152 |
this->FindWindowPlacementAndResize(desc); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
153 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
154 |
|
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
155 |
virtual void OnPaint() |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
156 |
{ |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
157 |
const Town *t = GetTown(this->window_number); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
158 |
int numact; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
159 |
uint buttons = GetMaskOfTownActions(&numact, _local_player, t); |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
160 |
|
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
161 |
SetVScrollCount(this, numact + 1); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
162 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
163 |
if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
164 |
this->sel_index = -1; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
165 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
166 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
167 |
this->SetWidgetDisabledState(6, this->sel_index == -1); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
168 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
169 |
SetDParam(0, this->window_number); |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9247
diff
changeset
|
170 |
this->DrawWidgets(); |
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
171 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
172 |
DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
173 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
174 |
/* Draw list of players */ |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
175 |
int y = 25; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
176 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
177 |
const Player *p; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
178 |
FOR_ALL_PLAYERS(p) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
179 |
if (p->is_active && (HasBit(t->have_ratings, p->index) || t->exclusivity == p->index)) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
180 |
DrawPlayerIcon(p->index, 2, y); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
181 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
182 |
SetDParam(0, p->index); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
183 |
SetDParam(1, p->index); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
184 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
185 |
int r = t->ratings[p->index]; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
186 |
StringID str; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
187 |
(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
188 |
(str++, r <= RATING_VERYPOOR) || // Very Poor |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
189 |
(str++, r <= RATING_POOR) || // Poor |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
190 |
(str++, r <= RATING_MEDIOCRE) || // Mediocore |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
191 |
(str++, r <= RATING_GOOD) || // Good |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
192 |
(str++, r <= RATING_VERYGOOD) || // Very Good |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
193 |
(str++, r <= RATING_EXCELLENT) || // Excellent |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
194 |
(str++, true); // Outstanding |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
195 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
196 |
SetDParam(2, str); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
197 |
if (t->exclusivity == p->index) { // red icon for player with exclusive rights |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
198 |
DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y); |
0 | 199 |
} |
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
200 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
201 |
DrawString(28, y, STR_2024, TC_FROMSTRING); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
202 |
y += 10; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
203 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
204 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
205 |
y = 107; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
206 |
int pos = this->vscroll.pos; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
207 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
208 |
if (--pos < 0) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
209 |
DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
210 |
y += 10; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
211 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
212 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
213 |
for (int i = 0; buttons; i++, buttons >>= 1) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
214 |
if (pos <= -5) break; ///< Draw only the 5 fitting lines |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
215 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
216 |
if ((buttons & 1) && --pos < 0) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
217 |
DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
218 |
y += 10; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
219 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
220 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
221 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
222 |
if (this->sel_index != -1) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
223 |
SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[this->sel_index]); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
224 |
SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + this->sel_index); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
225 |
DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + this->sel_index, 313); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
226 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
227 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
228 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
229 |
virtual void OnDoubleClick(Point pt, int widget) { HandleClick(pt, widget, true); } |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
230 |
virtual void OnClick(Point pt, int widget) { HandleClick(pt, widget, false); } |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
231 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
232 |
void HandleClick(Point pt, int widget, bool double_click) |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
233 |
{ |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
234 |
switch (widget) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
235 |
case TWA_COMMAND_LIST: { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
236 |
const Town *t = GetTown(this->window_number); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
237 |
int y = (pt.y - 0x6B) / 10; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
238 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
239 |
if (!IsInsideMM(y, 0, 5)) return; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
240 |
|
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
241 |
y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + this->vscroll.pos - 1); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
242 |
if (y >= 0) { |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
243 |
this->sel_index = y; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
244 |
this->SetDirty(); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
245 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
246 |
/* Fall through to clicking in case we are double-clicked */ |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
247 |
if (!double_click || y < 0) break; |
0 | 248 |
} |
249 |
||
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
250 |
case TWA_EXECUTE: |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
251 |
DoCommandP(GetTown(this->window_number)->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
252 |
break; |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
253 |
} |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
254 |
} |
0 | 255 |
|
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
256 |
virtual void OnHundredthTick() |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
257 |
{ |
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
258 |
this->SetDirty(); |
0 | 259 |
} |
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
260 |
}; |
0 | 261 |
|
262 |
static const WindowDesc _town_authority_desc = { |
|
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7058
diff
changeset
|
263 |
WDP_AUTO, WDP_AUTO, 317, 222, 317, 222, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
264 |
WC_TOWN_AUTHORITY, WC_NONE, |
0 | 265 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
266 |
_town_authority_widgets, |
|
267 |
}; |
|
268 |
||
410 | 269 |
static void ShowTownAuthorityWindow(uint town) |
0 | 270 |
{ |
9247
e6a5d49fd58f
(svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents:
9164
diff
changeset
|
271 |
AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town); |
0 | 272 |
} |
273 |
||
8933
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
274 |
|
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
275 |
enum TownViewWidget { |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
276 |
TVW_CAPTION = 1, |
8945
7fa9c9bf5522
(svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents:
8933
diff
changeset
|
277 |
TVW_STICKY, |
8933
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
278 |
TVW_CENTERVIEW = 6, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
279 |
TVW_SHOWAUTORITY, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
280 |
TVW_CHANGENAME, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
281 |
TVW_EXPAND, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
282 |
TVW_DELETE, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
283 |
}; |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
284 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
285 |
struct TownViewWindow : Window { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
286 |
TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
287 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
288 |
const Town *t = GetTown(this->window_number); |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
289 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
290 |
this->flags4 |= WF_DISABLE_VP_SCROLL; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
291 |
InitializeWindowViewport(this, 3, 17, 254, 86, t->xy, ZOOM_LVL_TOWN); |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
292 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
293 |
bool ingame = _game_mode != GM_EDITOR; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
294 |
if (t->larger_town) this->widget[TVW_CAPTION].data = STR_CITY; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
295 |
this->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
296 |
this->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
297 |
this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
298 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
299 |
if (ingame) { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
300 |
/* resize caption bar */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
301 |
this->widget[TVW_CAPTION].right = this->widget[TVW_STICKY].left -1; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
302 |
/* move the rename from top on scenario to bottom in game */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
303 |
this->widget[TVW_CHANGENAME].top = this->widget[TVW_EXPAND].top; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
304 |
this->widget[TVW_CHANGENAME].bottom = this->widget[TVW_EXPAND].bottom; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
305 |
this->widget[TVW_CHANGENAME].right = this->widget[TVW_STICKY].right; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
306 |
} |
9308
b2c24e2cdb7d
(svn r13176) -Fix (r13153): town window was glitchy while opening
smatz
parents:
9287
diff
changeset
|
307 |
|
b2c24e2cdb7d
(svn r13176) -Fix (r13153): town window was glitchy while opening
smatz
parents:
9287
diff
changeset
|
308 |
this->FindWindowPlacementAndResize(desc); |
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
309 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
310 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
311 |
virtual void OnPaint() |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
312 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
313 |
const Town *t = GetTown(this->window_number); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
314 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
315 |
/* disable renaming town in network games if you are not the server */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
316 |
this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
317 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
318 |
SetDParam(0, t->index); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
319 |
this->DrawWidgets(); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
320 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
321 |
SetDParam(0, t->population); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
322 |
SetDParam(1, t->num_houses); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
323 |
DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
324 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
325 |
SetDParam(0, t->act_pass); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
326 |
SetDParam(1, t->max_pass); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
327 |
DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
328 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
329 |
SetDParam(0, t->act_mail); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
330 |
SetDParam(1, t->max_mail); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
331 |
DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
332 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
333 |
this->DrawViewport(); |
0 | 334 |
} |
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
335 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
336 |
virtual void OnClick(Point pt, int widget) |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
337 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
338 |
Town *t = GetTown(this->window_number); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
339 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
340 |
switch (widget) { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
341 |
case TVW_CENTERVIEW: /* scroll to location */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
342 |
if (_ctrl_pressed) { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
343 |
ShowExtraViewPortWindow(t->xy); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
344 |
} else { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
345 |
ScrollMainWindowToTile(t->xy); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
346 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
347 |
break; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
348 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
349 |
case TVW_SHOWAUTORITY: /* town authority */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
350 |
ShowTownAuthorityWindow(this->window_number); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
351 |
break; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
352 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
353 |
case TVW_CHANGENAME: /* rename */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
354 |
SetDParam(0, this->window_number); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
355 |
ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
356 |
break; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
357 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
358 |
case TVW_EXPAND: /* expand town - only available on Scenario editor */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
359 |
ExpandTown(t); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
360 |
break; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
361 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
362 |
case TVW_DELETE: /* delete town - only available on Scenario editor */ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
363 |
delete t; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
364 |
break; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
365 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
366 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
367 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
368 |
virtual void OnQueryTextFinished(char *str) |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
369 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
370 |
if (!StrEmpty(str)) { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
371 |
_cmd_text = str; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
372 |
DoCommandP(0, this->window_number, 0, NULL, |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
373 |
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
374 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
375 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
376 |
}; |
0 | 377 |
|
378 |
||
379 |
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
|
380 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
8945
7fa9c9bf5522
(svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents:
8933
diff
changeset
|
381 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 172, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
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
|
382 |
{ 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
|
383 |
{ 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
|
384 |
{ 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
|
385 |
{ 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
|
386 |
{ 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
|
387 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL}, |
8945
7fa9c9bf5522
(svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents:
8933
diff
changeset
|
388 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 247, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
7fa9c9bf5522
(svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents:
8933
diff
changeset
|
389 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN}, |
7fa9c9bf5522
(svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents:
8933
diff
changeset
|
390 |
{ 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
|
391 |
{ WIDGETS_END}, |
0 | 392 |
}; |
393 |
||
394 |
static const WindowDesc _town_view_desc = { |
|
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7058
diff
changeset
|
395 |
WDP_AUTO, WDP_AUTO, 260, 150, 260, 150, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
396 |
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
|
397 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 398 |
_town_view_widgets, |
399 |
}; |
|
400 |
||
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
|
401 |
void ShowTownViewWindow(TownID town) |
0 | 402 |
{ |
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
403 |
AllocateWindowDescFront<TownViewWindow>(&_town_view_desc, town); |
0 | 404 |
} |
405 |
||
406 |
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
|
407 |
{ 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
|
408 |
{ 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
|
409 |
{ 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
|
410 |
{ 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
|
411 |
{ 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
|
412 |
{ 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
|
413 |
{ 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
|
414 |
{ 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
|
415 |
{ 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
|
416 |
{ WIDGETS_END}, |
0 | 417 |
}; |
418 |
||
419 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6247
diff
changeset
|
420 |
/* used to get a sorted list of the towns */ |
0 | 421 |
static uint _num_town_sort; |
422 |
||
423 |
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
|
424 |
static const Town* _last_town; |
0 | 425 |
|
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
|
426 |
static int CDECL TownNameSorter(const void *a, const void *b) |
0 | 427 |
{ |
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
|
428 |
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
|
429 |
const Town* tb = *(const Town**)b; |
0 | 430 |
char buf1[64]; |
431 |
int r; |
|
432 |
||
4416
442b18840569
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4354
diff
changeset
|
433 |
SetDParam(0, ta->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
434 |
GetString(buf1, STR_TOWN, lastof(buf1)); |
0 | 435 |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1093
diff
changeset
|
436 |
/* 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
|
437 |
* 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
|
438 |
* 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
|
439 |
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
|
440 |
_last_town = tb; |
4416
442b18840569
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4354
diff
changeset
|
441 |
SetDParam(0, tb->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
442 |
GetString(_bufcache, STR_TOWN, lastof(_bufcache)); |
0 | 443 |
} |
444 |
||
445 |
r = strcmp(buf1, _bufcache); |
|
446 |
if (_town_sort_order & 1) r = -r; |
|
447 |
return r; |
|
448 |
} |
|
449 |
||
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
|
450 |
static int CDECL TownPopSorter(const void *a, const void *b) |
0 | 451 |
{ |
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
|
452 |
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
|
453 |
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
|
454 |
int r = ta->population - tb->population; |
0 | 455 |
if (_town_sort_order & 1) r = -r; |
456 |
return r; |
|
457 |
} |
|
458 |
||
6247 | 459 |
static void MakeSortedTownList() |
0 | 460 |
{ |
2630 | 461 |
const Town* t; |
2639 | 462 |
uint n = 0; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
463 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
464 |
/* 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
|
465 |
_town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
466 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
467 |
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
|
468 |
|
0 | 469 |
_num_town_sort = n; |
470 |
||
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
|
471 |
_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
|
472 |
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
|
473 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
474 |
DEBUG(misc, 3, "Resorting towns list"); |
0 | 475 |
} |
476 |
||
477 |
||
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
478 |
struct TownDirectoryWindow : public Window { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
479 |
enum TownDirectoryWidget { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
480 |
TDW_SORTNAME = 3, |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
481 |
TDW_SORTPOPULATION, |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
482 |
TDW_CENTERTOWN, |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
483 |
}; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
484 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
485 |
TownDirectoryWindow(const WindowDesc *desc) : Window(desc, 0) |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
486 |
{ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
487 |
this->vscroll.cap = 16; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
488 |
this->resize.step_height = 10; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
489 |
this->resize.height = this->height - 10 * 6; // minimum of 10 items in the list, each item 10 high |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
490 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
491 |
this->FindWindowPlacementAndResize(desc); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
492 |
} |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
493 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
494 |
virtual void OnPaint() |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
495 |
{ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
496 |
if (_town_sort_dirty) { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
497 |
_town_sort_dirty = false; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
498 |
MakeSortedTownList(); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
499 |
} |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
500 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
501 |
SetVScrollCount(this, _num_town_sort); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
502 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
503 |
this->DrawWidgets(); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
504 |
this->DrawSortButtonState((_town_sort_order <= 1) ? TDW_SORTNAME : TDW_SORTPOPULATION, _town_sort_order & 1 ? SBS_DOWN : SBS_UP); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
505 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
506 |
{ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
507 |
int n = 0; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
508 |
uint16 i = this->vscroll.pos; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
509 |
int y = 28; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
510 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
511 |
while (i < _num_town_sort) { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
512 |
const Town* t = _town_sort[i]; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
513 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
514 |
assert(t->xy); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
515 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
516 |
SetDParam(0, t->index); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
517 |
SetDParam(1, t->population); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
518 |
DrawString(2, y, STR_2057, TC_FROMSTRING); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
519 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
520 |
y += 10; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
521 |
i++; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
522 |
if (++n == this->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
|
523 |
} |
0 | 524 |
|
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
525 |
SetDParam(0, GetWorldPopulation()); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
526 |
DrawString(3, this->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
527 |
} |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
528 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
529 |
|
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
530 |
virtual void OnClick(Point pt, int widget) |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
531 |
{ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
532 |
switch (widget) { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
533 |
case TDW_SORTNAME: /* Sort by Name ascending/descending */ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
534 |
_town_sort_order = (_town_sort_order == 0) ? 1 : 0; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
535 |
_town_sort_dirty = true; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
536 |
this->SetDirty(); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
537 |
break; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
538 |
|
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
539 |
case TDW_SORTPOPULATION: /* Sort by Population ascending/descending */ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
540 |
_town_sort_order = (_town_sort_order == 2) ? 3 : 2; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
541 |
_town_sort_dirty = true; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
542 |
this->SetDirty(); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
543 |
break; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
544 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
545 |
case TDW_CENTERTOWN: { /* Click on Town Matrix */ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
546 |
const Town* t; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
547 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
548 |
uint16 id_v = (pt.y - 28) / 10; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
549 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
550 |
if (id_v >= this->vscroll.cap) return; // click out of bounds |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
551 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
552 |
id_v += this->vscroll.pos; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
553 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
554 |
if (id_v >= _num_town_sort) return; // click out of town bounds |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
555 |
|
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
556 |
t = _town_sort[id_v]; |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
557 |
assert(t->xy); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
558 |
if (_ctrl_pressed) { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
559 |
ShowExtraViewPortWindow(t->xy); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
560 |
} else { |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
561 |
ScrollMainWindowToTile(t->xy); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
562 |
} |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
563 |
break; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
564 |
} |
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
565 |
} |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
566 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
567 |
|
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
568 |
virtual void OnHundredthTick() |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
569 |
{ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
570 |
this->SetDirty(); |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
571 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
572 |
|
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
573 |
virtual void OnResize(Point new_size, Point delta) |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
574 |
{ |
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
575 |
this->vscroll.cap += delta.y / 10; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
576 |
} |
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
577 |
}; |
0 | 578 |
|
579 |
static const WindowDesc _town_directory_desc = { |
|
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7058
diff
changeset
|
580 |
WDP_AUTO, WDP_AUTO, 208, 202, 208, 202, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
581 |
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
|
582 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 583 |
_town_directory_widgets, |
584 |
}; |
|
585 |
||
6247 | 586 |
void ShowTownDirectory() |
0 | 587 |
{ |
9312
cd2d59f498e5
(svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents:
9308
diff
changeset
|
588 |
new TownDirectoryWindow(&_town_directory_desc); |
0 | 589 |
} |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
590 |
|
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
591 |
void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2) |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
592 |
{ |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
593 |
if (success) { |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
594 |
SndPlayTileFx(SND_1F_SPLAT, tile); |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
595 |
ResetObjectToPlace(); |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
596 |
} |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
597 |
} |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
598 |
|
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
599 |
static void PlaceProc_Town(TileIndex tile) |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
600 |
{ |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
601 |
uint32 size = min(_scengen_town_size, (int)TSM_CITY); |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
602 |
uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED; |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
603 |
DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE)); |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
604 |
} |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
605 |
|
8933
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
606 |
enum TownScenarioEditorWidget { |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
607 |
TSEW_NEWTOWN = 4, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
608 |
TSEW_RANDOMTOWN, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
609 |
TSEW_MANYRANDOMTOWNS, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
610 |
TSEW_SMALLTOWN, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
611 |
TSEW_MEDIUMTOWN, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
612 |
TSEW_LARGETOWN, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
613 |
TSEW_CITY, |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
614 |
}; |
c1f075679c2e
(svn r12705) -Codechange: enumification of some more widgets
belugas
parents:
8932
diff
changeset
|
615 |
|
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
616 |
static const Widget _scen_edit_town_gen_widgets[] = { |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
617 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
618 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
619 |
{ WWT_STICKYBOX, RESIZE_NONE, 7, 148, 159, 0, 13, 0x0, STR_STICKY_BUTTON}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
620 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 159, 14, 94, 0x0, STR_NULL}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
621 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 16, 27, STR_0234_NEW_TOWN, STR_0235_CONSTRUCT_NEW_TOWN}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
622 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 29, 40, STR_023D_RANDOM_TOWN, STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
623 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 42, 53, STR_MANY_RANDOM_TOWNS, STR_RANDOM_TOWNS_TIP}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
624 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 53, 68, 79, STR_02A1_SMALL, STR_02A4_SELECT_TOWN_SIZE}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
625 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 54, 105, 68, 79, STR_02A2_MEDIUM, STR_02A4_SELECT_TOWN_SIZE}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
626 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 106, 157, 68, 79, STR_02A3_LARGE, STR_02A4_SELECT_TOWN_SIZE}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
627 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 81, 92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
628 |
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 54, 67, STR_02A5_TOWN_SIZE, STR_NULL}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
629 |
{ WIDGETS_END}, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
630 |
}; |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
631 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
632 |
struct ScenarioEditorTownGenerationWindow : Window |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
633 |
{ |
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
634 |
ScenarioEditorTownGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
635 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
636 |
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
637 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
638 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
639 |
virtual void OnPaint() |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
640 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
641 |
this->DrawWidgets(); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
642 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
643 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
644 |
virtual void OnClick(Point pt, int widget) |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
645 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
646 |
switch (widget) { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
647 |
case TSEW_NEWTOWN: |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
648 |
HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
649 |
break; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
650 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
651 |
case TSEW_RANDOMTOWN: { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
652 |
Town *t; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
653 |
uint size = min(_scengen_town_size, (int)TSM_CITY); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
654 |
TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
655 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
656 |
this->HandleButtonClick(TSEW_RANDOMTOWN); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
657 |
_generating_world = true; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
658 |
t = CreateRandomTown(20, mode, size); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
659 |
_generating_world = false; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
660 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
661 |
if (t == NULL) { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
662 |
ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
663 |
} else { |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
664 |
ScrollMainWindowToTile(t->xy); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
665 |
} |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
666 |
} break; |
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
667 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
668 |
case TSEW_MANYRANDOMTOWNS: |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
669 |
this->HandleButtonClick(TSEW_MANYRANDOMTOWNS); |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
670 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
671 |
_generating_world = true; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
672 |
if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
673 |
_generating_world = false; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
674 |
break; |
8932
c1650d1cdc31
(svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents:
8723
diff
changeset
|
675 |
|
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
676 |
case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY: |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
677 |
this->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
678 |
_scengen_town_size = widget - TSEW_SMALLTOWN; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
679 |
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
680 |
this->SetDirty(); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
681 |
break; |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
682 |
} |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
683 |
} |
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
684 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
685 |
virtual void OnTimeout() |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
686 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
687 |
this->RaiseWidget(TSEW_RANDOMTOWN); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
688 |
this->RaiseWidget(TSEW_MANYRANDOMTOWNS); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
689 |
this->SetDirty(); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
690 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
691 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
692 |
virtual void OnPlaceObject(Point pt, TileIndex tile) |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
693 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
694 |
_place_proc(tile); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
695 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
696 |
|
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
697 |
virtual void OnPlaceObjectAbort() |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
698 |
{ |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
699 |
this->RaiseButtons(); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
700 |
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
701 |
this->SetDirty(); |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
702 |
} |
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
703 |
}; |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
704 |
|
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
705 |
static const WindowDesc _scen_edit_town_gen_desc = { |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
706 |
WDP_AUTO, WDP_AUTO, 160, 95, 160, 95, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
707 |
WC_SCEN_TOWN_GEN, WC_NONE, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
708 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
709 |
_scen_edit_town_gen_widgets, |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
710 |
}; |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
711 |
|
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
712 |
void ShowBuildTownWindow() |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
713 |
{ |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
714 |
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return; |
9287
49870e5db0dd
(svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents:
9273
diff
changeset
|
715 |
AllocateWindowDescFront<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0); |
8723
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
716 |
} |
e513a23c2797
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
8717
diff
changeset
|
717 |