src/station_gui.cpp
author rubidium
Sun, 17 Aug 2008 21:07:09 +0000
changeset 9942 c3677fa5563f
parent 9913 d9ce89020cc0
child 10021 c737dd2eb7c9
permissions -rw-r--r--
(svn r14097) -Fix [FS#2085]: one couldn't get a list of vehicles sharing an order when the number of orders was 0; you could see that the vehicles had a shared order though.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9094
diff changeset
     3
/** @file station_gui.cpp The GUI for stations. */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6365
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1272
diff changeset
     7
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#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
     9
#include "window_gui.h"
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    10
#include "textbuf_gui.h"
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8762
diff changeset
    11
#include "station_base.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8224
diff changeset
    12
#include "player_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    13
#include "economy_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "town.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    15
#include "command_func.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    16
#include "variables.h"
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    17
#include "vehicle_gui.h"
6091
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 5893
diff changeset
    18
#include "cargotype.h"
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    19
#include "station_gui.h"
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8762
diff changeset
    20
#include "station_func.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8109
diff changeset
    21
#include "strings_func.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8121
diff changeset
    22
#include "core/alloc_func.hpp"
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: 8130
diff changeset
    23
#include "window_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8179
diff changeset
    24
#include "viewport_func.h"
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8179
diff changeset
    25
#include "gfx_func.h"
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents: 8268
diff changeset
    26
#include "widgets/dropdown_func.h"
8787
41d9d5adbe87 (svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents: 8785
diff changeset
    27
#include "newgrf_cargo.h"
9164
18e971e0b44f (svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
rubidium
parents: 9143
diff changeset
    28
#include "string_func.h"
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9652
diff changeset
    29
#include "player_base.h"
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
    30
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    31
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    32
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    33
8268
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    34
bool _station_show_coverage;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    35
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    36
/**
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    37
 * Draw small boxes of cargo amount and ratings data at the given
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    38
 * coordinates. If amount exceeds 576 units, it is shown 'full', same
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    39
 * goes for the rating: at above 90% orso (224) it is also 'full'
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    40
 *
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6365
diff changeset
    41
 * @param x coordinate to draw the box at
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6365
diff changeset
    42
 * @param y coordinate to draw the box at
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    43
 * @param type Cargo type
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    44
 * @param amount Cargo amount
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    45
 * @param rating ratings data for that particular cargo
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    46
 *
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    47
 * @note Each cargo-bar is 16 pixels wide and 6 pixels high
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    48
 * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    49
 */
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    50
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
{
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    52
	static const uint units_full  = 576; ///< number of units to show station as 'full'
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    53
	static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    54
6091
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 5893
diff changeset
    55
	const CargoSpec *cs = GetCargo(type);
6122
3359af5a1f54 (svn r8858) -Codechange: Replace magic number test with class method for determining if a cargo is valid/active.
peter1138
parents: 6091
diff changeset
    56
	if (!cs->IsValid()) return;
6091
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 5893
diff changeset
    57
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 5893
diff changeset
    58
	int colour = cs->rating_colour;
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    59
	uint w = (minu(amount, units_full) + 5) / 36;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    61
	/* Draw total cargo (limited) on station (fits into 16 pixels) */
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    62
	if (w != 0) GfxFillRect(x, y, x + w - 1, y + 6, colour);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    64
	/* Draw a one pixel-wide bar of additional cargo meter, useful
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    65
	 * for stations with only a small amount (<=30) */
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    66
	if (w == 0) {
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    67
		uint rest = amount / 5;
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    68
		if (rest != 0) {
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    69
			w += x;
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    70
			GfxFillRect(w, y + 6 - rest, w, y + 6, colour);
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    71
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7474
diff changeset
    74
	DrawString(x + 1, y, cs->abbrev, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    76
	/* Draw green/red ratings bar (fits into 14 pixels) */
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    77
	y += 8;
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    78
	GfxFillRect(x + 1, y, x + 14, y, 0xB8);
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    79
	rating = minu(rating, rating_full) / 16;
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    80
	if (rating != 0) GfxFillRect(x + 1, y, x + rating, y, 0xD0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
    83
typedef GUIList<const Station*> GUIStationList;
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    84
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    85
/**
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
    86
 * The list of stations per player.
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    87
 */
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    88
class PlayerStationsWindow : public Window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
{
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    90
protected:
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    91
	/* Runtime saved values */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    92
	static Listing last_sorting;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    93
	static byte facilities;               // types of stations of interest
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    94
	static bool include_empty;            // whether we should include stations without waiting cargo
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    95
	static const uint32 cargo_filter_max;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    96
	static uint32 cargo_filter;           // bitmap of cargo types to include
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    97
	static const Station *last_station;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    98
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    99
	/* Constants for sorting stations */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   100
	static const StringID sorter_names[];
9382
c25c7eb89d16 (svn r13292) -Fix (r13285): MSVC warnings
glx
parents: 9379
diff changeset
   101
	static GUIStationList::SortFunction *const sorter_funcs[];
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   102
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   103
	GUIStationList stations;
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   104
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   105
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   106
	/**
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   107
	 * (Re)Build station list
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   108
	 *
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   109
	 * @param owner player whose stations are to be in list
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   110
	 */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   111
	void BuildStationsList(const PlayerID owner)
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   112
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   113
		if (!this->stations.NeedRebuild()) return;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   114
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   115
		DEBUG(misc, 3, "Building station list for player %d", owner);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   116
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   117
		this->stations.Clear();
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   118
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   119
		const Station *st;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   120
		FOR_ALL_STATIONS(st) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   121
			if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   122
				if (this->facilities & st->facilities) { // only stations with selected facilities
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   123
					int num_waiting_cargo = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   124
					for (CargoID j = 0; j < NUM_CARGO; j++) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   125
						if (!st->goods[j].cargo.Empty()) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   126
							num_waiting_cargo++; // count number of waiting cargo
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   127
							if (HasBit(this->cargo_filter, j)) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   128
								*this->stations.Append() = st;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   129
								break;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   130
							}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   131
						}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   132
					}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   133
					/* stations without waiting cargo */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   134
					if (num_waiting_cargo == 0 && this->include_empty) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   135
						*this->stations.Append() = st;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   136
					}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   137
				}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   138
			}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   139
		}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   140
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   141
		this->stations.Compact();
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   142
		this->stations.RebuildDone();
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   143
	}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   144
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   145
	/** Sort stations by their name */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   146
	static int CDECL StationNameSorter(const Station* const *a, const Station* const *b)
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   147
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   148
		static char buf_cache[64];
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   149
		char buf[64];
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   150
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   151
		SetDParam(0, (*a)->index);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   152
		GetString(buf, STR_STATION, lastof(buf));
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   153
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   154
		if (*b != last_station) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   155
			last_station = *b;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   156
			SetDParam(0, (*b)->index);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   157
			GetString(buf_cache, STR_STATION, lastof(buf_cache));
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   158
		}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   159
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   160
		return strcmp(buf, buf_cache);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   161
	}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   162
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   163
	/** Sort stations by their type */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   164
	static int CDECL StationTypeSorter(const Station* const *a, const Station* const *b)
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   165
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   166
		return (*a)->facilities - (*b)->facilities;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   167
	}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   168
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   169
	/** Sort stations by their waiting cargo */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   170
	static int CDECL StationWaitingSorter(const Station* const *a, const Station* const *b)
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   171
	{
9580
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   172
		Money diff = 0;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   173
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   174
		for (CargoID j = 0; j < NUM_CARGO; j++) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   175
			if (!HasBit(cargo_filter, j)) continue;
9580
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   176
			if (!(*a)->goods[j].cargo.Empty()) diff += GetTransportedGoodsIncome((*a)->goods[j].cargo.Count(), 20, 50, j);
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   177
			if (!(*b)->goods[j].cargo.Empty()) diff -= GetTransportedGoodsIncome((*b)->goods[j].cargo.Count(), 20, 50, j);
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   178
		}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   179
