src/town_gui.cpp
author translators
Wed, 17 Dec 2008 18:01:19 +0000
changeset 10433 45f92593bd6e
parent 10340 a4757ae623ca
permissions -rw-r--r--
(svn r14686) -Update: WebTranslator2 update to 2008-12-17 18:01:03
arabic_egypt - 200 fixed, 28 changed by Azoo4oozi (228)
czech - 3 changed by Hadez (3)
indonesian - 1 fixed, 4 changed by fanioz (5)
korean - 1 changed by leejaeuk5 (1)
latvian - 299 fixed, 3 changed by marismols (302)
lithuanian - 79 fixed by Zogg (79)
serbian - 25 fixed by Jenraux (25)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9094
diff changeset
     3
/** @file town_gui.cpp GUI for towns. */
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1260
diff changeset
     7
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "town.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8131
diff changeset
     9
#include "viewport_func.h"
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8131
diff changeset
    10
#include "gfx_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    12
#include "window_gui.h"
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    13
#include "textbuf_gui.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    14
#include "command_func.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    15
#include "company_func.h"
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    16
#include "company_base.h"
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    17
#include "company_gui.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5431
diff changeset
    18
#include "network/network.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2070
diff changeset
    19
#include "variables.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    20
#include "strings_func.h"
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
    21
#include "sound_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    22
#include "economy_func.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8121
diff changeset
    23
