src/town_gui.cpp
author rubidium
Tue, 25 Dec 2007 11:26:07 +0000
changeset 8131 160939e24ed3
parent 8130 d2eb7d04f6e1
child 8224 c5a64d87cc54
permissions -rw-r--r--
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
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
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
     3
/** @file town_gui.cpp */
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
     4
0
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"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1323
diff changeset
     8
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 410
diff changeset
     9
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#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
    13
#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
    14
#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
    15
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "player.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5431
diff changeset
    17
#include "network/network.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2070
diff changeset
    18
#include "variables.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    19
#include "strings_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    20
#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
    21
#include "core/alloc_func.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    23
enum TownAuthorityWidget {
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    24
	TWA_CLOSEBOX = 0,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    25
	TWA_CAPTION,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    26
	TWA_RATING_INFO,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    27
	TWA_COMMAND_LIST,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    28
	TWA_SCROLLBAR,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    29
	TWA_ACTION_INFO,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    30
	TWA_EXECUTE,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    31
};
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    32
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
static const Widget _town_authority_widgets[] = {
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    34
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},              // TWA_CLOSEBOX
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    35
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   316,     0,    13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS},    // TWA_CAPTION
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    36
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   316,    14,   105, 0x0,                      STR_NULL},                           // TWA_RATING_INFO
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    37
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   304,   106,   157, 0x0,                      STR_2043_LIST_OF_THINGS_TO_DO_AT},   // TWA_COMMAND_LIST
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    38
{  WWT_SCROLLBAR,   RESIZE_NONE,    13,   305,   316,   106,   157, 0x0,                      STR_0190_SCROLL_BAR_SCROLLS_LIST},   // TWA_SCROLLBAR
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    39
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   316,   158,   209, 0x0,                      STR_NULL},                           // TWA_ACTION_INFO
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    40
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   316,   210,   221, STR_2042_DO_IT,           STR_2044_CARRY_OUT_THE_HIGHLIGHTED}, // TWA_EXECUTE
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
    41
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
extern const byte _town_action_costs[8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    46
enum TownActions {
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    47
	TACT_NONE             = 0x00,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    48
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    49
	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
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	TACT_BRIBE            = 0x80,
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    57
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    58
	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
    59
	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
    60
	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
    61
	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
    62
};
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    63
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    64
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
    65
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    66
/** 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
    67
 * @param nump if not NULL add put the number of available actions in it
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    68
 * @param pid the player that is querying the town
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
    69
 * @param t the town that is queried
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    70
 * @return bitmasked value of enabled actions
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    71
 */
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    72
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
{
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    74
	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
    75
	TownActions buttons = TACT_NONE;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    76
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    77
	/* Spectators and unwanted have no options */
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    78
	if (pid != PLAYER_SPECTATOR && !(_patches.bribe && t->unwanted[pid])) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
    80
		/* Things worth more than this are not shown */
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    81
		Money avail = GetPlayer(pid)->player_money + _price.station_value * 200;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    82
		Money ref = _price.build_industry >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    84
		/* 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
    85
		 * 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
    86
		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
    87
			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
    88
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    89
			/* Is the player not able to bribe ? */
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    90
			if (cur == TACT_BRIBE && (!_patches.bribe || t->ratings[pid] >= RATING_BRIBE_MAXIMUM))
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    91
				continue;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    92
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    93
			/* Is the player not able to buy exclusive rights ? */
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    94
			if (cur == TACT_BUY_RIGHTS && !_patches.exclusive_rights)
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    95
				continue;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    96
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    97
			/* Is the player not able to build a statue ? */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7824
diff changeset
    98
			if (cur == TACT_BUILD_STATUE && HasBit(t->statues, pid))
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
    99
				continue;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   100
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   101
			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
   102
				buttons |= cur;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   108
	if (nump != NULL) *nump = num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	return buttons;
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
7982
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   112
/**
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   113
 * Get the position of the Nth set bit.
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   114
 *
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   115
 * If there is no Nth bit set return -1
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   116
 *
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   117
 * @param bits The value to search in
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   118
 * @param n The Nth set bit from which we want to know the position
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   119
 * @return The position of the Nth set bit
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   120
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
static int GetNthSetBit(uint32 bits, int n)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	if (n >= 0) {
8005
2318a0547719 (svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents: 7997
diff changeset
   124
		uint i;
2318a0547719 (svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents: 7997
diff changeset
   125
		FOR_EACH_SET_BIT(i, bits) {
2318a0547719 (svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents: 7997
diff changeset
   126
			n--;
7982
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   127
			if (n < 0) return i;
0d1198a12414 (svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
skidd13
parents: 7954
diff changeset
   128
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
static void TownAuthorityWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
{
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   135
	switch (e->event) {
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   136
	case WE_PAINT: {
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   137
		const Town *t = GetTown(w->window_number);
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   138
		int numact;
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   139
		uint buttons = GetMaskOfTownActions(&numact, _local_player, t);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   140
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
		SetVScrollCount(w, numact + 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8040
diff changeset
   143
		if (WP(w, def_d).data_1 != -1 && !HasBit(buttons, WP(w,def_d).data_1))
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8040
diff changeset
   144
			WP(w, def_d).data_1 = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7982
diff changeset
   146
		w->SetWidgetDisabledState(6, WP(w, def_d).data_1 == -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
			int y;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3692
diff changeset
   150
			const Player *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
			int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
			StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   154
			SetDParam(0, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
			DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   157
			DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING);
122
6e56237f536c (svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents: 121
diff changeset
   158
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
   159
			/* Draw list of players */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
			y = 25;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
			FOR_ALL_PLAYERS(p) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7824
diff changeset
   162
				if (p->is_active && (HasBit(t->have_ratings, p->index) || t->exclusivity == p->index)) {
125
3716c3a69f4f (svn r126) Forgot to remove some test code
dominik
parents: 122
diff changeset
   163
					DrawPlayerIcon(p->index, 2, y);
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 69
diff changeset
   164
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7027
diff changeset
   165
					SetDParam(0, p->index);
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7027
diff changeset
   166
					SetDParam(1, p->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
					r = t->ratings[p->index];
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   169
					(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   170
					(str++,                    r <= RATING_VERYPOOR)  || // Very Poor
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   171
					(str++,                    r <= RATING_POOR)      || // Poor
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   172
					(str++,                    r <= RATING_MEDIOCRE)  || // Mediocore
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   173
					(str++,                    r <= RATING_GOOD)      || // Good
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   174
					(str++,                    r <= RATING_VERYGOOD)  || // Very Good
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   175
					(str++,                    r <= RATING_EXCELLENT) || // Excellent
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   176
					(str++,                    true);                    // Outstanding
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7027
diff changeset
   178
					SetDParam(2, str);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5609
diff changeset
   179
					if (t->exclusivity == p->index) { // red icon for player with exclusive rights
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5609
diff changeset
   180
						DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5609
diff changeset
   181
					}
246
de179e5f7c3d (svn r247) -Fix: Town exclusivity was not shown in town-window because stringformat ({YELLOW}) overrode colour-code. Now the exclusive player gets a red icon in front of its name
darkvater
parents: 222
diff changeset
   182
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   183
					DrawString(28, y, STR_2024, TC_FROMSTRING);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   184
					y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
   189
		/* Draw actions list */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
			int y = 107, i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
			int pos = w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			if (--pos < 0) {
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   195
				DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   196
				y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
			}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   198
			for (i = 0; buttons; i++, buttons >>= 1) {
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   199
				if (pos <= -5) break; ///< Draw only the 5 fitting lines
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   201
				if ((buttons & 1) && --pos < 0) {
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   202
					DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
					y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		}
122
6e56237f536c (svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents: 121
diff changeset
   207
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		{
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8040
diff changeset
   209
			int i = WP(w, def_d).data_1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   210
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   211
			if (i != -1) {
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   212
				SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[i]);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   213
				SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
				DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + i, 313);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   217
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   218
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
   220
	case WE_DOUBLE_CLICK:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   222
		switch (e->we.click.widget) {
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   223
		case TWA_COMMAND_LIST: {
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   224
			const Town *t = GetTown(w->window_number);
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   225
			int y = (e->we.click.pt.y - 0x6B) / 10;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   226
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
   227
			if (!IsInsideMM(y, 0, 5)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   229
			y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
			if (y >= 0) {
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8040
diff changeset
   231
				WP(w, def_d).data_1 = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
			}
7027
5ff15feffec8 (svn r10291) -Fix [FS#920]: double click in town-GUI didn't work as expected
truelight
parents: 7009
diff changeset
   234
			/* Fall through to clicking in case we are double-clicked */
5ff15feffec8 (svn r10291) -Fix [FS#920]: double click in town-GUI didn't work as expected
truelight
parents: 7009
diff changeset
   235
			if (e->event != WE_DOUBLE_CLICK || y < 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7386
diff changeset
   238
		case TWA_EXECUTE: {
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8040
diff changeset
   239
			DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w, def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
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
   252
	WDP_AUTO, WDP_AUTO, 317, 222, 317, 222,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   253
	WC_TOWN_AUTHORITY, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	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
   255
	_town_authority_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	TownAuthorityWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 246
diff changeset
   259
static void ShowTownAuthorityWindow(uint town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3692
diff changeset
   261
	Window *w = AllocateWindowDescFront(&_town_authority_desc, town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   263
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
		w->vscroll.cap = 5;
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8040
diff changeset
   265
		WP(w, def_d).data_1 = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
static void TownViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
{
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   271
	Town *t = GetTown(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   273
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	case WE_PAINT:
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
   275
		/* disable renaming town in network games if you are not the server */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7982
diff changeset
   276
		w->SetWidgetDisabledState(8, _networking && !_network_server);
891
8f020b87e3c6 (svn r1377) -Fix: only a server can rename a town in a MP game
darkvater
parents: 867
diff changeset
   277
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   278
		SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   280
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   281
		SetDParam(0, t->population);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   282
		SetDParam(1, t->num_houses);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   283
		DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   284
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   285
		SetDParam(0, t->act_pass);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   286
		SetDParam(1, t->max_pass);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   287
		DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   289
		SetDParam(0, t->act_mail);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   290
		SetDParam(1, t->max_mail);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   291
		DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   292
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   297
		switch (e->we.click.widget) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   298
			case 6: /* scroll to location */
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   299
				ScrollMainWindowToTile(t->xy);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   300
				break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   301
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   302
			case 7: /* town authority */
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   303
				ShowTownAuthorityWindow(w->window_number);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   304
				break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   305
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   306
			case 8: /* rename */
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   307
				SetDParam(0, w->window_number);
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5380
diff changeset
   308
				ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   309
				break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   310
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   311
			case 9: /* expand town */
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   312
				ExpandTown(t);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   313
				break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   314
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   315
			case 10: /* delete town */
7386
93f6a042d1c3 (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents: 7341
diff changeset
   316
				delete t;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   317
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2406
diff changeset
   321
	case WE_ON_EDIT_TEXT:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   322
		if (e->we.edittext.str[0] != '\0') {
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   323
			_cmd_text = e->we.edittext.str;
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1803
diff changeset
   324
			DoCommandP(0, w->window_number, 0, NULL,
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1803
diff changeset
   325
				CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1803
diff changeset
   326
		}
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2406
diff changeset
   327
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
static const Widget _town_view_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   333
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   334
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   247,     0,    13, STR_2005,                 STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   335
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   248,   259,     0,    13, 0x0,                      STR_STICKY_BUTTON},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   336
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,    14,   105, 0x0,                      STR_NULL},
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   337
{      WWT_INSET,   RESIZE_NONE,    13,     2,   257,    16,   103, 0x0,                      STR_NULL},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   338
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,   106,   137, 0x0,                      STR_NULL},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   339
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    85,   138,   149, STR_00E4_LOCATION,        STR_200B_CENTER_THE_MAIN_VIEW_ON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   340
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   138,   149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   341
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   259,   138,   149, STR_0130_RENAME,          STR_200C_CHANGE_TOWN_NAME},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   342
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
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
   346
	WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   347
	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
   348
	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
   349
	_town_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	TownViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
static const Widget _town_view_scen_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   354
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   355
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   172,     0,    13, STR_2005,          STR_018C_WINDOW_TITLE_DRAG_THIS},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   356
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   357
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,    14,   105, 0x0,               STR_NULL},
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   358
{      WWT_INSET,   RESIZE_NONE,    13,     2,   257,    16,   103, 0x0,               STR_NULL},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   359
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,   106,   137, 0x0,               STR_NULL},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   360
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    85,   138,   149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   361
{      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,               STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   362
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   173,   247,     0,    13, STR_0130_RENAME,   STR_200C_CHANGE_TOWN_NAME},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   363
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   138,   149, STR_023C_EXPAND,   STR_023B_INCREASE_SIZE_OF_TOWN},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   364
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   259,   138,   149, STR_0290_DELETE,   STR_0291_DELETE_THIS_TOWN_COMPLETELY},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   365
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
static const WindowDesc _town_view_scen_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
   369
	WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   370
	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
   371
	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
   372
	_town_view_scen_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	TownViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
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
   376
void ShowTownViewWindow(TownID town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	if (_game_mode != GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
		w = AllocateWindowDescFront(&_town_view_desc, town);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
		w = AllocateWindowDescFront(&_town_view_scen_desc, town);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   386
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		w->flags4 |= WF_DISABLE_VP_SCROLL;
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6422
diff changeset
   388
		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, ZOOM_LVL_TOWN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
static const Widget _town_directory_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   393
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   394
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   195,     0,    13, STR_2000_TOWNS,         STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   395
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   196,   207,     0,    13, 0x0,                    STR_STICKY_BUTTON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   396
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    98,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   397
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    99,   195,    14,    25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   398
{      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   195,    26,   189, 0x0,                    STR_200A_TOWN_NAMES_CLICK_ON_NAME},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   399
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   196,   207,    14,   189, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   400
{      WWT_PANEL,     RESIZE_TB,    13,     0,   195,   190,   201, 0x0,                    STR_NULL},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   401
{  WWT_RESIZEBOX,     RESIZE_TB,    13,   196,   207,   190,   201, 0x0,                    STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   402
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6247
diff changeset
   406
/* used to get a sorted list of the towns */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
static uint _num_town_sort;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
static char _bufcache[64];
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   410
static const Town* _last_town;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 125
diff changeset
   412
static int CDECL TownNameSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
{
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   414
	const Town* ta = *(const Town**)a;
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   415
	const Town* tb = *(const Town**)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	char buf1[64];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
4416
442b18840569 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   419
	SetDParam(0, ta->index);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   420
	GetString(buf1, STR_TOWN, lastof(buf1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1093
diff changeset
   422
	/* If 'b' is the same town as in the last round, use the cached value
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1093
diff changeset
   423
	 *  We do this to speed stuff up ('b' is called with the same value a lot of
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   424
	 *  times after eachother) */
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   425
	if (tb != _last_town) {
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   426
		_last_town = tb;
4416
442b18840569 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   427
		SetDParam(0, tb->index);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   428
		GetString(_bufcache, STR_TOWN, lastof(_bufcache));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	r = strcmp(buf1, _bufcache);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	if (_town_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 125
diff changeset
   436
static int CDECL TownPopSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
{
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   438
	const Town* ta = *(const Town**)a;
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   439
	const Town* tb = *(const Town**)b;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 125
diff changeset
   440
	int r = ta->population - tb->population;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	if (_town_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5893
diff changeset
   445
static void MakeSortedTownList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2549
diff changeset
   447
	const Town* t;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   448
	uint n = 0;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   449
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   450
	/* Create array for sorting */
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   451
	_town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1);
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   452
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   453
	FOR_ALL_TOWNS(t) _town_sort[n++] = t;
821
60524daa442c (svn r1292) -Codechange: also updated the town/industry sort-list to be uint16 compatible
truelight
parents: 758
diff changeset
   454
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	_num_town_sort = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   457
	_last_town = NULL; // used for "cache"
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   458
	qsort((void*)_town_sort, n, sizeof(_town_sort[0]), _town_sort_order & 2 ? TownPopSorter : TownNameSorter);
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 16
diff changeset
   459
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   460
	DEBUG(misc, 3, "Resorting towns list");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
static void TownDirectoryWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   466
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	case WE_PAINT: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
		if (_town_sort_dirty) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
			_town_sort_dirty = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
			MakeSortedTownList();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
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
   473
		SetVScrollCount(w, _num_town_sort);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
		DrawWindowWidgets(w);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   476
		DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_town_sort_order <= 1) ? 88 : 187, 15, TC_BLACK);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   477
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
   478
		{
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   479
			int n = 0;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   480
			uint16 i = w->vscroll.pos;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   481
			int y = 28;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
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
   483
			while (i < _num_town_sort) {
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   484
				const Town* t = _town_sort[i];
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   485
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   486
				assert(t->xy);
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   487
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   488
				SetDParam(0, t->index);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   489
				SetDParam(1, t->population);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   490
				DrawString(2, y, STR_2057, TC_FROMSTRING);
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   491
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   492
				y += 10;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   493
				i++;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   494
				if (++n == w->vscroll.cap) break; // max number of towns in 1 window
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   495
			}
1080
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1005
diff changeset
   496
			SetDParam(0, GetWorldPopulation());
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   497
			DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   502
		switch (e->we.click.widget) {
758
423ae0bcba07 (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 727
diff changeset
   503
		case 3: { /* Sort by Name ascending/descending */
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   504
			_town_sort_order = (_town_sort_order == 0) ? 1 : 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
			_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
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
   509
		case 4: { /* Sort by Population ascending/descending */
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   510
			_town_sort_order = (_town_sort_order == 2) ? 3 : 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
			_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
		} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   514
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
   515
		case 5: { /* Click on Town Matrix */
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   516
			const Town* t;
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   517
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   518
			uint16 id_v = (e->we.click.pt.y - 28) / 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   520
			if (id_v >= w->vscroll.cap) return; // click out of bounds
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   521
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   522
			id_v += w->vscroll.pos;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   523
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   524
			if (id_v >= _num_town_sort) return; // click out of town bounds
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   525
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   526
			t = _town_sort[id_v];
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   527
			assert(t->xy);
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   528
			ScrollMainWindowToTile(t->xy);
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   529
			break;
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   530
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   533
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
		break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   537
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   538
	case WE_RESIZE:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   539
		w->vscroll.cap += e->we.sizing.diff.y / 10;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   540
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   541
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
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
   545
	WDP_AUTO, WDP_AUTO, 208, 202, 208, 202,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5750
diff changeset
   546
	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
   547
	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
   548
	_town_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	TownDirectoryWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5893
diff changeset
   553
void ShowTownDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3692
diff changeset
   555
	Window *w = AllocateWindowDescFront(&_town_directory_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   557
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		w->vscroll.cap = 16;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   559
		w->resize.step_height = 10;
1080
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1005
diff changeset
   560
		w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
}