author | skidd13 |
Sun, 18 May 2008 12:25:46 +0000 | |
changeset 9292 | 176fb6c36f10 |
parent 9285 | 235e5e2d7f55 |
child 9317 | f14eb8815829 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6117
6507b2a7e71d
(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:
5931
diff
changeset
|
3 |
/** @file bridge_gui.cpp Graphical user interface for bridge construction */ |
2262
252cfd94c54d
(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 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1781
diff
changeset
|
6 |
#include "openttd.h" |
0 | 7 |
#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
|
8 |
#include "window_gui.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
9 |
#include "command_func.h" |
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
10 |
#include "economy_func.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2133
diff
changeset
|
11 |
#include "variables.h" |
2262
252cfd94c54d
(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" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8107
diff
changeset
|
13 |
#include "strings_func.h" |
8131
160939e24ed3
(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:
8121
diff
changeset
|
14 |
#include "window_func.h" |
8157
1505def01945
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8139
diff
changeset
|
15 |
#include "sound_func.h" |
8139
4e91c448c409
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8131
diff
changeset
|
16 |
#include "map_func.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8157
diff
changeset
|
17 |
#include "viewport_func.h" |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8157
diff
changeset
|
18 |
#include "gfx_func.h" |
8398
1e181e2e4e15
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8264
diff
changeset
|
19 |
#include "tunnelbridge.h" |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
20 |
#include "sortlist_type.h" |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
21 |
#include "widgets/dropdown_func.h" |
0 | 22 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8224
diff
changeset
|
23 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8224
diff
changeset
|
24 |
|
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
25 |
/* Save the sorting during runtime */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
26 |
static Listing _bridge_sorting = {false, 0}; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
27 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
28 |
/** |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
29 |
* Carriage for the data we need if we want to build a bridge |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
30 |
*/ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
31 |
struct BuildBridgeData { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
32 |
BridgeType index; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
33 |
const BridgeSpec *spec; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
34 |
Money cost; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
35 |
}; |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
36 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
37 |
typedef GUIList<BuildBridgeData> GUIBridgeList; |
0 | 38 |
|
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
39 |
/** Sort the bridges by their index */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
40 |
static int CDECL BridgeIndexSorter(const void *a, const void *b) |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
41 |
{ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
42 |
const BuildBridgeData* ba = (BuildBridgeData*)a; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
43 |
const BuildBridgeData* bb = (BuildBridgeData*)b; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
44 |
int r = ba->index - bb->index; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
45 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
46 |
return (_bridge_sorting.order) ? -r : r; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
47 |
} |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
48 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
49 |
/** Sort the bridges by their price */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
50 |
static int CDECL BridgePriceSorter(const void *a, const void *b) |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
51 |
{ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
52 |
const BuildBridgeData* ba = (BuildBridgeData*)a; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
53 |
const BuildBridgeData* bb = (BuildBridgeData*)b; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
54 |
int r = ba->cost - bb->cost; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
55 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
56 |
return (_bridge_sorting.order) ? -r : r; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
57 |
} |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
58 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
59 |
/** Sort the bridges by their maximum speed */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
60 |
static int CDECL BridgeSpeedSorter(const void *a, const void *b) |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
61 |
{ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
62 |
const BuildBridgeData* ba = (BuildBridgeData*)a; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
63 |
const BuildBridgeData* bb = (BuildBridgeData*)b; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
64 |
int r = ba->spec->speed - bb->spec->speed; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
65 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
66 |
return (_bridge_sorting.order) ? -r : r; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
67 |
} |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
68 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
69 |
typedef int CDECL BridgeSortListingTypeFunction(const void*, const void*); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
70 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
71 |
/* Availible bridge sorting functions */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
72 |
static BridgeSortListingTypeFunction* const _bridge_sorter[] = { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
73 |
&BridgeIndexSorter, |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
74 |
&BridgePriceSorter, |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
75 |
&BridgeSpeedSorter |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
76 |
}; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
77 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
78 |
/* Names of the sorting functions */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
79 |
static const StringID _bridge_sort_listing[] = { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
80 |
STR_SORT_BY_NUMBER, |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
81 |
STR_ENGINE_SORT_COST, |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
82 |
STR_SORT_BY_MAX_SPEED, |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
83 |
INVALID_STRING_ID |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
84 |
}; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
85 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
86 |
/** |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
87 |
* Callback executed after a build Bridge CMD has been called |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
88 |
* |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
89 |
* @param scucess True if the build succeded |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
90 |
* @param tile The tile where the command has been executed |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
91 |
* @param p1 not used |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
92 |
* @param p2 not used |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
93 |
*/ |
1977
37bbebf94434
(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 | 95 |
{ |
541 | 96 |
if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile); |
0 | 97 |
} |
98 |
||
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
99 |
/* Names of the build bridge selection window */ |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
100 |
enum BuildBridgeSelectionWidgets { |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
101 |
BBSW_CLOSEBOX = 0, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
102 |
BBSW_CAPTION, |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
103 |
BBSW_DROPDOWN_ORDER, |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
104 |
BBSW_DROPDOWN_CRITERIA, |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
105 |
BBSW_BRIDGE_LIST, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
106 |
BBSW_SCROLLBAR, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
107 |
BBSW_RESIZEBOX |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
108 |
}; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
109 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
110 |
class BuildBridgeWindow : public Window { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
111 |
private: |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
112 |
/* The last size of the build bridge window |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
113 |
* is saved during runtime */ |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
114 |
static uint last_size; |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
115 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
116 |
TileIndex start_tile; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
117 |
TileIndex end_tile; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
118 |
uint32 type; |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
119 |
GUIBridgeList *bridges; |
0 | 120 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
121 |
void BuildBridge(uint8 i) |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
122 |
{ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
123 |
DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->sort_list[i].index, |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
124 |
CcBuildBridge, CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE)); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
125 |
} |
0 | 126 |
|
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
127 |
/** Sort the builable bridges */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
128 |
void SortBridgeList() |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
129 |
{ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
130 |
/* Skip sorting if resort bit is not set */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
131 |
if (!(bridges->flags & VL_RESORT)) return; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
132 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
133 |
qsort(this->bridges->sort_list, this->bridges->list_length, sizeof(this->bridges->sort_list[0]), _bridge_sorter[_bridge_sorting.criteria]); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
134 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
135 |
/* Display the current sort variant */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
136 |
this->widget[BBSW_DROPDOWN_CRITERIA].data = _bridge_sort_listing[this->bridges->sort_type]; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
137 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
138 |
bridges->flags &= ~VL_RESORT; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
139 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
140 |
/* Set the modified widgets dirty */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
141 |
this->InvalidateWidget(BBSW_DROPDOWN_CRITERIA); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
142 |
this->InvalidateWidget(BBSW_BRIDGE_LIST); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
143 |
} |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
144 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
145 |
public: |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
146 |
BuildBridgeWindow(const WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(desc), |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
147 |
start_tile(start), |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
148 |
end_tile(end), |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
149 |
type(br_type), |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
150 |
bridges(bl) |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
151 |
{ |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
152 |
this->SortBridgeList(); |
0 | 153 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
154 |
/* Change the data, or the caption of the gui. Set it to road or rail, accordingly */ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
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; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
156 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
157 |
this->resize.step_height = 22; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
158 |
this->vscroll.count = bl->list_length; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
159 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
160 |
if (this->last_size <= 4) { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
161 |
this->vscroll.cap = 4; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
162 |
} else { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
163 |
/* Resize the bridge selection window if we used a bigger one the last time */ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
164 |
this->vscroll.cap = (this->vscroll.count > this->last_size) ? this->last_size : this->vscroll.count; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
165 |
ResizeWindow(this, 0, (this->vscroll.cap - 4) * this->resize.step_height); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
166 |
this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1; |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
167 |
} |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
168 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
169 |
this->FindWindowPlacementAndResize(desc); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
170 |
} |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
171 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
172 |
~BuildBridgeWindow() |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
173 |
{ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
174 |
free(this->bridges->sort_list); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
175 |
delete bridges; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
176 |
} |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
177 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
178 |
virtual void OnPaint() |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
179 |
{ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
180 |
this->DrawWidgets(); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
181 |
|
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
182 |
this->DrawSortButtonState(BBSW_DROPDOWN_ORDER, (this->bridges->flags & VL_DESC) ? SBS_DOWN : SBS_UP); |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
183 |
|
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
184 |
uint y = this->widget[BBSW_BRIDGE_LIST].top + 2; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
185 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
186 |
for (uint i = this->vscroll.pos; (i < (this->vscroll.cap + this->vscroll.pos)) && (i < this->bridges->list_length); i++) { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
187 |
const BridgeSpec *b = this->bridges->sort_list[i].spec; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
188 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
189 |
SetDParam(2, this->bridges->sort_list[i].cost); |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
190 |
SetDParam(1, b->speed * 10 / 16); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
191 |
SetDParam(0, b->material); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
192 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
193 |
DrawSprite(b->sprite, b->pal, 3, y); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
194 |
DrawString(44, y, STR_500D, TC_FROMSTRING); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
195 |
y += this->resize.step_height; |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
196 |
|
0 | 197 |
} |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
198 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
199 |
|
9285
235e5e2d7f55
(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:
9283
diff
changeset
|
200 |
virtual EventState OnKeyPress(uint16 key, uint16 keycode) |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
201 |
{ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
202 |
const uint8 i = keycode - '1'; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
203 |
if (i < 9 && i < this->bridges->list_length) { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
204 |
/* Build the requested bridge */ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
205 |
this->BuildBridge(i); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
206 |
delete this; |
9285
235e5e2d7f55
(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:
9283
diff
changeset
|
207 |
return ES_HANDLED; |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
208 |
} |
9285
235e5e2d7f55
(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:
9283
diff
changeset
|
209 |
return ES_NOT_HANDLED; |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
210 |
} |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
211 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
212 |
virtual void OnClick(Point pt, int widget) |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
213 |
{ |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
214 |
switch (widget) { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
215 |
default: break; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
216 |
case BBSW_BRIDGE_LIST: { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
217 |
uint i = ((int)pt.y - this->widget[BBSW_BRIDGE_LIST].top) / this->resize.step_height; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
218 |
if (i < this->vscroll.cap) { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
219 |
i += this->vscroll.pos; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
220 |
if (i < this->bridges->list_length) { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
221 |
this->BuildBridge(i); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
222 |
delete this; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
223 |
} |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
224 |
} |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
225 |
} break; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
226 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
227 |
case BBSW_DROPDOWN_ORDER: |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
228 |
/* Revers the sort order */ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
229 |
this->bridges->flags ^= VL_DESC; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
230 |
_bridge_sorting.order = !_bridge_sorting.order; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
231 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
232 |
this->bridges->flags |= VL_RESORT; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
233 |
this->SortBridgeList(); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
234 |
break; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
235 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
236 |
case BBSW_DROPDOWN_CRITERIA: |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
237 |
ShowDropDownMenu(this, _bridge_sort_listing, bridges->sort_type, BBSW_DROPDOWN_CRITERIA, 0, 0); |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
238 |
break; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
239 |
} |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
240 |
} |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
241 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
242 |
virtual void OnDropdownSelect(int widget, int index) |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
243 |
{ |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
244 |
if (widget == BBSW_DROPDOWN_CRITERIA && this->bridges->sort_type != index) { |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
245 |
this->bridges->sort_type = index; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
246 |
_bridge_sorting.criteria = index; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
247 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
248 |
this->bridges->flags |= VL_RESORT; |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
249 |
this->SortBridgeList(); |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
250 |
} |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
251 |
} |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
252 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
253 |
virtual void OnResize(Point new_size, Point delta) |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
254 |
{ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
255 |
this->vscroll.cap += delta.y / (int)this->resize.step_height; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
256 |
this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
257 |
SetVScrollCount(this, this->bridges->list_length); |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
258 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
259 |
this->last_size = this->vscroll.cap; |
0 | 260 |
} |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
261 |
}; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
262 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
263 |
/* Set the default size of the Build Bridge Window */ |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
264 |
uint BuildBridgeWindow::last_size = 4; |
0 | 265 |
|
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
266 |
/* Widget definition for the rail bridge selection window */ |
0 | 267 |
static const Widget _build_bridge_widgets[] = { |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
268 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BBSW_CLOSEBOX |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
269 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BBSW_CAPTION |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
270 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
271 |
{ WWT_TEXTBTN, RESIZE_NONE, 7, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP}, // BBSW_DROPDOWN_ORDER |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
272 |
{ WWT_DROPDOWN, RESIZE_NONE, 7, 81, 199, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, // BBSW_DROPDOWN_CRITERIA |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
273 |
|
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
274 |
{ WWT_MATRIX, RESIZE_BOTTOM, 7, 0, 187, 26, 113, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, // BBSW_BRIDGE_LIST |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
275 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 7, 188, 199, 26, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // BBSW_SCROLLBAR |
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
276 |
{ 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
|
277 |
{ WIDGETS_END}, |
0 | 278 |
}; |
279 |
||
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
280 |
/* Window definition for the rail bridge selection window */ |
0 | 281 |
static const WindowDesc _build_bridge_desc = { |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
282 |
WDP_AUTO, WDP_AUTO, 200, 114, 200, 114, |
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4634
diff
changeset
|
283 |
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
284 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE, |
0 | 285 |
_build_bridge_widgets, |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
286 |
NULL |
0 | 287 |
}; |
288 |
||
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
289 |
/** |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
290 |
* Add a buildable bridge to the list. |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
291 |
* If the list is empty a new one is created. |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
292 |
* |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
293 |
* @param bl The list which we want to manage |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
294 |
* @param item The item to add |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
295 |
* @return The pointer to the list |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
296 |
*/ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
297 |
static GUIBridgeList *PushBridgeList(GUIBridgeList *bl, BuildBridgeData item) |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
298 |
{ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
299 |
if (bl == NULL) { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
300 |
/* Create the list if needed */ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
301 |
bl = new GUIBridgeList(); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
302 |
bl->flags |= VL_RESORT; |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
303 |
if (_bridge_sorting.order) bl->flags |= VL_DESC; |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
304 |
bl->list_length = 1; |
9292
176fb6c36f10
(svn r13159) -Feature: Add the ability to sort availible bridges in the build bridge GUI
skidd13
parents:
9285
diff
changeset
|
305 |
bl->sort_type = _bridge_sorting.criteria; |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
306 |
} else { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
307 |
/* Resize the list */ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
308 |
bl->list_length++; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
309 |
} |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
310 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
311 |
bl->sort_list = ReallocT(bl->sort_list, bl->list_length); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
312 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
313 |
bl->sort_list[bl->list_length - 1] = item; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
314 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
315 |
return bl; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
316 |
} |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
317 |
|
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
318 |
/** |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
319 |
* Prepare the data for the build a bridge window. |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
320 |
* If we can't build a bridge under the given conditions |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
321 |
* show an error message. |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
322 |
* |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
323 |
* @parma start The start tile of the bridge |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
324 |
* @param end The end tile of the bridge |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
325 |
* @param transport_type The transport type |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
326 |
* @param bridge_type The bridge type |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
327 |
*/ |
8557
d5fb341fc220
(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:
8535
diff
changeset
|
328 |
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type) |
0 | 329 |
{ |
330 |
DeleteWindowById(WC_BUILD_BRIDGE, 0); |
|
331 |
||
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
332 |
/* Data type for the bridge. |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
333 |
* Bit 16,15 = transport type, |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
334 |
* 14..8 = road/rail pieces, |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
335 |
* 7..0 = type of bridge */ |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
336 |
uint32 type = (transport_type << 15) | (bridge_type << 8); |
0 | 337 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
338 |
/* only query bridge building possibility once, result is the same for all bridges! |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
339 |
* returns CMD_ERROR on failure, and price on success */ |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
340 |
StringID errmsg = INVALID_STRING_ID; |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
341 |
CommandCost ret = DoCommand(end, start, type, DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE); |
0 | 342 |
|
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
343 |
GUIBridgeList *bl = NULL; |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2639
diff
changeset
|
344 |
if (CmdFailed(ret)) { |
0 | 345 |
errmsg = _error_message; |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2470
diff
changeset
|
346 |
} else { |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
347 |
/* check which bridges can be built |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
348 |
* get absolute bridge length |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
349 |
* length of the middle parts of the bridge */ |
8398
1e181e2e4e15
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8264
diff
changeset
|
350 |
const uint bridge_len = GetTunnelBridgeLength(start, end); |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
351 |
/* total length of bridge */ |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
352 |
const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2); |
0 | 353 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
354 |
/* loop for all bridgetypes */ |
8532
ebe68d6899b6
(svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents:
8491
diff
changeset
|
355 |
for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) { |
ebe68d6899b6
(svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents:
8491
diff
changeset
|
356 |
if (CheckBridge_Stuff(brd_type, bridge_len)) { |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
357 |
/* bridge is accepted, add to list */ |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
358 |
BuildBridgeData item; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
359 |
item.index = brd_type; |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
360 |
item.spec = GetBridgeSpec(brd_type); |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
361 |
/* Add to terraforming & bulldozing costs the cost of the |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
362 |
* bridge itself (not computed with DC_QUERY_COST) */ |
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
363 |
item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * item.spec->price) >> 8); |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
364 |
bl = PushBridgeList(bl, item); |
0 | 365 |
} |
366 |
} |
|
367 |
} |
|
368 |
||
9283
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
369 |
if (bl != NULL) { |
dbccc281c38a
(svn r13149) -Codechange: make a class of the BuildBridgeWindow.
skidd13
parents:
9273
diff
changeset
|
370 |
new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl); |
0 | 371 |
} else { |
3422
a6eba3443452
(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
|
372 |
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE); |
0 | 373 |
} |
374 |
} |