annotate src/station_gui.cpp @ 11072:19fd43d5975d draft

(svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
author rubidium <rubidium@openttd.org>
date Sun, 08 Feb 2009 15:45:34 +0000
parents a1d256bf72e0
children 02d314ea4f63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 9094
diff changeset
3 /** @file station_gui.cpp The GUI for stations. */
6420
080aae477331 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents: 6365
diff changeset
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
6 #include "openttd.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
7 #include "debug.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
8 #include "gui.h"
8107
f65cf2bc3255 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium <rubidium@openttd.org>
parents: 8106
diff changeset
9 #include "window_gui.h"
f65cf2bc3255 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium <rubidium@openttd.org>
parents: 8106
diff changeset
10 #include "textbuf_gui.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
11 #include "company_func.h"
8116
9cc845deddfe (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents: 8114
diff changeset
12 #include "command_func.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "vehicle_gui.h"
6091
17ebeb5a2c37 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents: 5893
diff changeset
14 #include "cargotype.h"
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
15 #include "station_gui.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 8109
diff changeset
16 #include "strings_func.h"
8131
e300ac8001ae (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 <rubidium@openttd.org>
parents: 8130
diff changeset
17 #include "window_func.h"
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8179
diff changeset
18 #include "viewport_func.h"
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8179
diff changeset
19 #include "gfx_func.h"
8284
dbb7bfe0e95c (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138 <peter1138@openttd.org>
parents: 8268
diff changeset
20 #include "widgets/dropdown_func.h"
8787
ff327b646d49 (svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium <rubidium@openttd.org>
parents: 8785
diff changeset
21 #include "newgrf_cargo.h"
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
22 #include "station_map.h"
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
23 #include "tilehighlight_func.h"
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
24 #include "core/smallmap_type.hpp"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
25 #include "company_base.h"
10122
dff578338ffb (svn r14306) -Codechange: unify the code to draw the vehicle list.
rubidium <rubidium@openttd.org>
parents: 10021
diff changeset
26 #include "sortlist_type.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 10952
diff changeset
27 #include "settings_type.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
28
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
29 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
30 #include "table/sprites.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
31
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
32 /**
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
33 * Draw small boxes of cargo amount and ratings data at the given
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34 * coordinates. If amount exceeds 576 units, it is shown 'full', same
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
35 * goes for the rating: at above 90% orso (224) it is also 'full'
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
36 *
6420
080aae477331 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents: 6365
diff changeset
37 * @param x coordinate to draw the box at
080aae477331 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents: 6365
diff changeset
38 * @param y coordinate to draw the box at
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39 * @param type Cargo type
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40 * @param amount Cargo amount
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
41 * @param rating ratings data for that particular cargo
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
42 *
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
43 * @note Each cargo-bar is 16 pixels wide and 6 pixels high
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
44 * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
45 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
46 static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
47 {
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
48 static const uint units_full = 576; ///< number of units to show station as 'full'
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
49 static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
50
6091
17ebeb5a2c37 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents: 5893
diff changeset
51 const CargoSpec *cs = GetCargo(type);
6122
7b95b092af6d (svn r8858) -Codechange: Replace magic number test with class method for determining if a cargo is valid/active.
peter1138 <peter1138@openttd.org>
parents: 6091
diff changeset
52 if (!cs->IsValid()) return;
6091
17ebeb5a2c37 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents: 5893
diff changeset
53
17ebeb5a2c37 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents: 5893
diff changeset
54 int colour = cs->rating_colour;
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
55 uint w = (minu(amount, units_full) + 5) / 36;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
56
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
57 /* Draw total cargo (limited) on station (fits into 16 pixels) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
58 if (w != 0) GfxFillRect(x, y, x + w - 1, y + 6, colour);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
59
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
60 /* Draw a one pixel-wide bar of additional cargo meter, useful
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
61 * for stations with only a small amount (<=30) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
62 if (w == 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
63 uint rest = amount / 5;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
64 if (rest != 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
65 w += x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
66 GfxFillRect(w, y + 6 - rest, w, y + 6, colour);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
67 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
68 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
69
7824
7ae5bda4e8dd (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas <belugas@openttd.org>
parents: 7474
diff changeset
70 DrawString(x + 1, y, cs->abbrev, TC_BLACK);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
71
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
72 /* Draw green/red ratings bar (fits into 14 pixels) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
73 y += 8;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
74 GfxFillRect(x + 1, y, x + 14, y, 0xB8);
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
75 rating = minu(rating, rating_full) / 16;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
76 if (rating != 0) GfxFillRect(x + 1, y, x + rating, y, 0xD0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
77 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
78
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
79 typedef GUIList<const Station*> GUIStationList;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
80
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
81 /**
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
82 * The list of stations per company.
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
83 */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
84 class CompanyStationsWindow : public Window
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
85 {
10952
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
86 /** Enum for CompanyStations, referring to _company_stations_widgets */
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
87 enum StationListWidgets {
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
88 SLW_CLOSEBOX = 0, ///< Close window button
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
89 SLW_CAPTION, ///< Window caption
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
90 SLW_STICKY, ///< Sticky button
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
91 SLW_LIST, ///< The main panel, list of stations
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
92 SLW_SCROLLBAR, ///< Scrollbar next to the main panel
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
93 SLW_RESIZE, ///< Resize button
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
94
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
95 SLW_TRAIN, ///< 'TRAIN' button - list only facilities where is a railroad station
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
96 SLW_TRUCK, ///< 'TRUCK' button - list only facilities where is a truck stop
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
97 SLW_BUS, ///< 'BUS' button - list only facilities where is a bus stop
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
98 SLW_AIRPLANE, ///< 'AIRPLANE' button - list only facilities where is an airport
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
99 SLW_SHIP, ///< 'SHIP' button - list only facilities where is a dock
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
100 SLW_FACILALL, ///< 'ALL' button - list all facilities
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
101
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
102 SLW_PAN_BETWEEN, ///< Small panel between list of types of ficilities and list of cargo types
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
103 SLW_NOCARGOWAITING, ///< 'NO' button - list stations where no cargo is waiting
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
104 SLW_CARGOALL, ///< 'ALL' button - list all stations
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
105 SLW_PAN_RIGHT, ///< Panel right of list of cargo types
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
106
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
107 SLW_SORTBY, ///< 'Sort by' button - reverse sort direction
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
108 SLW_SORTDROPBTN, ///< Dropdown button
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
109 SLW_PAN_SORT_RIGHT, ///< Panel right of sorting options
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
110
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
111 SLW_CARGOSTART, ///< Widget numbers used for list of cargo types (not present in _company_stations_widgets)
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
112 };
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
113
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
114 protected:
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
115 /* Runtime saved values */
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
116 static Listing last_sorting;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
117 static byte facilities; // types of stations of interest
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
118 static bool include_empty; // whether we should include stations without waiting cargo
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
119 static const uint32 cargo_filter_max;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
120 static uint32 cargo_filter; // bitmap of cargo types to include
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
121 static const Station *last_station;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
122
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
123 /* Constants for sorting stations */
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
124 static const StringID sorter_names[];
9382
6d8ee9e0b359 (svn r13292) -Fix (r13285): MSVC warnings
glx <glx@openttd.org>
parents: 9379
diff changeset
125 static GUIStationList::SortFunction *const sorter_funcs[];
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
126
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
127 GUIStationList stations;
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
128
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
129
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
130 /**
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
131 * (Re)Build station list
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
132 *
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
133 * @param owner company whose stations are to be in list
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
134 */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
135 void BuildStationsList(const Owner owner)
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
136 {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
137 if (!this->stations.NeedRebuild()) return;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
138
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
139 DEBUG(misc, 3, "Building station list for company %d", owner);
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
140
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
141 this->stations.Clear();
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
142
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
143 const Station *st;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
144 FOR_ALL_STATIONS(st) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
145 if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
146 if (this->facilities & st->facilities) { // only stations with selected facilities
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
147 int num_waiting_cargo = 0;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
148 for (CargoID j = 0; j < NUM_CARGO; j++) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
149 if (!st->goods[j].cargo.Empty()) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
150 num_waiting_cargo++; // count number of waiting cargo
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
151 if (HasBit(this->cargo_filter, j)) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
152 *this->stations.Append() = st;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
153 break;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
154 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
155 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
156 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
157 /* stations without waiting cargo */
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
158 if (num_waiting_cargo == 0 && this->include_empty) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
159 *this->stations.Append() = st;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
160 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
161 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
162 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
163 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
164
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
165 this->stations.Compact();
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
166 this->stations.RebuildDone();
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
167 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
168
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
169 /** Sort stations by their name */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
170 static int CDECL StationNameSorter(const Station * const *a, const Station * const *b)
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
171 {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
172 static char buf_cache[64];
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
173 char buf[64];
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
174
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
175 SetDParam(0, (*a)->index);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
176 GetString(buf, STR_STATION, lastof(buf));
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
177
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
178 if (*b != last_station) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
179 last_station = *b;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
180 SetDParam(0, (*b)->index);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
181 GetString(buf_cache, STR_STATION, lastof(buf_cache));
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
182 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
183
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
184 return strcmp(buf, buf_cache);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
185 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
186
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
187 /** Sort stations by their type */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
188 static int CDECL StationTypeSorter(const Station * const *a, const Station * const *b)
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
189 {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
190 return (*a)->facilities - (*b)->facilities;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
191 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
192
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
193 /** Sort stations by their waiting cargo */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
194 static int CDECL StationWaitingSorter(const Station * const *a, const Station * const *b)
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
195 {
9580
5ef52e2f0601 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13 <skidd13@openttd.org>
parents: 9391
diff changeset
196 Money diff = 0;
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
197
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
198 for (CargoID j = 0; j < NUM_CARGO; j++) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
199 if (!HasBit(cargo_filter, j)) continue;
9580
5ef52e2f0601 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13 <skidd13@openttd.org>
parents: 9391
diff changeset
200 if (!(*a)->goods[j].cargo.Empty()) diff += GetTransportedGoodsIncome((*a)->goods[j].cargo.Count(), 20, 50, j);
5ef52e2f0601 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13 <skidd13@openttd.org>
parents: 9391
diff changeset
201 if (!(*b)->goods[j].cargo.Empty()) diff -= GetTransportedGoodsIncome((*b)->goods[j].cargo.Count(), 20, 50, j);
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
202 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
203
9580
5ef52e2f0601 (svn r13617) -Codechange: calculate the diff in StationWaitingSorter directly
skidd13 <skidd13@openttd.org>
parents: 9391
diff changeset
204 return ClampToI32(diff);
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
205 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
206
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
207 /** Sort stations by their rating */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
208 static int CDECL StationRatingMaxSorter(const Station * const *a, const Station * const *b)
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
209 {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
210 byte maxr1 = 0;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
211 byte maxr2 = 0;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
212
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
213 for (CargoID j = 0; j < NUM_CARGO; j++) {
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
214 if (HasBit((*a)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, (*a)->goods[j].rating);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
215 if (HasBit((*b)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, (*b)->goods[j].rating);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
216 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
217
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
218 return maxr1 - maxr2;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
219 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
220
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
221 /** Sort the stations list */
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
222 void SortStationsList()
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
223 {
9379
211a8cd2908e (svn r13286) -Codechange: GUIList Sort returns now if the list sequence has been altered
skidd13 <skidd13@openttd.org>
parents: 9378
diff changeset
224 if (!this->stations.Sort()) return;
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
225
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
226 /* Reset name sorter sort cache */
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
227 this->last_station = NULL;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
228
9389
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
229 /* Set the modified widget dirty */
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
230 this->InvalidateWidget(SLW_LIST);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
231 }
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
232
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
233 public:
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
234 CompanyStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
235 {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
236 this->caption_color = (byte)this->window_number;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
237 this->vscroll.cap = 12;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
238 this->resize.step_height = 10;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
239 this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
240
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
241 /* Add cargo filter buttons */
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
242 uint num_active = 0;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
243 for (CargoID c = 0; c < NUM_CARGO; c++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
244 if (GetCargo(c)->IsValid()) num_active++;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
245 }
5608
5dcef0df6a67 (svn r8065) -Feature: The station list does now remember the sort settings
celestar <celestar@openttd.org>
parents: 5587
diff changeset
246
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
247 this->widget_count += num_active;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
248 this->widget = ReallocT(this->widget, this->widget_count + 1);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
249 this->widget[this->widget_count].type = WWT_LAST;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
250
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
251 uint i = 0;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
252 for (CargoID c = 0; c < NUM_CARGO; c++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
253 if (!GetCargo(c)->IsValid()) continue;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
254
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
255 Widget *wi = &this->widget[SLW_CARGOSTART + i];
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
256 wi->type = WWT_PANEL;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
257 wi->display_flags = RESIZE_NONE;
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
258 wi->color = COLOUR_GREY;
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
259 wi->left = 89 + i * 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
260 wi->right = wi->left + 13;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
261 wi->top = 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
262 wi->bottom = 24;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
263 wi->data = 0;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
264 wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
265
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
266 if (HasBit(this->cargo_filter, c)) this->LowerWidget(SLW_CARGOSTART + i);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
267 i++;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
268 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
269
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
270 this->widget[SLW_NOCARGOWAITING].left += num_active * 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
271 this->widget[SLW_NOCARGOWAITING].right += num_active * 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
272 this->widget[SLW_CARGOALL].left += num_active * 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
273 this->widget[SLW_CARGOALL].right += num_active * 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
274 this->widget[SLW_PAN_RIGHT].left += num_active * 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
275
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
276 if (num_active > 15) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
277 /* Resize and fix the minimum width, if necessary */
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
278 ResizeWindow(this, (num_active - 15) * 14, 0);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
279 this->resize.width = this->width;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
280 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
281
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
282 if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
283
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
284 for (uint i = 0; i < 5; i++) {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
285 if (HasBit(this->facilities, i)) this->LowerWidget(i + SLW_TRAIN);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
286 }
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
287 this->SetWidgetLoweredState(SLW_FACILALL, this->facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
288 this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
289 this->SetWidgetLoweredState(SLW_NOCARGOWAITING, this->include_empty);
6271
56a8bb763a87 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138 <peter1138@openttd.org>
parents: 6260
diff changeset
290
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
291 this->stations.SetListing(this->last_sorting);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
292 this->stations.SetSortFuncs(this->sorter_funcs);
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
293 this->stations.ForceRebuild();
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
294 this->stations.NeedResort();
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
295 this->SortStationsList();
9333
5236ba6c7d54 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138 <peter1138@openttd.org>
parents: 9317
diff changeset
296
9389
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
297 this->widget[SLW_SORTDROPBTN].data = this->sorter_names[this->stations.SortType()];
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
298
9333
5236ba6c7d54 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138 <peter1138@openttd.org>
parents: 9317
diff changeset
299 this->FindWindowPlacementAndResize(desc);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
300 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
301
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
302 ~CompanyStationsWindow()
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
303 {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
304 this->last_sorting = this->stations.GetListing();
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
305 }
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
306
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
307 virtual void OnPaint()
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
308 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
309 const Owner owner = (Owner)this->window_number;
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
310
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
311 this->BuildStationsList(owner);
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
312 this->SortStationsList();
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
313
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
314 SetVScrollCount(this, this->stations.Length());
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
315
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
316 /* draw widgets, with company's name in the caption */
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
317 SetDParam(0, owner);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
318 SetDParam(1, this->vscroll.count);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
319
9273
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9214
diff changeset
320 this->DrawWidgets();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
321
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
322 /* draw arrow pointing up/down for ascending/descending sorting */
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
323 this->DrawSortButtonState(SLW_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
324
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
325 int cg_ofst;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
326 int x = 89;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
327 int y = 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
328 int xb = 2; ///< offset from left of widget
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
329
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
330 uint i = 0;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
331 for (CargoID c = 0; c < NUM_CARGO; c++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
332 const CargoSpec *cs = GetCargo(c);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
333 if (!cs->IsValid()) continue;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
334
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
335 cg_ofst = HasBit(this->cargo_filter, c) ? 2 : 1;
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
336 GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
337 DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
338 x += 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
339 i++;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
340 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
341
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
342 x += 6;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
343 cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
344 DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
345 x += 14;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
346 cg_ofst = this->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
347 DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
348
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
349 cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
350 DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
8338
133b06cabee8 (svn r11904) -Codechange: use dropdown widget in 3 more windows, build vehicle, group vehicle list and station list.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
351
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
352 if (this->vscroll.count == 0) { // company has no stations
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
353 DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
354 return;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
355 }
8338
133b06cabee8 (svn r11904) -Codechange: use dropdown widget in 3 more windows, build vehicle, group vehicle list and station list.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
356
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
357 int max = min(this->vscroll.pos + this->vscroll.cap, this->stations.Length());
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
358 y = 40; // start of the list-widget
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
359
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
360 for (int i = this->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
361 const Station *st = this->stations[i];
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
362 int x;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
363
10488
a9ecb9be9814 (svn r14743) -Codechange: use INVALID_TILE to indicate station doesn't have queried facility (or station/roadstop is invalid) instead of 0 (Yexo)
smatz <smatz@openttd.org>
parents: 10208
diff changeset
364 assert(st->xy != INVALID_TILE);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
365
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
366 /* Do not do the complex check HasStationInUse here, it may be even false
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
367 * when the order had been removed and the station list hasn't been removed yet */
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
368 assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
369
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
370 SetDParam(0, st->index);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
371 SetDParam(1, st->facilities);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
372 x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
373
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
374 /* show cargo waiting and station ratings */
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
375 for (CargoID j = 0; j < NUM_CARGO; j++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
376 if (!st->goods[j].cargo.Empty()) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
377 StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
378 x += 20;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
379 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
380 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
381 y += 10;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
382 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
383 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
384
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
385 virtual void OnClick(Point pt, int widget)
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
386 {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
387 switch (widget) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
388 case SLW_LIST: {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
389 uint32 id_v = (pt.y - 41) / 10;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
390
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
391 if (id_v >= this->vscroll.cap) return; // click out of bounds
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
392
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
393 id_v += this->vscroll.pos;
6271
56a8bb763a87 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138 <peter1138@openttd.org>
parents: 6260
diff changeset
394
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
395 if (id_v >= this->stations.Length()) return; // click out of list bound
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
396
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
397 const Station *st = this->stations[id_v];
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
398 /* do not check HasStationInUse - it is slow and may be invalid */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
399 assert(st->owner == (Owner)this->window_number || (st->owner == OWNER_NONE && !st->IsBuoy()));
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
400
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
401 if (_ctrl_pressed) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
402 ShowExtraViewPortWindow(st->xy);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
403 } else {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
404 ScrollMainWindowToTile(st->xy);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
405 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
406 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
407 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
408
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
409 case SLW_TRAIN:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
410 case SLW_TRUCK:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
411 case SLW_BUS:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
412 case SLW_AIRPLANE:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
413 case SLW_SHIP:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
414 if (_ctrl_pressed) {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
415 ToggleBit(this->facilities, widget - SLW_TRAIN);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
416 this->ToggleWidgetLoweredState(widget);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
417 } else {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
418 uint i;
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
419 FOR_EACH_SET_BIT(i, this->facilities) {
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
420 this->RaiseWidget(i + SLW_TRAIN);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
421 }
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
422 SetBit(this->facilities, widget - SLW_TRAIN);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
423 this->LowerWidget(widget);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
424 }
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
425 this->SetWidgetLoweredState(SLW_FACILALL, this->facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
426 this->stations.ForceRebuild();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
427 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
428 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
429
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
430 case SLW_FACILALL:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
431 for (uint i = 0; i < 5; i++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
432 this->LowerWidget(i + SLW_TRAIN);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
433 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
434 this->LowerWidget(SLW_FACILALL);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
435
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
436 this->facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
437 this->stations.ForceRebuild();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
438 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
439 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
440
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
441 case SLW_CARGOALL: {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
442 uint i = 0;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
443 for (CargoID c = 0; c < NUM_CARGO; c++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
444 if (!GetCargo(c)->IsValid()) continue;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
445 this->LowerWidget(i + SLW_CARGOSTART);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
446 i++;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
447 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
448 this->LowerWidget(SLW_NOCARGOWAITING);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
449 this->LowerWidget(SLW_CARGOALL);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
450
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
451 this->cargo_filter = _cargo_mask;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
452 this->include_empty = true;
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
453 this->stations.ForceRebuild();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
454 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
455 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
456 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
457
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
458 case SLW_SORTBY: // flip sorting method asc/desc
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
459 this->stations.ToggleSortOrder();
10180
e024f1d28082 (svn r14390) -Codechange: replace magic constants with symbolic constants.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
460 this->flags4 |= WF_TIMEOUT_BEGIN;
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
461 this->LowerWidget(SLW_SORTBY);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
462 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
463 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
464
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
465 case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
466 ShowDropDownMenu(this, this->sorter_names, this->stations.SortType(), SLW_SORTDROPBTN, 0, 0);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
467 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
468
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
469 case SLW_NOCARGOWAITING:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
470 if (_ctrl_pressed) {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
471 this->include_empty = !this->include_empty;
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
472 this->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
473 } else {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
474 for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
475 this->RaiseWidget(i);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
476 }
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
477
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
478 this->cargo_filter = 0;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
479 this->include_empty = true;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
480
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
481 this->LowerWidget(SLW_NOCARGOWAITING);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
482 }
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
483 this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
484 this->stations.ForceRebuild();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
485 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
486 break;
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
487
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
488 default:
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
489 if (widget >= SLW_CARGOSTART) { // change cargo_filter
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
490 /* Determine the selected cargo type */
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
491 CargoID c;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
492 int i = 0;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
493 for (c = 0; c < NUM_CARGO; c++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
494 if (!GetCargo(c)->IsValid()) continue;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
495 if (widget - SLW_CARGOSTART == i) break;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
496 i++;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
497 }
9094
a3f3038e9b9a (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138 <peter1138@openttd.org>
parents: 8992
diff changeset
498
a3f3038e9b9a (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138 <peter1138@openttd.org>
parents: 8992
diff changeset
499 if (_ctrl_pressed) {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
500 ToggleBit(this->cargo_filter, c);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
501 this->ToggleWidgetLoweredState(widget);
9094
a3f3038e9b9a (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138 <peter1138@openttd.org>
parents: 8992
diff changeset
502 } else {
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
503 for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
504 this->RaiseWidget(i);
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
505 }
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
506 this->RaiseWidget(SLW_NOCARGOWAITING);
6271
56a8bb763a87 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138 <peter1138@openttd.org>
parents: 6260
diff changeset
507
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
508 this->cargo_filter = 0;
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
509 this->include_empty = false;
6271
56a8bb763a87 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138 <peter1138@openttd.org>
parents: 6260
diff changeset
510
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
511 SetBit(this->cargo_filter, c);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
512 this->LowerWidget(widget);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
513 }
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
514 this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
515 this->stations.ForceRebuild();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
516 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
517 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
518 break;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
519 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
520 }
6271
56a8bb763a87 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138 <peter1138@openttd.org>
parents: 6260
diff changeset
521
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
522 virtual void OnDropdownSelect(int widget, int index)
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
523 {
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
524 if (this->stations.SortType() != index) {
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
525 this->stations.SetSortType(index);
9389
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
526
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
527 /* Display the current sort variant */
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
528 this->widget[SLW_SORTDROPBTN].data = this->sorter_names[this->stations.SortType()];
b81a2f5313a9 (svn r13299) -Fix (r13286): Stations sort type isn't updated correctly
skidd13 <skidd13@openttd.org>
parents: 9382
diff changeset
529
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
530 this->SetDirty();
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
531 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
532 }
6271
56a8bb763a87 (svn r9080) -Codechange: dynamically build cargo filter buttons in the station list window.
peter1138 <peter1138@openttd.org>
parents: 6260
diff changeset
533
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
534 virtual void OnTick()
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
535 {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
536 if (_pause_game != 0) return;
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
537 if (this->stations.NeedResort()) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
538 DEBUG(misc, 3, "Periodic rebuild station list company %d", this->window_number);
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
539 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
540 }
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
541 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
542
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
543 virtual void OnTimeout()
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
544 {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
545 this->RaiseWidget(SLW_SORTBY);
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
546 this->SetDirty();
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
547 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
548
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
549 virtual void OnResize(Point new_size, Point delta)
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
550 {
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
551 this->vscroll.cap += delta.y / 10;
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
552 }
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
553
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
554 virtual void OnInvalidateData(int data)
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
555 {
9377
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
556 if (data == 0) {
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
557 this->stations.ForceRebuild();
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
558 } else {
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
559 this->stations.ForceResort();
1d6f7b3bf9af (svn r13283) -Codechange: convert the inheritance of GUIList in PlayerStationsWindow to a member object
skidd13 <skidd13@openttd.org>
parents: 9365
diff changeset
560 }
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
561 }
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
562 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
563
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
564 Listing CompanyStationsWindow::last_sorting = {false, 0};
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
565 byte CompanyStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
566 bool CompanyStationsWindow::include_empty = true;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
567 const uint32 CompanyStationsWindow::cargo_filter_max = UINT32_MAX;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
568 uint32 CompanyStationsWindow::cargo_filter = UINT32_MAX;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
569 const Station *CompanyStationsWindow::last_station = NULL;
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
570
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
571 /* Availible station sorting functions */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
572 GUIStationList::SortFunction *const CompanyStationsWindow::sorter_funcs[] = {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
573 &StationNameSorter,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
574 &StationTypeSorter,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
575 &StationWaitingSorter,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
576 &StationRatingMaxSorter
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
577 };
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
578
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
579 /* Names of the sorting functions */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
580 const StringID CompanyStationsWindow::sorter_names[] = {
9378
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
581 STR_SORT_BY_DROPDOWN_NAME,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
582 STR_SORT_BY_FACILITY,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
583 STR_SORT_BY_WAITING,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
584 STR_SORT_BY_RATING_MAX,
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
585 INVALID_STRING_ID
cacef2552d9f (svn r13285) -Codechange: station sorting uses GUILists Sort() now
skidd13 <skidd13@openttd.org>
parents: 9377
diff changeset
586 };
9191
b61dc40f30a4 (svn r13054) -Codechange: make a class of the PlayerStationsWindow.
rubidium <rubidium@openttd.org>
parents: 9190
diff changeset
587
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
588
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
589 static const Widget _company_stations_widgets[] = {
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
590 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SLW_CLOSEBOX
10952
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
591 { WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 345, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, // SLW_CAPTION
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
592 { WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON}, // SLW_STICKY
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
593 { WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 345, 37, 161, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, // SLW_LIST
10952
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
594 { WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 346, 357, 37, 149, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // SLW_SCROLLBAR
1ec1f1ef7377 (svn r15291) -Cleanup: Move the station list widgets to their class from station_gui.h
Yexo <Yexo@openttd.org>
parents: 10739
diff changeset
595 { WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 346, 357, 150, 161, 0x0, STR_RESIZE_BUTTON}, // SLW_RESIZE
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
596
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
597 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 13, 14, 24, STR_TRAIN, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRAIN
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
598 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 14, 27, 14, 24, STR_LORRY, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRUCK
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
599 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 28, 41, 14, 24, STR_BUS, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_BUS
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
600 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 42, 55, 14, 24, STR_PLANE, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_AIRPLANE
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
601 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 56, 69, 14, 24, STR_SHIP, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_SHIP
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
602 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES}, // SLW_FACILALL
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
603
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
604 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 83, 88, 14, 24, 0x0, STR_NULL}, // SLW_PAN_BETWEEN
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
605 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 89, 102, 14, 24, 0x0, STR_NO_WAITING_CARGO}, // SLW_NOCARGOWAITING
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
606 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 103, 116, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, // SLW_CARGOALL
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
607 { WWT_PANEL, RESIZE_RIGHT, COLOUR_GREY, 117, 357, 14, 24, 0x0, STR_NULL}, // SLW_PAN_RIGHT
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
608
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
609 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP}, // SLW_SORTBY
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
610 { WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 81, 243, 25, 36, 0x0, STR_SORT_CRITERIA_TIP}, // SLW_SORTDROPBTN
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
611 { WWT_PANEL, RESIZE_RIGHT, COLOUR_GREY, 244, 357, 25, 36, 0x0, STR_NULL}, // SLW_PAN_SORT_RIGHT
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
612 { WIDGETS_END},
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
613 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
614
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
615 static const WindowDesc _company_stations_desc = {
7341
549c757023fc (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium <rubidium@openttd.org>
parents: 7058
diff changeset
616 WDP_AUTO, WDP_AUTO, 358, 162, 358, 162,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5745
diff changeset
617 WC_STATION_LIST, WC_NONE,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
618 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
619 _company_stations_widgets,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
620 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
621
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
622 /**
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
623 * Opens window with list of company's stations
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
624 *
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
625 * @param company whose stations' list show
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
626 */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
627 void ShowCompanyStations(CompanyID company)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
628 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
629 if (!IsValidCompanyID(company)) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
630
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
631 AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
632 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
633
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
634 static const Widget _station_view_widgets[] = {
9764
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
635 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SVW_CLOSEBOX
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
636 { WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS},
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
637 { WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON},
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
638 { WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 236, 14, 65, 0x0, STR_NULL}, // SVW_WAITING
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
639 { WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
640 { WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 0, 248, 66, 97, 0x0, STR_NULL}, // SVW_ACCEPTLIST / SVW_RATINGLIST
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
641 { WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 59, 98, 109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
642 { WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 60, 120, 98, 109, STR_3032_RATINGS, STR_3054_SHOW_STATION_RATINGS}, // SVW_RATINGS / SVW_ACCEPTS
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
643 { WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 121, 180, 98, 109, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, // SVW_RENAME
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
644 { WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 181, 194, 98, 109, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, // SVW_TRAINS
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
645 { WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 195, 208, 98, 109, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP }, // SVW_ROADVEHS
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
646 { WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 209, 222, 98, 109, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP }, // SVW_PLANES
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
647 { WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 223, 236, 98, 109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, // SVW_SHIPS
f301b0566657 (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas <belugas@openttd.org>
parents: 9659
diff changeset
648 { WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 237, 248, 98, 109, 0x0, STR_RESIZE_BUTTON},
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
649 { WIDGETS_END},
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
650 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
651
8762
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
652 SpriteID GetCargoSprite(CargoID i)
6364
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
653 {
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
654 const CargoSpec *cs = GetCargo(i);
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
655 SpriteID sprite;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
656
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
657 if (cs->sprite == 0xFFFF) {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
658 /* A value of 0xFFFF indicates we should draw a custom icon */
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
659 sprite = GetCustomCargoSprite(cs);
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
660 } else {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
661 sprite = cs->sprite;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
662 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents: 6364
diff changeset
663
6657
05dc53b3e64a (svn r9888) -Codechange: [NewGRF] allow non-spec cargo action2s to work, and using the goods sprite if really nothing is returned.
peter1138 <peter1138@openttd.org>
parents: 6420
diff changeset
664 if (sprite == 0) sprite = SPR_CARGO_GOODS;
6364
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
665
8762
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
666 return sprite;
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
667 }
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
668
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
669 /**
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
670 * Draws icons of waiting cargo in the StationView window
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
671 *
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
672 * @param i type of cargo
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
673 * @param waiting number of waiting units
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
674 * @param x x on-screen coordinate where to start with drawing icons
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
675 * @param y y coordinate
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
676 */
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
677 static void DrawCargoIcons(CargoID i, uint waiting, int x, int y, uint width)
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
678 {
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
679 uint num = min((waiting + 5) / 10, width / 10); // maximum is width / 10 icons so it won't overflow
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
680 if (num == 0) return;
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
681
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
682 SpriteID sprite = GetCargoSprite(i);
dcc2194ac748 (svn r12458) -Codechange: split acquiring the sprite ID for cargos from the actual drawing of them.
rubidium <rubidium@openttd.org>
parents: 8750
diff changeset
683
6364
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
684 do {
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
685 DrawSprite(sprite, PAL_NONE, x, y);
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
686 x += 10;
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
687 } while (--num);
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
688 }
12ef3186e753 (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 <peter1138@openttd.org>
parents: 6350
diff changeset
689
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
690 struct CargoData {
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
691 CargoID cargo;
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
692 StationID source;
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
693 uint count;
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
694
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
695 CargoData(CargoID cargo, StationID source, uint count) :
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
696 cargo(cargo),
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
697 source(source),
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
698 count(count)
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
699 { }
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
700 };
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
701
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
702 typedef std::list<CargoData> CargoDataList;
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
703
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
704 /**
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
705 * The StationView window
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
706 */
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
707 struct StationViewWindow : public Window {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
708 uint32 cargo; ///< Bitmask of cargo types to expand
9391
2903275601be (svn r13302) -Fix (r13301): GCC doesn't necessarily like what MSVC likes...
rubidium <rubidium@openttd.org>
parents: 9390
diff changeset
709 uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
710
9203
375bae14ff71 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium <rubidium@openttd.org>
parents: 9191
diff changeset
711 StationViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
712 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
713 Owner owner = GetStation(window_number)->owner;
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
714 if (owner != OWNER_NONE) this->caption_color = owner;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
715 this->vscroll.cap = 5;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
716 this->resize.step_height = 10;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
717
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
718 this->FindWindowPlacementAndResize(desc);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
719 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
720
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
721 ~StationViewWindow()
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
722 {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
723 WindowNumber wno =
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
724 (this->window_number << 16) | VLW_STATION_LIST | GetStation(this->window_number)->owner;
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
725
10528
faf41b99dbc3 (svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
726 DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11), false);
faf41b99dbc3 (svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
727 DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11), false);
faf41b99dbc3 (svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
728 DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11), false);
faf41b99dbc3 (svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
729 DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11), false);
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
730 }
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
731
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
732 virtual void OnPaint()
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
733 {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
734 StationID station_id = this->window_number;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
735 const Station *st = GetStation(station_id);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
736 CargoDataList cargolist;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
737 uint32 transfers = 0;
8750
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
738
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
739 /* count types of cargos waiting in station */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
740 for (CargoID i = 0; i < NUM_CARGO; i++) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
741 if (st->goods[i].cargo.Empty()) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
742 this->cargo_rows[i] = 0;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
743 } else {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
744 /* Add an entry for total amount of cargo of this type waiting. */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
745 cargolist.push_back(CargoData(i, INVALID_STATION, st->goods[i].cargo.Count()));
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
746
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
747 /* Set the row for this cargo entry for the expand/hide button */
9391
2903275601be (svn r13302) -Fix (r13301): GCC doesn't necessarily like what MSVC likes...
rubidium <rubidium@openttd.org>
parents: 9390
diff changeset
748 this->cargo_rows[i] = (uint16)cargolist.size();
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
749
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
750 /* Add an entry for each distinct cargo source. */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
751 const CargoList::List *packets = st->goods[i].cargo.Packets();
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
752 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
753 const CargoPacket *cp = *it;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
754 if (cp->source != station_id) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
755 bool added = false;
8750
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
756
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
757 /* Enable the expand/hide button for this cargo type */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
758 SetBit(transfers, i);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
759
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
760 /* Don't add cargo lines if not expanded */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
761 if (!HasBit(this->cargo, i)) break;
8750
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
762
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
763 /* Check if we already have this source in the list */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
764 for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
765 CargoData *cd = &(*jt);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
766 if (cd->cargo == i && cd->source == cp->source) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
767 cd->count += cp->count;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
768 added = true;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
769 break;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
770 }
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
771 }
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
772
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
773 if (!added) cargolist.push_back(CargoData(i, cp->source, cp->count));
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
774 }
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
775 }
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
776 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
777 }
9390
45c874394355 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium <rubidium@openttd.org>
parents: 9389
diff changeset
778 SetVScrollCount(this, (int)cargolist.size() + 1); // update scrollbar
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
779
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
780 /* disable some buttons */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10180
diff changeset
781 this->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_company);
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
782 this->SetWidgetDisabledState(SVW_TRAINS, !(st->facilities & FACIL_TRAIN));
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
783 this->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
784 this->SetWidgetDisabledState(SVW_PLANES, !(st->facilities & FACIL_AIRPORT));
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
785 this->SetWidgetDisabledState(SVW_SHIPS, !(st->facilities & FACIL_DOCK));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
786
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
787 SetDParam(0, st->index);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
788 SetDParam(1, st->facilities);
9273
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9214
diff changeset
789 this->DrawWidgets();
8964
ae064b8e200b (svn r12756) -Cleanup: variable scope and coding style in station*
smatz <smatz@openttd.org>
parents: 8857
diff changeset
790
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
791 int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
792 int y = 15;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
793 int pos = this->vscroll.pos; ///< = this->vscroll.pos
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
794
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
795 uint width = this->widget[SVW_WAITING].right - this->widget[SVW_WAITING].left - 4;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
796 int maxrows = this->vscroll.cap;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
797
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
798 StringID str;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
799
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
800 if (--pos < 0) {
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
801 str = STR_00D0_NOTHING;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
802 for (CargoID i = 0; i < NUM_CARGO; i++) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
803 if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
804 }
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
805 SetDParam(0, str);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
806 DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING);
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
807 y += 10;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
808 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
809
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
810 for (CargoDataList::const_iterator it = cargolist.begin(); it != cargolist.end() && pos > -maxrows; ++it) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
811 if (--pos < 0) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
812 const CargoData *cd = &(*it);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
813 if (cd->source == INVALID_STATION) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
814 /* Heading */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
815 DrawCargoIcons(cd->cargo, cd->count, x, y, width);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
816 SetDParam(0, cd->cargo);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
817 SetDParam(1, cd->count);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
818 if (HasBit(transfers, cd->cargo)) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
819 /* This cargo has transfers waiting so show the expand or shrink 'button' */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
820 const char *sym = HasBit(this->cargo, cd->cargo) ? "-" : "+";
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
821 DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
822 DoDrawString(sym, x + width - 6, y, TC_YELLOW);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
823 } else {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
824 DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
825 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
826 } else {
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
827 SetDParam(0, cd->cargo);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
828 SetDParam(1, cd->count);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
829 SetDParam(2, cd->source);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
830 DrawStringRightAlignedTruncated(x + width, y, STR_EN_ROUTE_FROM, TC_FROMSTRING, width);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
831 }
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
832
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
833 y += 10;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
834 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
835 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
836
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
837 if (this->widget[SVW_ACCEPTS].data == STR_3032_RATINGS) { // small window with list of accepted cargo
9648
b53049484e44 (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium <rubidium@openttd.org>
parents: 9580
diff changeset
838 char string[512];
b53049484e44 (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium <rubidium@openttd.org>
parents: 9580
diff changeset
839 char *b = string;
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
840 bool first = true;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
841
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
842 b = InlineString(b, STR_000C_ACCEPTS);
8041
085c454f158b (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz <smatz@openttd.org>
parents: 8040
diff changeset
843
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
844 for (CargoID i = 0; i < NUM_CARGO; i++) {
9648
b53049484e44 (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium <rubidium@openttd.org>
parents: 9580
diff changeset
845 if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
846 if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
847 if (first) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
848 first = false;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
849 } else {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
850 /* Add a comma if this is not the first item */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
851 *b++ = ',';
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
852 *b++ = ' ';
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
853 }
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
854 b = InlineString(b, GetCargo(i)->name);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
855 }
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
856 }
8041
085c454f158b (svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
smatz <smatz@openttd.org>
parents: 8040
diff changeset
857
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
858 /* If first is still true then no cargo is accepted */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
859 if (first) b = InlineString(b, STR_00D0_NOTHING);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
860
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
861 *b = '\0';
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
862
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
863 /* Make sure we detect any buffer overflow */
9648
b53049484e44 (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium <rubidium@openttd.org>
parents: 9580
diff changeset
864 assert(b < endof(string));
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
865
9648
b53049484e44 (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium <rubidium@openttd.org>
parents: 9580
diff changeset
866 SetDParamStr(0, string);
b53049484e44 (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium <rubidium@openttd.org>
parents: 9580
diff changeset
867 DrawStringMultiLine(2, this->widget[SVW_ACCEPTLIST].top + 1, STR_JUST_RAW_STRING, this->widget[SVW_ACCEPTLIST].right - this->widget[SVW_ACCEPTLIST].left);
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
868 } else { // extended window with list of cargo ratings
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
869 y = this->widget[SVW_RATINGLIST].top + 1;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
870
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
871 DrawString(2, y, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
872 y += 10;
6297
e7e15e4d1367 (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 <peter1138@openttd.org>
parents: 6285
diff changeset
873
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
874 for (CargoID i = 0; i < NUM_CARGO; i++) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
875 const CargoSpec *cs = GetCargo(i);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
876 if (!cs->IsValid()) continue;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
877
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
878 const GoodsEntry *ge = &st->goods[i];
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
879 if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
6297
e7e15e4d1367 (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 <peter1138@openttd.org>
parents: 6285
diff changeset
880
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
881 SetDParam(0, cs->name);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
882 SetDParam(2, ge->rating * 101 >> 8);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
883 SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
884 DrawString(8, y, STR_303D, TC_FROMSTRING);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
885 y += 10;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
886 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
887 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
888 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
889
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
890 void HandleCargoWaitingClick(int row)
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
891 {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
892 if (row == 0) return;
8750
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
893
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
894 for (CargoID c = 0; c < NUM_CARGO; c++) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
895 if (this->cargo_rows[c] == row) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
896 ToggleBit(this->cargo, c);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
897 this->InvalidateWidget(SVW_WAITING);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
898 break;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
899 }
8750
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
900 }
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
901 }
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
902
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
903 virtual void OnClick(Point pt, int widget)
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
904 {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
905 switch (widget) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
906 case SVW_WAITING:
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
907 this->HandleCargoWaitingClick((pt.y - this->widget[SVW_WAITING].top) / 10 + this->vscroll.pos);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
908 break;
8750
495247050dad (svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
peter1138 <peter1138@openttd.org>
parents: 8719
diff changeset
909
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
910 case SVW_LOCATION:
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
911 if (_ctrl_pressed) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
912 ShowExtraViewPortWindow(GetStation(this->window_number)->xy);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
913 } else {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
914 ScrollMainWindowToTile(GetStation(this->window_number)->xy);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
915 }
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
916 break;
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
917
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
918 case SVW_RATINGS:
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
919 this->SetDirty();
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
920
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
921 if (this->widget[SVW_RATINGS].data == STR_3032_RATINGS) {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
922 /* Switch to ratings view */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
923 this->widget[SVW_RATINGS].data = STR_3033_ACCEPTS;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
924 this->widget[SVW_RATINGS].tooltips = STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
925 ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, 100);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
926 } else {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
927 /* Switch to accepts view */
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
928 this->widget[SVW_RATINGS].data = STR_3032_RATINGS;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
929 this->widget[SVW_RATINGS].tooltips = STR_3054_SHOW_STATION_RATINGS;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
930 ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, -100);
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
931 }
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
932
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
933 this->SetDirty();
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
934 break;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
935
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
936 case SVW_RENAME:
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
937 SetDParam(0, this->window_number);
10148
81642658c8be (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents: 10145
diff changeset
938 ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
939 break;
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
940
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
941 case SVW_TRAINS: { // Show a list of scheduled trains to this station
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
942 const Station *st = GetStation(this->window_number);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
943 ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)this->window_number);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
944 break;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
945 }
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
946
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
947 case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
948 const Station *st = GetStation(this->window_number);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
949 ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)this->window_number);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
950 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
951 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
952
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
953 case SVW_PLANES: { // Show a list of scheduled aircraft to this station
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
954 const Station *st = GetStation(this->window_number);
10996
ce54bfd52120 (svn r15336) -Fix: do not use _current_company in the GUI as there are no guarantees that _current_company is the same as _local_company.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
955 /* Since oilrigs have no owners, show the scheduled aircraft of local company */
ce54bfd52120 (svn r15336) -Fix: do not use _current_company in the GUI as there are no guarantees that _current_company is the same as _local_company.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
956 Owner owner = (st->owner == OWNER_NONE) ? _local_company : st->owner;
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
957 ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)this->window_number);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
958 break;
6202
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
959 }
eb0fdb88a922 (svn r8988) -Fix: Indenting, variable scope, variable type and minor duffage
peter1138 <peter1138@openttd.org>
parents: 6122
diff changeset
960
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
961 case SVW_SHIPS: { // Show a list of scheduled ships to this station
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
962 const Station *st = GetStation(this->window_number);
10996
ce54bfd52120 (svn r15336) -Fix: do not use _current_company in the GUI as there are no guarantees that _current_company is the same as _local_company.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
963 /* Since oilrigs/bouys have no owners, show the scheduled ships of local company */
ce54bfd52120 (svn r15336) -Fix: do not use _current_company in the GUI as there are no guarantees that _current_company is the same as _local_company.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
964 Owner owner = (st->owner == OWNER_NONE) ? _local_company : st->owner;
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
965 ShowVehicleListWindow(owner, VEH_SHIP, (StationID)this->window_number);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
966 break;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
967 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
968 }
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
969 }
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
970
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
971 virtual void OnQueryTextFinished(char *str)
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
972 {
10148
81642658c8be (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents: 10145
diff changeset
973 if (str == NULL) return;
81642658c8be (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents: 10145
diff changeset
974
10499
45ca88a8de7d (svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents: 10488
diff changeset
975 DoCommandP(0, this->window_number, 0, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION), NULL, str);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
976 }
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
977
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
978 virtual void OnResize(Point new_size, Point delta)
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
979 {
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
980 if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME);
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
981 this->vscroll.cap += delta.y / (int)this->resize.step_height;
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
982 }
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
983 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
984
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
985
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
986 static const WindowDesc _station_view_desc = {
7341
549c757023fc (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium <rubidium@openttd.org>
parents: 7058
diff changeset
987 WDP_AUTO, WDP_AUTO, 249, 110, 249, 110,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5745
diff changeset
988 WC_STATION_VIEW, WC_NONE,
8420
370ea805f591 (svn r11990) -Codechange: Show all cargo sources (en-route from) in the station view
peter1138 <peter1138@openttd.org>
parents: 8349
diff changeset
989 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
990 _station_view_widgets,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
991 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
992
8016
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
993 /**
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
994 * Opens StationViewWindow for given station
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
995 *
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
996 * @param station station which window should be opened
f60addd19e1a (svn r11576) -Codechange: enumerize and comment station GUI
smatz <smatz@openttd.org>
parents: 8005
diff changeset
997 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
998 void ShowStationViewWindow(StationID station)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
999 {
9185
227f376591eb (svn r13048) -Codechange: make a class of the StationViewWindow.
rubidium <rubidium@openttd.org>
parents: 9164
diff changeset
1000 AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1001 }
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1002
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1003 static SmallVector<StationID, 8> _stations_nearby_list;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1004 static SmallMap<TileIndex, StationID, 8> _deleted_stations_nearby;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1005
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1006 /** Context for FindStationsNearby */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1007 struct FindNearbyStationContext {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1008 TileIndex tile; ///< Base tile of station to be built
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1009 uint w; ///< Width of station to be built
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1010 uint h; ///< Height of station to be built
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1011 };
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1012
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1013 /**
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1014 * Add station on this tile to _stations_nearby_list if it's fully within the
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1015 * station spread.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1016 * @param tile Tile just being checked
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1017 * @param user_data Pointer to FindNearbyStationContext context
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1018 */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1019 static bool AddNearbyStation(TileIndex tile, void *user_data)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1020 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1021 FindNearbyStationContext *ctx = (FindNearbyStationContext *)user_data;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1022
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1023 /* First check if there was a deleted station here */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1024 SmallPair<TileIndex, StationID> *dst = _deleted_stations_nearby.Find(tile);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1025 if (dst != _deleted_stations_nearby.End()) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1026 _stations_nearby_list.Include(dst->second);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1027 return false;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1028 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1029
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1030 /* Check if own station and if we stay within station spread */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1031 if (!IsTileType(tile, MP_STATION)) return false;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1032
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1033 StationID sid = GetStationIndex(tile);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1034 Station *st = GetStation(sid);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1035 if (st->owner != _local_company || _stations_nearby_list.Contains(sid)) return false;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1036
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1037 if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST)) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1038 *_stations_nearby_list.Append() = sid;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1039 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1040
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1041 return false; // We want to include *all* nearby stations
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1042 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1043
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1044 /**
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1045 * Circulate around the to-be-built station to find stations we could join.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1046 * Make sure that only stations are returned where joining wouldn't exceed
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1047 * station spread and are our own station.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1048 * @param tile Base tile of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1049 * @param w Width of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1050 * @param h Height of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1051 * @param distant_join Search for adjacent stations (false) or stations fully
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1052 * within station spread
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1053 **/
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1054 static const Station *FindStationsNearby(TileIndex tile, int w, int h, bool distant_join)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1055 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1056 FindNearbyStationContext ctx;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1057 ctx.tile = tile;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1058 ctx.w = w;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1059 ctx.h = h;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1060
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1061 _stations_nearby_list.Clear();
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1062 _deleted_stations_nearby.Clear();
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1063
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1064 /* Check the inside, to return, if we sit on another station */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1065 BEGIN_TILE_LOOP(t, w, h, tile)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1066 if (t < MapSize() && IsTileType(t, MP_STATION)) return GetStationByTile(t);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1067 END_TILE_LOOP(t, w, h, tile)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1068
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1069 /* Look for deleted stations */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1070 const Station *st;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1071 FOR_ALL_STATIONS(st) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1072 if (st->facilities == 0 && st->owner == _local_company) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1073 /* Include only within station spread (yes, it is strictly less than) */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1074 if (max(DistanceMax(tile, st->xy), DistanceMax(TILE_ADDXY(tile, w - 1, h - 1), st->xy)) < _settings_game.station.station_spread) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1075 _deleted_stations_nearby.Insert(st->xy, st->index);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1076
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1077 /* Add the station when it's within where we're going to build */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1078 if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1079 IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1080 AddNearbyStation(st->xy, &ctx);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1081 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1082 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1083 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1084 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1085
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1086 /* Only search tiles where we have a chance to stay within the station spread.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1087 * The complete check needs to be done in the callback as we don't know the
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1088 * extent of the found station, yet. */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1089 if (distant_join && min(w, h) >= _settings_game.station.station_spread) return NULL;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1090 uint max_dist = distant_join ? _settings_game.station.station_spread - min(w, h) : 1;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1091
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1092 tile = TILE_ADD(ctx.tile, TileOffsByDir(DIR_N));
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1093 CircularTileSearch(&tile, max_dist, w, h, AddNearbyStation, &ctx);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1094
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1095 return NULL;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1096 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1097
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1098 enum JoinStationWidgets {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1099 JSW_WIDGET_CLOSEBOX = 0,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1100 JSW_WIDGET_CAPTION,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1101 JSW_PANEL,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1102 JSW_SCROLLBAR,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1103 JSW_EMPTY,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1104 JSW_RESIZEBOX,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1105 };
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1106
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1107 static const Widget _select_station_widgets[] = {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1108 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1109 { WWT_CAPTION, RESIZE_RIGHT, COLOUR_DARK_GREEN, 11, 199, 0, 13, STR_SELECT_STATION_TO_JOIN, STR_018C_WINDOW_TITLE_DRAG_THIS},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1110 { WWT_PANEL, RESIZE_RB, COLOUR_DARK_GREEN, 0, 187, 14, 79, 0x0, STR_NULL},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1111 { WWT_SCROLLBAR, RESIZE_LRB, COLOUR_DARK_GREEN, 188, 199, 14, 79, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1112 { WWT_PANEL, RESIZE_RTB, COLOUR_DARK_GREEN, 0, 187, 80, 91, 0x0, STR_NULL},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1113 { WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_DARK_GREEN, 188, 199, 80, 91, 0x0, STR_RESIZE_BUTTON},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1114 { WIDGETS_END},
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1115 };
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1116
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1117 struct SelectStationWindow : Window {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1118 CommandContainer select_station_cmd; ///< Command to build new station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1119 TileIndex tile; ///< Base tile of new station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1120 int size_x; ///< Size in x direction of new station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1121 int size_y; ///< Size in y direction of new station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1122
10739
b7d66e786eff (svn r15072) -Fix (r14919): Distant-join search-area was determined inconsistently.
frosch <frosch@openttd.org>
parents: 10736
diff changeset
1123 SelectStationWindow(const WindowDesc *desc, CommandContainer cmd, int w, int h) :
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1124 Window(desc, 0),
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1125 select_station_cmd(cmd),
10739
b7d66e786eff (svn r15072) -Fix (r14919): Distant-join search-area was determined inconsistently.
frosch <frosch@openttd.org>
parents: 10736
diff changeset
1126 tile(cmd.tile),
b7d66e786eff (svn r15072) -Fix (r14919): Distant-join search-area was determined inconsistently.
frosch <frosch@openttd.org>
parents: 10736
diff changeset
1127 size_x(w),
b7d66e786eff (svn r15072) -Fix (r14919): Distant-join search-area was determined inconsistently.
frosch <frosch@openttd.org>
parents: 10736
diff changeset
1128 size_y(h)
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1129 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1130 this->vscroll.cap = 6;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1131 this->resize.step_height = 10;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1132
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1133 FindStationsNearby(this->tile, this->size_x, this->size_y, true);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1134
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1135 this->FindWindowPlacementAndResize(desc);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1136 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1137
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1138 virtual void OnPaint()
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1139 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1140 SetVScrollCount(this, _stations_nearby_list.Length() + 1);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1141
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1142 this->DrawWidgets();
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1143
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1144 uint y = 17;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1145 if (this->vscroll.pos == 0) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1146 DrawStringTruncated(3, y, STR_CREATE_SPLITTED_STATION, TC_FROMSTRING, this->widget[JSW_PANEL].right - 5);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1147 y += 10;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1148 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1149
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1150 for (uint i = max<uint>(1, this->vscroll.pos); i <= _stations_nearby_list.Length(); ++i, y += 10) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1151 /* Don't draw anything if it extends past the end of the window. */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1152 if (i - this->vscroll.pos >= this->vscroll.cap) break;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1153
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1154 const Station *st = GetStation(_stations_nearby_list[i - 1]);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1155 SetDParam(0, st->index);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1156 SetDParam(1, st->facilities);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1157 DrawStringTruncated(3, y, STR_3049_0, TC_FROMSTRING, this->widget[JSW_PANEL].right - 5);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1158 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1159 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1160
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1161 virtual void OnClick(Point pt, int widget)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1162 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1163 if (widget != JSW_PANEL) return;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1164
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1165 uint32 st_index = (pt.y - 16) / 10 + this->vscroll.pos;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1166 bool distant_join = (st_index > 0);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1167 if (distant_join) st_index--;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1168
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1169 if (distant_join && st_index >= _stations_nearby_list.Length()) return;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1170
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1171 /* Insert station to be joined into stored command */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1172 SB(this->select_station_cmd.p2, 16, 16,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1173 (distant_join ? _stations_nearby_list[st_index] : INVALID_STATION));
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1174
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1175 /* Execute stored Command */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1176 DoCommandP(&this->select_station_cmd);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1177
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1178 /* Close Window; this might cause double frees! */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1179 DeleteWindowById(WC_SELECT_STATION, 0);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1180 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1181
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1182 virtual void OnTick()
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1183 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1184 if (_thd.dirty & 2) {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1185 _thd.dirty &= ~2;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1186 this->SetDirty();
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1187 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1188 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1189
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1190 virtual void OnResize(Point new_size, Point delta)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1191 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1192 this->vscroll.cap = (this->widget[JSW_PANEL].bottom - this->widget[JSW_PANEL].top) / 10;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1193 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1194
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1195 virtual void OnInvalidateData(int data)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1196 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1197 FindStationsNearby(this->tile, this->size_x, this->size_y, true);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1198 this->SetDirty();
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1199 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1200 };
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1201
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1202 static const WindowDesc _select_station_desc = {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1203 WDP_AUTO, WDP_AUTO, 200, 92, 200, 182,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1204 WC_SELECT_STATION, WC_NONE,
10998
a1d256bf72e0 (svn r15338) -Fix [FS#2598]: close all construction related windows whenever changing company.
rubidium <rubidium@openttd.org>
parents: 10996
diff changeset
1205 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE | WDF_CONSTRUCTION,
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1206 _select_station_widgets,
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1207 };
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1208
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1209
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1210 /**
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1211 * Check whether we need to show the station selection window.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1212 * @param cmd Command to build the station.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1213 * @param w Width of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1214 * @param h Height of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1215 * @return whether we need to show the station selection window.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1216 */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1217 static bool StationJoinerNeeded(CommandContainer cmd, int w, int h)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1218 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1219 /* Only show selection if distant join is enabled in the settings */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1220 if (!_settings_game.station.distant_join_stations) return false;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1221
10732
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1222 /* If a window is already opened and we didn't ctrl-click,
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1223 * return true (i.e. just flash the old window) */
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1224 Window *selection_window = FindWindowById(WC_SELECT_STATION, 0);
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1225 if (selection_window != NULL) {
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1226 if (!_ctrl_pressed) return true;
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1227
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1228 /* Abort current distant-join and start new one */
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1229 delete selection_window;
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1230 UpdateTileSelection();
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1231 }
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1232
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1233 /* only show the popup, if we press ctrl */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1234 if (!_ctrl_pressed) return false;
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1235
10732
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1236 /* Now check if we could build there */
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1237 if (CmdFailed(DoCommand(&cmd, CommandFlagsToDCFlags(GetCommandFlags(cmd.cmd))))) return false;
cb1b114429c8 (svn r15065) -Change (r14919): Allow to select a new station location by ctrl-clicking while distant-join window is open. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10693
diff changeset
1238
10736
6f72f80df252 (svn r15069) -Change (r14919): Make distant-join less intelligent but more transparent to the user by always showing the selection window, even if there is only one option to choose from. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10732
diff changeset
1239 /* Test for adjacent station or station below selection.
6f72f80df252 (svn r15069) -Change (r14919): Make distant-join less intelligent but more transparent to the user by always showing the selection window, even if there is only one option to choose from. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10732
diff changeset
1240 * If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
6f72f80df252 (svn r15069) -Change (r14919): Make distant-join less intelligent but more transparent to the user by always showing the selection window, even if there is only one option to choose from. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10732
diff changeset
1241 * but join the other station immediatelly. */
6f72f80df252 (svn r15069) -Change (r14919): Make distant-join less intelligent but more transparent to the user by always showing the selection window, even if there is only one option to choose from. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10732
diff changeset
1242 const Station *st = FindStationsNearby(cmd.tile, w, h, false);
6f72f80df252 (svn r15069) -Change (r14919): Make distant-join less intelligent but more transparent to the user by always showing the selection window, even if there is only one option to choose from. (PhilSophus)
frosch <frosch@openttd.org>
parents: 10732
diff changeset
1243 return st == NULL && (_settings_game.station.adjacent_stations || _stations_nearby_list.Length() == 0);
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1244 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1245
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1246 /**
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1247 * Show the station selection window when needed. If not, build the station.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1248 * @param cmd Command to build the station.
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1249 * @param w Width of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1250 * @param h Height of the to-be-built station
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1251 */
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1252 void ShowSelectStationIfNeeded(CommandContainer cmd, int w, int h)
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1253 {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1254 if (StationJoinerNeeded(cmd, w, h)) {
11072
19fd43d5975d (svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
rubidium <rubidium@openttd.org>
parents: 10998
diff changeset
1255 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1256 if (BringWindowToFrontById(WC_SELECT_STATION, 0)) return;
10739
b7d66e786eff (svn r15072) -Fix (r14919): Distant-join search-area was determined inconsistently.
frosch <frosch@openttd.org>
parents: 10736
diff changeset
1257 new SelectStationWindow(&_select_station_desc, cmd, w, h);
10626
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1258 } else {
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1259 DoCommandP(&cmd);
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1260 }
3189a053f43a (svn r14919) -Feature: distant joining of stations (Frostregen and PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10565
diff changeset
1261 }