9580
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   180
		return ClampToI32(diff);
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   181
	}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   182
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   183
	/** Sort stations by their rating */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   184
	static int CDECL StationRatingMaxSorter(const Station* const *a, const Station* const *b)
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   185
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   186
		byte maxr1 = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   187
		byte maxr2 = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   188
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   189
		for (CargoID j = 0; j < NUM_CARGO; j++) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   190
			if (HasBit((*a)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, (*a)->goods[j].rating);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   191
			if (HasBit((*b)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, (*b)->goods[j].rating);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   192
		}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   193
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   194
		return maxr1 - maxr2;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   195
	}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   196
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   197
	/** Sort the stations list */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   198
	void SortStationsList()
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   199
	{
9379
2c6c6a0e2233 (svn r13286) -Codechange: GUIList Sort returns now if the list sequence has been altered
skidd13
parents: 9378
diff changeset
   200
		if (!this->stations.Sort()) return;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   201
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   202
		/* Reset name sorter sort cache */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   203
		this->last_station = NULL;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   204
9389
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   205
		/* Set the modified widget dirty */
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   206
		this->InvalidateWidget(SLW_LIST);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   207
	}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   208
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   209
public:
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9191
diff changeset
   210
	PlayerStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   211
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   212
		this->caption_color = (byte)this->window_number;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   213
		this->vscroll.cap = 12;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   214
		this->resize.step_height = 10;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   215
		this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
8338
598af8119b97 (svn r11904) -Codechange: use dropdown widget in 3 more windows, build vehicle, group vehicle list and station list.
peter1138
parents: 8284
diff changeset
   216
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   217
		/* Add cargo filter buttons */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   218
		uint num_active = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   219
		for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   220
			if (GetCargo(c)->IsValid()) num_active++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   221
		}
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   222
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   223
		this->widget_count += num_active;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   224
		this->widget = ReallocT(this->widget, this->widget_count + 1);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   225
		this->widget[this->widget_count].type = WWT_LAST;
