src/autoreplace_gui.cpp
author rubidium
Tue, 18 Dec 2007 20:58:12 +0000
changeset 8103 cf92483a0abf
parent 8082 63240e1bd6cc
child 8106 e6790dd9e750
permissions -rw-r--r--
(svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6117
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 5955
diff changeset
     3
/** @file autoreplace_gui.cpp */
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 5955
diff changeset
     4
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1859
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     7
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     8
#include "functions.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1309
diff changeset
     9
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 505
diff changeset
    10
#include "table/strings.h"
7266
b16e67e992b4 (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7258
diff changeset
    11
#include "strings.h"
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    12
#include "window.h"
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    13
#include "gui.h"
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    14
#include "command.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    15
#include "variables.h"
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    16
#include "vehicle_gui.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2951
diff changeset
    17
#include "newgrf_engine.h"
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
    18
#include "group.h"
8103
cf92483a0abf (svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents: 8082
diff changeset
    19
#include "rail.h"
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    20
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    21
5809
f6bb84b5d6fc (svn r8371) -Codechange: [autoreplace GUI] moved the autoreplace GUI to a file of it's own
bjarni
parents: 5808
diff changeset
    22
static RailType _railtype_selected_in_replace_gui;
505
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    23
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    24
static bool _rebuild_left_list;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    25
static bool _rebuild_right_list;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    26
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    27
static const StringID _rail_types_list[] = {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    28
	STR_RAIL_VEHICLES,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    29
	STR_ELRAIL_VEHICLES,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    30
	STR_MONORAIL_VEHICLES,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    31
	STR_MAGLEV_VEHICLES,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    32
	INVALID_STRING_ID
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    33
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    34
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    35
/* General Vehicle GUI based procedures that are independent of vehicle types */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
    36
void InitializeVehiclesGuiList()
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    37
{
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    38
	_railtype_selected_in_replace_gui = RAILTYPE_RAIL;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    39
}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    40
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    41
/** Rebuild the left autoreplace list if an engine is removed or added
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    42
 * @param e Engine to check if it is removed or added
7096
9b231813f232 (svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents: 7059
diff changeset
    43
 * @param id_g The group the engine belongs to
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    44
 *  Note: this function only works if it is called either
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    45
 *   - when a new vehicle is build, but before it's counted in num_engines
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    46
 *   - when a vehicle is deleted and after it's substracted from num_engines
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    47
 *   - when not changing the count (used when changing replace orders)
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    48
 */
7096
9b231813f232 (svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents: 7059
diff changeset
    49
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    50
{
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    51
	Player *p = GetPlayer(_local_player);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    52
	byte type = GetEngine(e)->type;
7481
7d8d1dd8da4c (svn r10992) -Fix [FS#1132]: huge amount of vehicles in the "ungrouped" group. Patch by frosch.
rubidium
parents: 7341
diff changeset
    53
	uint num_engines = GetGroupNumEngines(_local_player, id_g, e);
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    54
7096
9b231813f232 (svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents: 7059
diff changeset
    55
	if (num_engines == 0 || p->num_engines[e] == 0) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    56
		/* We don't have any of this engine type.
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    57
		 * Either we just sold the last one, we build a new one or we stopped replacing it.
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    58
		 * In all cases, we need to update the left list */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    59
		_rebuild_left_list = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    60
	} else {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    61
		_rebuild_left_list = false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    62
	}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    63
	_rebuild_right_list = false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    64
	InvalidateWindowData(WC_REPLACE_VEHICLE, type);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    65
}
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
    66
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    67
/** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    68
 * @param type The type of engine
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    69
 */
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6398
diff changeset
    70
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    71
{
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    72
	_rebuild_left_list = false; // left list is only for the vehicles the player owns and is not related to being buildable
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    73
	_rebuild_right_list = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    74
	InvalidateWindowData(WC_REPLACE_VEHICLE, type); // Update the autoreplace window
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    75
	InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    76
}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    77
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    78
/** Get the default cargo type for an engine
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    79
 * @param engine the EngineID to get the cargo for
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    80
 * @return the cargo type carried by the engine (CT_INVALID if engine got no cargo capacity)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    81
 */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    82
static CargoID EngineCargo(EngineID engine)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    83
{
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    84
	if (engine == INVALID_ENGINE) return CT_INVALID; // surely INVALID_ENGINE can't carry anything but CT_INVALID
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    85
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    86
	switch (GetEngine(engine)->type) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    87
		default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
    88
		case VEH_TRAIN:
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    89
			if (RailVehInfo(engine)->capacity == 0) return CT_INVALID; // no capacity -> can't carry cargo
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    90
			return RailVehInfo(engine)->cargo_type;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
    91
		case VEH_ROAD:       return RoadVehInfo(engine)->cargo_type;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
    92
		case VEH_SHIP:       return ShipVehInfo(engine)->cargo_type;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
    93
		case VEH_AIRCRAFT:   return CT_PASSENGERS; // all planes are build with passengers by default
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    94
	}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    95
}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    96
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    97
/** Figure out if an engine should be added to a list
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    98
 * @param e The EngineID
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
    99
 * @param draw_left If true, then the left list is drawn (the engines specific to the railtype you selected)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   100
 * @param show_engines if truem then locomotives are drawn, else wagons (never both)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   101
 * @return true if the engine should be in the list (based on this check)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   102
 */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   103
static bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   104
{
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   105
	const RailVehicleInfo *rvi = RailVehInfo(e);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   106
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   107
	/* Ensure that the wagon/engine selection fits the engine. */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   108
	if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   109
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   110
	if (draw_left && show_engines) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   111
		/* Ensure that the railtype is specific to the selected one */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   112
		if (rvi->railtype != _railtype_selected_in_replace_gui) return false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   113
	} else {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   114
		/* Ensure that it's a compatible railtype to the selected one (like electric <-> diesel)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   115
		 * The vehicle do not have to have power on the railtype in question, only able to drive (pulled if needed) */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   116
		if (!IsCompatibleRail(rvi->railtype, _railtype_selected_in_replace_gui)) return false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   117
	}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   118
	return true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   119
}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   120
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   121
/** Figure out if two engines got at least one type of cargo in common (refitting if needed)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   122
 * @param engine_a one of the EngineIDs
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   123
 * @param engine_b the other EngineID
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   124
 * @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   125
 */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   126
static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   127
{
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   128
	CargoID a = EngineCargo(engine_a);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   129
	CargoID b = EngineCargo(engine_b);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   130
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   131
	 /* we should always be able to refit to/from locomotives without capacity
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   132
	  * Because of that, CT_INVALID shoudl always return true */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   133
	if (a == CT_INVALID || b == CT_INVALID || a == b) return true; // they carry no ro the same type by default
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   134
	if (EngInfo(engine_a)->refit_mask & EngInfo(engine_b)->refit_mask) return true; // both can refit to the same
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   135
	if (CanRefitTo(engine_a, b) || CanRefitTo(engine_b, a)) return true; // one can refit to what the other one carries
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   136
	return false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   137
}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   138
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   139
/** Generate a list
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   140
 * @param w Window, that contains the list
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   141
 * @param draw_left true if generating the left list, otherwise false
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   142
 */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   143
static void GenerateReplaceVehList(Window *w, bool draw_left)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   144
{
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   145
	EngineID e;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   146
	EngineID selected_engine = INVALID_ENGINE;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   147
	byte type = w->window_number;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   148
	byte i = draw_left ? 0 : 1;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   149
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   150
	EngineList *list = &WP(w, replaceveh_d).list[i];
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   151
	EngList_RemoveAll(list);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   152
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   153
	FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   154
		if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   155
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   156
		if (draw_left) {
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   157
			const GroupID selected_group = WP(w, replaceveh_d).sel_group;
7481
7d8d1dd8da4c (svn r10992) -Fix [FS#1132]: huge amount of vehicles in the "ungrouped" group. Patch by frosch.
rubidium
parents: 7341
diff changeset
   158
			const uint num_engines = GetGroupNumEngines(_local_player, selected_group, e);
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   159
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   160
			/* Skip drawing the engines we don't have any of and haven't set for replacement */
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   161
			if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   162
		} else {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   163
			/* This is for engines we can replace to and they should depend on what we selected to replace from */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   164
			if (!IsEngineBuildable(e, type, _local_player)) continue; // we need to be able to build the engine
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   165
			if (!EnginesGotCargoInCommon(e, WP(w, replaceveh_d).sel_engine[0])) continue; // the engines needs to be able to carry the same cargo
6687
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6643
diff changeset
   166
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6643
diff changeset
   167
			/* Road vehicles can't be replaced by trams and vice-versa */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7824
diff changeset
   168
			if (type == VEH_ROAD && HasBit(EngInfo(WP(w, replaceveh_d).sel_engine[0])->misc_flags, EF_ROAD_TRAM) != HasBit(EngInfo(e)->misc_flags, EF_ROAD_TRAM)) continue;
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   169
			if (e == WP(w, replaceveh_d).sel_engine[0]) continue; // we can't replace an engine into itself (that would be autorenew)
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   170
		}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   171
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   172
		EngList_Add(list, e);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   173
		if (e == WP(w, replaceveh_d).sel_engine[i]) selected_engine = e; // The selected engine is still in the list
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   174
	}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   175
	WP(w, replaceveh_d).sel_engine[i] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   176
}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   177
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   178
/** Generate the lists
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   179
 * @param w Window containing the lists
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   180
 */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   181
static void GenerateLists(Window *w)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   182
{
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   183
	EngineID e = WP(w, replaceveh_d).sel_engine[0];
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   184
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   185
	if (WP(w, replaceveh_d).update_left == true) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   186
		/* We need to rebuild the left list */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   187
		GenerateReplaceVehList(w, true);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   188
		SetVScrollCount(w, EngList_Count(&WP(w, replaceveh_d).list[0]));
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   189
		if (WP(w, replaceveh_d).init_lists && WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE && EngList_Count(&WP(w, replaceveh_d).list[0]) != 0) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   190
			WP(w, replaceveh_d).sel_engine[0] = WP(w, replaceveh_d).list[0][0];
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   191
		}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   192
	}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   193
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   194
	if (WP(w, replaceveh_d).update_right || e != WP(w, replaceveh_d).sel_engine[0]) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   195
		/* Either we got a request to rebuild the right list or the left list selected a different engine */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   196
		if (WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   197
			/* Always empty the right list when nothing is selected in the left list */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   198
			EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   199
			WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   200
		} else {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   201
			GenerateReplaceVehList(w, false);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   202
			SetVScroll2Count(w, EngList_Count(&WP(w, replaceveh_d).list[1]));
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   203
			if (WP(w, replaceveh_d).init_lists && WP(w, replaceveh_d).sel_engine[1] == INVALID_ENGINE && EngList_Count(&WP(w, replaceveh_d).list[1]) != 0) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   204
				WP(w, replaceveh_d).sel_engine[1] = WP(w, replaceveh_d).list[1][0];
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   205
			}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   206
		}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   207
	}
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   208
	/* Reset the flags about needed updates */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   209
	WP(w, replaceveh_d).update_left  = false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   210
	WP(w, replaceveh_d).update_right = false;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   211
	WP(w, replaceveh_d).init_lists   = false;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   212
}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   213
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   214
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   215
void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   216
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   217
static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   218
{
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   219
	/* Strings for the pulldown menu */
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   220
	static const StringID _vehicle_type_names[] = {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   221
		STR_019F_TRAIN,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   222
		STR_019C_ROAD_VEHICLE,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   223
		STR_019E_SHIP,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   224
		STR_019D_AIRCRAFT
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   225
	};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   226
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   227
	switch (e->event) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   228
		case WE_CREATE:
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   229
			WP(w, replaceveh_d).wagon_btnstate = true; // start with locomotives (all other vehicles will not read this bool)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   230
			EngList_Create(&WP(w, replaceveh_d).list[0]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   231
			EngList_Create(&WP(w, replaceveh_d).list[1]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   232
			WP(w, replaceveh_d).update_left   = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   233
			WP(w, replaceveh_d).update_right  = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   234
			WP(w, replaceveh_d).init_lists    = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   235
			WP(w, replaceveh_d).sel_engine[0] = INVALID_ENGINE;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   236
			WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   237
			break;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   238
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   239
		case WE_PAINT: {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   240
			if (WP(w, replaceveh_d).update_left || WP(w, replaceveh_d).update_right) GenerateLists(w);
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   241
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   242
			Player *p = GetPlayer(_local_player);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   243
			EngineID selected_id[2];
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 7997
diff changeset
   244
			const GroupID selected_group = WP(w, replaceveh_d).sel_group;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   245
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   246
			selected_id[0] = WP(w, replaceveh_d).sel_engine[0];
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   247
			selected_id[1] = WP(w, replaceveh_d).sel_engine[1];
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   248
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   249
			/* Disable the "Start Replacing" button if:
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   250
			 *    Either list is empty
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   251
			 * or The selected replacement engine has a replacement (to prevent loops)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   252
			 * or The right list (new replacement) has the existing replacement vehicle selected */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   253
			w->SetWidgetDisabledState(4,
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   254
										 selected_id[0] == INVALID_ENGINE ||
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   255
										 selected_id[1] == INVALID_ENGINE ||
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   256
										 EngineReplacementForPlayer(p, selected_id[1], selected_group) != INVALID_ENGINE ||
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   257
										 EngineReplacementForPlayer(p, selected_id[0], selected_group) == selected_id[1]);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   258
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   259
			/* Disable the "Stop Replacing" button if:
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   260
			 *   The left list (existing vehicle) is empty
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   261
			 *   or The selected vehicle has no replacement set up */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   262
			w->SetWidgetDisabledState(6,
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   263
										 selected_id[0] == INVALID_ENGINE ||
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   264
										 !EngineHasReplacementForPlayer(p, selected_id[0], selected_group));
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   265
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   266
			/* now the actual drawing of the window itself takes place */
5955
fe61588d5188 (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 5944
diff changeset
   267
			SetDParam(0, _vehicle_type_names[w->window_number]);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   268
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   269
			if (w->window_number == VEH_TRAIN) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   270
				/* set on/off for renew_keep_length */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   271
				SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   272
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   273
				/* set wagon/engine button */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   274
				SetDParam(2, WP(w, replaceveh_d).wagon_btnstate ? STR_ENGINES : STR_WAGONS);
6398
35d30aee9e8c (svn r9528) -Fix r8610: don't try to modify non-existent widgets (many thanks to Bruce Perence, the libefence developer)
glx
parents: 6259
diff changeset
   275
35d30aee9e8c (svn r9528) -Fix r8610: don't try to modify non-existent widgets (many thanks to Bruce Perence, the libefence developer)
glx
parents: 6259
diff changeset
   276
				/* sets the colour of that art thing */
35d30aee9e8c (svn r9528) -Fix r8610: don't try to modify non-existent widgets (many thanks to Bruce Perence, the libefence developer)
glx
parents: 6259
diff changeset
   277
				w->widget[13].color = _player_colors[_local_player];
35d30aee9e8c (svn r9528) -Fix r8610: don't try to modify non-existent widgets (many thanks to Bruce Perence, the libefence developer)
glx
parents: 6259
diff changeset
   278
				w->widget[16].color = _player_colors[_local_player];
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   279
			}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   280
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   281
			DrawWindowWidgets(w);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   282
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   283
			if (w->window_number == VEH_TRAIN) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   284
				/* Draw the selected railtype in the pulldown menu */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   285
				RailType railtype = _railtype_selected_in_replace_gui;
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7481
diff changeset
   286
				DrawString(157, w->widget[14].top + 1, _rail_types_list[railtype], TC_BLACK);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   287
			}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   288
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   289
			/* sets up the string for the vehicle that is being replaced to */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   290
			if (selected_id[0] != INVALID_ENGINE) {
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   291
				if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   292
					SetDParam(0, STR_NOT_REPLACING);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   293
				} else {
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 6687
diff changeset
   294
					SetDParam(0, STR_ENGINE_NAME);
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 6687
diff changeset
   295
					SetDParam(1, EngineReplacementForPlayer(p, selected_id[0], selected_group));
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   296
				}
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   297
			} else {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   298
				SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   299
			}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   300
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7481
diff changeset
   301
			DrawString(145, w->widget[5].top + 1, STR_02BD, TC_BLACK);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   302
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   303
			/* Draw the lists */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   304
			for(byte i = 0; i < 2; i++) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   305
				uint16 x        = i == 0 ? 2 : 230; // at what X offset
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   306
				EngineList list = WP(w, replaceveh_d).list[i]; // which list to draw
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   307
				EngineID start  = i == 0 ? w->vscroll.pos : w->vscroll2.pos; // what is the offset for the start (scrolling)
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   308
				EngineID end    = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list));
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   309
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   310
				/* Do the actual drawing */
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   311
				DrawEngineList((VehicleType)w->window_number, x, 15, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0, selected_group);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   312
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   313
				/* Also draw the details if an engine is selected */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   314
				if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   315
					const Widget *wi = &w->widget[i == 0 ? 3 : 11];
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   316
					DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, WP(w, replaceveh_d).sel_engine[i]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   317
				}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   318
			}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   319
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   320
		} break;   // end of paint
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   321
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   322
		case WE_CLICK: {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   323
			switch (e->we.click.widget) {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   324
				case 12:
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   325
					WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   326
					WP(w, replaceveh_d).update_left = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   327
					WP(w, replaceveh_d).init_lists  = true;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   328
					SetWindowDirty(w);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   329
					break;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   330
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   331
				case 14:
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   332
				case 15: /* Railtype selection dropdown menu */
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   333
					ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   334
					break;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   335
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   336
				case 17: /* toggle renew_keep_length */
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   337
					DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   338
					break;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   339
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   340
				case 4: { /* Start replacing */
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   341
					EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   342
					EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   343
					DoCommandP(0, 3 + (WP(w, replaceveh_d).sel_group << 16) , veh_from + (veh_to << 16), NULL, CMD_SET_AUTOREPLACE);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   344
				} break;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   345
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   346
				case 6: { /* Stop replacing */
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   347
					EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   348
					DoCommandP(0, 3 + (WP(w, replaceveh_d).sel_group << 16), veh_from + (INVALID_ENGINE << 16), NULL, CMD_SET_AUTOREPLACE);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   349
				} break;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   350
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   351
				case 7:
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   352
				case 9: {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   353
					uint i = (e->we.click.pt.y - 14) / w->resize.step_height;
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   354
					uint16 click_scroll_pos = e->we.click.widget == 7 ? w->vscroll.pos : w->vscroll2.pos;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   355
					uint16 click_scroll_cap = e->we.click.widget == 7 ? w->vscroll.cap : w->vscroll2.cap;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   356
					byte click_side         = e->we.click.widget == 7 ? 0 : 1;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   357
					uint16 engine_count     = EngList_Count(&WP(w, replaceveh_d).list[click_side]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   358
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   359
					if (i < click_scroll_cap) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   360
						i += click_scroll_pos;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   361
						EngineID e = engine_count > i ? WP(w, replaceveh_d).list[click_side][i] : INVALID_ENGINE;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   362
						if (e == WP(w, replaceveh_d).sel_engine[click_side]) break; // we clicked the one we already selected
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   363
						WP(w, replaceveh_d).sel_engine[click_side] = e;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   364
						if (click_side == 0) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   365
							WP(w, replaceveh_d).update_right = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   366
							WP(w, replaceveh_d).init_lists   = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   367
						}
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   368
						SetWindowDirty(w);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   369
						}
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   370
					break;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   371
					}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   372
			}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   373
			break;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   374
		}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   375
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   376
		case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   377
			RailType temp = (RailType)e->we.dropdown.index;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   378
			if (temp == _railtype_selected_in_replace_gui) break; // we didn't select a new one. No need to change anything
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   379
			_railtype_selected_in_replace_gui = temp;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   380
			/* Reset scrollbar positions */
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   381
			w->vscroll.pos  = 0;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   382
			w->vscroll2.pos = 0;
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   383
			/* Rebuild the lists */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   384
			WP(w, replaceveh_d).update_left  = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   385
			WP(w, replaceveh_d).update_right = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   386
			WP(w, replaceveh_d).init_lists   = true;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   387
			SetWindowDirty(w);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   388
		} break;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   389
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   390
		case WE_RESIZE:
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   391
			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   392
			w->vscroll2.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   393
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   394
			w->widget[7].data = (w->vscroll.cap  << 8) + 1;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   395
			w->widget[9].data = (w->vscroll2.cap << 8) + 1;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   396
			break;
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   397
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   398
		case WE_INVALIDATE_DATA:
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   399
			if (_rebuild_left_list) WP(w, replaceveh_d).update_left = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   400
			if (_rebuild_right_list) WP(w, replaceveh_d).update_right = true;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   401
			SetWindowDirty(w);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   402
			break;
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   403
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   404
		case WE_DESTROY:
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   405
			EngList_RemoveAll(&WP(w, replaceveh_d).list[0]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   406
			EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   407
		break;
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   408
	}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   409
}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   410
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   411
static const Widget _replace_rail_vehicle_widgets[] = {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   412
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,       STR_018B_CLOSE_WINDOW},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   413
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   414
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,       STR_STICKY_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   415
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   227, 0x0,            STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   416
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   240,   251, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   417
{      WWT_PANEL,     RESIZE_TB,    14,   139,   316,   228,   239, 0x0,            STR_REPLACE_HELP_REPLACE_INFO_TAB},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   418
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   240,   251, STR_REPLACE_VEHICLES_STOP,  STR_REPLACE_HELP_STOP_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   419
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,          STR_REPLACE_HELP_LEFT_ARRAY},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   420
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   421
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,          STR_REPLACE_HELP_RIGHT_ARRAY},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   422
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   423
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   227, 0x0,            STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   424
// train specific stuff
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   425
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   228,   239, STR_REPLACE_ENGINE_WAGON_SELECT,       STR_REPLACE_ENGINE_WAGON_SELECT_HELP},  // widget 12
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   426
{      WWT_PANEL,     RESIZE_TB,    14,   139,   153,   240,   251, 0x0,            STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   427
{      WWT_PANEL,     RESIZE_TB,    14,   154,   277,   240,   251, 0x0,            STR_REPLACE_HELP_RAILTYPE},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   428
{    WWT_TEXTBTN,     RESIZE_TB,    14,   278,   289,   240,   251, STR_0225,       STR_REPLACE_HELP_RAILTYPE},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   429
{      WWT_PANEL,     RESIZE_TB,    14,   290,   305,   240,   251, 0x0,            STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   430
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   317,   455,   228,   239, STR_REPLACE_REMOVE_WAGON,       STR_REPLACE_REMOVE_WAGON_HELP},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   431
// end of train specific stuff
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   432
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   240,   251, STR_NULL,       STR_RESIZE_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   433
{   WIDGETS_END},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   434
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   435
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   436
static const Widget _replace_road_vehicle_widgets[] = {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   437
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   438
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   439
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   440
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   217, 0x0,                         STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   441
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   218,   229, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   442
{      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   218,   229, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   443
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   218,   229, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   444
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,                       STR_REPLACE_HELP_LEFT_ARRAY},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   445
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   446
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,                       STR_REPLACE_HELP_RIGHT_ARRAY},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   447
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   448
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   217, 0x0,                         STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   449
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   218,   229, STR_NULL,                    STR_RESIZE_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   450
{   WIDGETS_END},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   451
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   452
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   453
static const Widget _replace_ship_aircraft_vehicle_widgets[] = {
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   454
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   455
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   456
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   457
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   110,   201, 0x0,                         STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   458
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   202,   213, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   459
{      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   202,   213, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   460
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   202,   213, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   461
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   109, 0x401,                       STR_REPLACE_HELP_LEFT_ARRAY},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   462
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   463
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   109, 0x401,                       STR_REPLACE_HELP_RIGHT_ARRAY},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   464
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   465
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   110,   201, 0x0,                         STR_NULL},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   466
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   202,   213, STR_NULL,                    STR_RESIZE_BUTTON},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   467
{   WIDGETS_END},
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   468
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   469
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   470
static const WindowDesc _replace_rail_vehicle_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   471
	WDP_AUTO, WDP_AUTO, 456, 252, 456, 252,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5868
