src/town_gui.cpp
author smatz
Sun, 25 May 2008 15:57:45 +0000
changeset 10696 efdc786ba921
parent 10682 3b753d908205
child 10703 2c998f3776d1
permissions -rw-r--r--
(svn r13244) -Fix: allow only one town directory window to be opened
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10411
diff changeset
     3
/** @file town_gui.cpp GUI for towns. */
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6573
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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"
10445
2dd7d9d0a957 (svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents: 10434
diff changeset
    25
#include "tilehighlight_func.h"
10484
e8beb2845f13 (svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
rubidium
parents: 10481
diff changeset
    26
#include "string_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    28
#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
    29
#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
    30
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
    31
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
    32
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
    33
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
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
    35
{   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
    36
{    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
    37
{      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
    38
{      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
    39
{  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
    40
{      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
    41
{ 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
    42
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
extern const byte _town_action_costs[8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
8153
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    47
enum TownActions {
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    48
	TACT_NONE             = 0x00,
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    49
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	TACT_BRIBE            = 0x80,
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    58
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    59
	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
    60
	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
    61
	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
    62
	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
    63
};
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    64
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    65
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
    66
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    67
/** 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
    68
 * @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
    69
 * @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
    70
 * @param t the town that is queried
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    71
 * @return bitmasked value of enabled actions
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    72
 */
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    73
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
{
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    75
	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
    76
	TownActions buttons = TACT_NONE;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    77
8153
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    78
	/* 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
    79
	if (pid != PLAYER_SPECTATOR && !(_patches.bribe && t->unwanted[pid])) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6573
diff changeset
    81
		/* 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
    82
		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
    83
		Money ref = _price.build_industry >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
8153
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    85
		/* 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
    86
		 * 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
    87
		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
    88
			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
    89
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    90
			/* 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
    91
			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
    92
				continue;
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    93
32f871f7e7f7 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7882
diff changeset
    94
			/* 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
    95
			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
    96
				continue;
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 build a statue ? */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8320
diff changeset
    99
			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
   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
			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
   103
				buttons |= cur;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   109
	if (nump != NULL) *nump = num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	return buttons;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
8478
11bf86f9d6b7 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 8450
diff changeset
   113
/**
11bf86f9d6b7 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 8450
diff changeset
   114
 * 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
   115
 *
11bf86f9d6b7 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 8450
diff changeset
   116
 * 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
   117
 *
11bf86f9d6b7 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 8450
diff changeset
   118
 * @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
   119
 * @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
   120
 * @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
   121
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
static int GetNthSetBit(uint32 bits, int n)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	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
   125
		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
   126
		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
   127
			n--;
8478
11bf86f9d6b7 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 8450
diff changeset
   128
			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
   129
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   134
struct TownAuthorityWindow : Window {
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   135
private:
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   136
	Town *town;
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   137
	int sel_index;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   138
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   139
	enum TownAuthorityWidget {
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   140
		TWA_CLOSEBOX = 0,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   141
		TWA_CAPTION,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   142
		TWA_RATING_INFO,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   143
		TWA_COMMAND_LIST,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   144
		TWA_SCROLLBAR,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   145
		TWA_ACTION_INFO,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   146
		TWA_EXECUTE,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   147
	};
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   148
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   149
public:
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   150
	TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) :
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   151
			Window(desc, window_number), sel_index(-1)
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   152
	{
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   153
		this->town = GetTown(this->window_number);
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   154
		this->vscroll.cap = 5;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   155
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   156
		this->FindWindowPlacementAndResize(desc);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   157
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   158
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   159
	virtual void OnPaint()
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   160
	{
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   161
		int numact;
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   162
		uint buttons = GetMaskOfTownActions(&numact, _local_player, this->town);
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   163
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   164
		SetVScrollCount(this, numact + 1);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   165
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   166
		if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   167
			this->sel_index = -1;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   168
		}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   169
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   170
		this->SetWidgetDisabledState(6, this->sel_index == -1);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   171
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   172
		SetDParam(0, this->window_number);
10595
7957c71b0dfe (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 10569
diff changeset
   173
		this->DrawWidgets();
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   174
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   175
		DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   176
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   177
		/* Draw list of players */
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   178
		int y = 25;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   179
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   180
		const Player *p;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   181
		FOR_ALL_PLAYERS(p) {
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   182
			if (p->is_active && (HasBit(this->town->have_ratings, p->index) || this->town->exclusivity == p->index)) {
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   183
				DrawPlayerIcon(p->index, 2, y);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   184
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   185
				SetDParam(0, p->index);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   186
				SetDParam(1, p->index);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   187
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   188
				int r = this->town->ratings[p->index];
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   189
				StringID str;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   190
				(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   191
				(str++,                    r <= RATING_VERYPOOR)  || // Very Poor
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   192
				(str++,                    r <= RATING_POOR)      || // Poor
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   193
				(str++,                    r <= RATING_MEDIOCRE)  || // Mediocore
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   194
				(str++,                    r <= RATING_GOOD)      || // Good
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   195
				(str++,                    r <= RATING_VERYGOOD)  || // Very Good
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   196
				(str++,                    r <= RATING_EXCELLENT) || // Excellent
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   197
				(str++,                    true);                    // Outstanding
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   198
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   199
				SetDParam(2, str);
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   200
				if (this->town->exclusivity == p->index) { // red icon for player with exclusive rights
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   201
					DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
				}
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   203
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   204
				DrawString(28, y, STR_2024, TC_FROMSTRING);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   205
				y += 10;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   206
			}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   207
		}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   208
		y = 107;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   209
		int pos = this->vscroll.pos;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   210
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   211
		if (--pos < 0) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   212
			DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   213
			y += 10;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   214
		}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   215
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   216
		for (int i = 0; buttons; i++, buttons >>= 1) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   217
			if (pos <= -5) break; ///< Draw only the 5 fitting lines
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   218
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   219
			if ((buttons & 1) && --pos < 0) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   220
				DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   221
				y += 10;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   222
			}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   223
		}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   224
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   225
		if (this->sel_index != -1) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   226
			SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[this->sel_index]);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   227
			SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + this->sel_index);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   228
			DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + this->sel_index, 313);
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   229
		}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   230
	}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   231
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   232
	virtual void OnDoubleClick(Point pt, int widget) { HandleClick(pt, widget, true); }
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   233
	virtual void OnClick(Point pt, int widget) { HandleClick(pt, widget, false); }
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   234
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   235
	void HandleClick(Point pt, int widget, bool double_click)
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   236
	{
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   237
		switch (widget) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   238
			case TWA_COMMAND_LIST: {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   239
				int y = (pt.y - 0x6B) / 10;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   240
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   241
				if (!IsInsideMM(y, 0, 5)) return;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   242
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   243
				y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, this->town), y + this->vscroll.pos - 1);
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   244
				if (y >= 0) {
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   245
					this->sel_index = y;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   246
					this->SetDirty();
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   247
				}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   248
				/* Fall through to clicking in case we are double-clicked */
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   249
				if (!double_click || y < 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   252
			case TWA_EXECUTE:
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   253
				DoCommandP(this->town->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   254
				break;
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   255
		}
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   256
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   258
	virtual void OnHundredthTick()
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   259
	{
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   260
		this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	}
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   262
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
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
   265
	WDP_AUTO, WDP_AUTO, 317, 222, 317, 222,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   266
	WC_TOWN_AUTHORITY, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	_town_authority_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 246
diff changeset
   271
static void ShowTownAuthorityWindow(uint town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
{
10569
1359ca399ddd (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 10484
diff changeset
   273
	AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   276
struct TownViewWindow : Window {
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   277
private:
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   278
	Town *town;
10174
76f8d0eb10b7 (svn r12705) -Codechange: enumification of some more widgets
belugas
parents: 10173
diff changeset
   279
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   280
	enum TownViewWidget {
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   281
		TVW_CAPTION = 1,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   282
		TVW_STICKY,
10682
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   283
		TVW_VIEWPORTPANEL,
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   284
		TVW_INFOPANEL = 5,
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   285
		TVW_CENTERVIEW,
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   286
		TVW_SHOWAUTORITY,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   287
		TVW_CHANGENAME,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   288
		TVW_EXPAND,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   289
		TVW_DELETE,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   290
	};
10174
76f8d0eb10b7 (svn r12705) -Codechange: enumification of some more widgets
belugas
parents: 10173
diff changeset
   291
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   292
public:
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   293
	TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   294
	{
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   295
		this->town = GetTown(this->window_number);
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   296
		bool ingame = _game_mode != GM_EDITOR;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   297
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   298
		this->flags4 |= WF_DISABLE_VP_SCROLL;
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   299
		InitializeWindowViewport(this, 3, 17, 254, 86, this->town->xy, ZOOM_LVL_TOWN);
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   300
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   301
		if (this->town->larger_town) this->widget[TVW_CAPTION].data = STR_CITY;
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   302
		this->SetWidgetHiddenState(TVW_DELETE, ingame);  // hide delete button on game mode
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   303
		this->SetWidgetHiddenState(TVW_EXPAND, ingame);  // hide expand button on game mode
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   304
		this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   305
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   306
		if (ingame) {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   307
			/* resize caption bar */
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   308
			this->widget[TVW_CAPTION].right = this->widget[TVW_STICKY].left -1;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   309
			/* move the rename from top on scenario to bottom in game */
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   310
			this->widget[TVW_CHANGENAME].top = this->widget[TVW_EXPAND].top;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   311
			this->widget[TVW_CHANGENAME].bottom = this->widget[TVW_EXPAND].bottom;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   312
			this->widget[TVW_CHANGENAME].right = this->widget[TVW_STICKY].right;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   313
		}
10632
d5c2eaf56253 (svn r13176) -Fix (r13153): town window was glitchy while opening
smatz
parents: 10609
diff changeset
   314
10682
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   315
		/* Space required for showing noise level information */
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   316
		if (_patches.station_noise_level) {
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   317
			ResizeWindowForWidget(this, TVW_INFOPANEL, 0, 10);
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   318
		}
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   319
10632
d5c2eaf56253 (svn r13176) -Fix (r13153): town window was glitchy while opening
smatz
parents: 10609
diff changeset
   320
		this->FindWindowPlacementAndResize(desc);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   321
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   322
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   323
	virtual void OnPaint()
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   324
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   325
		/* disable renaming town in network games if you are not the server */
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   326
		this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   327
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   328
		SetDParam(0, this->town->index);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   329
		this->DrawWidgets();
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   330
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   331
		SetDParam(0, this->town->population);
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   332
		SetDParam(1, this->town->num_houses);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   333
		DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   334
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   335
		SetDParam(0, this->town->act_pass);
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   336
		SetDParam(1, this->town->max_pass);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   337
		DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   338
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   339
		SetDParam(0, this->town->act_mail);
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   340
		SetDParam(1, this->town->max_mail);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   341
		DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   342
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   343
		this->DrawViewport();
10682
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   344
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   345
		/* only show the town noise, if the noise option is activated. */
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   346
		if (_patches.station_noise_level) {
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   347
			SetDParam(0, this->town->noise_reached);
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   348
			SetDParam(1, this->town->MaxTownNoise());
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   349
			DrawString(2, 137, STR_NOISE_IN_TOWN, 0);
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   350
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	}
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   352
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   353
	virtual void OnClick(Point pt, int widget)
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   354
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   355
		switch (widget) {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   356
			case TVW_CENTERVIEW: /* scroll to location */
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   357
				if (_ctrl_pressed) {
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   358
					ShowExtraViewPortWindow(this->town->xy);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   359
				} else {
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   360
					ScrollMainWindowToTile(this->town->xy);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   361
				}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   362
				break;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   363
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   364
			case TVW_SHOWAUTORITY: /* town authority */
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   365
				ShowTownAuthorityWindow(this->window_number);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   366
				break;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   367
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   368
			case TVW_CHANGENAME: /* rename */
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   369
				SetDParam(0, this->window_number);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   370
				ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   371
				break;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   372
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   373
			case TVW_EXPAND: /* expand town - only available on Scenario editor */
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   374
				ExpandTown(this->town);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   375
				break;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   376
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   377
			case TVW_DELETE: /* delete town - only available on Scenario editor */
10666
777224e1d482 (svn r13210) -Codechange: make town (previously named t) a private member of the different Town guis and assign it only once, at creation
belugas
parents: 10665
diff changeset
   378
				delete this->town;
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   379
				break;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   380
		}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   381
	}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   382
10682
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   383
	virtual void OnInvalidateData(int data = 0)
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   384
	{
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   385
		/* Called when setting station noise have changed, in order to resize the window */
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   386
		this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   387
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   388
		if (_patches.station_noise_level) { // adjust depending
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   389
			if (this->height == 150) { // window is smaller, needs to be bigger
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   390
				ResizeWindowForWidget(this, TVW_INFOPANEL, 0, 10);
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   391
			}
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   392
		} else {
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   393
			if (this->height != 150) { // window is bigger, needs to be smaller
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   394
				ResizeWindowForWidget(this, TVW_INFOPANEL, 0, -10);
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   395
			}
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   396
		}
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   397
	}
3b753d908205 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 10681
diff changeset
   398
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   399
	virtual void OnQueryTextFinished(char *str)
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   400
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   401
		if (!StrEmpty(str)) {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   402
			_cmd_text = str;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   403
			DoCommandP(0, this->window_number, 0, NULL,
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   404
				CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   405
		}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   406
	}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   407
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
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
   411
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
10201
3c351c28c246 (svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents: 10174
diff changeset
   412
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   172,     0,    13, STR_2005,                 STR_018C_WINDOW_TITLE_DRAG_THIS},
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
   413
{  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
   414
{      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
   415
{      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
   416
{      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
   417
{ 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
   418
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   138,   149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
10201
3c351c28c246 (svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents: 10174
diff changeset
   419
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   247,     0,    13, STR_0130_RENAME,          STR_200C_CHANGE_TOWN_NAME},
3c351c28c246 (svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents: 10174
diff changeset
   420
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   138,   149, STR_023C_EXPAND,          STR_023B_INCREASE_SIZE_OF_TOWN},
3c351c28c246 (svn r12733) -Codechange: Merge two more Widgets arrays (town views ) into one.
belugas
parents: 10174
diff changeset
   421
{ 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
   422
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
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
   426
	WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   427
	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
   428
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	_town_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
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
   432
void ShowTownViewWindow(TownID town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
{
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   434
	AllocateWindowDescFront<TownViewWindow>(&_town_view_desc, town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
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
   438
{   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
   439
{    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
   440
{  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
   441
{ 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
   442
{ 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
   443
{      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
   444
{  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
   445
{      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
   446
{  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
   447
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6573
diff changeset
   451
/* used to get a sorted list of the towns */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
static uint _num_town_sort;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
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
   455
static const Town* _last_town;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
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
   457
static int CDECL TownNameSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
{
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
   459
	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
   460
	const Town* tb = *(const Town**)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	char buf1[64];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   464
	SetDParam(0, ta->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   465
	GetString(buf1, STR_TOWN, lastof(buf1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1093
diff changeset
   467
	/* 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
   468
	 *  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
   469
	 *  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
   470
	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
   471
		_last_town = tb;
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   472
		SetDParam(0, tb->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   473
		GetString(_bufcache, STR_TOWN, lastof(_bufcache));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	r = strcmp(buf1, _bufcache);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	if (_town_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
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
   481
static int CDECL TownPopSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
{
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
   483
	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
   484
	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
   485
	int r = ta->population - tb->population;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	if (_town_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6144
diff changeset
   490
static void MakeSortedTownList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   492
	const Town* t;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   493
	uint n = 0;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   494
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   495
	/* 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
   496
	_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
   497
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   498
	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
   499
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	_num_town_sort = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
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
   502
	_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
   503
	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
   504
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   505
	DEBUG(misc, 3, "Resorting towns list");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   509
struct TownDirectoryWindow : public Window {
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   510
private:
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   511
	enum TownDirectoryWidget {
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   512
		TDW_SORTNAME = 3,
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   513
		TDW_SORTPOPULATION,
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   514
		TDW_CENTERTOWN,
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   515
	};
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   516
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   517
public:
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   518
	TownDirectoryWindow(const WindowDesc *desc) : Window(desc, 0)
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   519
	{
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   520
		this->vscroll.cap = 16;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   521
		this->resize.step_height = 10;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   522
		this->resize.height = this->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   523
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   524
		this->FindWindowPlacementAndResize(desc);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   525
	}
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   526
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   527
	virtual void OnPaint()
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   528
	{
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   529
		if (_town_sort_dirty) {
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   530
			_town_sort_dirty = false;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   531
			MakeSortedTownList();
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   532
		}
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   533
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   534
		SetVScrollCount(this, _num_town_sort);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   535
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   536
		this->DrawWidgets();
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   537
		this->DrawSortButtonState((_town_sort_order <= 1) ? TDW_SORTNAME : TDW_SORTPOPULATION, _town_sort_order & 1 ? SBS_DOWN : SBS_UP);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   538
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   539
		{
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   540
			int n = 0;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   541
			uint16 i = this->vscroll.pos;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   542
			int y = 28;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   543
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   544
			while (i < _num_town_sort) {
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   545
				const Town* t = _town_sort[i];
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   546
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   547
				assert(t->xy);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   548
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   549
				SetDParam(0, t->index);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   550
				SetDParam(1, t->population);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   551
				DrawString(2, y, STR_2057, TC_FROMSTRING);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   552
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   553
				y += 10;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   554
				i++;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   555
				if (++n == this->vscroll.cap) break; // max number of towns in 1 window
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   556
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   558
			SetDParam(0, GetWorldPopulation());
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   559
			DrawString(3, this->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   560
		}
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   561
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   562
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   563
	virtual void OnClick(Point pt, int widget)
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   564
	{
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   565
		switch (widget) {
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   566
			case TDW_SORTNAME: /* Sort by Name ascending/descending */
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   567
				_town_sort_order = (_town_sort_order == 0) ? 1 : 0;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   568
				_town_sort_dirty = true;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   569
				this->SetDirty();
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   570
				break;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   571
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   572
			case TDW_SORTPOPULATION: /* Sort by Population ascending/descending */
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   573
				_town_sort_order = (_town_sort_order == 2) ? 3 : 2;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   574
				_town_sort_dirty = true;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   575
				this->SetDirty();
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   576
				break;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   577
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   578
			case TDW_CENTERTOWN: { /* Click on Town Matrix */
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   579
				const Town* t;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   580
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   581
				uint16 id_v = (pt.y - 28) / 10;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   582
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   583
				if (id_v >= this->vscroll.cap) return; // click out of bounds
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   584
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   585
				id_v += this->vscroll.pos;
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   586
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   587
				if (id_v >= _num_town_sort) return; // click out of town bounds
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   588
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   589
				t = _town_sort[id_v];
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   590
				assert(t->xy);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   591
				if (_ctrl_pressed) {
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   592
					ShowExtraViewPortWindow(t->xy);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   593
				} else {
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   594
					ScrollMainWindowToTile(t->xy);
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   595
				}
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   596
				break;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   597
			}
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   598
		}
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   599
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   600
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   601
	virtual void OnHundredthTick()
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   602
	{
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   603
		this->SetDirty();
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   604
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   605
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   606
	virtual void OnResize(Point new_size, Point delta)
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   607
	{
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   608
		this->vscroll.cap += delta.y / 10;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   609
	}
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   610
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
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
   613
	WDP_AUTO, WDP_AUTO, 208, 202, 208, 202,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   614
	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
   615
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	_town_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6144
diff changeset
   619
void ShowTownDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
{
10696
efdc786ba921 (svn r13244) -Fix: allow only one town directory window to be opened
smatz
parents: 10682
diff changeset
   621
	if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
10636
4ce88e802272 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 10632
diff changeset
   622
	new TownDirectoryWindow(&_town_directory_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
}
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
   624
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
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
   626
{
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
	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
   628
		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
   629
		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
   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
}
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
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
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
   634
{
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
	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
   636
	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
   637
	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
   638
}
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
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
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
   641
{   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
   642
{    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
   643
{  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
   644
{      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
   645
{    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
   646
{    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
   647
{    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
   648
{    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
   649
{    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
   650
{    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
   651
{    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
   652
{      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
   653
{   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
   654
};
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
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   656
struct ScenarioEditorTownGenerationWindow : Window
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
   657
{
10665
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   658
private:
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   659
	enum TownScenarioEditorWidget {
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   660
		TSEW_NEWTOWN = 4,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   661
		TSEW_RANDOMTOWN,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   662
		TSEW_MANYRANDOMTOWNS,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   663
		TSEW_SMALLTOWN,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   664
		TSEW_MEDIUMTOWN,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   665
		TSEW_LARGETOWN,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   666
		TSEW_CITY,
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   667
	};
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   668
7c0c33da488b (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 10641
diff changeset
   669
public:
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   670
	ScenarioEditorTownGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   671
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   672
		this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
10681
3aa3de4d448b (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 10666
diff changeset
   673
		this->FindWindowPlacementAndResize(desc);
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   674
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   675
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   676
	virtual void OnPaint()
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   677
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   678
		this->DrawWidgets();
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   679
	}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   680
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   681
	virtual void OnClick(Point pt, int widget)
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   682
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   683
		switch (widget) {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   684
			case TSEW_NEWTOWN:
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   685
				HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   686
				break;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   687
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   688
			case TSEW_RANDOMTOWN: {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   689
				Town *t;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   690
				uint size = min(_scengen_town_size, (int)TSM_CITY);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   691
				TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   692
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   693
				this->HandleButtonClick(TSEW_RANDOMTOWN);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   694
				_generating_world = true;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   695
				t = CreateRandomTown(20, mode, size);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   696
				_generating_world = false;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   697
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   698
				if (t == NULL) {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   699
					ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   700
				} else {
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   701
					ScrollMainWindowToTile(t->xy);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   702
				}
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   703
			} break;
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   704
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   705
			case TSEW_MANYRANDOMTOWNS:
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   706
				this->HandleButtonClick(TSEW_MANYRANDOMTOWNS);
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
   707
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   708
				_generating_world = true;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   709
				if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   710
				_generating_world = false;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   711
				break;
10173
7357281c34d0 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 9219
diff changeset
   712
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   713
			case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY:
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   714
				this->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   715
				_scengen_town_size = widget - TSEW_SMALLTOWN;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   716
				this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   717
				this->SetDirty();
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   718
				break;
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   719
		}
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
   720
	}
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   721
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   722
	virtual void OnTimeout()
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   723
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   724
		this->RaiseWidget(TSEW_RANDOMTOWN);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   725
		this->RaiseWidget(TSEW_MANYRANDOMTOWNS);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   726
		this->SetDirty();
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   727
	}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   728
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   729
	virtual void OnPlaceObject(Point pt, TileIndex tile)
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   730
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   731
		_place_proc(tile);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   732
	}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   733
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   734
	virtual void OnPlaceObjectAbort()
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   735
	{
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   736
		this->RaiseButtons();
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   737
		this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   738
		this->SetDirty();
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   739
	}
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   740
};
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
   741
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
   742
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
   743
	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
   744
	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
   745
	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
   746
	_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
   747
};
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
   748
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
   749
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
   750
{
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
   751
	if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
10609
b6ebc6c30a83 (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 10595
diff changeset
   752
	AllocateWindowDescFront<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0);
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
   753
}
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
   754