6271
a17b8a4e17e8 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6260
diff changeset
   226
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   227
		uint i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   228
		for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   229
			if (!GetCargo(c)->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   230
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   231
			Widget *wi = &this->widget[SLW_CARGOSTART + i];
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   232
			wi->type     = WWT_PANEL;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   233
			wi->display_flags = RESIZE_NONE;
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   234
			wi->color    = COLOUR_GREY;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   235
			wi->left     = 89 + i * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   236
			wi->right    = wi->left + 13;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   237
			wi->top      = 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   238
			wi->bottom   = 24;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   239
			wi->data     = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   240
			wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   241
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   242
			if (HasBit(this->cargo_filter, c)) this->LowerWidget(SLW_CARGOSTART + i);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   243
			i++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   244
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   245
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   246
		this->widget[SLW_NOCARGOWAITING].left += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   247
		this->widget[SLW_NOCARGOWAITING].right += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   248
		this->widget[SLW_CARGOALL].left += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   249
		this->widget[SLW_CARGOALL].right += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   250
		this->widget[SLW_PAN_RIGHT].left += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   251
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   252
		if (num_active > 15) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   253
			/* Resize and fix the minimum width, if necessary */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   254
			ResizeWindow(this, (num_active - 15) * 14, 0);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   255
			this->resize.width = this->width;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   256
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   257
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   258
		if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   259
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   260
		for (uint i = 0; i < 5; i++) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   261
			if (HasBit(this->facilities, i)) this->LowerWidget(i + SLW_TRAIN);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   262
		}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   263
		this->SetWidgetLoweredState(SLW_FACILALL, this->facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   264
		this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   265
		this->SetWidgetLoweredState(SLW_NOCARGOWAITING, this->include_empty);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   266
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   267
		this->stations.SetListing(this->last_sorting);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   268
		this->stations.SetSortFuncs(this->sorter_funcs);
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   269
		this->stations.ForceRebuild();
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   270
		this->stations.NeedResort();
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   271
		this->SortStationsList();
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
   272
9389
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   273
		this->widget[SLW_SORTDROPBTN].data = this->sorter_names[this->stations.SortType()];
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   274
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
   275
		this->FindWindowPlacementAndResize(desc);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   276
	}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   277
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   278
	~PlayerStationsWindow()
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   279
	{
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   280
		this->last_sorting = this->stations.GetListing();
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   281
	}
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   282
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   283
	virtual void OnPaint()
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   284
	{
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   285
		const PlayerID owner = (PlayerID)this->window_number;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   286
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   287
		this->BuildStationsList(owner);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   288
		this->SortStationsList();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   289
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   290
		SetVScrollCount(this, this->stations.Length());
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   291
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   292
		/* draw widgets, with player's name in the caption */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   293
		SetDParam(0, owner);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   294
		SetDParam(1, this->vscroll.count);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   295
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9214
diff changeset
   296
		this->DrawWidgets();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   297
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   298
		/* draw arrow pointing up/down for ascending/descending sorting */
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   299
		this->DrawSortButtonState(SLW_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   300
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   301
		int cg_ofst;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   302
		int x = 89;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   303
		int y = 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   304
		int xb = 2; ///< offset from left of widget
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   305
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   306
		uint i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   307
		for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   308
			const CargoSpec *cs = GetCargo(c);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   309
			if (!cs->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   310
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   311
			cg_ofst = HasBit(this->cargo_filter, c) ? 2 : 1;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   312
			GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   313
			DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   314
			x += 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   315
			i++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   316
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   317
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   318
		x += 6;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   319
		cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   320
		DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   321
		x += 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   322
		cg_ofst = this->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   323
		DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   324
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   325
		cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   326
		DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   327
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   328
		if (this->vscroll.count == 0) { // player has no stations
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   329
			DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   330
			return;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   331
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   332
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   333
		int max = min(this->vscroll.pos + this->vscroll.cap, this->stations.Length());
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   334
		y = 40; // start of the list-widget
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   335
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   336
		for (int i = this->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   337
			const Station *st = this->stations[i];
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   338
			int x;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   339
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   340
			assert(st->xy != 0);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   341
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   342
			/* Do not do the complex check HasStationInUse here, it may be even false
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   343
				* when the order had been removed and the station list hasn't been removed yet */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   344
			assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   345
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   346
			SetDParam(0, st->index);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   347
			SetDParam(1, st->facilities);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   348
			x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   349
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   350
			/* show cargo waiting and station ratings */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   351
			for (CargoID j = 0; j < NUM_CARGO; j++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   352
				if (!st->goods[j].cargo.Empty()) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   353
					StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   354
					x += 20;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   355
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   356
			}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   357
			y += 10;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   358
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   359
	}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   360
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   361
	virtual void OnClick(Point pt, int widget)
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   362
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   363
		switch (widget) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   364
			case SLW_LIST: {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   365
				uint32 id_v = (pt.y - 41) / 10;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   366
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   367
				if (id_v >= this->vscroll.cap) return; // click out of bounds
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   368
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   369
				id_v += this->vscroll.pos;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   370
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   371
				if (id_v >= this->stations.Length()) return; // click out of list bound
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   372
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   373
				const Station *st = this->stations[id_v];
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   374
				/* do not check HasStationInUse - it is slow and may be invalid */
9214
933c86db8e44 (svn r13080) -Fix: warning about unused variable when compiling without asserts
smatz
parents: 9203
diff changeset
   375
				assert(st->owner == (PlayerID)this->window_number || (st->owner == OWNER_NONE && !st->IsBuoy()));
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   376
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   377
				if (_ctrl_pressed) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   378
					ShowExtraViewPortWindow(st->xy);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   379
				} else {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   380
					ScrollMainWindowToTile(st->xy);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   381
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   382
				break;
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   383
			}
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   384
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   385
			case SLW_TRAIN:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   386
			case SLW_TRUCK:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   387
			case SLW_BUS:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   388
			case SLW_AIRPLANE:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   389
			case SLW_SHIP:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   390
				if (_ctrl_pressed) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   391
					ToggleBit(this->facilities, widget - SLW_TRAIN);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   392
					this->ToggleWidgetLoweredState(widget);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   393
				} else {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   394
					uint i;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   395
					FOR_EACH_SET_BIT(i, this->facilities) {
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   396
						this->RaiseWidget(i + SLW_TRAIN);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   397
					}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   398
					SetBit(this->facilities, widget - SLW_TRAIN);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   399
					this->LowerWidget(widget);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   400
				}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   401
				this->SetWidgetLoweredState(SLW_FACILALL, this->facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   402
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   403
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   404
				break;
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   405
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   406
			case SLW_FACILALL:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   407
				for (uint i = 0; i < 5; i++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   408
					this->LowerWidget(i + SLW_TRAIN);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   409
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   410
				this->LowerWidget(SLW_FACILALL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   412
				this->facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   413
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   414
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   415
				break;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   416
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   417
			case SLW_CARGOALL: {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   418
				uint i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   419
				for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   420
					if (!GetCargo(c)->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   421
					this->LowerWidget(i + SLW_CARGOSTART);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   422
					i++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   423
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   424
				this->LowerWidget(SLW_NOCARGOWAITING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   425
				this->LowerWidget(SLW_CARGOALL);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   426
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   427
				this->cargo_filter = _cargo_mask;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   428
				this->include_empty = true;
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   429
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   430
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   431
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   433
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   434
			case SLW_SORTBY: // flip sorting method asc/desc
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   435
				this->stations.ToggleSortOrder();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   436
				this->flags4 |= 5 << WF_TIMEOUT_SHL;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   437
				this->LowerWidget(SLW_SORTBY);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   438
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   439
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   441
			case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   442
				ShowDropDownMenu(this, this->sorter_names, this->stations.SortType(), SLW_SORTDROPBTN, 0, 0);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   443
				break;
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   444
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   445
			case SLW_NOCARGOWAITING:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   446
				if (_ctrl_pressed) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   447
					this->include_empty = !this->include_empty;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   448
					this->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   449
				} else {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   450
					for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   451
						this->RaiseWidget(i);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   452
					}
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   453
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   454
					this->cargo_filter = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   455
					this->include_empty = true;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   456
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   457
					this->LowerWidget(SLW_NOCARGOWAITING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   458
				}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   459
				this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   460
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   461
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   462
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   463
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   464
			default:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   465
				if (widget >= SLW_CARGOSTART) { // change cargo_filter
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   466
					/* Determine the selected cargo type */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   467
					CargoID c;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   468
					int i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   469
					for (c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   470
						if (!GetCargo(c)->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   471
						if (widget - SLW_CARGOSTART == i) break;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   472
						i++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   473
					}
9094
48004fcef409 (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138
parents: 8992
diff changeset
   474
48004fcef409 (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138
parents: 8992
diff changeset
   475
					if (_ctrl_pressed) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   476
						ToggleBit(this->cargo_filter, c);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   477
						this->ToggleWidgetLoweredState(widget);
9094
48004fcef409 (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138
parents: 8992
diff changeset
   478
					} else {
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   479
						for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   480
							this->RaiseWidget(i);
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   481
						}
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   482
						this->RaiseWidget(SLW_NOCARGOWAITING);
6271
a17b8a4e17e8 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6260
diff changeset
   483
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   484
						this->cargo_filter = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   485
						this->include_empty = false;
6271
a17b8a4e17e8 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6260
diff changeset
   486
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   487
						SetBit(this->cargo_filter, c);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   488
						this->LowerWidget(widget);
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   489
					}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   490
					this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   491
					this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   492
					this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   493
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   494
				break;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   495
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   496
	}
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   497
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   498
	virtual void OnDropdownSelect(int widget, int index)
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   499
	{
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   500
		if (this->stations.SortType() != index) {
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   501
			this->stations.SetSortType(index);
9389
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   502
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   503
			/* Display the current sort variant */
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   504
			this->widget[SLW_SORTDROPBTN].data = this->sorter_names[this->stations.SortType()];
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   505
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   506
			this->SetDirty();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   507
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   508
	}
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   509
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   510
	virtual void OnTick()
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   511
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   512
		if (_pause_game != 0) return;
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   513
		if (this->stations.NeedResort()) {
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   514
			DEBUG(misc, 3, "Periodic rebuild station list player %d", this->window_number);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   515
			this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   516
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   517
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   519
	virtual void OnTimeout()
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   520
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   521
		this->RaiseWidget(SLW_SORTBY);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   522
		this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   523
	}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 817
diff changeset
   524
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   525
	virtual void OnResize(Point new_size, Point delta)
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   526
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   527
		this->vscroll.cap += delta.y / 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	}
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   529
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   530
	virtual void OnInvalidateData(int data)
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   531
	{
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   532
		if (data == 0) {
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   533
			this->stations.ForceRebuild();
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   534
		} else {
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   535
			this->stations.ForceResort();
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   536
		}
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   537
	}
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   538
};
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   539
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   540
Listing PlayerStationsWindow::last_sorting = {false, 0};
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   541
byte PlayerStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   542
bool PlayerStationsWindow::include_empty = true;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   543
const uint32 PlayerStationsWindow::cargo_filter_max = UINT32_MAX;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   544
uint32 PlayerStationsWindow::cargo_filter = UINT32_MAX;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   545
const Station *PlayerStationsWindow::last_station = NULL;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   546
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   547
/* Availible station sorting functions */
9382
c25c7eb89d16 (svn r13292) -Fix (r13285): MSVC warnings
glx
parents: 9379
diff changeset
   548
GUIStationList::SortFunction *const PlayerStationsWindow::sorter_funcs[] = {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   549
	&StationNameSorter,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   550
	&StationTypeSorter,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   551
	&StationWaitingSorter,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   552
	&StationRatingMaxSorter
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   553
};
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   554
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   555
/* Names of the sorting functions */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   556
const StringID PlayerStationsWindow::sorter_names[] = {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   557
	STR_SORT_BY_DROPDOWN_NAME,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   558
	STR_SORT_BY_FACILITY,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   559
	STR_SORT_BY_WAITING,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   560
	STR_SORT_BY_RATING_MAX,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   561
	INVALID_STRING_ID
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   562
};
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   563
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
static const Widget _player_stations_widgets[] = {
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   566
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // SLW_CLOSEBOX
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   567
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_GREY,    11,   345,     0,    13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   568
{  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_GREY,   346,   357,     0,    13, 0x0,               STR_STICKY_BUTTON},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   569
{      WWT_PANEL,     RESIZE_RB,  COLOUR_GREY,     0,   345,    37,   161, 0x0,               STR_3057_STATION_NAMES_CLICK_ON},  // SLW_LIST
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   570
{  WWT_SCROLLBAR,    RESIZE_LRB,  COLOUR_GREY,   346,   357,    37,   149, 0x0,               STR_0190_SCROLL_BAR_SCROLLS_LIST},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   571
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_GREY,   346,   357,   150,   161, 0x0,               STR_RESIZE_BUTTON},
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   572
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   573
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    13,    14,    24, STR_TRAIN,         STR_USE_CTRL_TO_SELECT_MORE},      // SLW_TRAIN
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   574
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    14,    27,    14,    24, STR_LORRY,         STR_USE_CTRL_TO_SELECT_MORE},      // SLW_TRUCK
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   575
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    28,    41,    14,    24, STR_BUS,           STR_USE_CTRL_TO_SELECT_MORE},      // SLW_BUS
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   576
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    42,    55,    14,    24, STR_PLANE,         STR_USE_CTRL_TO_SELECT_MORE},      // SLW_AIRPLANE
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   577
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    56,    69,    14,    24, STR_SHIP,          STR_USE_CTRL_TO_SELECT_MORE},      // SLW_SHIP
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   578
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,    70,    83,    14,    24, 0x0,               STR_SELECT_ALL_FACILITIES},        // SLW_FACILALL
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   579
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   580
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,    83,    88,    14,    24, 0x0,               STR_NULL},                         // SLW_PAN_BETWEEN
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   581
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,    89,   102,    14,    24, 0x0,               STR_NO_WAITING_CARGO},             // SLW_NOCARGOWAITING
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   582
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,   103,   116,    14,    24, 0x0,               STR_SELECT_ALL_TYPES},             // SLW_CARGOALL
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   583
{      WWT_PANEL,  RESIZE_RIGHT,  COLOUR_GREY,   117,   357,    14,    24, 0x0,               STR_NULL},                         // SLW_PAN_RIGHT
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   584
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   585
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    80,    25,    36, STR_SORT_BY,       STR_SORT_ORDER_TIP},               // SLW_SORTBY
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   586
{   WWT_DROPDOWN,   RESIZE_NONE,  COLOUR_GREY,    81,   243,    25,    36, 0x0,               STR_SORT_CRITERIA_TIP},            // SLW_SORTDROPBTN
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   587
{      WWT_PANEL,  RESIZE_RIGHT,  COLOUR_GREY,   244,   357,    25,    36, 0x0,               STR_NULL},                         // SLW_PAN_SORT_RIGHT
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   588
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
static const WindowDesc _player_stations_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7058
diff changeset
   592
	WDP_AUTO, WDP_AUTO, 358, 162, 358, 162,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5745
