src/station_gui.cpp
author rubidium
Sun, 13 Jan 2008 01:21:35 +0000
changeset 8760 ce0891c412ce
parent 8750 fdd6054e7bae
child 8764 65746a5248ec
permissions -rw-r--r--
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
     3
/** @file station_gui.cpp */
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
1299
0a6510cc889b (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"
8603
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8602
diff changeset
     9
#include "window_gui.h"
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8602
diff changeset
    10
#include "textbuf_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "station.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8720
diff changeset
    12
#include "player_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
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"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    15
#include "command_func.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    16
#include "variables.h"
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    17
#include "vehicle_gui.h"
6417
26acff62d001 (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: 6144
diff changeset
    18
#include "cargotype.h"
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    19
#include "station_gui.h"
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
    20
#include "station.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8605
diff changeset
    21
#include "strings_func.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8617
diff changeset
    22
#include "core/alloc_func.hpp"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8626
diff changeset
    23
#include "window_func.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8675
diff changeset
    24
#include "viewport_func.h"
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8675
diff changeset
    25
#include "gfx_func.h"
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
    26
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    27
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    28
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    29
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    30
typedef int CDECL StationSortListingTypeFunction(const void*, const void*);
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    31
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    32
static StationSortListingTypeFunction StationNameSorter;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    33
static StationSortListingTypeFunction StationTypeSorter;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    34
static StationSortListingTypeFunction StationWaitingSorter;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    35
static StationSortListingTypeFunction StationRatingMaxSorter;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    36
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    37
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    38
 * Draw small boxes of cargo amount and ratings data at the given
5293
4d59f970b2fe (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
4d59f970b2fe (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'
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    41
 *
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
    42
 * @param x coordinate to draw the box at
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
    43
 * @param y coordinate to draw the box at
5293
4d59f970b2fe (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
4d59f970b2fe (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
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    46
 * @param rating ratings data for that particular cargo
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    47
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    48
 * @note Each cargo-bar is 16 pixels wide and 6 pixels high
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    49
 * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    50
 */
5293
4d59f970b2fe (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
{
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    53
	static const uint units_full  = 576; ///< number of units to show station as 'full'
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    54
	static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    55
6417
26acff62d001 (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: 6144
diff changeset
    56
	const CargoSpec *cs = GetCargo(type);
6448
a749c78812a7 (svn r8858) -Codechange: Replace magic number test with class method for determining if a cargo is valid/active.
peter1138
parents: 6417
diff changeset
    57
	if (!cs->IsValid()) return;
6417
26acff62d001 (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: 6144
diff changeset
    58
26acff62d001 (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: 6144
diff changeset
    59
	int colour = cs->rating_colour;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
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
4d59f970b2fe (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) */
4d59f970b2fe (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
4d59f970b2fe (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
4d59f970b2fe (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) */
4d59f970b2fe (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) {
4d59f970b2fe (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;
4d59f970b2fe (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) {
4d59f970b2fe (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;
4d59f970b2fe (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);
4d59f970b2fe (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
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
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
4d59f970b2fe (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) */
4d59f970b2fe (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;
4d59f970b2fe (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);
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
    80
	rating = minu(rating, rating_full) / 16;
5293
4d59f970b2fe (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
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    84
const StringID _station_sort_listing[] = {
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    85
	STR_SORT_BY_DROPDOWN_NAME,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    86
	STR_SORT_BY_FACILITY,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    87
	STR_SORT_BY_WAITING,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    88
	STR_SORT_BY_RATING_MAX,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    89
	INVALID_STRING_ID
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    90
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
static char _bufcache[64];
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
    93
static const Station* _last_station;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
    94
static int _internal_sort_order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 69
diff changeset
    96
static int CDECL StationNameSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
{
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
    98
	const Station* st1 = *(const Station**)a;
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
    99
	const Station* st2 = *(const Station**)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	char buf1[64];
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   101
	int r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   103
	SetDParam(0, st1->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   104
	GetString(buf1, STR_STATION, lastof(buf1));
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 69
diff changeset
   105
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   106
	if (st2 != _last_station) {
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   107
		_last_station = st2;
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   108
		SetDParam(0, st2->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   109
		GetString(_bufcache, STR_STATION, lastof(_bufcache));
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 69
diff changeset
   110
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   112
	r = strcmp(buf1, _bufcache); // sort by name
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   113
	return (_internal_sort_order & 1) ? -r : r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   116
static int CDECL StationTypeSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
{
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   118
	const Station* st1 = *(const Station**)a;
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   119
	const Station* st2 = *(const Station**)b;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   120
	return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   121
}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   122
8382
f1be7a96ac28 (svn r11437) -Change: when sorting stations by cargo sum, only sum the cargos that are selected in the filter. Patch by divide.
rubidium
parents: 8338
diff changeset
   123
static const uint32 _cargo_filter_max = ~0;
f1be7a96ac28 (svn r11437) -Change: when sorting stations by cargo sum, only sum the cargos that are selected in the filter. Patch by divide.
rubidium
parents: 8338
diff changeset
   124
static uint32 _cargo_filter = _cargo_filter_max;
f1be7a96ac28 (svn r11437) -Change: when sorting stations by cargo sum, only sum the cargos that are selected in the filter. Patch by divide.
rubidium
parents: 8338
diff changeset
   125
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   126
static int CDECL StationWaitingSorter(const void *a, const void *b)
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   127
{
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   128
	const Station* st1 = *(const Station**)a;
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   129
	const Station* st2 = *(const Station**)b;
7486
d130c10f4dab (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 7153
diff changeset
   130
	Money sum1 = 0, sum2 = 0;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   131
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   132
	for (CargoID j = 0; j < NUM_CARGO; j++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   133
		if (!HasBit(_cargo_filter, j)) continue;
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   134
		if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   135
		if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   136
	}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   137
7486
d130c10f4dab (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 7153
diff changeset
   138
	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   139
}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   140
6579
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   141
/**
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   142
 * qsort-compatible version of sorting two stations by maximum rating
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   143
 * @param a   First object to be sorted, must be of type (const Station *)
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   144
 * @param b   Second object to be sorted, must be of type (const Station *)
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   145
 * @return    The sort order
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   146
 * @retval >0 a should come before b in the list
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   147
 * @retval <0 b should come before a in the list
2eb90ced504b (svn r9062) -Fix (r4822, FS#595): The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting (KeeperOfTheSoul). While at it, doxygen the function
celestar
parents: 6574
diff changeset
   148
 */
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   149
static int CDECL StationRatingMaxSorter(const void *a, const void *b)
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   150
{
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   151
	const Station* st1 = *(const Station**)a;
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   152
	const Station* st2 = *(const Station**)b;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   153
	byte maxr1 = 0;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   154
	byte maxr2 = 0;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   155
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   156
	for (CargoID j = 0; j < NUM_CARGO; j++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   157
		if (HasBit(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating);
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   158
		if (HasBit(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   159
	}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   160
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   161
	return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   162
}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   163
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   164
/** Flags for station list */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   165
enum StationListFlags {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   166
	SL_ORDER   = 1 << 0, ///< Order - ascending (=0), descending (=1)
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   167
	SL_RESORT  = 1 << 1, ///< Resort the list
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   168
	SL_REBUILD = 1 << 2, ///< Rebuild the list
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   169
};
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   170
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   171
DECLARE_ENUM_AS_BIT_SET(StationListFlags);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   172
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   173
/** Information about station list */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   174
struct plstations_d {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   175
	const Station** sort_list; ///< Pointer to list of stations
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   176
	uint16 list_length;        ///< Number of stations in list
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   177
	uint16 resort_timer;       ///< Tick counter to resort the list
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   178
	byte sort_type;            ///< Sort type - name, waiting, ...
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   179
	byte flags;                ///< Flags - SL_ORDER, SL_RESORT, SL_REBUILD
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   180
};
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   181
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   182
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   183
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   184
 * Set the 'SL_REBUILD' flag for all station lists
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   185
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6528
diff changeset
   186
void RebuildStationLists()
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   187
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5070
diff changeset
   188
	Window* const *wz;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   189
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5070
diff changeset
   190
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5070
diff changeset
   191
		Window *w = *wz;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   192
		if (w->window_class == WC_STATION_LIST) {
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   193
			WP(w, plstations_d).flags |= SL_REBUILD;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   194
			SetWindowDirty(w);
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   195
		}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   196
	}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   197
}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   198
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   199
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   200
 * Set the 'SL_RESORT' flag for all station lists
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   201
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6528
diff changeset
   202
void ResortStationLists()
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   203
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5070
diff changeset
   204
	Window* const *wz;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   205
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5070
diff changeset
   206
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5070
diff changeset
   207
		Window *w = *wz;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   208
		if (w->window_class == WC_STATION_LIST) {
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   209
			WP(w, plstations_d).flags |= SL_RESORT;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   210
			SetWindowDirty(w);
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   211
		}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   212
	}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   213
}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   214
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   215
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   216
 * Rebuild station list if the SL_REBUILD flag is set
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   217
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   218
 * @param sl pointer to plstations_d (station list and flags)
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   219
 * @param owner player whose stations are to be in list
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   220
 * @param facilities types of stations of interest
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   221
 * @param cargo_filter bitmap of cargo types to include
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   222
 * @param include_empty whether we should include stations without waiting cargo
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   223
 */
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   224
static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   225
{
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   226
	uint n = 0;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   227
	const Station *st;
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   228
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   229
	if (!(sl->flags & SL_REBUILD)) return;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   230
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   231
	/* Create array for sorting */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5859
diff changeset
   232
	const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5293
diff changeset
   234
	DEBUG(misc, 3, "Building station list for player %d", owner);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   235
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	FOR_ALL_STATIONS(st) {
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   237
		if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) {
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   238
			if (facilities & st->facilities) { //only stations with selected facilities
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   239
				int num_waiting_cargo = 0;
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   240
				for (CargoID j = 0; j < NUM_CARGO; j++) {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   241
					if (!st->goods[j].cargo.Empty()) {
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   242
						num_waiting_cargo++; //count number of waiting cargo
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   243
						if (HasBit(cargo_filter, j)) {
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   244
							station_sort[n++] = st;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   245
							break;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   246
						}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   247
					}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   248
				}
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
   249
				/* stations without waiting cargo */
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   250
				if (num_waiting_cargo == 0 && include_empty) {
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   251
					station_sort[n++] = st;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   252
				}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   253
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   257
	free((void*)sl->sort_list);
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5859
diff changeset
   258
	sl->sort_list = MallocT<const Station*>(n);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   259
	sl->list_length = n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   261
	for (uint i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 69
diff changeset
   262
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   263
	sl->flags &= ~SL_REBUILD;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   264
	sl->flags |= SL_RESORT;
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   265
	free((void*)station_sort);
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   266
}
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   267
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   268
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   269
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   270
 * Sort station list if the SL_RESORT flag is set
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   271
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   272
 * @param sl pointer to plstations_d (station list and flags)
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   273
 */
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   274
static void SortStationsList(plstations_d *sl)
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   275
{
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   276
	static StationSortListingTypeFunction* const _station_sorter[] = {
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   277
		&StationNameSorter,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   278
		&StationTypeSorter,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   279
		&StationWaitingSorter,
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   280
		&StationRatingMaxSorter
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   281
	};
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 69
diff changeset
   282
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   283
	if (!(sl->flags & SL_RESORT)) return;
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
   284
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   285
	_internal_sort_order = sl->flags & SL_ORDER;
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   286
	_last_station = NULL; // used for "cache" in namesorting
4280
3265e76b7016 (svn r5910) Fix some more warnings on MSVC by using (void*) casts. Followup of r5907.
Darkvater
parents: 4277
diff changeset
   287
	qsort((void*)sl->sort_list, sl->list_length, sizeof(sl->sort_list[0]), _station_sorter[sl->sort_type]);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   288
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   289
	sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   290
	sl->flags &= ~SL_RESORT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   293
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   294
 * Fuction called when any WindowEvent occurs for PlayerStations window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   295
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   296
 * @param w pointer to the PlayerStations window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   297
 * @param e pointer to window event
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   298
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
static void PlayerStationsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   301
	const PlayerID owner = (PlayerID)w->window_number;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   302
	static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
5859
158718283d16 (svn r8065) -Feature: The station list does now remember the sort settings
celestar
parents: 5838
diff changeset
   303
	static Listing station_sort = {0, 0};
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   304
	static bool include_empty = true;
5859
158718283d16 (svn r8065) -Feature: The station list does now remember the sort settings
celestar
parents: 5838
diff changeset
   305
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   306
	plstations_d *sl = &WP(w, plstations_d);
3820
cdd48144c074 (svn r4830) - Codechange: simplify station sorting a bit by recalculating the clicked-states on drawing the window. This also allows the 'Sort by' button to be visually clickable
Darkvater
parents: 3813
diff changeset
   307
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   308
	switch (e->event) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   309
		case WE_CREATE:
6611
b7c7829c8fc7 (svn r9104) -Fix(r9080, r9081): UINT32_MAX is undefined on MSVC, std::numeric_limits doesn't exist in gcc 2.95 (MorphOS), so back to tree and use ~0 instead (peter1138)
KUDr
parents: 6598
diff changeset
   310
			if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   311
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   312
			for (uint i = 0; i < 5; i++) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   313
				if (HasBit(facilities, i)) w->LowerWidget(i + SLW_TRAIN);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   314
			}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   315
			w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   316
			w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   317
			w->SetWidgetLoweredState(SLW_NOCARGOWAITING, include_empty);
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   318
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   319
			sl->sort_list = NULL;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   320
			sl->flags = SL_REBUILD;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   321
			sl->sort_type = station_sort.criteria;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   322
			if (station_sort.order) sl->flags |= SL_ORDER;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   323
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   324
			/* set up resort timer */
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   325
			sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   326
			break;
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   327
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   328
		case WE_PAINT: {
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   329
			BuildStationsList(sl, owner, facilities, _cargo_filter, include_empty);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   330
			SortStationsList(sl);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   332
			SetVScrollCount(w, sl->list_length);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   334
			/* draw widgets, with player's name in the caption */
7554
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7506
diff changeset
   335
			SetDParam(0, owner);
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7506
diff changeset
   336
			SetDParam(1, w->vscroll.count);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
			DrawWindowWidgets(w);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   338
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   339
			/* draw sorting criteria string */
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   340
			DrawString(85, 26, _station_sort_listing[sl->sort_type], TC_BLACK);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   341
			/* draw arrow pointing up/down for ascending/descending sorting */
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   342
			DoDrawString(sl->flags & SL_ORDER ? DOWNARROW : UPARROW, 69, 26, TC_BLACK);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   343
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   344
			int cg_ofst;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   345
			int x = 89;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   346
			int y = 14;
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
   347
			int xb = 2; ///< offset from left of widget
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   348
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   349
			uint i = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   350
			for (CargoID c = 0; c < NUM_CARGO; c++) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   351
				const CargoSpec *cs = GetCargo(c);
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   352
				if (!cs->IsValid()) continue;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   353
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   354
				cg_ofst = HasBit(_cargo_filter, c) ? 2 : 1;
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   355
				GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   356
				DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   357
				x += 14;
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   358
				i++;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   359
			}
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   360
5292
99fd0bfe7299 (svn r7445) -Codechange (r4822): Properly draw the cargo colours in the station list and centre the
Darkvater
parents: 5291
diff changeset
   361
			x += 6;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   362
			cg_ofst = w->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   363
			DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   364
			x += 14;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   365
			cg_ofst = w->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   366
			DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   367
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   368
			cg_ofst = w->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   369
			DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1962
diff changeset
   371
			if (w->vscroll.count == 0) { // player has no stations
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   372
				DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   375
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   376
			int max = min(w->vscroll.pos + w->vscroll.cap, sl->list_length);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   377
			y = 40; // start of the list-widget
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   379
			for (int i = w->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
5293
4d59f970b2fe (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
   380
				const Station *st = sl->sort_list[i];
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   381
				int x;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
5293
4d59f970b2fe (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
   383
				assert(st->xy != 0);
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   384
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   385
 				/* Do not do the complex check HasStationInUse here, it may be even false
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   386
				 * when the order had been removed and the station list hasn't been removed yet */
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   387
				assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
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
   388
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   389
				SetDParam(0, st->index);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   390
				SetDParam(1, st->facilities);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   391
				x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
   393
				/* show cargo waiting and station ratings */
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6623
diff changeset
   394
				for (CargoID j = 0; j < NUM_CARGO; j++) {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   395
					if (!st->goods[j].cargo.Empty()) {
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   396
						StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
5293
4d59f970b2fe (svn r7446) -Feature: Double the length of the cargo and rating indicators in the station list window,
Darkvater
parents: 5292
diff changeset
   397
						x += 20;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
				y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
			}
4268
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   402
			break;
78373df5a67a (svn r5896) Remove pointless indirection similar to r5894 and remove an unnecessary global variable
tron
parents: 4261
diff changeset
   403
		}
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
   404
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   405
		case WE_CLICK:
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   406
			switch (e->we.click.widget) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   407
				case SLW_LIST: {
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   408
					uint32 id_v = (e->we.click.pt.y - 41) / 10;
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   409
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   410
					if (id_v >= w->vscroll.cap) return; // click out of bounds
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   411
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   412
					id_v += w->vscroll.pos;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   413
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   414
					if (id_v >= sl->list_length) return; // click out of list bound
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   415
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   416
					const Station *st = sl->sort_list[id_v];
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   417
					/* do not check HasStationInUse - it is slow and may be invalid */
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8603
diff changeset
   418
					assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   419
					ScrollMainWindowToTile(st->xy);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   420
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   421
				}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   422
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   423
				case SLW_TRAIN:
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   424
				case SLW_TRUCK:
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   425
				case SLW_BUS:
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   426
				case SLW_AIRPLANE:
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   427
				case SLW_SHIP:
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   428
					if (_ctrl_pressed) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   429
						ToggleBit(facilities, e->we.click.widget - SLW_TRAIN);
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8428
diff changeset
   430
						w->ToggleWidgetLoweredState(e->we.click.widget);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   431
					} else {
8501
66d88113ba24 (svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents: 8493
diff changeset
   432
						uint i;
66d88113ba24 (svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents: 8493
diff changeset
   433
						FOR_EACH_SET_BIT(i, facilities) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   434
							w->RaiseWidget(i + SLW_TRAIN);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   435
						}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   436
						SetBit(facilities, e->we.click.widget - SLW_TRAIN);
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8428
diff changeset
   437
						w->LowerWidget(e->we.click.widget);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   438
					}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   439
					w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   440
					sl->flags |= SL_REBUILD;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   441
					SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   442
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   443
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   444
				case SLW_FACILALL:
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   445
					for (uint i = 0; i < 5; i++) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   446
						w->LowerWidget(i + SLW_TRAIN);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   447
					}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   448
					w->LowerWidget(SLW_FACILALL);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   449
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   450
					facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   451
					sl->flags |= SL_REBUILD;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   452
					SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   453
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   454
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   455
				case SLW_CARGOALL: {
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   456
					uint i = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   457
					for (CargoID c = 0; c < NUM_CARGO; c++) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   458
						if (!GetCargo(c)->IsValid()) continue;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   459
						w->LowerWidget(i + SLW_CARGOSTART);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   460
						i++;
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   461
					}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   462
					w->LowerWidget(SLW_NOCARGOWAITING);
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   463
					w->LowerWidget(SLW_CARGOALL);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   464
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   465
					_cargo_filter = _cargo_mask;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   466
					include_empty = true;
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   467
					sl->flags |= SL_REBUILD;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   468
					SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   469
					break;
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   470
				}
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   471
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   472
				case SLW_SORTBY: // flip sorting method asc/desc
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   473
					sl->flags ^= SL_ORDER; //DESC-flag
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   474
					station_sort.order = HasBit(sl->flags, 0);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   475
					sl->flags |= SL_RESORT;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   476
					w->flags4 |= 5 << WF_TIMEOUT_SHL;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   477
					w->LowerWidget(SLW_SORTBY);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   478
					SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   479
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   480
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   481
				case SLW_SORTCRITERIA:
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   482
				case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   483
					ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, SLW_SORTDROPBTN, 0, 0);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   484
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   485
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   486
				case SLW_NOCARGOWAITING:
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   487
					if (_ctrl_pressed) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   488
						include_empty = !include_empty;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   489
						w->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   490
					} else {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   491
						for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8428
diff changeset
   492
							w->RaiseWidget(i);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   493
						}
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   494
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   495
						_cargo_filter = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   496
						include_empty = true;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   497
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   498
						w->LowerWidget(SLW_NOCARGOWAITING);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   499
					}
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   500
					sl->flags |= SL_REBUILD;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   501
					w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   502
					SetWindowDirty(w);
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   503
					break;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   504
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   505
				default:
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   506
					if (e->we.click.widget >= SLW_CARGOSTART) { // change cargo_filter
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   507
						/* Determine the selected cargo type */
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   508
						CargoID c;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   509
						int i = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   510
						for (c = 0; c < NUM_CARGO; c++) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   511
							if (!GetCargo(c)->IsValid()) continue;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   512
							if (e->we.click.widget - SLW_CARGOSTART == i) break;
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   513
							i++;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   514
						}
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   515
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   516
						if (_ctrl_pressed) {
8428
f8300c908bd9 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 8427
diff changeset
   517
							ToggleBit(_cargo_filter, c);
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8428
diff changeset
   518
							w->ToggleWidgetLoweredState(e->we.click.widget);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   519
						} else {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   520
							for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8428
diff changeset
   521
								w->RaiseWidget(i);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   522
							}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   523
							w->RaiseWidget(SLW_NOCARGOWAITING);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   524
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   525
							_cargo_filter = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   526
							include_empty = false;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   527
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   528
							SetBit(_cargo_filter, c);
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8428
diff changeset
   529
							w->LowerWidget(e->we.click.widget);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   530
						}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   531
						sl->flags |= SL_REBUILD;
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   532
						w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   533
						SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   534
					}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   535
					break;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   536
			}
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   537
			break;
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   538
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   539
		case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   540
			if (sl->sort_type != e->we.dropdown.index) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6691
diff changeset
   541
				/* value has changed -> resort */
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   542
				sl->sort_type = e->we.dropdown.index;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   543
				station_sort.criteria = sl->sort_type;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   544
				sl->flags |= SL_RESORT;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   545
			}
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   546
			SetWindowDirty(w);
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   547
			break;
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   548
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   549
		case WE_TICK:
8675
5ff307aa5048 (svn r11742) -Codechange [FS#1319]: Run window tick events when paused, so that news pop-ups and the about window still progress. For other windows the events are ignored when paused.
peter1138
parents: 8640
diff changeset
   550
			if (_pause_game != 0) break;
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   551
			if (--sl->resort_timer == 0) {
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   552
				DEBUG(misc, 3, "Periodic rebuild station list player %d", owner);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   553
				sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   554
				sl->flags |= SL_REBUILD;
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   555
				SetWindowDirty(w);
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   556
			}
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   557
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   559
		case WE_TIMEOUT:
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   560
			w->RaiseWidget(SLW_SORTBY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
			SetWindowDirty(w);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   562
			break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 817
diff changeset
   563
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   564
		case WE_RESIZE:
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   565
			w->vscroll.cap += e->we.sizing.diff.y / 10;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   566
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
static const Widget _player_stations_widgets[] = {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   571
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // SLW_CLOSEBOX
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   572
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   345,     0,    13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   573
{  WWT_STICKYBOX,     RESIZE_LR,    14,   346,   357,     0,    13, 0x0,               STR_STICKY_BUTTON},
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   574
{      WWT_PANEL,     RESIZE_RB,    14,     0,   345,    37,   161, 0x0,               STR_3057_STATION_NAMES_CLICK_ON},  // SLW_LIST
5128
c75525088fb9 (svn r7209) -Codechange: Alter position of scroll bar in the station list; the filter line isn't scrollable...
peter1138
parents: 5124
diff changeset
   575
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   346,   357,    37,   149, 0x0,               STR_0190_SCROLL_BAR_SCROLLS_LIST},
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   576
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   346,   357,   150,   161, 0x0,               STR_RESIZE_BUTTON},
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   577
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   578
{    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,    13,    14,    24, STR_TRAIN,         STR_USE_CTRL_TO_SELECT_MORE},      // SLW_TRAIN
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   579
{    WWT_TEXTBTN,   RESIZE_NONE,    14,    14,    27,    14,    24, STR_LORRY,         STR_USE_CTRL_TO_SELECT_MORE},      // SLW_TRUCK
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   580
{    WWT_TEXTBTN,   RESIZE_NONE,    14,    28,    41,    14,    24, STR_BUS,           STR_USE_CTRL_TO_SELECT_MORE},      // SLW_BUS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   581
{    WWT_TEXTBTN,   RESIZE_NONE,    14,    42,    55,    14,    24, STR_PLANE,         STR_USE_CTRL_TO_SELECT_MORE},      // SLW_AIRPLANE
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   582
{    WWT_TEXTBTN,   RESIZE_NONE,    14,    56,    69,    14,    24, STR_SHIP,          STR_USE_CTRL_TO_SELECT_MORE},      // SLW_SHIP
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   583
{      WWT_PANEL,   RESIZE_NONE,    14,    70,    83,    14,    24, 0x0,               STR_SELECT_ALL_FACILITIES},        // SLW_FACILALL
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3554
diff changeset
   584
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   585
{      WWT_PANEL,   RESIZE_NONE,    14,    83,    88,    14,    24, 0x0,               STR_NULL},                         // SLW_PAN_BETWEEN
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   586
{      WWT_PANEL,   RESIZE_NONE,    14,    89,   102,    14,    24, 0x0,               STR_NO_WAITING_CARGO},             // SLW_NOCARGOWAITING
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   587
{      WWT_PANEL,   RESIZE_NONE,    14,   103,   116,    14,    24, 0x0,               STR_SELECT_ALL_TYPES},             // SLW_CARGOALL
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   588
{      WWT_PANEL,  RESIZE_RIGHT,    14,   117,   357,    14,    24, 0x0,               STR_NULL},                         // SLW_PAN_RIGHT
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   589
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   590
{    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,    80,    25,    36, STR_SORT_BY,       STR_SORT_ORDER_TIP},               // SLW_SORTBY
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   591
{      WWT_PANEL,   RESIZE_NONE,    14,    81,   232,    25,    36, 0x0,               STR_SORT_CRITERIA_TIP},            // SLW_SORTCRITERIA
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   592
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   233,   243,    25,    36, STR_0225,          STR_SORT_CRITERIA_TIP},            // SLW_SORTDROPBTN
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   593
{      WWT_PANEL,  RESIZE_RIGHT,    14,   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
   594
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
static const WindowDesc _player_stations_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7554
diff changeset
   598
	WDP_AUTO, WDP_AUTO, 358, 162, 358, 162,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5996
diff changeset
   599
	WC_STATION_LIST, WC_NONE,
5271
419c6746fd90 (svn r7413) -Fix[FS#386,#412]: Station list window NONE button now behaves correctly.
belugas
parents: 5247
diff changeset
   600
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	_player_stations_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	PlayerStationsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   605
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   606
 * Opens window with list of player's stations
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   607
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   608
 * @param player player whose stations' list show
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   609
 */
2475
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2186
diff changeset
   610
void ShowPlayerStations(PlayerID player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
{
5005
21e84e53c732 (svn r7022) -Fix [FS#292]: Properly guard against viewing company-sensitive information from
Darkvater
parents: 4938
diff changeset
   612
	if (!IsValidPlayer(player)) return;
21e84e53c732 (svn r7022) -Fix [FS#292]: Properly guard against viewing company-sensitive information from
Darkvater
parents: 4938
diff changeset
   613
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   614
	Window *w = AllocateWindowDescFront(&_player_stations_desc, player);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   615
	if (w == NULL) return;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   616
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   617
	w->caption_color = (byte)w->window_number;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   618
	w->vscroll.cap = 12;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   619
	w->resize.step_height = 10;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   620
	w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   621
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   622
	/* Add cargo filter buttons */
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   623
	uint num_active = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   624
	for (CargoID c = 0; c < NUM_CARGO; c++) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   625
		if (GetCargo(c)->IsValid()) num_active++;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   626
	}
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   627
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   628
	w->widget_count += num_active;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   629
	w->widget = ReallocT(w->widget, w->widget_count + 1);
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   630
	w->widget[w->widget_count].type = WWT_LAST;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   631
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   632
	uint i = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   633
	for (CargoID c = 0; c < NUM_CARGO; c++) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   634
		if (!GetCargo(c)->IsValid()) continue;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   635
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   636
		Widget *wi = &w->widget[SLW_CARGOSTART + i];
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   637
		wi->type     = WWT_PANEL;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   638
		wi->display_flags = RESIZE_NONE;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   639
		wi->color    = 14;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   640
		wi->left     = 89 + i * 14;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   641
		wi->right    = wi->left + 13;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   642
		wi->top      = 14;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   643
		wi->bottom   = 24;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   644
		wi->data     = 0;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   645
		wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   646
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   647
		if (HasBit(_cargo_filter, c)) w->LowerWidget(SLW_CARGOSTART + i);
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   648
		i++;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   649
	}
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   650
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   651
	w->widget[SLW_NOCARGOWAITING].left += num_active * 14;
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   652
	w->widget[SLW_NOCARGOWAITING].right += num_active * 14;
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   653
	w->widget[SLW_CARGOALL].left += num_active * 14;
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   654
	w->widget[SLW_CARGOALL].right += num_active * 14;
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   655
	w->widget[SLW_PAN_RIGHT].left += num_active * 14;
6597
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   656
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   657
	if (num_active > 15) {
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   658
		/* Resize and fix the minimum width, if necessary */
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   659
		ResizeWindow(w, (num_active - 15) * 14, 0);
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   660
		w->resize.width = w->width;
e4ce4b1aa3bf (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138
parents: 6586
diff changeset
   661
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
static const Widget _station_view_expanded_widgets[] = {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   665
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},                // SVW_CLOSEBOX
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   666
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   236,     0,    13, STR_300A_0,        STR_018C_WINDOW_TITLE_DRAG_THIS},
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   667
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   237,   248,     0,    13, 0x0,               STR_STICKY_BUTTON},
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   668
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   236,    14,    65, 0x0,               STR_NULL},                             // SVW_WAITING
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   669
{  WWT_SCROLLBAR,   RESIZE_NONE,    14,   237,   248,    14,    65, 0x0,               STR_0190_SCROLL_BAR_SCROLLS_LIST},
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   670
{      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,               STR_NULL},                             // SVW_ACCEPTLIST
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   671
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   248,    66,   197, 0x0,               STR_NULL},                             // SVW_RATINGLIST
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   672
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    63,   198,   209, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   673
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    64,   128,   198,   209, STR_3033_ACCEPTS,  STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO}, // SVW_ACCEPTS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   674
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   129,   192,   198,   209, STR_0130_RENAME,   STR_3055_CHANGE_NAME_OF_STATION},      // SVW_RENAME
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   675
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   193,   206,   198,   209, STR_TRAIN,         STR_SCHEDULED_TRAINS_TIP },            // SVW_TRAINS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   676
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   207,   220,   198,   209, STR_LORRY,         STR_SCHEDULED_ROAD_VEHICLES_TIP },     // SVW_ROADVEHS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   677
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   221,   234,   198,   209, STR_PLANE,         STR_SCHEDULED_AIRCRAFT_TIP },          // SVW_PLANES
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   678
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   235,   248,   198,   209, STR_SHIP,          STR_SCHEDULED_SHIPS_TIP },             // SVW_SHIPS
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   679
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
static const Widget _station_view_widgets[] = {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   683
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},                // SVW_CLOSEBOX
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   684
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   236,     0,    13, STR_300A_0,        STR_018C_WINDOW_TITLE_DRAG_THIS},
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   685
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   237,   248,     0,    13, 0x0,               STR_STICKY_BUTTON},
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   686
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   236,    14,    65, 0x0,               STR_NULL},                             // SVW_WAITING
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 2725
diff changeset
   687
{  WWT_SCROLLBAR,   RESIZE_NONE,    14,   237,   248,    14,    65, 0x0,               STR_0190_SCROLL_BAR_SCROLLS_LIST},
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   688
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   248,    66,    97, 0x0,               STR_NULL},                             // SVW_ACCEPTLIST
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   689
{      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,               STR_NULL},                             // SVW_RATINGLIST
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   690
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    63,    98,   109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   691
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    64,   128,    98,   109, STR_3032_RATINGS,  STR_3054_SHOW_STATION_RATINGS},        // SVW_RATINGS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   692
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   129,   192,    98,   109, STR_0130_RENAME,   STR_3055_CHANGE_NAME_OF_STATION},      // SVW_RENAME
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   693
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   193,   206,    98,   109, STR_TRAIN,         STR_SCHEDULED_TRAINS_TIP },            // SVW_TRAINS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   694
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   207,   220,    98,   109, STR_LORRY,         STR_SCHEDULED_ROAD_VEHICLES_TIP },     // SVW_ROADVEHS
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   695
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   221,   234,    98,   109, STR_PLANE,         STR_SCHEDULED_AIRCRAFT_TIP },          // SVW_PLANES
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   696
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   235,   248,    98,   109, STR_SHIP,          STR_SCHEDULED_SHIPS_TIP },             // SVW_SHIPS
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   697
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   700
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   701
 * Draws icons of wainting cargo in the StationView window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   702
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   703
 * @param i type of cargo
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   704
 * @param waiting number of wainting units
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   705
 * @param x x on-screen coordinate where to start with drawing icons
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   706
 * @param y y coordinate
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   707
 */
6690
d037c31fd4cf (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: 6676
diff changeset
   708
static void DrawCargoIcons(CargoID i, uint waiting, int x, int y)
d037c31fd4cf (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: 6676
diff changeset
   709
{
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   710
	uint num = min((waiting + 5) / 10, 23); // maximum is 23 icons so it won't overflow
6690
d037c31fd4cf (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: 6676
diff changeset
   711
	if (num == 0) return;
d037c31fd4cf (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: 6676
diff changeset
   712
d037c31fd4cf (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: 6676
diff changeset
   713
	const CargoSpec *cs = GetCargo(i);
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   714
	SpriteID sprite;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   715
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   716
	if (cs->sprite == 0xFFFF) {
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   717
		/* A value of 0xFFFF indicates we should draw a custom icon */
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   718
		sprite = GetCustomCargoSprite(cs);
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   719
	} else {
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   720
		sprite = cs->sprite;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   721
	}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6690
diff changeset
   722
7153
85b73fcc076b (svn r9888) -Codechange: [NewGRF] allow non-spec cargo action2s to work, and using the goods sprite if really nothing is returned.
peter1138
parents: 6916
diff changeset
   723
	if (sprite == 0) sprite = SPR_CARGO_GOODS;
6690
d037c31fd4cf (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: 6676
diff changeset
   724
d037c31fd4cf (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: 6676
diff changeset
   725
	do {
d037c31fd4cf (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: 6676
diff changeset
   726
		DrawSprite(sprite, PAL_NONE, x, y);
d037c31fd4cf (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: 6676
diff changeset
   727
		x += 10;
d037c31fd4cf (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: 6676
diff changeset
   728
	} while (--num);
d037c31fd4cf (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: 6676
diff changeset
   729
}
d037c31fd4cf (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: 6676
diff changeset
   730
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   731
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   732
 * Redraws whole StationView window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   733
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   734
 * @param w pointer to window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   735
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
static void DrawStationViewWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   738
	StationID station_id = w->window_number;
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   739
	const Station* st = GetStation(station_id);
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   740
	uint num;     ///< number of cargo types waiting at station
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   741
	int x, y;     ///< coordinates used for printing waiting/accepted/rating of cargo
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   742
	int pos;      ///< = w->vscroll.pos
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   745
	/* count types of cargos waiting in station */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	num = 1;
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6623
diff changeset
   747
	for (CargoID i = 0; i < NUM_CARGO; i++) {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   748
		if (!st->goods[i].cargo.Empty()) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
			num++;
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   750
			if (st->goods[i].cargo.Source() != station_id) num++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	}
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   753
	SetVScrollCount(w, num); // update scrollbar
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   755
	/* disable some buttons */
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   756
	w->SetWidgetDisabledState(SVW_RENAME,   st->owner != _local_player);
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   757
	w->SetWidgetDisabledState(SVW_TRAINS,   !(st->facilities & FACIL_TRAIN));
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   758
	w->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   759
	w->SetWidgetDisabledState(SVW_PLANES,   !(st->facilities & FACIL_AIRPORT));
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   760
	w->SetWidgetDisabledState(SVW_SHIPS,    !(st->facilities & FACIL_DOCK));
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 534
diff changeset
   761
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   762
	SetDParam(0, st->index);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   763
	SetDParam(1, st->facilities);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
	x = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	y = 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
	pos = w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
	if (--pos < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
		str = STR_00D0_NOTHING;
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6623
diff changeset
   772
		for (CargoID i = 0; i < NUM_CARGO; i++) {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   773
			if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   774
		}
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   775
		SetDParam(0, str);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   776
		DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6623
diff changeset
   780
	for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   781
		uint waiting = st->goods[i].cargo.Count();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   782
		if (waiting == 0) continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   783
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   784
		if (st->goods[i].cargo.Source() == station_id) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
			if (--pos < 0) {
6690
d037c31fd4cf (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: 6676
diff changeset
   786
				DrawCargoIcons(i, waiting, x, y);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   787
				SetDParam(1, waiting);
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4727
diff changeset
   788
				SetDParam(0, i);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   789
				DrawStringRightAligned(x + 234, y, STR_0009, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
				y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
			/* enroute */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
			if (--pos < 0) {
6690
d037c31fd4cf (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: 6676
diff changeset
   795
				DrawCargoIcons(i, waiting, x, y);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   796
				SetDParam(1, waiting);
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4727
diff changeset
   797
				SetDParam(0, i);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   798
				DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
				y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
			if (pos > -5 && --pos < 0) {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   803
				SetDParam(0, st->goods[i].cargo.Source());
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   804
				DrawStringRightAligned(x + 234, y, STR_000B, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
				y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		}
6586
2c91b61219e1 (svn r9069) -Codechange: Change a do ... while loop with a for loop. This fixes some warning that I never got anyway...
peter1138
parents: 6585
diff changeset
   808
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   809
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   810
	if (IsWindowOfPrototype(w, _station_view_widgets)) { // small window with list of accepted cargo
1556
4fd2c95e6bc4 (svn r2060) Clean up some string construction and remove now unused macro
tron
parents: 1553
diff changeset
   811
		char *b = _userstring;
5038
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   812
		bool first = true;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1323
diff changeset
   813
1553
4976359e2bf9 (svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
tron
parents: 1474
diff changeset
   814
		b = InlineString(b, STR_000C_ACCEPTS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6623
diff changeset
   816
		for (CargoID i = 0; i < NUM_CARGO; i++) {
8537
0b4ab7d8b018 (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz
parents: 8536
diff changeset
   817
			if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   818
			if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
5038
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   819
				if (first) {
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   820
					first = false;
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   821
				} else {
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   822
					/* Add a comma if this is not the first item */
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   823
					*b++ = ',';
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   824
					*b++ = ' ';
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   825
				}
6417
26acff62d001 (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: 6144
diff changeset
   826
				b = InlineString(b, GetCargo(i)->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   829
5038
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   830
		/* If first is still true then no cargo is accepted */
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   831
		if (first) b = InlineString(b, STR_00D0_NOTHING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
5038
cd0a32afb616 (svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents: 5005
diff changeset
   833
		*b = '\0';
8537
0b4ab7d8b018 (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz
parents: 8536
diff changeset
   834
0b4ab7d8b018 (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz
parents: 8536
diff changeset
   835
		/* Make sure we detect any buffer overflow */
0b4ab7d8b018 (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz
parents: 8536
diff changeset
   836
		assert(b < endof(_userstring));
0b4ab7d8b018 (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz
parents: 8536
diff changeset
   837
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
		DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245);
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   839
	} else { // extended window with list of cargo ratings
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   840
		DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		y = 77;
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6623
diff changeset
   843
		for (CargoID i = 0; i < NUM_CARGO; i++) {
6623
1115fe0767a9 (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: 6611
diff changeset
   844
			const CargoSpec *cs = GetCargo(i);
1115fe0767a9 (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: 6611
diff changeset
   845
			if (!cs->IsValid()) continue;
1115fe0767a9 (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: 6611
diff changeset
   846
1115fe0767a9 (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: 6611
diff changeset
   847
			const GoodsEntry *ge = &st->goods[i];
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8382
diff changeset
   848
			if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
6623
1115fe0767a9 (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: 6611
diff changeset
   849
1115fe0767a9 (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: 6611
diff changeset
   850
			SetDParam(0, cs->name);
1115fe0767a9 (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: 6611
diff changeset
   851
			SetDParam(2, ge->rating * 101 >> 8);
1115fe0767a9 (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: 6611
diff changeset
   852
			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7970
diff changeset
   853
			DrawString(8, y, STR_303D, TC_FROMSTRING);
6623
1115fe0767a9 (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: 6611
diff changeset
   854
			y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   860
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   861
 * Fuction called when any WindowEvent occurs for any StationView window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   862
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   863
 * @param w pointer to the StationView window
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   864
 * @param e pointer to window event
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   865
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
static void StationViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   868
	switch (e->event) {
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   869
		case WE_PAINT:
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   870
			DrawStationViewWindow(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   873
		case WE_CLICK:
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   874
			switch (e->we.click.widget) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   875
				case SVW_LOCATION:
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   876
					ScrollMainWindowToTile(GetStation(w->window_number)->xy);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   877
					break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   878
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   879
				case SVW_RATINGS:
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   880
					SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   881
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   882
					/* toggle height/widget set */
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   883
					if (IsWindowOfPrototype(w, _station_view_expanded_widgets)) {
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   884
						AssignWidgetToWindow(w, _station_view_widgets);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   885
						w->height = 110;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   886
					} else {
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   887
						AssignWidgetToWindow(w, _station_view_expanded_widgets);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   888
						w->height = 210;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   889
					}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   890
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   891
					SetWindowDirty(w);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   892
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   893
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   894
				case SVW_RENAME:
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   895
					SetDParam(0, w->window_number);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   896
					ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w, CS_ALPHANUMERAL);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   897
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   898
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   899
				case SVW_TRAINS: { // Show a list of scheduled trains to this station
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   900
					const Station *st = GetStation(w->window_number);
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6579
diff changeset
   901
					ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)w->window_number);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   902
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   903
				}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   904
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   905
				case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   906
					const Station *st = GetStation(w->window_number);
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6579
diff changeset
   907
					ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)w->window_number);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   908
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   909
				}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   910
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   911
				case SVW_PLANES: { // Show a list of scheduled aircraft to this station
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   912
					const Station *st = GetStation(w->window_number);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   913
					/* Since oilrigs have no owners, show the scheduled aircraft of current player */
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   914
					PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6579
diff changeset
   915
					ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)w->window_number);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   916
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   917
				}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   918
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   919
				case SVW_SHIPS: { // Show a list of scheduled ships to this station
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   920
					const Station *st = GetStation(w->window_number);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   921
					/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   922
					PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6579
diff changeset
   923
					ShowVehicleListWindow(owner, VEH_SHIP, (StationID)w->window_number);
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   924
					break;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   925
				}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 817
diff changeset
   926
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   929
		case WE_ON_EDIT_TEXT:
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   930
			if (e->we.edittext.str[0] != '\0') {
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   931
				_cmd_text = e->we.edittext.str;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   932
				DoCommandP(0, w->window_number, 0, NULL,
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   933
					CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   934
			}
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   935
			break;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 534
diff changeset
   936
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   937
		case WE_DESTROY: {
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   938
			WindowNumber wno =
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   939
				(w->window_number << 16) | GetStation(w->window_number)->owner;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   940
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   941
			DeleteWindowById(WC_TRAINS_LIST, wno);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   942
			DeleteWindowById(WC_ROADVEH_LIST, wno);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   943
			DeleteWindowById(WC_SHIPS_LIST, wno);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   944
			DeleteWindowById(WC_AIRCRAFT_LIST, wno);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 534
diff changeset
   945
			break;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 534
diff changeset
   946
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
static const WindowDesc _station_view_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7554
diff changeset
   952
	WDP_AUTO, WDP_AUTO, 249, 110, 249, 110,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5996
diff changeset
   953
	WC_STATION_VIEW, WC_NONE,
758
bd9e868b9fae (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 603
diff changeset
   954
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	_station_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	StationViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   959
/**
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   960
 * Opens StationViewWindow for given station
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   961
 *
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   962
 * @param station station which window should be opened
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8501
diff changeset
   963
 */
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2484
diff changeset
   964
void ShowStationViewWindow(StationID station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
{
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   966
	Window *w = AllocateWindowDescFront(&_station_view_desc, station);
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   967
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
6528
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   969
	PlayerID owner = GetStation(w->window_number)->owner;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   970
	if (owner != OWNER_NONE) w->caption_color = owner;
b705912233fa (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138
parents: 6448
diff changeset
   971
	w->vscroll.cap = 5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
}