#include "core/alloc_func.hpp"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    24
#include "settings_type.h"
9127
14f21c5954ee (svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents: 9116
diff changeset
    25
#include "tilehighlight_func.h"
9164
18e971e0b44f (svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
rubidium
parents: 9161
diff changeset
    26
#include "string_func.h"
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
    27
#include "sortlist_type.h"
10289
801e5451f0ca (svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium
parents: 10208
diff changeset
    28
#include "road_cmd.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    30
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    31
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    32
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
    33
typedef GUIList<const Town*> GUITownList;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
    34
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
    35
extern bool GenerateTowns();
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
    36
static int _scengen_town_size = 1; // depress medium-sized towns per default
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
    37
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
static const Widget _town_authority_widgets[] = {
9778
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    39
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_BROWN,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},              // TWA_CLOSEBOX
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    40
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_BROWN,    11,   316,     0,    13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS},    // TWA_CAPTION
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    41
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_BROWN,     0,   316,    14,   105, 0x0,                      STR_NULL},                           // TWA_RATING_INFO
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    42
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_BROWN,     0,   304,   106,   157, 0x0,                      STR_2043_LIST_OF_THINGS_TO_DO_AT},   // TWA_COMMAND_LIST
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    43
{  WWT_SCROLLBAR,   RESIZE_NONE,  COLOUR_BROWN,   305,   316,   106,   157, 0x0,                      STR_0190_SCROLL_BAR_SCROLLS_LIST},   // TWA_SCROLLBAR
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    44
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_BROWN,     0,   316,   158,   209, 0x0,                      STR_NULL},                           // TWA_ACTION_INFO
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
    45
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,     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
    46
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
extern const byte _town_action_costs[8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    51
enum TownActions {
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    52
	TACT_NONE             = 0x00,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    53
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    54
	TACT_ADVERTISE_SMALL  = 0x01,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    55
	TACT_ADVERTISE_MEDIUM = 0x02,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    56
	TACT_ADVERTISE_LARGE  = 0x04,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    57
	TACT_ROAD_REBUILD     = 0x08,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    58
	TACT_BUILD_STATUE     = 0x10,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    59
	TACT_FOUND_BUILDINGS  = 0x20,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    60
	TACT_BUY_RIGHTS       = 0x40,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    61
	TACT_BRIBE            = 0x80,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    62
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    63
	TACT_ADVERTISE        = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    64
	TACT_CONSTRUCTION     = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    65
	TACT_FUNDS            = TACT_BUY_RIGHTS | TACT_BRIBE,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    66
	TACT_ALL              = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    67
};
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    68
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    69
DECLARE_ENUM_AS_BIT_SET(TownActions);
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    70
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    71
/** Get a list of available actions to do at a town.
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
    72
 * @param nump if not NULL add put the number of available actions in it
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    73
 * @param cid the company that is querying the town
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
    74
 * @param t the town that is queried
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    75
 * @return bitmasked value of enabled actions
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    76
 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    77
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
{
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    79
	int num = 0;
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    80
	TownActions buttons = TACT_NONE;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    81
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    82
	/* Spectators and unwanted have no options */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    83
	if (cid != COMPANY_SPECTATOR && !(_settings_game.economy.bribe && t->unwanted[cid])) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
    85
		/* Things worth more than this are not shown */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    86
		Money avail = GetCompany(cid)->money + _price.station_value * 200;
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    87
		Money ref = _price.build_industry >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    89
		/* Check the action bits for validity and
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    90
		 * if they are valid add them */
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    91
		for (uint i = 0; i != lengthof(_town_action_costs); i++) {
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    92
			const TownActions cur = (TownActions)(1 << i);
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    93
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    94
			/* Is the company not able to bribe ? */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    95
			if (cur == TACT_BRIBE && (!_settings_game.economy.bribe || t->ratings[cid] >= RATING_BRIBE_MAXIMUM))
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    96
				continue;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    97
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
    98
			/* Is the company not able to buy exclusive rights ? */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9390
diff changeset
    99
			if (cur == TACT_BUY_RIGHTS && !_settings_game.economy.exclusive_rights)
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   100
				continue;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   101
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   102
			/* Is the company not able to build a statue ? */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   103
			if (cur == TACT_BUILD_STATUE && HasBit(t->statues, cid))
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   104
				continue;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   105
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   106
			if (avail >= _town_action_costs[i] * ref) {
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   107
				buttons |= cur;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
		}
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
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   113
	if (nump != NULL) *nump = num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	return buttons;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   117
struct TownAuthorityWindow : Window {
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   118
private:
9326
6ba54f0cb15c (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: 9325
diff changeset
   119
	Town *town;
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   120
	int sel_index;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   121
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   122
	enum TownAuthorityWidget {
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   123
		TWA_CLOSEBOX = 0,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   124
		TWA_CAPTION,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   125
		TWA_RATING_INFO,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   126
		TWA_COMMAND_LIST,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   127
		TWA_SCROLLBAR,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   128
		TWA_ACTION_INFO,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   129
		TWA_EXECUTE,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   130
	};
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   131
9627
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   132
	/**
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   133
	 * Get the position of the Nth set bit.
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   134
	 *
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   135
	 * If there is no Nth bit set return -1
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   136
	 *
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   137
	 * @param bits The value to search in
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   138
	 * @param n The Nth set bit from which we want to know the position
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   139
	 * @return The position of the Nth set bit
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   140
	 */
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   141
	static int GetNthSetBit(uint32 bits, int n)
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   142
	{
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   143
		if (n >= 0) {
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   144
			uint i;
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   145
			FOR_EACH_SET_BIT(i, bits) {
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   146
				n--;
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   147
				if (n < 0) return i;
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   148
			}
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   149
		}
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   150
		return -1;
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   151
	}
3497448171a8 (svn r13683) -Codechange: privatize a function that is not used outside of the class who calls it
belugas
parents: 9529
diff changeset
   152
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   153
public:
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   154
	TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) :
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   155
			Window(desc, window_number), sel_index(-1)
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   156
	{
9326
6ba54f0cb15c (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: 9325
diff changeset
   157
		this->town = GetTown(this->window_number);
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   158
		this->vscroll.cap = 5;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   159
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   160
		this->FindWindowPlacementAndResize(desc);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   161
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   162
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   163
	virtual void OnPaint()
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   164
	{
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   165
		int numact;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   166
		uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   167
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   168
		SetVScrollCount(this, numact + 1);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   169
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   170
		if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   171
			this->sel_index = -1;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   172
		}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   173
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   174
		this->SetWidgetDisabledState(6, this->sel_index == -1);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   175
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   176
		SetDParam(0, this->window_number);
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9247
diff changeset
   177
		this->DrawWidgets();
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   178
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   179
		DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   180
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   181
		/* Draw list of companies */
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   182
		int y = 25;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   183
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   184
		const Company *c;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   185
		FOR_ALL_COMPANIES(c) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   186
			if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   187
				DrawCompanyIcon(c->index, 2, y);
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   188
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   189
				SetDParam(0, c->index);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   190
				SetDParam(1, c->index);
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   191
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   192
				int r = this->town->ratings[c->index];
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   193
				StringID str;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   194
				(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   195
				(str++,                    r <= RATING_VERYPOOR)  || // Very Poor
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   196
				(str++,                    r <= RATING_POOR)      || // Poor
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   197
				(str++,                    r <= RATING_MEDIOCRE)  || // Mediocore
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   198
				(str++,                    r <= RATING_GOOD)      || // Good
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   199
				(str++,                    r <= RATING_VERYGOOD)  || // Very Good
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   200
				(str++,                    r <= RATING_EXCELLENT) || // Excellent
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   201
				(str++,                    true);                    // Outstanding
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   202
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   203
				SetDParam(2, str);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   204
				if (this->town->exclusivity == c->index) { // red icon for company with exclusive rights
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   205
					DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
				}
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   207
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   208
				DrawString(28, y, STR_2024, TC_FROMSTRING);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   209
				y += 10;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   210
			}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   211
		}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   212
		y = 107;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   213
		int pos = this->vscroll.pos;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   214
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   215
		if (--pos < 0) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   216
			DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   217
			y += 10;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   218
		}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   219
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   220
		for (int i = 0; buttons; i++, buttons >>= 1) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   221
			if (pos <= -5) break; ///< Draw only the 5 fitting lines
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   222
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   223
			if ((buttons & 1) && --pos < 0) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   224
				DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   225
				y += 10;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   226
			}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   227
		}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   228
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   229
		if (this->sel_index != -1) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   230
			SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[this->sel_index]);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   231
			SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + this->sel_index);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   232
			DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + this->sel_index, 313);
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   233
		}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   234
	}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   235
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   236
	virtual void OnDoubleClick(Point pt, int widget) { HandleClick(pt, widget, true); }
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   237
	virtual void OnClick(Point pt, int widget) { HandleClick(pt, widget, false); }
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   238
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   239
	void HandleClick(Point pt, int widget, bool double_click)
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   240
	{
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   241
		switch (widget) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   242
			case TWA_COMMAND_LIST: {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   243
				int y = (pt.y - 0x6B) / 10;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   244
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   245
				if (!IsInsideMM(y, 0, 5)) return;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   246
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   247
				y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_company, this->town), y + this->vscroll.pos - 1);
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   248
				if (y >= 0) {
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   249
					this->sel_index = y;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   250
					this->SetDirty();
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   251
				}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   252
				/* Fall through to clicking in case we are double-clicked */
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   253
				if (!double_click || y < 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   256
			case TWA_EXECUTE:
9326
6ba54f0cb15c (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: 9325
diff changeset
   257
				DoCommandP(this->town->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   258
				break;
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   259
		}
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   260
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   262
	virtual void OnHundredthTick()
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   263
	{
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   264
		this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	}
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   266
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
static const WindowDesc _town_authority_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7058
diff changeset
   269
	WDP_AUTO, WDP_AUTO, 317, 222, 317, 222,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   270
	WC_TOWN_AUTHORITY, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	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
   272
	_town_authority_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 246
diff changeset
   275
static void ShowTownAuthorityWindow(uint town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
{
9247
e6a5d49fd58f (svn r13113) -Codechange: make a class of the TownAuthorityWindow.
rubidium
parents: 9164
diff changeset
   277
	AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   280
struct TownViewWindow : Window {
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   281
private:
9326
6ba54f0cb15c (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: 9325
diff changeset
   282
	Town *town;
8933
c1f075679c2e (svn r12705) -Codechange: enumification of some more widgets
belugas
parents: 8932
diff changeset
   283
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   284
	enum TownViewWidget {
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   285
		TVW_CAPTION = 1,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   286
		TVW_STICKY,
9334
28ac6c8e0795 (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: 9333
diff changeset
   287
		TVW_VIEWPORTPANEL,
28ac6c8e0795 (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: 9333
diff changeset
   288
		TVW_INFOPANEL = 5,
28ac6c8e0795 (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: 9333
diff changeset
   289
		TVW_CENTERVIEW,
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   290
		TVW_SHOWAUTORITY,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   291
		TVW_CHANGENAME,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   292
		TVW_EXPAND,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   293
		TVW_DELETE,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   294
	};
8933
c1f075679c2e (svn r12705) -Codechange: enumification of some more widgets
belugas
parents: 8932
diff changeset
   295
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   296
public:
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   297
	TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   298
	{
9326
6ba54f0cb15c (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: 9325
diff changeset
   299
		this->town = GetTown(this->window_number);
6ba54f0cb15c (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: 9325
diff changeset
   300
		bool ingame = _game_mode != GM_EDITOR;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   301
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   302
		this->flags4 |= WF_DISABLE_VP_SCROLL;
9326
6ba54f0cb15c (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: 9325
diff changeset
   303
		InitializeWindowViewport(this, 3, 17, 254, 86, this->town->xy, ZOOM_LVL_TOWN);
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   304
9326
6ba54f0cb15c (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: 9325
diff changeset
   305
		if (this->town->larger_town) this->widget[TVW_CAPTION].data = STR_CITY;
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   306
		this->SetWidgetHiddenState(TVW_DELETE, ingame);  // hide delete button on game mode
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   307
		this->SetWidgetHiddenState(TVW_EXPAND, ingame);  // hide expand button on game mode
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   308
		this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   309
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   310
		if (ingame) {
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   311
			/* resize caption bar */
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   312
			this->widget[TVW_CAPTION].right = this->widget[TVW_STICKY].left -1;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   313
			/* move the rename from top on scenario to bottom in game */
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   314
			this->widget[TVW_CHANGENAME].top = this->widget[TVW_EXPAND].top;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   315
			this->widget[TVW_CHANGENAME].bottom = this->widget[TVW_EXPAND].bottom;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   316
			this->widget[TVW_CHANGENAME].right = this->widget[TVW_STICKY].right;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   317
		}
9308
b2c24e2cdb7d (svn r13176) -Fix (r13153): town window was glitchy while opening
smatz
parents: 9287
diff changeset
   318
9334
28ac6c8e0795 (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: 9333
diff changeset
   319
		/* Space required for showing noise level information */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9390
diff changeset
   320
		if (_settings_game.economy.station_noise_level) {
9334
28ac6c8e0795 (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: 9333
diff changeset
   321
			ResizeWindowForWidget(this, TVW_INFOPANEL, 0, 10);
28ac6c8e0795 (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: 9333
diff changeset
   322
		}
28ac6c8e0795 (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: 9333
diff changeset
   323
9308
b2c24e2cdb7d (svn r13176) -Fix (r13153): town window was glitchy while opening
smatz
parents: 9287
diff changeset
   324
		this->FindWindowPlacementAndResize(desc);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   325
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   326
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   327
	virtual void OnPaint()
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   328
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   329
		/* disable renaming town in network games if you are not the server */
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   330
		this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   331
9326
6ba54f0cb15c (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: 9325
diff changeset
   332
		SetDParam(0, this->town->index);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   333
		this->DrawWidgets();
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   334
9326
6ba54f0cb15c (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: 9325
diff changeset
   335
		SetDParam(0, this->town->population);
6ba54f0cb15c (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: 9325
diff changeset
   336
		SetDParam(1, this->town->num_houses);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   337
		DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   338
9326
6ba54f0cb15c (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: 9325
diff changeset
   339
		SetDParam(0, this->town->act_pass);
6ba54f0cb15c (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: 9325
diff changeset
   340
		SetDParam(1, this->town->max_pass);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   341
		DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   342
9326
6ba54f0cb15c (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: 9325
diff changeset
   343
		SetDParam(0, this->town->act_mail);
6ba54f0cb15c (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: 9325
diff changeset
   344
		SetDParam(1, this->town->max_mail);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   345
		DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   346
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   347
		this->DrawViewport();
9334
28ac6c8e0795 (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: 9333
diff changeset
   348
28ac6c8e0795 (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: 9333
diff changeset
   349
		/* only show the town noise, if the noise option is activated. */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9390
diff changeset
   350
		if (_settings_game.economy.station_noise_level) {
9334
28ac6c8e0795 (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: 9333
diff changeset
   351
			SetDParam(0, this->town->noise_reached);
28ac6c8e0795 (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: 9333
diff changeset
   352
			SetDParam(1, this->town->MaxTownNoise());
28ac6c8e0795 (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: 9333
diff changeset
   353
			DrawString(2, 137, STR_NOISE_IN_TOWN, 0);
28ac6c8e0795 (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: 9333
diff changeset
   354
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	}
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   356
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   357
	virtual void OnClick(Point pt, int widget)
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   358
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   359
		switch (widget) {
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   360
			case TVW_CENTERVIEW: /* scroll to location */
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   361
				if (_ctrl_pressed) {
9326
6ba54f0cb15c (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: 9325
diff changeset
   362
					ShowExtraViewPortWindow(this->town->xy);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   363
				} else {
9326
6ba54f0cb15c (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: 9325
diff changeset
   364
					ScrollMainWindowToTile(this->town->xy);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   365
				}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   366
				break;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   367
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   368
			case TVW_SHOWAUTORITY: /* town authority */
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   369
				ShowTownAuthorityWindow(this->window_number);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   370
				break;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   371
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   372
			case TVW_CHANGENAME: /* rename */
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   373
				SetDParam(0, this->window_number);
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   374
				ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   375
				break;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   376
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   377
			case TVW_EXPAND: /* expand town - only available on Scenario editor */
9326
6ba54f0cb15c (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: 9325
diff changeset
   378
				ExpandTown(this->town);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   379
				break;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   380
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   381
			case TVW_DELETE: /* delete town - only available on Scenario editor */
9326
6ba54f0cb15c (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: 9325
diff changeset
   382
				delete this->town;
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   383
				break;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   384
		}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   385
	}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   386
9334
28ac6c8e0795 (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: 9333
diff changeset
   387
	virtual void OnInvalidateData(int data = 0)
28ac6c8e0795 (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: 9333
diff changeset
   388
	{
28ac6c8e0795 (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: 9333
diff changeset
   389
		/* Called when setting station noise have changed, in order to resize the window */
28ac6c8e0795 (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: 9333
diff changeset
   390
		this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
28ac6c8e0795 (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: 9333
diff changeset
   391
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9390
diff changeset
   392
		if (_settings_game.economy.station_noise_level) { // adjust depending
9334
28ac6c8e0795 (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: 9333
diff changeset
   393
			if (this->height == 150) { // window is smaller, needs to be bigger
28ac6c8e0795 (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: 9333
diff changeset
   394
				ResizeWindowForWidget(this, TVW_INFOPANEL, 0, 10);
28ac6c8e0795 (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: 9333
diff changeset
   395
			}
28ac6c8e0795 (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: 9333
diff changeset
   396
		} else {
28ac6c8e0795 (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: 9333
diff changeset
   397
			if (this->height != 150) { // window is bigger, needs to be smaller
28ac6c8e0795 (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: 9333
diff changeset
   398
				ResizeWindowForWidget(this, TVW_INFOPANEL, 0, -10);
28ac6c8e0795 (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: 9333
diff changeset
   399
			}
28ac6c8e0795 (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: 9333
diff changeset
   400
		}
28ac6c8e0795 (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: 9333
diff changeset
   401
	}
28ac6c8e0795 (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: 9333
diff changeset
   402
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   403
	virtual void OnQueryTextFinished(char *str)
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   404
	{
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   405
		if (str == NULL) return;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   406
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   407
		_cmd_text = str;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   408
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   409
	}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   410
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
static const Widget _town_view_widgets[] = {
9778
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   414
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_BROWN,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   415
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_BROWN,    11,   172,     0,    13, STR_2005,                 STR_018C_WINDOW_TITLE_DRAG_THIS},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   416
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_BROWN,   248,   259,     0,    13, 0x0,                      STR_STICKY_BUTTON},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   417
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_BROWN,     0,   259,    14,   105, 0x0,                      STR_NULL},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   418
{      WWT_INSET,   RESIZE_NONE,  COLOUR_BROWN,     2,   257,    16,   103, 0x0,                      STR_NULL},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   419
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_BROWN,     0,   259,   106,   137, 0x0,                      STR_NULL},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   420
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,     0,    85,   138,   149, STR_00E4_LOCATION,        STR_200B_CENTER_THE_MAIN_VIEW_ON},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   421
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,    86,   171,   138,   149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   422
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,   172,   247,     0,    13, STR_0130_RENAME,          STR_200C_CHANGE_TOWN_NAME},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   423
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,    86,   171,   138,   149, STR_023C_EXPAND,          STR_023B_INCREASE_SIZE_OF_TOWN},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   424
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,   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
   425
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
static const WindowDesc _town_view_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7058
diff changeset
   429
	WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   430
	WC_TOWN_VIEW, WC_NONE,
758
423ae0bcba07 (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 727
diff changeset
   431
	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
   432
	_town_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
3349
716104d39983 (svn r4133) - Some miscellaneous changes (unconverted TownID in function definition, Owner instead of byte, remove obsolete member and compare waypoint index with 0 not STR_NULL)
Darkvater
parents: 2952
diff changeset
   435
void ShowTownViewWindow(TownID town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
{
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   437
	AllocateWindowDescFront<TownViewWindow>(&_town_view_desc, town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
static const Widget _town_directory_widgets[] = {
9778
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   441
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_BROWN,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   442
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_BROWN,    11,   195,     0,    13, STR_2000_TOWNS,         STR_018C_WINDOW_TITLE_DRAG_THIS},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   443
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_BROWN,   196,   207,     0,    13, 0x0,                    STR_STICKY_BUTTON},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   444
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,     0,    98,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   445
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_BROWN,    99,   195,    14,    25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   446
{      WWT_PANEL, RESIZE_BOTTOM,  COLOUR_BROWN,     0,   195,    26,   189, 0x0,                    STR_200A_TOWN_NAMES_CLICK_ON_NAME},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   447
{  WWT_SCROLLBAR, RESIZE_BOTTOM,  COLOUR_BROWN,   196,   207,    14,   189, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   448
{      WWT_PANEL,     RESIZE_TB,  COLOUR_BROWN,     0,   195,   190,   201, 0x0,                    STR_NULL},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   449
{  WWT_RESIZEBOX,     RESIZE_TB,  COLOUR_BROWN,   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
   450
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   454
struct TownDirectoryWindow : public Window {
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   455
private:
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   456
	enum TownDirectoryWidget {
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   457
		TDW_SORTNAME = 3,
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   458
		TDW_SORTPOPULATION,
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   459
		TDW_CENTERTOWN,
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   460
	};
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   461
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   462
	/* Runtime saved values */
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   463
	static Listing last_sorting;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   464
	static const Town *last_town;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   465
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   466
	/* Constants for sorting towns */
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9387
diff changeset
   467
	static GUITownList::SortFunction * const sorter_funcs[];
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   468
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   469
	GUITownList towns;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   470
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   471
	void BuildTownList()
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   472
	{
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   473
		if (!this->towns.NeedRebuild()) return;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   474
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   475
		this->towns.Clear();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   476
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   477
		const Town *t;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   478
		FOR_ALL_TOWNS(t) {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   479
			*this->towns.Append() = t;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   480
		}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   481
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   482
		this->towns.Compact();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   483
		this->towns.RebuildDone();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   484
	}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   485
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   486
	void SortTownList()
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   487
	{
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   488
		last_town = NULL;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   489
		this->towns.Sort();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   490
	}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   491
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   492
	/** Sort by town name */
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   493
	static int CDECL TownNameSorter(const Town * const *a, const Town * const *b)
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   494
	{
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   495
		static char buf_cache[64];
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   496
		const Town *ta = *a;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   497
		const Town *tb = *b;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   498
		char buf[64];
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   499
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   500
		SetDParam(0, ta->index);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   501
		GetString(buf, STR_TOWN, lastof(buf));
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   502
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   503
		/* If 'b' is the same town as in the last round, use the cached value
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   504
		 * We do this to speed stuff up ('b' is called with the same value a lot of
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   505
		 * times after eachother) */
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   506
		if (tb != last_town) {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   507
			last_town = tb;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   508
			SetDParam(0, tb->index);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   509
			GetString(buf_cache, STR_TOWN, lastof(buf_cache));
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   510
		}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   511
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   512
		return strcmp(buf, buf_cache);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   513
	}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   514
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   515
	/** Sort by population */
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   516
	static int CDECL TownPopulationSorter(const Town * const *a, const Town * const *b)
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   517
	{
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   518
		return (*a)->population - (*b)->population;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   519
	}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   520
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   521
public:
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   522
	TownDirectoryWindow(const WindowDesc *desc) : Window(desc, 0)
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   523
	{
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   524
		this->vscroll.cap = 16;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   525
		this->resize.step_height = 10;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   526
		this->resize.height = this->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   527
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   528
		this->towns.SetListing(this->last_sorting);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   529
		this->towns.SetSortFuncs(this->sorter_funcs);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   530
		this->towns.ForceRebuild();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   531
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   532
		this->FindWindowPlacementAndResize(desc);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   533
	}
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   534
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   535
	~TownDirectoryWindow()
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   536
	{
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   537
		this->last_sorting = this->towns.GetListing();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   538
	}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   539
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   540
	virtual void OnPaint()
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   541
	{
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   542
		this->BuildTownList();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   543
		this->SortTownList();
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   544
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   545
		SetVScrollCount(this, this->towns.Length());
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   546
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   547
		this->DrawWidgets();
9529
00028640ee3a (svn r13533) -Codechange: Replace direct class member access of GUIList with the appropriate function calls
skidd13
parents: 9413
diff changeset
   548
		this->DrawSortButtonState(this->towns.SortType() == 0 ? TDW_SORTNAME : TDW_SORTPOPULATION, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   549
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   550
		{
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   551
			int n = 0;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   552
			uint16 i = this->vscroll.pos;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   553
			int y = 28;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   554
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   555
			while (i < this->towns.Length()) {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   556
				const Town *t = this->towns[i];
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   557
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   558
				assert(t->xy);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   559
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   560
				SetDParam(0, t->index);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   561
				SetDParam(1, t->population);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   562
				DrawString(2, y, STR_2057, TC_FROMSTRING);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   563
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   564
				y += 10;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   565
				i++;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   566
				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
   567
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   569
			SetDParam(0, GetWorldPopulation());
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   570
			DrawString(3, this->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   571
		}
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   572
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   573
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   574
	virtual void OnClick(Point pt, int widget)
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   575
	{
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   576
		switch (widget) {
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   577
			case TDW_SORTNAME: /* Sort by Name ascending/descending */
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   578
				if (this->towns.SortType() == 0) {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   579
					this->towns.ToggleSortOrder();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   580
				} else {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   581
					this->towns.SetSortType(0);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   582
				}
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   583
				this->SetDirty();
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   584
				break;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   585
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   586
			case TDW_SORTPOPULATION: /* Sort by Population ascending/descending */
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   587
				if (this->towns.SortType() == 1) {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   588
					this->towns.ToggleSortOrder();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   589
				} else {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   590
					this->towns.SetSortType(1);
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   591
				}
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   592
				this->SetDirty();
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   593
				break;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   594
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   595
			case TDW_CENTERTOWN: { /* Click on Town Matrix */
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   596
				uint16 id_v = (pt.y - 28) / 10;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   597
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   598
				if (id_v >= this->vscroll.cap) return; // click out of bounds
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   599
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   600
				id_v += this->vscroll.pos;
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   601
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   602
				if (id_v >= this->towns.Length()) return; // click out of town bounds
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   603
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   604
				const Town *t = this->towns[id_v];
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   605
				assert(t->xy);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   606
				if (_ctrl_pressed) {
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   607
					ShowExtraViewPortWindow(t->xy);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   608
				} else {
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   609
					ScrollMainWindowToTile(t->xy);
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   610
				}
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   611
				break;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   612
			}
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   613
		}
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   614
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   615
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   616
	virtual void OnHundredthTick()
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   617
	{
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   618
		this->SetDirty();
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   619
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   620
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   621
	virtual void OnResize(Point new_size, Point delta)
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   622
	{
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   623
		this->vscroll.cap += delta.y / 10;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   624
	}
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   625
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   626
	virtual void OnInvalidateData(int data)
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   627
	{
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   628
		if (data == 0) {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   629
			this->towns.ForceRebuild();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   630
		} else {
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   631
			this->towns.ForceResort();
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   632
		}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   633
	}
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   634
};
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   635
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   636
Listing TownDirectoryWindow::last_sorting = {false, 0};
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   637
const Town *TownDirectoryWindow::last_town = NULL;
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   638
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   639
/* Available town directory sorting functions */
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9387
diff changeset
   640
GUITownList::SortFunction * const TownDirectoryWindow::sorter_funcs[] = {
9387
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   641
	&TownNameSorter,
ede823d445f5 (svn r13297) -Codechange: Use GUIList for the town directory window
peter1138
parents: 9354
diff changeset
   642
	&TownPopulationSorter,
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   643
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
static const WindowDesc _town_directory_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7058
diff changeset
   646
	WDP_AUTO, WDP_AUTO, 208, 202, 208, 202,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   647
	WC_TOWN_DIRECTORY, WC_NONE,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   648
	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
   649
	_town_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5893
diff changeset
   652
void ShowTownDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
{
9347
923cdb28b336 (svn r13244) -Fix: allow only one town directory window to be opened
smatz
parents: 9334
diff changeset
   654
	if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
9312
cd2d59f498e5 (svn r13180) -Codechange: make a window class of the TownDirectoryWindow.
peter1138
parents: 9308
diff changeset
   655
	new TownDirectoryWindow(&_town_directory_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
}
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   657
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   658
void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   659
{
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   660
	if (success) {
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   661
		SndPlayTileFx(SND_1F_SPLAT, tile);
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   662
		ResetObjectToPlace();
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   663
	}
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   664
}
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   665
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   666
static void PlaceProc_Town(TileIndex tile)
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   667
{
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   668
	uint32 size = min(_scengen_town_size, (int)TSM_CITY);
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   669
	uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   670
	DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE));
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   671
}
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   672
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   673
static const Widget _scen_edit_town_gen_widgets[] = {
9778
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   674
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,    0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   675
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,   11,   147,     0,    13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   676
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,  148,   159,     0,    13, 0x0,                      STR_STICKY_BUTTON},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   677
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,    0,   159,    14,    94, 0x0,                      STR_NULL},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   678
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,          2,   157,    16,    27, STR_0234_NEW_TOWN,        STR_0235_CONSTRUCT_NEW_TOWN},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   679
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,          2,   157,    29,    40, STR_023D_RANDOM_TOWN,     STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   680
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,          2,   157,    42,    53, STR_MANY_RANDOM_TOWNS,    STR_RANDOM_TOWNS_TIP},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   681
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,          2,    53,    68,    79, STR_02A1_SMALL,           STR_02A4_SELECT_TOWN_SIZE},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   682
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,         54,   105,    68,    79, STR_02A2_MEDIUM,          STR_02A4_SELECT_TOWN_SIZE},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   683
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,        106,   157,    68,    79, STR_02A3_LARGE,           STR_02A4_SELECT_TOWN_SIZE},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   684
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,          2,   157,    81,    92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE},
c5dd94ed7c16 (svn r13919) -Codechange: Replace numbers with Colours enum on osk(forgot 2 assignations), statusbar, subsidy, terraform, timetable, toolbar, town, tree and vehicle guis.
belugas
parents: 9659
diff changeset
   685
{      WWT_LABEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,    0,   147,    54,    67, STR_02A5_TOWN_SIZE,       STR_NULL},
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   686
{   WIDGETS_END},
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   687
};
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   688
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   689
struct ScenarioEditorTownGenerationWindow : Window
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   690
{
9325
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   691
private:
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   692
	enum TownScenarioEditorWidget {
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   693
		TSEW_NEWTOWN = 4,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   694
		TSEW_RANDOMTOWN,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   695
		TSEW_MANYRANDOMTOWNS,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   696
		TSEW_SMALLTOWN,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   697
		TSEW_MEDIUMTOWN,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   698
		TSEW_LARGETOWN,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   699
		TSEW_CITY,
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   700
	};
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   701
40c766e7b959 (svn r13209) -Codechange: Privatize what should be private.
belugas
parents: 9317
diff changeset
   702
public:
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   703
	ScenarioEditorTownGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   704
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   705
		this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9326
diff changeset
   706
		this->FindWindowPlacementAndResize(desc);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   707
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   708
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   709
	virtual void OnPaint()
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   710
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   711
		this->DrawWidgets();
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   712
	}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   713
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   714
	virtual void OnClick(Point pt, int widget)
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   715
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   716
		switch (widget) {
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   717
			case TSEW_NEWTOWN:
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   718
				HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   719
				break;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   720
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   721
			case TSEW_RANDOMTOWN: {
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   722
				Town *t;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   723
				uint size = min(_scengen_town_size, (int)TSM_CITY);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   724
				TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   725
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   726
				this->HandleButtonClick(TSEW_RANDOMTOWN);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   727
				_generating_world = true;
10340
a4757ae623ca (svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz
parents: 10289
diff changeset
   728
				UpdateNearestTownForRoadTiles(true);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   729
				t = CreateRandomTown(20, mode, size);
10340
a4757ae623ca (svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz
parents: 10289
diff changeset
   730
				UpdateNearestTownForRoadTiles(false);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   731
				_generating_world = false;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   732
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   733
				if (t == NULL) {
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   734
					ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   735
				} else {
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   736
					ScrollMainWindowToTile(t->xy);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   737
				}
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   738
			} break;
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   739
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   740
			case TSEW_MANYRANDOMTOWNS:
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   741
				this->HandleButtonClick(TSEW_MANYRANDOMTOWNS);
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   742
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   743
				_generating_world = true;
10340
a4757ae623ca (svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz
parents: 10289
diff changeset
   744
				UpdateNearestTownForRoadTiles(true);
10289
801e5451f0ca (svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium
parents: 10208
diff changeset
   745
				if (!GenerateTowns()) {
801e5451f0ca (svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium
parents: 10208
diff changeset
   746
					ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
801e5451f0ca (svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium
parents: 10208
diff changeset
   747
				}
10340
a4757ae623ca (svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz
parents: 10289
diff changeset
   748
				UpdateNearestTownForRoadTiles(false);
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   749
				_generating_world = false;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   750
				break;
8932
c1650d1cdc31 (svn r12704) -Codechange: code style cleanup, mostly switch case alignment
belugas
parents: 8723
diff changeset
   751
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   752
			case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY:
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   753
				this->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   754
				_scengen_town_size = widget - TSEW_SMALLTOWN;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   755
				this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   756
				this->SetDirty();
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   757
				break;
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   758
		}
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   759
	}
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   760
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   761
	virtual void OnTimeout()
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   762
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   763
		this->RaiseWidget(TSEW_RANDOMTOWN);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   764
		this->RaiseWidget(TSEW_MANYRANDOMTOWNS);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   765
		this->SetDirty();
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   766
	}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   767
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   768
	virtual void OnPlaceObject(Point pt, TileIndex tile)
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   769
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   770
		_place_proc(tile);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   771
	}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   772
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   773
	virtual void OnPlaceObjectAbort()
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   774
	{
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   775
		this->RaiseButtons();
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   776
		this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   777
		this->SetDirty();
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   778
	}
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   779
};
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   780
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   781
static const WindowDesc _scen_edit_town_gen_desc = {
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   782
	WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   783
	WC_SCEN_TOWN_GEN, WC_NONE,
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   784
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   785
	_scen_edit_town_gen_widgets,
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   786
};
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   787
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   788
void ShowBuildTownWindow()
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   789
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   790
	if (_game_mode != GM_EDITOR && !IsValidCompanyID(_current_company)) return;
9287
49870e5db0dd (svn r13153) -Codechange: make classes of the TownViewWindow and the ScenarioEditorTownGenerationWindow.
rubidium
parents: 9273
diff changeset
   791
	AllocateWindowDescFront<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0);
8723
e513a23c2797 (svn r12398) -Codechange [FS#1770]: Move toolbar related code to it's own little neighbourhood. Based on a patch by Dominik.
rubidium
parents: 8717
diff changeset
   792
}