diff changeset
   593
	WC_STATION_LIST, WC_NONE,
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   594
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	_player_stations_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   598
/**
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   599
 * Opens window with list of player's stations
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   600
 *
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   601
 * @param player player whose stations' list show
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   602
 */
2475
efdcc705cb61 (svn r3001) s/Player*/const Player*/
tron
parents: 2186
diff changeset
   603
void ShowPlayerStations(PlayerID player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
{
9652
0405e98d8e96 (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 9648
diff changeset
   605
	if (!IsValidPlayerID(player)) return;
5005
f5086bd3945a (svn r7022) -Fix [FS#292]: Properly guard against viewing company-sensitive information from
Darkvater
parents: 4938
diff changeset
   606
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   607
	AllocateWindowDescFront<PlayerStationsWindow>(&_player_stations_desc, player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
static const Widget _station_view_widgets[] = {
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   611
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},                // SVW_CLOSEBOX
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   612
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_GREY,    11,   236,     0,    13, STR_300A_0,        STR_018C_WINDOW_TITLE_DRAG_THIS},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   613
{  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_GREY,   237,   248,     0,    13, 0x0,               STR_STICKY_BUTTON},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   614
{      WWT_PANEL,     RESIZE_RB,  COLOUR_GREY,     0,   236,    14,    65, 0x0,               STR_NULL},                             // SVW_WAITING
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   615
{  WWT_SCROLLBAR,    RESIZE_LRB,  COLOUR_GREY,   237,   248,    14,    65, 0x0,               STR_0190_SCROLL_BAR_SCROLLS_LIST},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   616
{      WWT_PANEL,    RESIZE_RTB,  COLOUR_GREY,     0,   248,    66,    97, 0x0,               STR_NULL},                             // SVW_ACCEPTLIST / SVW_RATINGLIST
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   617
{ WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_GREY,     0,    59,    98,   109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   618
{ WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_GREY,    60,   120,    98,   109, STR_3032_RATINGS,  STR_3054_SHOW_STATION_RATINGS},        // SVW_RATINGS / SVW_ACCEPTS
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   619
{ WWT_PUSHTXTBTN,    RESIZE_RTB,  COLOUR_GREY,   121,   180,    98,   109, STR_0130_RENAME,   STR_3055_CHANGE_NAME_OF_STATION},      // SVW_RENAME
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   620
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,  COLOUR_GREY,   181,   194,    98,   109, STR_TRAIN,         STR_SCHEDULED_TRAINS_TIP },            // SVW_TRAINS
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   621
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,  COLOUR_GREY,   195,   208,    98,   109, STR_LORRY,         STR_SCHEDULED_ROAD_VEHICLES_TIP },     // SVW_ROADVEHS
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   622
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,  COLOUR_GREY,   209,   222,    98,   109, STR_PLANE,         STR_SCHEDULED_AIRCRAFT_TIP },          // SVW_PLANES
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   623
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,  COLOUR_GREY,   223,   236,    98,   109, STR_SHIP,          STR_SCHEDULED_SHIPS_TIP },             // SVW_SHIPS
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   624
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_GREY,   237,   248,    98,   109, 0x0,               STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   625
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
8762
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   628
SpriteID GetCargoSprite(CargoID i)
6364
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   629
{
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   630
	const CargoSpec *cs = GetCargo(i);
6365
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   631
	SpriteID sprite;
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   632
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   633
	if (cs->sprite == 0xFFFF) {
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   634
		/* A value of 0xFFFF indicates we should draw a custom icon */
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   635
		sprite = GetCustomCargoSprite(cs);
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   636
	} else {
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   637
		sprite = cs->sprite;
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   638
	}
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   639
6657
75f1dccae0dd (svn r9888) -Codechange: [NewGRF] allow non-spec cargo action2s to work, and using the goods sprite if really nothing is returned.
peter1138
parents: 6420
diff changeset
   640
	if (sprite == 0) sprite = SPR_CARGO_GOODS;
6364
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   641
8762
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   642
	return sprite;
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   643
}
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   644
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   645
/**
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   646
 * Draws icons of waiting cargo in the StationView window
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   647
 *
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   648
 * @param i type of cargo
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   649
 * @param waiting number of waiting units
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   650
 * @param x x on-screen coordinate where to start with drawing icons
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   651
 * @param y y coordinate
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   652
 */
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   653
static void DrawCargoIcons(CargoID i, uint waiting, int x, int y, uint width)
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   654
{
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   655
	uint num = min((waiting + 5) / 10, width / 10); // maximum is width / 10 icons so it won't overflow
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   656
	if (num == 0) return;
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   657
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   658
	SpriteID sprite = GetCargoSprite(i);
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   659
6364
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   660
	do {
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   661
		DrawSprite(sprite, PAL_NONE, x, y);
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   662
		x += 10;
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   663
	} while (--num);
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   664
}
ec741938a286 (svn r9417) -Fix (r1): Waiting cargo icons in the station view window were incorrectly drawn if the cargo list was scrolled, resulting in overlapping images
peter1138
parents: 6350
diff changeset
   665
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   666
struct CargoData {
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   667
	CargoID cargo;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   668
	StationID source;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   669
	uint count;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   670
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   671
	CargoData(CargoID cargo, StationID source, uint count) :
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   672
		cargo(cargo),
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   673
		source(source),
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   674
		count(count)
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   675
	{ }
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   676
};
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   677
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   678
typedef std::list<CargoData> CargoDataList;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   679
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   680
/**
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   681
 * The StationView window
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   682
 */
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   683
struct StationViewWindow : public Window {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   684
	uint32 cargo;                 ///< Bitmask of cargo types to expand
9391
f58b6427dd4e (svn r13302) -Fix (r13301): GCC doesn't necessarily like what MSVC likes...
rubidium
parents: 9390
diff changeset
   685
	uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type
8750
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   686
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9191
diff changeset
   687
	StationViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   688
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   689
		PlayerID owner = GetStation(window_number)->owner;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   690
		if (owner != OWNER_NONE) this->caption_color = owner;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   691
		this->vscroll.cap = 5;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   692
		this->resize.step_height = 10;
8750
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   693
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   694
		this->FindWindowPlacementAndResize(desc);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   695
	}
8750
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   696
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   697
	~StationViewWindow()
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   698
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   699
		WindowNumber wno =
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   700
			(this->window_number << 16) | VLW_STATION_LIST | GetStation(this->window_number)->owner;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   701
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   702
		DeleteWindowById(WC_TRAINS_LIST, wno);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   703
		DeleteWindowById(WC_ROADVEH_LIST, wno);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   704
		DeleteWindowById(WC_SHIPS_LIST, wno);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   705
		DeleteWindowById(WC_AIRCRAFT_LIST, wno);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   706
	}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   707
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   708
	virtual void OnPaint()
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   709
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   710
		StationID station_id = this->window_number;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   711
		const Station *st = GetStation(station_id);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   712
		CargoDataList cargolist;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   713
		uint32 transfers = 0;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   714
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   715
		/* count types of cargos waiting in station */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   716
		for (CargoID i = 0; i < NUM_CARGO; i++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   717
			if (st->goods[i].cargo.Empty()) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   718
				this->cargo_rows[i] = 0;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   719
			} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   720
				/* Add an entry for total amount of cargo of this type waiting. */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   721
				cargolist.push_back(CargoData(i, INVALID_STATION, st->goods[i].cargo.Count()));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   722
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   723
				/* Set the row for this cargo entry for the expand/hide button */
