src/station_gui.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10208 72c00af5c95d
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
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"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    12
#include "company_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"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    29
#include "company_base.h"
10122
c524226103f1 (svn r14306) -Codechange: unify the code to draw the vehicle list.
rubidium
parents: 10021
diff changeset
    30
#include "sortlist_type.h"
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
    31
8264
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/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
    33
#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
    34
8268
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    35
bool _station_show_coverage;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    36
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    37
/**
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    38
 * 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
    39
 * 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
    40
 * 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
    41
 *
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
    42
 * @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
    43
 * @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
    44
 * @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
    45
 * @param amount Cargo amount
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    46
 * @param rating ratings data for that particular cargo
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    47
 *
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    48
 * @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
    49
 * @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
    50
 */
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    51
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
    52
{
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    53
	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
    54
	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
    55
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
    56
	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
    57
	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
    58
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
    59
	int colour = cs->rating_colour;
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    60
	uint w = (minu(amount, units_full) + 5) / 36;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    62
	/* 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
    63
	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
    64
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    65
	/* 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
    66
	 * 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
    67
	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
    68
		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
    69
		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
    70
			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
    71
			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
    72
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
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
    75
	DrawString(x + 1, y, cs->abbrev, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
5293
4cc0c1f2f95c (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
    77
	/* 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
    78
	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
    79
	GfxFillRect(x + 1, y, x + 14, y, 0xB8);
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    80
	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
    81
	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
    82
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
    84
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
    85
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    86
/**
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    87
 * The list of stations per company.
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
    88
 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    89
class CompanyStationsWindow : public Window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
{
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    91
protected:
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    92
	/* Runtime saved values */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    93
	static Listing last_sorting;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    94
	static byte facilities;               // types of stations of interest
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    95
	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
    96
	static const uint32 cargo_filter_max;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    97
	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
    98
	static const Station *last_station;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
    99
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   100
	/* Constants for sorting stations */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   101
	static const StringID sorter_names[];
9382
c25c7eb89d16 (svn r13292) -Fix (r13285): MSVC warnings
glx
parents: 9379
diff changeset
   102
	static GUIStationList::SortFunction *const sorter_funcs[];
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   103
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   104
	GUIStationList stations;
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   105
9378
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
	/**
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   108
	 * (Re)Build station list
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   109
	 *
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   110
	 * @param owner company whose stations are to be in list
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   111
	 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   112
	void BuildStationsList(const Owner owner)
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   113
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   114
		if (!this->stations.NeedRebuild()) return;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   115
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   116
		DEBUG(misc, 3, "Building station list for company %d", owner);
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   117
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   118
		this->stations.Clear();
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   119
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   120
		const Station *st;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   121
		FOR_ALL_STATIONS(st) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   122
			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
   123
				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
   124
					int num_waiting_cargo = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   125
					for (CargoID j = 0; j < NUM_CARGO; j++) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   126
						if (!st->goods[j].cargo.Empty()) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   127
							num_waiting_cargo++; // count number of waiting cargo
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   128
							if (HasBit(this->cargo_filter, j)) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   129
								*this->stations.Append() = st;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   130
								break;
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
					}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   134
					/* stations without waiting cargo */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   135
					if (num_waiting_cargo == 0 && this->include_empty) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   136
						*this->stations.Append() = st;
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   142
		this->stations.Compact();
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   143
		this->stations.RebuildDone();
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   146
	/** Sort stations by their name */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   147
	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
   148
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   149
		static char buf_cache[64];
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   150
		char buf[64];
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   151
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   152
		SetDParam(0, (*a)->index);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   153
		GetString(buf, STR_STATION, lastof(buf));
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   154
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   155
		if (*b != last_station) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   156
			last_station = *b;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   157
			SetDParam(0, (*b)->index);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   158
			GetString(buf_cache, STR_STATION, lastof(buf_cache));
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   161
		return strcmp(buf, buf_cache);
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   164
	/** Sort stations by their type */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   165
	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
   166
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   167
		return (*a)->facilities - (*b)->facilities;
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   170
	/** Sort stations by their waiting cargo */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   171
	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
   172
	{
9580
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   173
		Money diff = 0;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   174
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   175
		for (CargoID j = 0; j < NUM_CARGO; j++) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   176
			if (!HasBit(cargo_filter, j)) continue;
9580
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   177
			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
   178
			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
   179
		}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   180
9580
e1f4d6991e31 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13
parents: 9391
diff changeset
   181
		return ClampToI32(diff);
9378
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   184
	/** Sort stations by their rating */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   185
	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
   186
	{
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   187
		byte maxr1 = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   188
		byte maxr2 = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   189
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   190
		for (CargoID j = 0; j < NUM_CARGO; j++) {
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   191
			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
   192
			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
   193
		}
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   194
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   195
		return maxr1 - maxr2;
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   198
	/** Sort the stations list */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   199
	void SortStationsList()
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   200
	{
9379
2c6c6a0e2233 (svn r13286) -Codechange: GUIList Sort returns now if the list sequence has been altered
skidd13
parents: 9378
diff changeset
   201
		if (!this->stations.Sort()) return;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   202
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   203
		/* Reset name sorter sort cache */
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   204
		this->last_station = NULL;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   205
9389
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   206
		/* Set the modified widget dirty */
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   207
		this->InvalidateWidget(SLW_LIST);
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   210
public:
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   211
	CompanyStationsWindow(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
   212
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   213
		this->caption_color = (byte)this->window_number;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   214
		this->vscroll.cap = 12;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   215
		this->resize.step_height = 10;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   216
		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
   217
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   218
		/* Add cargo filter buttons */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   219
		uint num_active = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   220
		for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   221
			if (GetCargo(c)->IsValid()) num_active++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   222
		}
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
   223
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   224
		this->widget_count += num_active;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   225
		this->widget = ReallocT(this->widget, this->widget_count + 1);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   226
		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
   227
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   228
		uint i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   229
		for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   230
			if (!GetCargo(c)->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   231
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   232
			Widget *wi = &this->widget[SLW_CARGOSTART + i];
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   233
			wi->type     = WWT_PANEL;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   234
			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
   235
			wi->color    = COLOUR_GREY;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   236
			wi->left     = 89 + i * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   237
			wi->right    = wi->left + 13;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   238
			wi->top      = 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   239
			wi->bottom   = 24;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   240
			wi->data     = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   241
			wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   242
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   243
			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
   244
			i++;
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
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   247
		this->widget[SLW_NOCARGOWAITING].left += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   248
		this->widget[SLW_NOCARGOWAITING].right += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   249
		this->widget[SLW_CARGOALL].left += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   250
		this->widget[SLW_CARGOALL].right += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   251
		this->widget[SLW_PAN_RIGHT].left += num_active * 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   252
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   253
		if (num_active > 15) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   254
			/* Resize and fix the minimum width, if necessary */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   255
			ResizeWindow(this, (num_active - 15) * 14, 0);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   256
			this->resize.width = this->width;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   257
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   258
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   259
		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
   260
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   261
		for (uint i = 0; i < 5; i++) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   262
			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
   263
		}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   264
		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
   265
		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
   266
		this->SetWidgetLoweredState(SLW_NOCARGOWAITING, this->include_empty);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   267
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   268
		this->stations.SetListing(this->last_sorting);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   269
		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
   270
		this->stations.ForceRebuild();
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   271
		this->stations.NeedResort();
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   272
		this->SortStationsList();
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
   273
9389
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   274
		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
   275
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
   276
		this->FindWindowPlacementAndResize(desc);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   277
	}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   278
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   279
	~CompanyStationsWindow()
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   280
	{
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   281
		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
   282
	}
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   283
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   284
	virtual void OnPaint()
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   285
	{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   286
		const Owner owner = (Owner)this->window_number;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   287
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   288
		this->BuildStationsList(owner);
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   289
		this->SortStationsList();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   290
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   291
		SetVScrollCount(this, this->stations.Length());
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   292
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   293
		/* draw widgets, with company's name in the caption */
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   294
		SetDParam(0, owner);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   295
		SetDParam(1, this->vscroll.count);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   296
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9214
diff changeset
   297
		this->DrawWidgets();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   298
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   299
		/* 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
   300
		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
   301
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   302
		int cg_ofst;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   303
		int x = 89;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   304
		int y = 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   305
		int xb = 2; ///< offset from left of widget
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   306
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   307
		uint i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   308
		for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   309
			const CargoSpec *cs = GetCargo(c);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   310
			if (!cs->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   311
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   312
			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
   313
			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
   314
			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
   315
			x += 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   316
			i++;
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
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   319
		x += 6;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   320
		cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   321
		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
   322
		x += 14;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   323
		cg_ofst = this->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   324
		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
   325
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   326
		cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   327
		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
   328
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   329
		if (this->vscroll.count == 0) { // company has no stations
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   330
			DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   331
			return;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   332
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   333
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   334
		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
   335
		y = 40; // start of the list-widget
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   336
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   337
		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
   338
			const Station *st = this->stations[i];
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   339
			int x;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   340
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   341
			assert(st->xy != 0);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   342
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   343
			/* 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
   344
				* 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
   345
			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
   346
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   347
			SetDParam(0, st->index);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   348
			SetDParam(1, st->facilities);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   349
			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
   350
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   351
			/* show cargo waiting and station ratings */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   352
			for (CargoID j = 0; j < NUM_CARGO; j++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   353
				if (!st->goods[j].cargo.Empty()) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   354
					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
   355
					x += 20;
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
			}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   358
			y += 10;
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
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   362
	virtual void OnClick(Point pt, int widget)
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   363
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   364
		switch (widget) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   365
			case SLW_LIST: {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   366
				uint32 id_v = (pt.y - 41) / 10;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   367
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   368
				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
   369
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   370
				id_v += this->vscroll.pos;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   371
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   372
				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
   373
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   374
				const Station *st = this->stations[id_v];
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   375
				/* do not check HasStationInUse - it is slow and may be invalid */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   376
				assert(st->owner == (Owner)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
   377
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   378
				if (_ctrl_pressed) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   379
					ShowExtraViewPortWindow(st->xy);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   380
				} else {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   381
					ScrollMainWindowToTile(st->xy);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   382
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   383
				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
   384
			}
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   385
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   386
			case SLW_TRAIN:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   387
			case SLW_TRUCK:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   388
			case SLW_BUS:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   389
			case SLW_AIRPLANE:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   390
			case SLW_SHIP:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   391
				if (_ctrl_pressed) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   392
					ToggleBit(this->facilities, widget - SLW_TRAIN);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   393
					this->ToggleWidgetLoweredState(widget);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   394
				} else {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   395
					uint i;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   396
					FOR_EACH_SET_BIT(i, this->facilities) {
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   397
						this->RaiseWidget(i + SLW_TRAIN);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   398
					}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   399
					SetBit(this->facilities, widget - SLW_TRAIN);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   400
					this->LowerWidget(widget);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   401
				}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   402
				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
   403
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   404
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   405
				break;
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   406
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   407
			case SLW_FACILALL:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   408
				for (uint i = 0; i < 5; i++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   409
					this->LowerWidget(i + SLW_TRAIN);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   410
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   411
				this->LowerWidget(SLW_FACILALL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   413
				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
   414
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   415
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   416
				break;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   417
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   418
			case SLW_CARGOALL: {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   419
				uint i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   420
				for (CargoID c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   421
					if (!GetCargo(c)->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   422
					this->LowerWidget(i + SLW_CARGOSTART);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   423
					i++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   424
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   425
				this->LowerWidget(SLW_NOCARGOWAITING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   426
				this->LowerWidget(SLW_CARGOALL);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   427
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   428
				this->cargo_filter = _cargo_mask;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   429
				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
   430
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   431
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   432
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   434
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   435
			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
   436
				this->stations.ToggleSortOrder();
10180
a99cf854c6d0 (svn r14390) -Codechange: replace magic constants with symbolic constants.
rubidium
parents: 10148
diff changeset
   437
				this->flags4 |= WF_TIMEOUT_BEGIN;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   438
				this->LowerWidget(SLW_SORTBY);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   439
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   440
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   442
			case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   443
				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
   444
				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
   445
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   446
			case SLW_NOCARGOWAITING:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   447
				if (_ctrl_pressed) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   448
					this->include_empty = !this->include_empty;
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   449
					this->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   450
				} else {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   451
					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
   452
						this->RaiseWidget(i);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   453
					}
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   454
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   455
					this->cargo_filter = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   456
					this->include_empty = true;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   457
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   458
					this->LowerWidget(SLW_NOCARGOWAITING);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   459
				}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   460
				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
   461
				this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   462
				this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   463
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   464
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   465
			default:
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   466
				if (widget >= SLW_CARGOSTART) { // change cargo_filter
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   467
					/* Determine the selected cargo type */
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   468
					CargoID c;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   469
					int i = 0;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   470
					for (c = 0; c < NUM_CARGO; c++) {
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   471
						if (!GetCargo(c)->IsValid()) continue;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   472
						if (widget - SLW_CARGOSTART == i) break;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   473
						i++;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   474
					}
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
   475
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
   476
					if (_ctrl_pressed) {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   477
						ToggleBit(this->cargo_filter, c);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   478
						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
   479
					} else {
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   480
						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
   481
							this->RaiseWidget(i);
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   482
						}
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   483
						this->RaiseWidget(SLW_NOCARGOWAITING);
6271
a17b8a4e17e8 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6260
diff changeset
   484
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   485
						this->cargo_filter = 0;
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   486
						this->include_empty = false;
6271
a17b8a4e17e8 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6260
diff changeset
   487
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   488
						SetBit(this->cargo_filter, c);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   489
						this->LowerWidget(widget);
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   490
					}
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   491
					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
   492
					this->stations.ForceRebuild();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   493
					this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   494
				}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   495
				break;
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   496
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   497
	}
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   498
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   499
	virtual void OnDropdownSelect(int widget, int index)
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   500
	{
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   501
		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
   502
			this->stations.SetSortType(index);
9389
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   503
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   504
			/* Display the current sort variant */
b547cd1aaac2 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13
parents: 9382
diff changeset
   505
			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
   506
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   507
			this->SetDirty();
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   508
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   509
	}
5271
a2e9e1dd7cb2 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   510
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   511
	virtual void OnTick()
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   512
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   513
		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
   514
		if (this->stations.NeedResort()) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   515
			DEBUG(misc, 3, "Periodic rebuild station list company %d", this->window_number);
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   516
			this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   517
		}
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   518
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   520
	virtual void OnTimeout()
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   521
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   522
		this->RaiseWidget(SLW_SORTBY);
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   523
		this->SetDirty();
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   524
	}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 817
diff changeset
   525
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   526
	virtual void OnResize(Point new_size, Point delta)
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   527
	{
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   528
		this->vscroll.cap += delta.y / 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	}
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   530
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   531
	virtual void OnInvalidateData(int data)
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   532
	{
9377
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   533
		if (data == 0) {
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   534
			this->stations.ForceRebuild();
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   535
		} else {
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   536
			this->stations.ForceResort();
1a67c4e4ec7c (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13
parents: 9365
diff changeset
   537
		}
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9273
diff changeset
   538
	}
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   539
};
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   540
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   541
Listing CompanyStationsWindow::last_sorting = {false, 0};
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   542
byte CompanyStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   543
bool CompanyStationsWindow::include_empty = true;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   544
const uint32 CompanyStationsWindow::cargo_filter_max = UINT32_MAX;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   545
uint32 CompanyStationsWindow::cargo_filter = UINT32_MAX;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   546
const Station *CompanyStationsWindow::last_station = NULL;
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   547
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   548
/* Availible station sorting functions */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   549
GUIStationList::SortFunction *const CompanyStationsWindow::sorter_funcs[] = {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   550
	&StationNameSorter,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   551
	&StationTypeSorter,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   552
	&StationWaitingSorter,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   553
	&StationRatingMaxSorter
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
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   556
/* Names of the sorting functions */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   557
const StringID CompanyStationsWindow::sorter_names[] = {
9378
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   558
	STR_SORT_BY_DROPDOWN_NAME,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   559
	STR_SORT_BY_FACILITY,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   560
	STR_SORT_BY_WAITING,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   561
	STR_SORT_BY_RATING_MAX,
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   562
	INVALID_STRING_ID
37a5be34ca86 (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13
parents: 9377
diff changeset
   563
};
9191
471b623a46b8 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium
parents: 9190
diff changeset
   564
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   566
static const Widget _company_stations_widgets[] = {
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   567
{   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
   568
{    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
   569
{  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
   570
{      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
   571
{  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
   572
{  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
   573
9764
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,     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
   575
{    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
   576
{    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
   577
{    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
   578
{    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
   579
{      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
   580
9764
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,    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
   582
{      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
   583
{      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
   584
{      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
   585
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
   586
{    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
   587
{   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
   588
{      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
   589
{   WIDGETS_END},
0
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
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   592
static const WindowDesc _company_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
   593
	WDP_AUTO, WDP_AUTO, 358, 162, 358, 162,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5745
diff changeset
   594
	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
   595
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   596
	_company_stations_widgets,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   599
/**
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   600
 * Opens window with list of company's stations
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   601
 *
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   602
 * @param company whose stations' list show
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   603
 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   604
void ShowCompanyStations(CompanyID company)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   606
	if (!IsValidCompanyID(company)) return;
5005
f5086bd3945a (svn r7022) -Fix [FS#292]: Properly guard against viewing company-sensitive information from
Darkvater
parents: 4938
diff changeset
   607
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   608
	AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
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
   612
{   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
   613
{    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
   614
{  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
   615
{      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
   616
{  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
   617
{      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
   618
{ 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
   619
{ 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
   620
{ 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
   621
{ 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
   622
{ 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
   623
{ 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
   624
{ 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
   625
{  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
   626
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
8762
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   629
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
   630
{
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
   631
	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
   632
	SpriteID sprite;
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   633
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   634
	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
   635
		/* 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
   636
		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
   637
	} else {
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   638
		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
   639
	}
b52bd4ca10b6 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6364
diff changeset
   640
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
   641
	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
   642
8762
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   643
	return sprite;
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
/**
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   647
 * 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
   648
 *
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   649
 * @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
   650
 * @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
   651
 * @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
   652
 * @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
   653
 */
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   654
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
   655
{
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   656
	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
   657
	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
   658
bbe195577e21 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium
parents: 8750
diff changeset
   659
	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
   660
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
   661
	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
   662
		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
   663
		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
   664
	} 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
   665
}
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
   666
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   667
struct CargoData {
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   668
	CargoID cargo;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   669
	StationID source;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   670
	uint count;
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   671
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   672
	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
   673
		cargo(cargo),
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   674
		source(source),
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   675
		count(count)
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
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   679
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
   680
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   681
/**
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   682
 * The StationView window
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8005
diff changeset
   683
 */
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   684
struct StationViewWindow : public Window {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   685
	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
   686
	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
   687
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
   688
	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
   689
	{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   690
		Owner owner = GetStation(window_number)->owner;
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   691
		if (owner != OWNER_NONE) this->caption_color = owner;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   692
		this->vscroll.cap = 5;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   693
		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
   694
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   695
		this->FindWindowPlacementAndResize(desc);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   696
	}
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
   697
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   698
	~StationViewWindow()
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   699
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   700
		WindowNumber wno =
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   701
			(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
   702
10021
c737dd2eb7c9 (svn r14180) -Fix (r8293): close all related vehicle lists when closing a station window (and not only the train list).
glx
parents: 9913
diff changeset
   703
		DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11));
c737dd2eb7c9 (svn r14180) -Fix (r8293): close all related vehicle lists when closing a station window (and not only the train list).
glx
parents: 9913
diff changeset
   704
		DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11));
c737dd2eb7c9 (svn r14180) -Fix (r8293): close all related vehicle lists when closing a station window (and not only the train list).
glx
parents: 9913
diff changeset
   705
		DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11));
c737dd2eb7c9 (svn r14180) -Fix (r8293): close all related vehicle lists when closing a station window (and not only the train list).
glx
parents: 9913
diff changeset
   706
		DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11));
9185
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
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   709
	virtual void OnPaint()
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   710
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   711
		StationID station_id = this->window_number;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   712
		const Station *st = GetStation(station_id);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   713
		CargoDataList cargolist;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   714
		uint32 transfers = 0;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   715
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   716
		/* count types of cargos waiting in station */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   717
		for (CargoID i = 0; i < NUM_CARGO; i++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   718
			if (st->goods[i].cargo.Empty()) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   719
				this->cargo_rows[i] = 0;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   720
			} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   721
				/* 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
   722
				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
   723
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   724
				/* 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
   725
				this->cargo_rows[i] = (uint16)cargolist.size();
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   726
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   727
				/* Add an entry for each distinct cargo source. */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   728
				const CargoList::List *packets = st->goods[i].cargo.Packets();
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   729
				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
   730
					const CargoPacket *cp = *it;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   731
					if (cp->source != station_id) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   732
						bool added = false;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   733
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   734
						/* Enable the expand/hide button for this cargo type */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   735
						SetBit(transfers, i);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   736
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   737
						/* Don't add cargo lines if not expanded */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   738
						if (!HasBit(this->cargo, i)) break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   739
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   740
						/* 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
   741
						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
   742
							CargoData *cd = &(*jt);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   743
							if (cd->cargo == i && cd->source == cp->source) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   744
								cd->count += cp->count;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   745
								added = true;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   746
								break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   747
							}
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   748
						}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   749
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   750
						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
   751
					}
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   752
				}
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   753
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		}
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9389
diff changeset
   755
		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
   756
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   757
		/* disable some buttons */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   758
		this->SetWidgetDisabledState(SVW_RENAME,   st->owner != _local_company);
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   759
		this->SetWidgetDisabledState(SVW_TRAINS,   !(st->facilities & FACIL_TRAIN));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   760
		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
   761
		this->SetWidgetDisabledState(SVW_PLANES,   !(st->facilities & FACIL_AIRPORT));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   762
		this->SetWidgetDisabledState(SVW_SHIPS,    !(st->facilities & FACIL_DOCK));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   764
		SetDParam(0, st->index);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   765
		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
   766
		this->DrawWidgets();
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   767
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   768
		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
   769
		int y = 15;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   770
		int pos = this->vscroll.pos; ///< = this->vscroll.pos
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   771
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   772
		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
   773
		int maxrows = this->vscroll.cap;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   774
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   775
		StringID str;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   776
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   777
		if (--pos < 0) {
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   778
			str = STR_00D0_NOTHING;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   779
			for (CargoID i = 0; i < NUM_CARGO; i++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   780
				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
   781
			}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   782
			SetDParam(0, str);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   783
			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
   784
			y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   787
		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
   788
			if (--pos < 0) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   789
				const CargoData *cd = &(*it);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   790
				if (cd->source == INVALID_STATION) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   791
					/* Heading */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   792
					DrawCargoIcons(cd->cargo, cd->count, x, y, width);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   793
					SetDParam(0, cd->cargo);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   794
					SetDParam(1, cd->count);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   795
					if (HasBit(transfers, cd->cargo)) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   796
						/* 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
   797
						const char *sym = HasBit(this->cargo, cd->cargo) ? "-" : "+";
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   798
						DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   799
						DoDrawString(sym, x + width - 6, y, TC_YELLOW);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   800
					} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   801
						DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   802
					}
5038
12fd4db0cdb5 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   803
				} else {
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   804
					SetDParam(0, cd->cargo);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   805
					SetDParam(1, cd->count);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   806
					SetDParam(2, cd->source);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   807
					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
   808
				}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   809
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   810
				y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   813
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   814
		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
   815
			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
   816
			char *b = string;
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   817
			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
   818
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   819
			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
   820
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   821
			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
   822
				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
   823
				if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   824
					if (first) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   825
						first = false;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   826
					} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   827
						/* 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
   828
						*b++ = ',';
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   829
						*b++ = ' ';
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   830
					}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   831
					b = InlineString(b, GetCargo(i)->name);
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
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   835
			/* 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
   836
			if (first) b = InlineString(b, STR_00D0_NOTHING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   837
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   838
			*b = '\0';
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   839
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   840
			/* 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
   841
			assert(b < endof(string));
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   842
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
   843
			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
   844
			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
   845
		} else { // extended window with list of cargo ratings
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   846
			y = this->widget[SVW_RATINGLIST].top + 1;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   847
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   848
			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
   849
			y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   851
			for (CargoID i = 0; i < NUM_CARGO; i++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   852
				const CargoSpec *cs = GetCargo(i);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   853
				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
   854
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   855
				const GoodsEntry *ge = &st->goods[i];
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   856
				if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   857
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   858
				SetDParam(0, cs->name);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   859
				SetDParam(2, ge->rating * 101 >> 8);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   860
				SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   861
				DrawString(8, y, STR_303D, TC_FROMSTRING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   862
				y += 10;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   863
			}
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
   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
	}
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
   866
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   867
	void HandleCargoWaitingClick(int row)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   868
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   869
		if (row == 0) return;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   870
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   871
		for (CargoID c = 0; c < NUM_CARGO; c++) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   872
			if (this->cargo_rows[c] == row) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   873
				ToggleBit(this->cargo, c);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   874
				this->InvalidateWidget(SVW_WAITING);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   875
				break;
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
		}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   878
	}
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   879
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   880
	virtual void OnClick(Point pt, int widget)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   881
	{
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   882
		switch (widget) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   883
			case SVW_WAITING:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   884
				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
   885
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   886
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   887
			case SVW_LOCATION:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   888
				if (_ctrl_pressed) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   889
					ShowExtraViewPortWindow(GetStation(this->window_number)->xy);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   890
				} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   891
					ScrollMainWindowToTile(GetStation(this->window_number)->xy);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   892
				}
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   893
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   894
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   895
			case SVW_RATINGS:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   896
				this->SetDirty();
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   897
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   898
				if (this->widget[SVW_RATINGS].data == STR_3032_RATINGS) {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   899
					/* Switch to ratings view */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   900
					this->widget[SVW_RATINGS].data = STR_3033_ACCEPTS;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   901
					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
   902
					ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, 100);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   903
				} else {
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   904
					/* Switch to accepts view */
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   905
					this->widget[SVW_RATINGS].data = STR_3032_RATINGS;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   906
					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
   907
					ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, -100);
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   908
				}
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   909
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   910
				this->SetDirty();
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   911
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   913
			case SVW_RENAME:
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   914
				SetDParam(0, this->window_number);
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   915
				ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   916
				break;
6202
4ec72ee98c7d (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6122
diff changeset
   917
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   918
			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
   919
				const Station *st = GetStation(this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   920
				ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   921
				break;
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
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   924
			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
   925
				const Station *st = GetStation(this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   926
				ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   927
				break;
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
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   930
			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
   931
				const Station *st = GetStation(this->window_number);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   932
				/* Since oilrigs have no owners, show the scheduled aircraft of current company */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   933
				Owner owner = (st->owner == OWNER_NONE) ? _current_company : st->owner;
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   934
				ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   935
				break;
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
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   938
			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
   939
				const Station *st = GetStation(this->window_number);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   940
				/* Since oilrigs/bouys have no owners, show the scheduled ships of current company */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   941
				Owner owner = (st->owner == OWNER_NONE) ? _current_company : st->owner;
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   942
				ShowVehicleListWindow(owner, VEH_SHIP, (StationID)this->window_number);
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   943
				break;
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   944
			}
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 534
diff changeset
   945
		}
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   946
	}
8420
4ebc9752e7bd (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138
parents: 8349
diff changeset
   947
9185
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   948
	virtual void OnQueryTextFinished(char *str)
6753f417e92e (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium
parents: 9164
diff changeset
   949
	{
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   950
		if (str == NULL) return;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   951
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   952
		_cmd_text = str;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
   953
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
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
}