diff changeset
   472
	WC_REPLACE_VEHICLE, WC_NONE,
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   473
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   474
	_replace_rail_vehicle_widgets,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   475
	ReplaceVehicleWndProc
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   476
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   477
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   478
static const WindowDesc _replace_road_vehicle_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   479
	WDP_AUTO, WDP_AUTO, 456, 230, 456, 230,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5868
diff changeset
   480
	WC_REPLACE_VEHICLE, WC_NONE,
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   481
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   482
	_replace_road_vehicle_widgets,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   483
	ReplaceVehicleWndProc
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   484
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   485
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   486
static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   487
	WDP_AUTO, WDP_AUTO, 456, 214, 456, 214,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5868
diff changeset
   488
	WC_REPLACE_VEHICLE, WC_NONE,
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   489
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   490
	_replace_ship_aircraft_vehicle_widgets,
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   491
	ReplaceVehicleWndProc
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   492
};
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   493
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   494
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6398
diff changeset
   495
void ShowReplaceVehicleWindow(VehicleType vehicletype)
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   496
{
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   497
	Window *w;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   498
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   499
	DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   500
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   501
	switch (vehicletype) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   502
		case VEH_TRAIN:
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   503
			w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   504
			w->vscroll.cap  = 8;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   505
			w->resize.step_height = 14;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   506
			WP(w, replaceveh_d).wagon_btnstate = true;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   507
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   508
		case VEH_ROAD:
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   509
			w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   510
			w->vscroll.cap  = 8;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   511
			w->resize.step_height = 14;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   512
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   513
		case VEH_SHIP:
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   514
		case VEH_AIRCRAFT:
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   515
			w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   516
			w->vscroll.cap  = 4;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   517
			w->resize.step_height = 24;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   518
			break;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   519
		default: return;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   520
	}
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   521
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   522
	w->caption_color = _local_player;
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   523
	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   524
	WP(w, replaceveh_d).sel_group = DEFAULT_GROUP;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   525
 }
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   526
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   527
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   528
{
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   529
	Window *w;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   530
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   531
	DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   532
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   533
	switch (vehicletype) {
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   534
		default: NOT_REACHED();
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   535
		case VEH_TRAIN:
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   536
			w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   537
			w->vscroll.cap  = 8;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   538
			w->resize.step_height = 14;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   539
			WP(w, replaceveh_d).wagon_btnstate = true;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   540
			break;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   541
		case VEH_ROAD:
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   542
			w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   543
			w->vscroll.cap  = 8;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   544
			w->resize.step_height = 14;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   545
			break;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   546
		case VEH_SHIP:
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   547
		case VEH_AIRCRAFT:
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   548
			w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   549
			w->vscroll.cap  = 4;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   550
			w->resize.step_height = 24;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   551
			break;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   552
	}
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   553
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   554
	w->caption_color = _local_player;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   555
	WP(w, replaceveh_d).sel_group = id_g;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   556
	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
5808
c34443483ed3 (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 5801
diff changeset
   557
}