9391
f58b6427dd4e (svn r13302) -Fix (r13301): GCC doesn't necessarily like what MSVC likes...
rubidium
parents: 9390
diff changeset
   724
				this->cargo_rows[i] = (uint16)cargolist.size();
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   725
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   726
				/* Add an entry for each distinct cargo source. */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   727
				const CargoList::List *packets = st->goods[i].cargo.Packets();
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   728
				for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   729
					const CargoPacket *cp = *it;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   730
					if (cp->source != station_id) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   731
						bool added = false;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   732
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   733
						/* Enable the expand/hide button for this cargo type */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   734
						SetBit(transfers, i);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   735
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   736
						/* Don't add cargo lines if not expanded */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   737
						if (!HasBit(this->cargo, i)) break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   738
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   739
						/* Check if we already have this source in the list */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   740
						for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   741
							CargoData *cd = &(*jt);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   742
							if (cd->cargo == i && cd->source == cp->source) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   743
								cd->count += cp->count;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   744
								added = true;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   745
								break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   746
							}
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   747
						}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   748
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   749
						if (!added) cargolist.push_back(CargoData(i, cp->source, cp->count));
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   750
					}
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   751
				}
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   752
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
		}
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9389
diff changeset
   754
		SetVScrollCount(this, (int)cargolist.size() + 1); // update scrollbar
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8857
diff changeset
   755
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   756
		/* disable some buttons */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   757
		this->SetWidgetDisabledState(SVW_RENAME,   st->owner != _local_player);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   758
		this->SetWidgetDisabledState(SVW_TRAINS,   !(st->facilities & FACIL_TRAIN));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   759
		this->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   760
		this->SetWidgetDisabledState(SVW_PLANES,   !(st->facilities & FACIL_AIRPORT));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   761
		this->SetWidgetDisabledState(SVW_SHIPS,    !(st->facilities & FACIL_DOCK));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   763
		SetDParam(0, st->index);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   764
		SetDParam(1, st->facilities);
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9214
diff changeset
   765
		this->DrawWidgets();
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   766
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   767
		int x = 2;  ///< coordinates used for printing waiting/accepted/rating of cargo
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   768
		int y = 15;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   769
		int pos = this->vscroll.pos; ///< = this->vscroll.pos
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   770
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   771
		uint width = this->widget[SVW_WAITING].right - this->widget[SVW_WAITING].left - 4;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   772
		int maxrows = this->vscroll.cap;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   773
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   774
		StringID str;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   775
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   776
		if (--pos < 0) {
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   777
			str = STR_00D0_NOTHING;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   778
			for (CargoID i = 0; i < NUM_CARGO; i++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   779
				if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
			}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   781
			SetDParam(0, str);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   782
			DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING);
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   783
			y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   786
		for (CargoDataList::const_iterator it = cargolist.begin(); it != cargolist.end() && pos > -maxrows; ++it) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   787
			if (--pos < 0) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   788
				const CargoData *cd = &(*it);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   789
				if (cd->source == INVALID_STATION) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   790
					/* Heading */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   791
					DrawCargoIcons(cd->cargo, cd->count, x, y, width);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   792
					SetDParam(0, cd->cargo);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   793
					SetDParam(1, cd->count);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   794
					if (HasBit(transfers, cd->cargo)) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   795
						/* This cargo has transfers waiting so show the expand or shrink 'button' */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   796
						const char *sym = HasBit(this->cargo, cd->cargo) ? "-" : "+";
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   797
						DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   798
						DoDrawString(sym, x + width - 6, y, TC_YELLOW);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   799
					} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   800
						DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   801
					}
