author | convert-repo |
Mon, 07 Apr 2008 16:21:55 +0000 | |
changeset 10076 | dfd70e42c4ae |
parent 9219 | d232ad03c54c |
child 10173 | 7357281c34d0 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
3 |
/** @file town_gui.cpp */ |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(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" |
8720
4e60c30e2006
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8627
diff
changeset
|
9 |
#include "viewport_func.h" |
4e60c30e2006
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8627
diff
changeset
|
10 |
#include "gfx_func.h" |
0 | 11 |
#include "gui.h" |
8603
88c5ce6a5215
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8602
diff
changeset
|
12 |
#include "window_gui.h" |
88c5ce6a5215
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8602
diff
changeset
|
13 |
#include "textbuf_gui.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
14 |
#include "command_func.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8720
diff
changeset
|
15 |
#include "player_func.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8720
diff
changeset
|
16 |
#include "player_base.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8720
diff
changeset
|
17 |
#include "player_gui.h" |
5720
cc0ceeafaa55
(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:
5682
diff
changeset
|
18 |
#include "network/network.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2070
diff
changeset
|
19 |
#include "variables.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8603
diff
changeset
|
20 |
#include "strings_func.h" |
9219
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
21 |
#include "sound_func.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
22 |
#include "economy_func.h" |
8626
440dfcd14c4a
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8617
diff
changeset
|
23 |
#include "core/alloc_func.hpp" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
24 |
#include "settings_type.h" |
0 | 25 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
26 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
27 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
28 |
|
9219
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
29 |
extern bool GenerateTowns(); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
30 |
static int _scengen_town_size = 1; // depress medium-sized towns per default |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
31 |
|
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
32 |
enum TownAuthorityWidget { |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
33 |
TWA_CLOSEBOX = 0, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
34 |
TWA_CAPTION, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
35 |
TWA_RATING_INFO, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
36 |
TWA_COMMAND_LIST, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
37 |
TWA_SCROLLBAR, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
38 |
TWA_ACTION_INFO, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
39 |
TWA_EXECUTE, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
40 |
}; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
41 |
|
0 | 42 |
static const Widget _town_authority_widgets[] = { |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
43 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // TWA_CLOSEBOX |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
44 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS}, // TWA_CAPTION |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
45 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 14, 105, 0x0, STR_NULL}, // TWA_RATING_INFO |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
46 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 304, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT}, // TWA_COMMAND_LIST |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
47 |
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 305, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // TWA_SCROLLBAR |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
48 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 158, 209, 0x0, STR_NULL}, // TWA_ACTION_INFO |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
49 |
{ 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
|
50 |
{ WIDGETS_END}, |
0 | 51 |
}; |
52 |
||
53 |
extern const byte _town_action_costs[8]; |
|
54 |
||
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
55 |
enum TownActions { |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
56 |
TACT_NONE = 0x00, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
57 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
58 |
TACT_ADVERTISE_SMALL = 0x01, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
59 |
TACT_ADVERTISE_MEDIUM = 0x02, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
60 |
TACT_ADVERTISE_LARGE = 0x04, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
61 |
TACT_ROAD_REBUILD = 0x08, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
62 |
TACT_BUILD_STATUE = 0x10, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
63 |
TACT_FOUND_BUILDINGS = 0x20, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
64 |
TACT_BUY_RIGHTS = 0x40, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
65 |
TACT_BRIBE = 0x80, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
66 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
67 |
TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
68 |
TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
69 |
TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
70 |
TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS, |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
71 |
}; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
72 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
73 |
DECLARE_ENUM_AS_BIT_SET(TownActions); |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
74 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
75 |
/** Get a list of available actions to do at a town. |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
76 |
* @param nump if not NULL add put the number of available actions in it |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
77 |
* @param pid the player that is querying the town |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
78 |
* @param t the town that is queried |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
79 |
* @return bitmasked value of enabled actions |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
80 |
*/ |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
81 |
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t) |
0 | 82 |
{ |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
83 |
int num = 0; |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
84 |
TownActions buttons = TACT_NONE; |
2639 | 85 |
|
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
86 |
/* Spectators and unwanted have no options */ |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
87 |
if (pid != PLAYER_SPECTATOR && !(_patches.bribe && t->unwanted[pid])) { |
0 | 88 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
89 |
/* Things worth more than this are not shown */ |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
90 |
Money avail = GetPlayer(pid)->player_money + _price.station_value * 200; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
91 |
Money ref = _price.build_industry >> 8; |
0 | 92 |
|
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
93 |
/* Check the action bits for validity and |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
94 |
* if they are valid add them */ |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
95 |
for (uint i = 0; i != lengthof(_town_action_costs); i++) { |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
96 |
const TownActions cur = (TownActions)(1 << i); |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
97 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
98 |
/* Is the player not able to bribe ? */ |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
99 |
if (cur == TACT_BRIBE && (!_patches.bribe || t->ratings[pid] >= RATING_BRIBE_MAXIMUM)) |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
100 |
continue; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
101 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
102 |
/* Is the player not able to buy exclusive rights ? */ |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
103 |
if (cur == TACT_BUY_RIGHTS && !_patches.exclusive_rights) |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
104 |
continue; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
105 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
106 |
/* Is the player not able to build a statue ? */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8320
diff
changeset
|
107 |
if (cur == TACT_BUILD_STATUE && HasBit(t->statues, pid)) |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
108 |
continue; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
109 |
|
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
110 |
if (avail >= _town_action_costs[i] * ref) { |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
111 |
buttons |= cur; |
0 | 112 |
num++; |
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
117 |
if (nump != NULL) *nump = num; |
0 | 118 |
return buttons; |
119 |
} |
|
120 |
||
8478
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
121 |
/** |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
122 |
* Get the position of the Nth set bit. |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
123 |
* |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
124 |
* If there is no Nth bit set return -1 |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
125 |
* |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
126 |
* @param bits The value to search in |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
127 |
* @param n The Nth set bit from which we want to know the position |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
128 |
* @return The position of the Nth set bit |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
129 |
*/ |
0 | 130 |
static int GetNthSetBit(uint32 bits, int n) |
131 |
{ |
|
132 |
if (n >= 0) { |
|
8501
66d88113ba24
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
8493
diff
changeset
|
133 |
uint i; |
66d88113ba24
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
8493
diff
changeset
|
134 |
FOR_EACH_SET_BIT(i, bits) { |
66d88113ba24
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
8493
diff
changeset
|
135 |
n--; |
8478
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
136 |
if (n < 0) return i; |
11bf86f9d6b7
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents:
8450
diff
changeset
|
137 |
} |
0 | 138 |
} |
139 |
return -1; |
|
140 |
} |
|
141 |
||
142 |
static void TownAuthorityWndProc(Window *w, WindowEvent *e) |
|
143 |
{ |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
144 |
switch (e->event) { |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
145 |
case WE_PAINT: { |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
146 |
const Town *t = GetTown(w->window_number); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
147 |
int numact; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
148 |
uint buttons = GetMaskOfTownActions(&numact, _local_player, t); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
149 |
|
0 | 150 |
SetVScrollCount(w, numact + 1); |
151 |
||
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8536
diff
changeset
|
152 |
if (WP(w, def_d).data_1 != -1 && !HasBit(buttons, WP(w,def_d).data_1)) |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8536
diff
changeset
|
153 |
WP(w, def_d).data_1 = -1; |
0 | 154 |
|
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8478
diff
changeset
|
155 |
w->SetWidgetDisabledState(6, WP(w, def_d).data_1 == -1); |
0 | 156 |
|
157 |
{ |
|
158 |
int y; |
|
4171 | 159 |
const Player *p; |
0 | 160 |
int r; |
161 |
StringID str; |
|
162 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
163 |
SetDParam(0, w->window_number); |
0 | 164 |
DrawWindowWidgets(w); |
165 |
||
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
166 |
DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING); |
122
6e56237f536c
(svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents:
121
diff
changeset
|
167 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
168 |
/* Draw list of players */ |
0 | 169 |
y = 25; |
170 |
FOR_ALL_PLAYERS(p) { |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8320
diff
changeset
|
171 |
if (p->is_active && (HasBit(t->have_ratings, p->index) || t->exclusivity == p->index)) { |
125 | 172 |
DrawPlayerIcon(p->index, 2, y); |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
69
diff
changeset
|
173 |
|
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7523
diff
changeset
|
174 |
SetDParam(0, p->index); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7523
diff
changeset
|
175 |
SetDParam(1, p->index); |
0 | 176 |
|
177 |
r = t->ratings[p->index]; |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
178 |
(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
179 |
(str++, r <= RATING_VERYPOOR) || // Very Poor |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
180 |
(str++, r <= RATING_POOR) || // Poor |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
181 |
(str++, r <= RATING_MEDIOCRE) || // Mediocore |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
182 |
(str++, r <= RATING_GOOD) || // Good |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
183 |
(str++, r <= RATING_VERYGOOD) || // Very Good |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
184 |
(str++, r <= RATING_EXCELLENT) || // Excellent |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
185 |
(str++, true); // Outstanding |
0 | 186 |
|
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7523
diff
changeset
|
187 |
SetDParam(2, str); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
188 |
if (t->exclusivity == p->index) { // red icon for player with exclusive rights |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
189 |
DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
190 |
} |
246
de179e5f7c3d
(svn r247) -Fix: Town exclusivity was not shown in town-window because stringformat ({YELLOW}) overrode colour-code. Now the exclusive player gets a red icon in front of its name
darkvater
parents:
222
diff
changeset
|
191 |
|
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
192 |
DrawString(28, y, STR_2024, TC_FROMSTRING); |
2639 | 193 |
y += 10; |
0 | 194 |
} |
195 |
} |
|
196 |
} |
|
197 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
198 |
/* Draw actions list */ |
0 | 199 |
{ |
200 |
int y = 107, i; |
|
201 |
int pos = w->vscroll.pos; |
|
202 |
||
203 |
if (--pos < 0) { |
|
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
204 |
DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING); |
2639 | 205 |
y += 10; |
0 | 206 |
} |
2639 | 207 |
for (i = 0; buttons; i++, buttons >>= 1) { |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
208 |
if (pos <= -5) break; ///< Draw only the 5 fitting lines |
0 | 209 |
|
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7882
diff
changeset
|
210 |
if ((buttons & 1) && --pos < 0) { |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
211 |
DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE); |
0 | 212 |
y += 10; |
213 |
} |
|
214 |
} |
|
215 |
} |
|
122
6e56237f536c
(svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents:
121
diff
changeset
|
216 |
|
0 | 217 |
{ |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8536
diff
changeset
|
218 |
int i = WP(w, def_d).data_1; |
2639 | 219 |
|
220 |
if (i != -1) { |
|
7498
ce6588257e8d
(svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents:
7487
diff
changeset
|
221 |
SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[i]); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
222 |
SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i); |
0 | 223 |
DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + i, 313); |
224 |
} |
|
225 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
226 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1363
diff
changeset
|
227 |
} break; |
0 | 228 |
|
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7498
diff
changeset
|
229 |
case WE_DOUBLE_CLICK: |
0 | 230 |
case WE_CLICK: |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
231 |
switch (e->we.click.widget) { |
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
232 |
case TWA_COMMAND_LIST: { |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
233 |
const Town *t = GetTown(w->window_number); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
234 |
int y = (e->we.click.pt.y - 0x6B) / 10; |
0 | 235 |
|
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
236 |
if (!IsInsideMM(y, 0, 5)) return; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
237 |
|
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
238 |
y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
239 |
if (y >= 0) { |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
240 |
WP(w, def_d).data_1 = y; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
241 |
SetWindowDirty(w); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
242 |
} |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
243 |
/* Fall through to clicking in case we are double-clicked */ |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
244 |
if (e->event != WE_DOUBLE_CLICK || y < 0) break; |
0 | 245 |
} |
246 |
||
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
247 |
case TWA_EXECUTE: |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
248 |
DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w, def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
249 |
break; |
0 | 250 |
} |
251 |
break; |
|
252 |
||
253 |
case WE_4: |
|
254 |
SetWindowDirty(w); |
|
255 |
break; |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
static const WindowDesc _town_authority_desc = { |
|
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7554
diff
changeset
|
260 |
WDP_AUTO, WDP_AUTO, 317, 222, 317, 222, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6001
diff
changeset
|
261 |
WC_TOWN_AUTHORITY, WC_NONE, |
0 | 262 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
263 |
_town_authority_widgets, |
|
264 |
TownAuthorityWndProc |
|
265 |
}; |
|
266 |
||
410 | 267 |
static void ShowTownAuthorityWindow(uint town) |
0 | 268 |
{ |
4171 | 269 |
Window *w = AllocateWindowDescFront(&_town_authority_desc, town); |
0 | 270 |
|
2639 | 271 |
if (w != NULL) { |
0 | 272 |
w->vscroll.cap = 5; |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8536
diff
changeset
|
273 |
WP(w, def_d).data_1 = -1; |
0 | 274 |
} |
275 |
} |
|
276 |
||
277 |
static void TownViewWndProc(Window *w, WindowEvent *e) |
|
278 |
{ |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
279 |
Town *t = GetTown(w->window_number); |
0 | 280 |
|
2639 | 281 |
switch (e->event) { |
9213
0fba721c4ee1
(svn r12391) -Feature: Show whether a town is a "city" in the town description title bar.
maedhros
parents:
9074
diff
changeset
|
282 |
case WE_CREATE: |
0fba721c4ee1
(svn r12391) -Feature: Show whether a town is a "city" in the town description title bar.
maedhros
parents:
9074
diff
changeset
|
283 |
if (t->larger_town) w->widget[1].data = STR_CITY; |
0fba721c4ee1
(svn r12391) -Feature: Show whether a town is a "city" in the town description title bar.
maedhros
parents:
9074
diff
changeset
|
284 |
break; |
0fba721c4ee1
(svn r12391) -Feature: Show whether a town is a "city" in the town description title bar.
maedhros
parents:
9074
diff
changeset
|
285 |
|
0 | 286 |
case WE_PAINT: |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
287 |
/* disable renaming town in network games if you are not the server */ |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8478
diff
changeset
|
288 |
w->SetWidgetDisabledState(8, _networking && !_network_server); |
891
b701cd0b20ae
(svn r1377) -Fix: only a server can rename a town in a MP game
darkvater
parents:
867
diff
changeset
|
289 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
290 |
SetDParam(0, t->index); |
0 | 291 |
DrawWindowWidgets(w); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
292 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
293 |
SetDParam(0, t->population); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
294 |
SetDParam(1, t->num_houses); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
295 |
DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
296 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
297 |
SetDParam(0, t->act_pass); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
298 |
SetDParam(1, t->max_pass); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
299 |
DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING); |
0 | 300 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
301 |
SetDParam(0, t->act_mail); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
302 |
SetDParam(1, t->max_mail); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
303 |
DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
304 |
|
0 | 305 |
DrawWindowViewport(w); |
306 |
break; |
|
307 |
||
308 |
case WE_CLICK: |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
309 |
switch (e->we.click.widget) { |
2639 | 310 |
case 6: /* scroll to location */ |
311 |
ScrollMainWindowToTile(t->xy); |
|
312 |
break; |
|
313 |
||
314 |
case 7: /* town authority */ |
|
315 |
ShowTownAuthorityWindow(w->window_number); |
|
316 |
break; |
|
317 |
||
318 |
case 8: /* rename */ |
|
319 |
SetDParam(0, w->window_number); |
|
5682
eeddbbacd4ac
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5568
diff
changeset
|
320 |
ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL); |
2639 | 321 |
break; |
322 |
||
323 |
case 9: /* expand town */ |
|
324 |
ExpandTown(t); |
|
325 |
break; |
|
326 |
||
327 |
case 10: /* delete town */ |
|
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7837
diff
changeset
|
328 |
delete t; |
2639 | 329 |
break; |
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
330 |
} break; |
0 | 331 |
|
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2406
diff
changeset
|
332 |
case WE_ON_EDIT_TEXT: |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
333 |
if (e->we.edittext.str[0] != '\0') { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
334 |
_cmd_text = e->we.edittext.str; |
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1803
diff
changeset
|
335 |
DoCommandP(0, w->window_number, 0, NULL, |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1803
diff
changeset
|
336 |
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1803
diff
changeset
|
337 |
} |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2406
diff
changeset
|
338 |
break; |
0 | 339 |
} |
340 |
} |
|
341 |
||
342 |
||
343 |
static const Widget _town_view_widgets[] = { |
|
4344
5d0e40cd67b9
(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
|
344 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
5d0e40cd67b9
(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
|
345 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 247, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
5d0e40cd67b9
(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
|
346 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
347 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL}, |
4939
ede0f6777b3c
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
348 |
{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
349 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL}, |
4344
5d0e40cd67b9
(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
|
350 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON}, |
5d0e40cd67b9
(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
|
351 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL}, |
5d0e40cd67b9
(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
|
352 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
353 |
{ WIDGETS_END}, |
0 | 354 |
}; |
355 |
||
356 |
static const WindowDesc _town_view_desc = { |
|
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7554
diff
changeset
|
357 |
WDP_AUTO, WDP_AUTO, 260, 150, 260, 150, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6001
diff
changeset
|
358 |
WC_TOWN_VIEW, WC_NONE, |
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
727
diff
changeset
|
359 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 360 |
_town_view_widgets, |
361 |
TownViewWndProc |
|
362 |
}; |
|
363 |
||
364 |
static const Widget _town_view_scen_widgets[] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4299
diff
changeset
|
365 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
5d0e40cd67b9
(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
|
366 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 172, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
367 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
368 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL}, |
4939
ede0f6777b3c
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
369 |
{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
370 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL}, |
4344
5d0e40cd67b9
(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
|
371 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON}, |
5d0e40cd67b9
(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
|
372 |
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, |
5d0e40cd67b9
(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
|
373 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 173, 247, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME}, |
5d0e40cd67b9
(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
|
374 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN}, |
5d0e40cd67b9
(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
|
375 |
{ 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
|
376 |
{ WIDGETS_END}, |
0 | 377 |
}; |
378 |
||
379 |
static const WindowDesc _town_view_scen_desc = { |
|
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7554
diff
changeset
|
380 |
WDP_AUTO, WDP_AUTO, 260, 150, 260, 150, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6001
diff
changeset
|
381 |
WC_TOWN_VIEW, WC_NONE, |
758
bd9e868b9fae
(svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents:
727
diff
changeset
|
382 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 383 |
_town_view_scen_widgets, |
384 |
TownViewWndProc |
|
385 |
}; |
|
386 |
||
3349
1ad72db34298
(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
|
387 |
void ShowTownViewWindow(TownID town) |
0 | 388 |
{ |
389 |
Window *w; |
|
390 |
||
391 |
if (_game_mode != GM_EDITOR) { |
|
392 |
w = AllocateWindowDescFront(&_town_view_desc, town); |
|
393 |
} else { |
|
394 |
w = AllocateWindowDescFront(&_town_view_scen_desc, town); |
|
395 |
} |
|
396 |
||
2639 | 397 |
if (w != NULL) { |
0 | 398 |
w->flags4 |= WF_DISABLE_VP_SCROLL; |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6918
diff
changeset
|
399 |
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, ZOOM_LVL_TOWN); |
0 | 400 |
} |
401 |
} |
|
402 |
||
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
403 |
enum TownDirectoryWidget { |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
404 |
TDW_SORTNAME = 3, |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
405 |
TDW_SORTPOPULATION, |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
406 |
TDW_CENTERTOWN, |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
407 |
}; |
0 | 408 |
static const Widget _town_directory_widgets[] = { |
4344
5d0e40cd67b9
(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_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
5d0e40cd67b9
(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_CAPTION, RESIZE_NONE, 13, 11, 195, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
5d0e40cd67b9
(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_STICKYBOX, RESIZE_NONE, 13, 196, 207, 0, 13, 0x0, STR_STICKY_BUTTON}, |
5d0e40cd67b9
(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
|
412 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 98, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, |
5d0e40cd67b9
(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_PUSHTXTBTN, RESIZE_NONE, 13, 99, 195, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
414 |
{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 195, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, |
4344
5d0e40cd67b9
(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_SCROLLBAR, RESIZE_BOTTOM, 13, 196, 207, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4913
diff
changeset
|
416 |
{ WWT_PANEL, RESIZE_TB, 13, 0, 195, 190, 201, 0x0, STR_NULL}, |
4344
5d0e40cd67b9
(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
|
417 |
{ 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
|
418 |
{ WIDGETS_END}, |
0 | 419 |
}; |
420 |
||
421 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6573
diff
changeset
|
422 |
/* used to get a sorted list of the towns */ |
0 | 423 |
static uint _num_town_sort; |
424 |
||
425 |
static char _bufcache[64]; |
|
4277
3539bd14f023
(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
|
426 |
static const Town* _last_town; |
0 | 427 |
|
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
|
428 |
static int CDECL TownNameSorter(const void *a, const void *b) |
0 | 429 |
{ |
4277
3539bd14f023
(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
|
430 |
const Town* ta = *(const Town**)a; |
3539bd14f023
(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
|
431 |
const Town* tb = *(const Town**)b; |
0 | 432 |
char buf1[64]; |
433 |
int r; |
|
434 |
||
4416
e0e9a72882d0
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4354
diff
changeset
|
435 |
SetDParam(0, ta->index); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
436 |
GetString(buf1, STR_TOWN, lastof(buf1)); |
0 | 437 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1093
diff
changeset
|
438 |
/* If 'b' is the same town as in the last round, use the cached value |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1093
diff
changeset
|
439 |
* We do this to speed stuff up ('b' is called with the same value a lot of |
4277
3539bd14f023
(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 |
* times after eachother) */ |
3539bd14f023
(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
|
441 |
if (tb != _last_town) { |
3539bd14f023
(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
|
442 |
_last_town = tb; |
4416
e0e9a72882d0
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4354
diff
changeset
|
443 |
SetDParam(0, tb->index); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
444 |
GetString(_bufcache, STR_TOWN, lastof(_bufcache)); |
0 | 445 |
} |
446 |
||
447 |
r = strcmp(buf1, _bufcache); |
|
448 |
if (_town_sort_order & 1) r = -r; |
|
449 |
return r; |
|
450 |
} |
|
451 |
||
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
|
452 |
static int CDECL TownPopSorter(const void *a, const void *b) |
0 | 453 |
{ |
4277
3539bd14f023
(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
|
454 |
const Town* ta = *(const Town**)a; |
3539bd14f023
(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
|
455 |
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
|
456 |
int r = ta->population - tb->population; |
0 | 457 |
if (_town_sort_order & 1) r = -r; |
458 |
return r; |
|
459 |
} |
|
460 |
||
6573 | 461 |
static void MakeSortedTownList() |
0 | 462 |
{ |
2630 | 463 |
const Town* t; |
2639 | 464 |
uint n = 0; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
465 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
466 |
/* Create array for sorting */ |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
467 |
_town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
468 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
469 |
FOR_ALL_TOWNS(t) _town_sort[n++] = t; |
821
4af53631a47a
(svn r1292) -Codechange: also updated the town/industry sort-list to be uint16 compatible
truelight
parents:
758
diff
changeset
|
470 |
|
0 | 471 |
_num_town_sort = n; |
472 |
||
4277
3539bd14f023
(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
|
473 |
_last_town = NULL; // used for "cache" |
3539bd14f023
(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
|
474 |
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
|
475 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
476 |
DEBUG(misc, 3, "Resorting towns list"); |
0 | 477 |
} |
478 |
||
479 |
||
480 |
static void TownDirectoryWndProc(Window *w, WindowEvent *e) |
|
481 |
{ |
|
2639 | 482 |
switch (e->event) { |
0 | 483 |
case WE_PAINT: { |
484 |
if (_town_sort_dirty) { |
|
485 |
_town_sort_dirty = false; |
|
486 |
MakeSortedTownList(); |
|
487 |
} |
|
488 |
||
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
|
489 |
SetVScrollCount(w, _num_town_sort); |
0 | 490 |
|
491 |
DrawWindowWidgets(w); |
|
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
492 |
DrawSortButtonState(w, (_town_sort_order <= 1) ? TDW_SORTNAME : TDW_SORTPOPULATION, _town_sort_order & 1 ? SBS_DOWN : SBS_UP); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
493 |
|
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
|
494 |
{ |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
495 |
int n = 0; |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
496 |
uint16 i = w->vscroll.pos; |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
497 |
int y = 28; |
0 | 498 |
|
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
|
499 |
while (i < _num_town_sort) { |
4277
3539bd14f023
(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
|
500 |
const Town* t = _town_sort[i]; |
174
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
501 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
502 |
assert(t->xy); |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
503 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
504 |
SetDParam(0, t->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
505 |
SetDParam(1, t->population); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
506 |
DrawString(2, y, STR_2057, TC_FROMSTRING); |
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
|
507 |
|
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
508 |
y += 10; |
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
509 |
i++; |
2549 | 510 |
if (++n == w->vscroll.cap) break; // max number of towns in 1 window |
174
bd79fb899824
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents:
164
diff
changeset
|
511 |
} |
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1005
diff
changeset
|
512 |
SetDParam(0, GetWorldPopulation()); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8153
diff
changeset
|
513 |
DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING); |
0 | 514 |
} |
515 |
} break; |
|
516 |
||
517 |
case WE_CLICK: |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
518 |
switch (e->we.click.widget) { |
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
519 |
case TDW_SORTNAME: { /* Sort by Name ascending/descending */ |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
520 |
_town_sort_order = (_town_sort_order == 0) ? 1 : 0; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
521 |
_town_sort_dirty = true; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
522 |
SetWindowDirty(w); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
523 |
} break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
524 |
|
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
525 |
case TDW_SORTPOPULATION: { /* Sort by Population ascending/descending */ |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
526 |
_town_sort_order = (_town_sort_order == 2) ? 3 : 2; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
527 |
_town_sort_dirty = true; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
528 |
SetWindowDirty(w); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
529 |
} break; |
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
|
530 |
|
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
531 |
case TDW_CENTERTOWN: { /* Click on Town Matrix */ |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
532 |
const Town* t; |
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
|
533 |
|
9074
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
534 |
uint16 id_v = (e->we.click.pt.y - 28) / 10; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
535 |
|
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
536 |
if (id_v >= w->vscroll.cap) return; // click out of bounds |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
537 |
|
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
538 |
id_v += w->vscroll.pos; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
539 |
|
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
540 |
if (id_v >= _num_town_sort) return; // click out of town bounds |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
541 |
|
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
542 |
t = _town_sort[id_v]; |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
543 |
assert(t->xy); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
544 |
ScrollMainWindowToTile(t->xy); |
a2c95cd8a7e4
(svn r12159) -Codechange: Enumify some widget magical numbers
belugas
parents:
8845
diff
changeset
|
545 |
} break; |
0 | 546 |
} |
547 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
548 |
|
0 | 549 |
case WE_4: |
550 |
SetWindowDirty(w); |
|
551 |
break; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
552 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
553 |
case WE_RESIZE: |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4434
diff
changeset
|
554 |
w->vscroll.cap += e->we.sizing.diff.y / 10; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
555 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
556 |
} |
0 | 557 |
} |
558 |
||
559 |
static const WindowDesc _town_directory_desc = { |
|
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7554
diff
changeset
|
560 |
WDP_AUTO, WDP_AUTO, 208, 202, 208, 202, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6001
diff
changeset
|
561 |
WC_TOWN_DIRECTORY, WC_NONE, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
562 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 563 |
_town_directory_widgets, |
564 |
TownDirectoryWndProc |
|
565 |
}; |
|
566 |
||
567 |
||
6573 | 568 |
void ShowTownDirectory() |
0 | 569 |
{ |
4171 | 570 |
Window *w = AllocateWindowDescFront(&_town_directory_desc, 0); |
0 | 571 |
|
2639 | 572 |
if (w != NULL) { |
0 | 573 |
w->vscroll.cap = 16; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
821
diff
changeset
|
574 |
w->resize.step_height = 10; |
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1005
diff
changeset
|
575 |
w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high |
0 | 576 |
} |
577 |
} |
|
9219
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
578 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
579 |
void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2) |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
580 |
{ |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
581 |
if (success) { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
582 |
SndPlayTileFx(SND_1F_SPLAT, tile); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
583 |
ResetObjectToPlace(); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
584 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
585 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
586 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
587 |
static void PlaceProc_Town(TileIndex tile) |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
588 |
{ |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
589 |
uint32 size = min(_scengen_town_size, (int)TSM_CITY); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
590 |
uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
591 |
DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE)); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
592 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
593 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
594 |
static const Widget _scen_edit_town_gen_widgets[] = { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
595 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
596 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
597 |
{ WWT_STICKYBOX, RESIZE_NONE, 7, 148, 159, 0, 13, 0x0, STR_STICKY_BUTTON}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
598 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 159, 14, 94, 0x0, STR_NULL}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
599 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 16, 27, STR_0234_NEW_TOWN, STR_0235_CONSTRUCT_NEW_TOWN}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
600 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 29, 40, STR_023D_RANDOM_TOWN, STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
601 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 42, 53, STR_MANY_RANDOM_TOWNS, STR_RANDOM_TOWNS_TIP}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
602 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 53, 68, 79, STR_02A1_SMALL, STR_02A4_SELECT_TOWN_SIZE}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
603 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 54, 105, 68, 79, STR_02A2_MEDIUM, STR_02A4_SELECT_TOWN_SIZE}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
604 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 106, 157, 68, 79, STR_02A3_LARGE, STR_02A4_SELECT_TOWN_SIZE}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
605 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 81, 92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
606 |
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 54, 67, STR_02A5_TOWN_SIZE, STR_NULL}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
607 |
{ WIDGETS_END}, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
608 |
}; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
609 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
610 |
static void ScenEditTownGenWndProc(Window *w, WindowEvent *e) |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
611 |
{ |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
612 |
switch (e->event) { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
613 |
case WE_PAINT: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
614 |
DrawWindowWidgets(w); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
615 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
616 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
617 |
case WE_CREATE: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
618 |
w->LowerWidget(_scengen_town_size + 7); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
619 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
620 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
621 |
case WE_CLICK: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
622 |
switch (e->we.click.widget) { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
623 |
case 4: // new town |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
624 |
HandlePlacePushButton(w, 4, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
625 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
626 |
case 5: {// random town |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
627 |
Town *t; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
628 |
uint size = min(_scengen_town_size, (int)TSM_CITY); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
629 |
TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
630 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
631 |
w->HandleButtonClick(5); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
632 |
_generating_world = true; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
633 |
t = CreateRandomTown(20, mode, size); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
634 |
_generating_world = false; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
635 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
636 |
if (t == NULL) { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
637 |
ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
638 |
} else { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
639 |
ScrollMainWindowToTile(t->xy); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
640 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
641 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
642 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
643 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
644 |
case 6: {// many random towns |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
645 |
w->HandleButtonClick(6); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
646 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
647 |
_generating_world = true; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
648 |
if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
649 |
_generating_world = false; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
650 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
651 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
652 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
653 |
case 7: case 8: case 9: case 10: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
654 |
w->RaiseWidget(_scengen_town_size + 7); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
655 |
_scengen_town_size = e->we.click.widget - 7; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
656 |
w->LowerWidget(_scengen_town_size + 7); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
657 |
SetWindowDirty(w); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
658 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
659 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
660 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
661 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
662 |
case WE_TIMEOUT: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
663 |
w->RaiseWidget(5); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
664 |
w->RaiseWidget(6); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
665 |
SetWindowDirty(w); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
666 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
667 |
case WE_PLACE_OBJ: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
668 |
_place_proc(e->we.place.tile); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
669 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
670 |
case WE_ABORT_PLACE_OBJ: |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
671 |
w->RaiseButtons(); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
672 |
w->LowerWidget(_scengen_town_size + 7); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
673 |
SetWindowDirty(w); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
674 |
break; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
675 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
676 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
677 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
678 |
static const WindowDesc _scen_edit_town_gen_desc = { |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
679 |
WDP_AUTO, WDP_AUTO, 160, 95, 160, 95, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
680 |
WC_SCEN_TOWN_GEN, WC_NONE, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
681 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
682 |
_scen_edit_town_gen_widgets, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
683 |
ScenEditTownGenWndProc, |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
684 |
}; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
685 |
|
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
686 |
void ShowBuildTownWindow() |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
687 |
{ |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
688 |
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return; |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
689 |
AllocateWindowDescFront(&_scen_edit_town_gen_desc, 0); |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
690 |
} |
d232ad03c54c
(svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents:
9213
diff
changeset
|
691 |