src/bridge_gui.cpp
author peter1138
Mon, 26 May 2008 16:23:23 +0000
changeset 10716 2406d1520245
parent 10658 ac7884765615
child 10719 96129d85f5d8
permissions -rw-r--r--
(svn r13266) -Codechange: Use SmallVector in GUIList
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6443
b8f06d8eb7be (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 6182
diff changeset
     3
/** @file bridge_gui.cpp Graphical user interface for bridge construction */
2262
bd59b2d8d75f (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2186
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1781
diff changeset
     6
#include "openttd.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gui.h"
8603
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8602
diff changeset
     8
#include "window_gui.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
     9
#include "command_func.h"
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    10
#include "economy_func.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2133
diff changeset
    11
#include "variables.h"
2262
bd59b2d8d75f (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2186
diff changeset
    12
#include "bridge.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8603
diff changeset
    13
#include "strings_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8617
diff changeset
    14
#include "window_func.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8635
diff changeset
    15
#include "sound_func.h"
8635
3bbb6f87fced (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8627
diff changeset
    16
#include "map_func.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8653
diff changeset
    17
#include "viewport_func.h"
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8653
diff changeset
    18
#include "gfx_func.h"
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8760
diff changeset
    19
#include "tunnelbridge.h"
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    20
#include "sortlist_type.h"
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    21
#include "widgets/dropdown_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8720
diff changeset
    23
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8720
diff changeset
    24
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    25
/* Save the sorting during runtime */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    26
static Listing _bridge_sorting = {false, 0};
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    27
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    28
/**
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    29
 * Carriage for the data we need if we want to build a bridge
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    30
 */
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    31
struct BuildBridgeData {
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    32
	BridgeType index;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    33
	const BridgeSpec *spec;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    34
	Money cost;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    35
};
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
    36
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    37
typedef GUIList<BuildBridgeData> GUIBridgeList;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    39
/** Sort the bridges by their index */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    40
static int CDECL BridgeIndexSorter(const void *a, const void *b)
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    41
{
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    42
	const BuildBridgeData* ba = (BuildBridgeData*)a;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    43
	const BuildBridgeData* bb = (BuildBridgeData*)b;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    44
	int r = ba->index - bb->index;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    45
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    46
	return (_bridge_sorting.order) ? -r : r;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    47
}
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    48
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    49
/** Sort the bridges by their price */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    50
static int CDECL BridgePriceSorter(const void *a, const void *b)
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    51
{
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    52
	const BuildBridgeData* ba = (BuildBridgeData*)a;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    53
	const BuildBridgeData* bb = (BuildBridgeData*)b;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    54
	int r = ba->cost - bb->cost;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    55
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    56
	return (_bridge_sorting.order) ? -r : r;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    57
}
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    58
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    59
/** Sort the bridges by their maximum speed */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    60
static int CDECL BridgeSpeedSorter(const void *a, const void *b)
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    61
{
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    62
	const BuildBridgeData* ba = (BuildBridgeData*)a;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    63
	const BuildBridgeData* bb = (BuildBridgeData*)b;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    64
	int r = ba->spec->speed - bb->spec->speed;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    65
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    66
	return (_bridge_sorting.order) ? -r : r;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    67
}
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    68
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    69
typedef int CDECL BridgeSortListingTypeFunction(const void*, const void*);
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    70
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    71
/* Availible bridge sorting functions */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    72
static BridgeSortListingTypeFunction* const _bridge_sorter[] = {
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    73
	&BridgeIndexSorter,
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    74
	&BridgePriceSorter,
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    75
	&BridgeSpeedSorter
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    76
};
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    77
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    78
/* Names of the sorting functions */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    79
static const StringID _bridge_sort_listing[] = {
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    80
	STR_SORT_BY_NUMBER,
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    81
	STR_ENGINE_SORT_COST,
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    82
	STR_SORT_BY_MAX_SPEED,
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    83
	INVALID_STRING_ID
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    84
};
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
    85
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    86
/**
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    87
 * Callback executed after a build Bridge CMD has been called
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    88
 *
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    89
 * @param scucess True if the build succeded
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    90
 * @param tile The tile where the command has been executed
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    91
 * @param p1 not used
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    92
 * @param p2 not used
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
    93
 */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    94
void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
{
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
    96
	if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
    99
/* Names of the build bridge selection window */
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   100
enum BuildBridgeSelectionWidgets {
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   101
	BBSW_CLOSEBOX = 0,
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   102
	BBSW_CAPTION,
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   103
	BBSW_DROPDOWN_ORDER,
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   104
	BBSW_DROPDOWN_CRITERIA,
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   105
	BBSW_BRIDGE_LIST,
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   106
	BBSW_SCROLLBAR,
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   107
	BBSW_RESIZEBOX
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   108
};
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   109
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   110
class BuildBridgeWindow : public Window {
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   111
private:
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   112
	/* The last size of the build bridge window
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   113
	 * is saved during runtime */
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   114
	static uint last_size;
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   115
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   116
	TileIndex start_tile;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   117
	TileIndex end_tile;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   118
	uint32 type;
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   119
	GUIBridgeList *bridges;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   121
	void BuildBridge(uint8 i)
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   122
	{
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   123
		DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index,
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   124
				CcBuildBridge, CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE));
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   125
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   127
	/** Sort the builable bridges */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   128
	void SortBridgeList()
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   129
	{
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   130
		/* Skip sorting if resort bit is not set */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   131
		if (!(bridges->flags & VL_RESORT)) return;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   132
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   133
		qsort(this->bridges->Begin(), this->bridges->Length(), sizeof(this->bridges->Begin()), _bridge_sorter[_bridge_sorting.criteria]);
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   134
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   135
		/* Display the current sort variant */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   136
		this->widget[BBSW_DROPDOWN_CRITERIA].data = _bridge_sort_listing[this->bridges->sort_type];
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   137
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   138
		bridges->flags &= ~VL_RESORT;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   139
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   140
		/* Set the modified widgets dirty */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   141
		this->InvalidateWidget(BBSW_DROPDOWN_CRITERIA);
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   142
		this->InvalidateWidget(BBSW_BRIDGE_LIST);
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   143
	}
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   144
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   145
public:
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   146
	BuildBridgeWindow(const WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(desc),
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   147
		start_tile(start),
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   148
		end_tile(end),
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   149
		type(br_type),
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   150
		bridges(bl)
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   151
	{
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   152
		this->SortBridgeList();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   154
		/* Change the data, or the caption of the gui. Set it to road or rail, accordingly */
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   155
		this->widget[BBSW_CAPTION].data = (GB(this->type, 15, 2) == TRANSPORT_ROAD) ? STR_1803_SELECT_ROAD_BRIDGE : STR_100D_SELECT_RAIL_BRIDGE;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   156
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   157
		this->resize.step_height = 22;
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   158
		this->vscroll.count = bl->Length();
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   159
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   160
		if (this->last_size <= 4) {
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   161
			this->vscroll.cap = 4;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   162
		} else {
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   163
			/* Resize the bridge selection window if we used a bigger one the last time */
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   164
			this->vscroll.cap = (this->vscroll.count > this->last_size) ? this->last_size : this->vscroll.count;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   165
			ResizeWindow(this, 0, (this->vscroll.cap - 4) * this->resize.step_height);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   166
			this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1;
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   167
		}
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   168
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   169
		this->FindWindowPlacementAndResize(desc);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   170
	}
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   171
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   172
	~BuildBridgeWindow()
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   173
	{
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   174
		delete bridges;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   175
	}
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   176
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   177
	virtual void OnPaint()
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   178
	{
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   179
		this->DrawWidgets();
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   180
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   181
		this->DrawSortButtonState(BBSW_DROPDOWN_ORDER, (this->bridges->flags & VL_DESC) ? SBS_DOWN : SBS_UP);
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   182
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   183
		uint y = this->widget[BBSW_BRIDGE_LIST].top + 2;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   184
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   185
		for (int i = this->vscroll.pos; (i < (this->vscroll.cap + this->vscroll.pos)) && (i < (int)this->bridges->Length()); i++) {
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   186
			const BridgeSpec *b = this->bridges->Get(i)->spec;
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   187
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   188
			SetDParam(2, this->bridges->Get(i)->cost);
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   189
			SetDParam(1, b->speed * 10 / 16);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   190
			SetDParam(0, b->material);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   191
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   192
			DrawSprite(b->sprite, b->pal, 3, y);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   193
			DrawString(44, y, STR_500D, TC_FROMSTRING);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   194
			y += this->resize.step_height;
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   195
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
		}
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   197
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   198
10607
1ab30cead125 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 10605
diff changeset
   199
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   200
	{
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   201
		const uint8 i = keycode - '1';
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   202
		if (i < 9 && i < this->bridges->Length()) {
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   203
			/* Build the requested bridge */
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   204
			this->BuildBridge(i);
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   205
			delete this;
10607
1ab30cead125 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 10605
diff changeset
   206
			return ES_HANDLED;
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   207
		}
10607
1ab30cead125 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 10605
diff changeset
   208
		return ES_NOT_HANDLED;
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   209
	}
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   210
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   211
	virtual void OnClick(Point pt, int widget)
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   212
	{
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   213
		switch (widget) {
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   214
			default: break;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   215
			case BBSW_BRIDGE_LIST: {
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   216
				uint i = ((int)pt.y - this->widget[BBSW_BRIDGE_LIST].top) / this->resize.step_height;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   217
				if (i < this->vscroll.cap) {
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   218
					i += this->vscroll.pos;
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   219
					if (i < this->bridges->Length()) {
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   220
						this->BuildBridge(i);
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   221
						delete this;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   222
					}
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   223
				}
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   224
			} break;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   225
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   226
			case BBSW_DROPDOWN_ORDER:
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   227
				/* Revers the sort order */
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   228
				this->bridges->flags ^= VL_DESC;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   229
				_bridge_sorting.order = !_bridge_sorting.order;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   230
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   231
				this->bridges->flags |= VL_RESORT;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   232
				this->SortBridgeList();
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   233
				break;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   234
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   235
			case BBSW_DROPDOWN_CRITERIA:
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   236
				ShowDropDownMenu(this, _bridge_sort_listing, bridges->sort_type, BBSW_DROPDOWN_CRITERIA, 0, 0);
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   237
				break;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   238
		}
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   239
	}
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   240
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   241
	virtual void OnDropdownSelect(int widget, int index)
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   242
	{
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   243
		if (widget == BBSW_DROPDOWN_CRITERIA && this->bridges->sort_type != index) {
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   244
			this->bridges->sort_type = index;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   245
			_bridge_sorting.criteria = index;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   246
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   247
			this->bridges->flags |= VL_RESORT;
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   248
			this->SortBridgeList();
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   249
		}
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   250
	}
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   251
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   252
	virtual void OnResize(Point new_size, Point delta)
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   253
	{
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   254
		this->vscroll.cap += delta.y / (int)this->resize.step_height;
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   255
		this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1;
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   256
		SetVScrollCount(this, this->bridges->Length());
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   257
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   258
		this->last_size = this->vscroll.cap;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	}
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   260
};
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   261
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   262
/* Set the default size of the Build Bridge Window */
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   263
uint BuildBridgeWindow::last_size = 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   265
/* Widget definition for the rail bridge selection window */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
static const Widget _build_bridge_widgets[] = {
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   267
{   WWT_CLOSEBOX,   RESIZE_NONE,  7,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW},            // BBSW_CLOSEBOX
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   268
{    WWT_CAPTION,   RESIZE_NONE,  7,  11, 199,   0,  13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},  // BBSW_CAPTION
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   269
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   270
{    WWT_TEXTBTN,   RESIZE_NONE,  7,   0,  80,  14,  25, STR_SORT_BY,                 STR_SORT_ORDER_TIP},               // BBSW_DROPDOWN_ORDER
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   271
{   WWT_DROPDOWN,   RESIZE_NONE,  7,  81, 199,  14,  25, 0x0,                         STR_SORT_CRITERIA_TIP},            // BBSW_DROPDOWN_CRITERIA
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   272
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   273
{     WWT_MATRIX, RESIZE_BOTTOM,  7,   0, 187,  26, 113, 0x401,                       STR_101F_BRIDGE_SELECTION_CLICK},  // BBSW_BRIDGE_LIST
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   274
{  WWT_SCROLLBAR, RESIZE_BOTTOM,  7, 188, 199,  26, 101, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST}, // BBSW_SCROLLBAR
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   275
{  WWT_RESIZEBOX,     RESIZE_TB,  7, 188, 199, 102, 113, 0x0,                         STR_RESIZE_BUTTON},                // BBSW_RESIZEBOX
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 0
diff changeset
   276
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
8516
e7ce655f85ef (svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents: 8479
diff changeset
   279
/* Window definition for the rail bridge selection window */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
static const WindowDesc _build_bridge_desc = {
10615
58fb0e062812 (svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents: 10607
diff changeset
   281
	WDP_AUTO, WDP_AUTO, 200, 114, 200, 114,
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 4634
diff changeset
   282
	WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   283
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
	_build_bridge_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   287
/**
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   288
 * Prepare the data for the build a bridge window.
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   289
 *  If we can't build a bridge under the given conditions
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   290
 *  show an error message.
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   291
 *
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   292
 * @parma start The start tile of the bridge
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   293
 * @param end The end tile of the bridge
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   294
 * @param transport_type The transport type
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   295
 * @param bridge_type The bridge type
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   296
 */
9053
13c47e8836eb (svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents: 9031
diff changeset
   297
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	DeleteWindowById(WC_BUILD_BRIDGE, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   301
	/* Data type for the bridge.
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   302
	 * Bit 16,15 = transport type,
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   303
	 *     14..8 = road/rail pieces,
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   304
	 *      7..0 = type of bridge */
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   305
	uint32 type = (transport_type << 15) | (bridge_type << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   307
	/* only query bridge building possibility once, result is the same for all bridges!
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   308
	 * returns CMD_ERROR on failure, and price on success */
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   309
	StringID errmsg = INVALID_STRING_ID;
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   310
	CommandCost ret = DoCommand(end, start, type, DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   312
	GUIBridgeList *bl = NULL;
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2639
diff changeset
   313
	if (CmdFailed(ret)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
		errmsg = _error_message;
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2470
diff changeset
   315
	} else {
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   316
		/* check which bridges can be built
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   317
		 * get absolute bridge length
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   318
		 * length of the middle parts of the bridge */
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8760
diff changeset
   319
		const uint bridge_len = GetTunnelBridgeLength(start, end);
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   320
		/* total length of bridge */
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   321
		const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   323
		bl = new GUIBridgeList();
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   324
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   325
		/* loop for all bridgetypes */
9028
501b3b351df7 (svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents: 8987
diff changeset
   326
		for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
501b3b351df7 (svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents: 8987
diff changeset
   327
			if (CheckBridge_Stuff(brd_type, bridge_len)) {
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   328
				/* bridge is accepted, add to list */
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   329
				BuildBridgeData *item = bl->Append();
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   330
				item->index = brd_type;
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   331
				item->spec = GetBridgeSpec(brd_type);
8479
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   332
				/* Add to terraforming & bulldozing costs the cost of the
a1ab2afafb84 (svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents: 8320
diff changeset
   333
				 * bridge itself (not computed with DC_QUERY_COST) */
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   334
				item->cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * item->spec->price) >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   339
	if (bl != NULL && bl->Length() != 0) {
10605
87e6826b9901 (svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents: 10595
diff changeset
   340
		new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	} else {
10716
2406d1520245 (svn r13266) -Codechange: Use SmallVector in GUIList
peter1138
parents: 10658
diff changeset
   342
		if (bl != NULL) delete bl;
3422
12cdb13ddb56 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 2952
diff changeset
   343
		ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
0
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
}