5038
12fd4db0cdb5 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   802
				} else {
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   803
					SetDParam(0, cd->cargo);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   804
					SetDParam(1, cd->count);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   805
					SetDParam(2, cd->source);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   806
					DrawStringRightAlignedTruncated(x + width, y, STR_EN_ROUTE_FROM, TC_FROMSTRING, width);
5038
12fd4db0cdb5 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   807
				}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   808
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   809
				y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   812
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   813
		if (this->widget[SVW_ACCEPTS].data == STR_3032_RATINGS) { // small window with list of accepted cargo
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9580
diff changeset
   814
			char string[512];
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9580
diff changeset
   815
			char *b = string;
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   816
			bool first = true;
6297
3ff4d685839e (svn r9127) -Codechange: Check if a cargo is valid before displaying it in a station's cargo rating list. (And duff up the block a little)
peter1138
parents: 6285
diff changeset
   817
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   818
			b = InlineString(b, STR_000C_ACCEPTS);
6297
3ff4d685839e (svn r9127) -Codechange: Check if a cargo is valid before displaying it in a station's cargo rating list. (And duff up the block a little)
peter1138
parents: 6285
diff changeset
   819
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   820
			for (CargoID i = 0; i < NUM_CARGO; i++) {
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9580
diff changeset
   821
				if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   822
				if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   823
					if (first) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   824
						first = false;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   825
					} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   826
						/* Add a comma if this is not the first item */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   827
						*b++ = ',';
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   828
						*b++ = ' ';
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   829
					}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   830
					b = InlineString(b, GetCargo(i)->name);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   831
				}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   832
			}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   833
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   834
			/* If first is still true then no cargo is accepted */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   835
			if (first) b = InlineString(b, STR_00D0_NOTHING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   836
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   837
			*b = '\0';
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   838
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   839
			/* Make sure we detect any buffer overflow */
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9580
diff changeset
   840
			assert(b < endof(string));
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   841
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9580
diff changeset
   842
			SetDParamStr(0, string);
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9580
diff changeset
   843
			DrawStringMultiLine(2, this->widget[SVW_ACCEPTLIST].top + 1, STR_JUST_RAW_STRING, this->widget[SVW_ACCEPTLIST].right - this->widget[SVW_ACCEPTLIST].left);
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   844
		} else { // extended window with list of cargo ratings
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   845
			y = this->widget[SVW_RATINGLIST].top + 1;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   846
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   847
			DrawString(2, y, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
6297
3ff4d685839e (svn r9127) -Codechange: Check if a cargo is valid before displaying it in a station's cargo rating list. (And duff up the block a little)
peter1138
parents: 6285
diff changeset
   848
			y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   850
			for (CargoID i = 0; i < NUM_CARGO; i++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   851
				const CargoSpec *cs = GetCargo(i);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   852
				if (!cs->IsValid()) continue;
8750
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   853
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   854
				const GoodsEntry *ge = &st->goods[i];
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   855
				if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   856
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   857
				SetDParam(0, cs->name);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   858
				SetDParam(2, ge->rating * 101 >> 8);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   859
				SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   860
				DrawString(8, y, STR_303D, TC_FROMSTRING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   861
				y += 10;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   862
			}
8750
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   863
		}
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   864
	}
375a8bcd4948 (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138
parents: 8719
diff changeset
   865
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   866
	void HandleCargoWaitingClick(int row)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   867
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   868
		if (row == 0) return;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   869
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   870
		for (CargoID c = 0; c < NUM_CARGO; c++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   871
			if (this->cargo_rows[c] == row) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   872
				ToggleBit(this->cargo, c);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   873
				this->InvalidateWidget(SVW_WAITING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   874
				break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   875
			}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   876
		}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   877
	}
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   878
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   879
	virtual void OnClick(Point pt, int widget)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   880
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   881
		switch (widget) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   882
			case SVW_WAITING:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   883
				this->HandleCargoWaitingClick((pt.y - this->widget[SVW_WAITING].top) / 10 + this->vscroll.pos);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   884
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   885
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   886
			case SVW_LOCATION:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   887
				if (_ctrl_pressed) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   888
					ShowExtraViewPortWindow(GetStation(this->window_number)->xy);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   889
				} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   890
					ScrollMainWindowToTile(GetStation(this->window_number)->xy);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   891
				}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   892
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   893
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   894
			case SVW_RATINGS:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   895
				this->SetDirty();
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   896
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   897
				if (this->widget[SVW_RATINGS].data == STR_3032_RATINGS) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   898
					/* Switch to ratings view */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   899
					this->widget[SVW_RATINGS].data = STR_3033_ACCEPTS;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   900
					this->widget[SVW_RATINGS].tooltips = STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   901
					ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, 100);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   902
				} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   903
					/* Switch to accepts view */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   904
					this->widget[SVW_RATINGS].data = STR_3032_RATINGS;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   905
					this->widget[SVW_RATINGS].tooltips = STR_3054_SHOW_STATION_RATINGS;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   906
					ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, -100);
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   907
				}
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   908
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   909
				this->SetDirty();
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   910
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   912
			case SVW_RENAME:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   913
				SetDParam(0, this->window_number);
9913
d9ce89020cc0 (svn r14063) -Codechange: replace some "magic" constants with enumified constants.
rubidium
parents: 9764
diff changeset
   914
				ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL);
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   915
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   916
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   917
			case SVW_TRAINS: { // Show a list of scheduled trains to this station
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   918
				const Station *st = GetStation(this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   919
				ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   920
				break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   921
			}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   922
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   923
			case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   924
				const Station *st = GetStation(this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   925
				ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   926
				break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   927
			}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   928
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   929
			case SVW_PLANES: { // Show a list of scheduled aircraft to this station
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   930
				const Station *st = GetStation(this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   931
				/* Since oilrigs have no owners, show the scheduled aircraft of current player */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   932
				PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   933
				ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   934
				break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   935
			}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   936
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   937
			case SVW_SHIPS: { // Show a list of scheduled ships to this station
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   938
				const Station *st = GetStation(this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   939
				/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   940
				PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   941
				ShowVehicleListWindow(owner, VEH_SHIP, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   942
				break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   943
			}
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 534
diff changeset
   944
		}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   945
	}
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   946
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   947
	virtual void OnQueryTextFinished(char *str)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   948
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   949
		if (!StrEmpty(str)) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   950
			_cmd_text = str;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   951
			DoCommandP(0, this->window_number, 0, NULL,
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   952
				CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   953
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   955
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   956
	virtual void OnResize(Point new_size, Point delta)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   957
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   958
		if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   959
		this->vscroll.cap += delta.y / (int)this->resize.step_height;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   960
	}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   961
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
static const WindowDesc _station_view_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7058
diff changeset
   965
	WDP_AUTO, WDP_AUTO, 249, 110, 249, 110,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5745
diff changeset
   966
	WC_STATION_VIEW, WC_NONE,
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   967
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	_station_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   971
/**
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   972
 * Opens StationViewWindow for given station
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   973
 *
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   974
 * @param station station which window should be opened
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   975
 */
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2484
diff changeset
   976
void ShowStationViewWindow(StationID station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
{
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   978
	AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
}