src/autoreplace_gui.cpp
author bjarni
Tue, 13 Feb 2007 11:09:58 +0000
branchcpp_gui
changeset 6241 6a7a41b0cd32
parent 6235 5077e6ed3788
child 6246 2a4c2c4d66f0
permissions -rw-r--r--
(svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
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
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1859
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1309
diff changeset
     7
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 505
diff changeset
     8
#include "table/strings.h"
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
     9
#include "window.h"
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    10
#include "gui.h"
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    11
#include "command.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    12
#include "variables.h"
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    13
#include "vehicle_gui.h"
2962
dbd168a4703a (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
    14
#include "newgrf_engine.h"
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    15
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    16
6060
8388a1bcb7c8 (svn r8371) -Codechange: [autoreplace GUI] moved the autoreplace GUI to a file of it's own
bjarni
parents: 6059
diff changeset
    17
static RailType _railtype_selected_in_replace_gui;
505
11582dcada49 (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
    18
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    19
static bool _rebuild_left_list;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    20
static bool _rebuild_right_list;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    21
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    22
static const StringID _rail_types_list[] = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    23
	STR_RAIL_VEHICLES,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    24
	STR_ELRAIL_VEHICLES,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    25
	STR_MONORAIL_VEHICLES,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    26
	STR_MAGLEV_VEHICLES,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    27
	INVALID_STRING_ID
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    28
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    29
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    30
/* General Vehicle GUI based procedures that are independent of vehicle types */
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    31
void InitializeVehiclesGuiList(void)
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    32
{
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    33
	_railtype_selected_in_replace_gui = RAILTYPE_RAIL;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    34
}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    35
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    36
/** Rebuild the left autoreplace list if an engine is removed or added
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    37
 * @param e Engine to check if it is removed or added
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    38
 *  Note: this function only works if it is called either
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    39
 *   - when a new vehicle is build, but before it's counted in num_engines
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    40
 *   - when a vehicle is deleted and after it's substracted from num_engines
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    41
 *   - when not changing the count (used when changing replace orders)
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    42
 */
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    43
void InvalidateAutoreplaceWindow(EngineID e)
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    44
{
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    45
	Player *p = GetPlayer(_local_player);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    46
	byte type = GetEngine(e)->type;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    47
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    48
	if (p->num_engines[e] == 0) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    49
		/* We don't have any of this engine type.
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    50
		 * Either we just sold the last one, we build a new one or we stopped replacing it.
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    51
		 * In all cases, we need to update the left list */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    52
		_rebuild_left_list = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    53
	} else {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    54
		_rebuild_left_list = false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    55
	}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    56
	_rebuild_right_list = false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    57
	InvalidateWindowData(WC_REPLACE_VEHICLE, type);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    58
}
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
    59
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    60
/** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    61
 * @param type The type of engine
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    62
 */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    63
void AddRemoveEngineFromAutoreplaceAndBuildWindows(byte type)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    64
{
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    65
	_rebuild_left_list = false; // left list is only for the vehicles the player owns and is not related to being buildable
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    66
	_rebuild_right_list = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    67
	InvalidateWindowData(WC_REPLACE_VEHICLE, type); // Update the autoreplace window
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    68
	InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    69
}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    70
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    71
/** Get the default cargo type for an engine
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    72
 * @param engine the EngineID to get the cargo for
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    73
 * @return the cargo type carried by the engine (CT_INVALID if engine got no cargo capacity)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    74
 */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    75
static CargoID EngineCargo(EngineID engine)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    76
{
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    77
	if (engine == INVALID_ENGINE) return CT_INVALID; // surely INVALID_ENGINE can't carry anything but CT_INVALID
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    78
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    79
	switch (GetEngine(engine)->type) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    80
		default: NOT_REACHED();
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    81
		case VEH_Train:
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    82
			if (RailVehInfo(engine)->capacity == 0) return CT_INVALID; // no capacity -> can't carry cargo
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    83
			return RailVehInfo(engine)->cargo_type;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    84
		case VEH_Road:       return RoadVehInfo(engine)->cargo_type;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    85
		case VEH_Ship:       return ShipVehInfo(engine)->cargo_type;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    86
		case VEH_Aircraft:   return CT_PASSENGERS; // all planes are build with passengers by default
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    87
	}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    88
}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    89
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    90
/** Figure out if an engine should be added to a list
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    91
 * @param e The EngineID
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    92
 * @param draw_left If true, then the left list is drawn (the engines specific to the railtype you selected)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    93
 * @param show_engines if truem then locomotives are drawn, else wagons (never both)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    94
 * @return true if the engine should be in the list (based on this check)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    95
 */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    96
static bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    97
{
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    98
	const RailVehicleInfo *rvi = RailVehInfo(e);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
    99
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   100
	/* Ensure that the wagon/engine selection fits the engine. */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   101
	if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   102
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   103
	if (draw_left && show_engines) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   104
		/* Ensure that the railtype is specific to the selected one */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   105
		if (rvi->railtype != _railtype_selected_in_replace_gui) return false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   106
	} else {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   107
		/* Ensure that it's a compatible railtype to the selected one (like electric <-> diesel)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   108
		 * The vehicle do not have to have power on the railtype in question, only able to drive (pulled if needed) */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   109
		if (!IsCompatibleRail(rvi->railtype, _railtype_selected_in_replace_gui)) return false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   110
	}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   111
	return true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   112
}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   113
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   114
/** Figure out if two engines got at least one type of cargo in common (refitting if needed)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   115
 * @param engine_a one of the EngineIDs
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   116
 * @param engine_b the other EngineID
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   117
 * @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   118
 */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   119
static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   120
{
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   121
	CargoID a = EngineCargo(engine_a);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   122
	CargoID b = EngineCargo(engine_b);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   123
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   124
	 /* we should always be able to refit to/from locomotives without capacity
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   125
	  * Because of that, CT_INVALID shoudl always return true */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   126
	if (a == CT_INVALID || b == CT_INVALID || a == b) return true; // they carry no ro the same type by default
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   127
	if (EngInfo(engine_a)->refit_mask & EngInfo(engine_b)->refit_mask) return true; // both can refit to the same
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   128
	if (CanRefitTo(engine_a, b) || CanRefitTo(engine_b, a)) return true; // one can refit to what the other one carries
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   129
	return false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   130
}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   131
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   132
/** Generate a list
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   133
 * @param w Window, that contains the list
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   134
 * @param draw_left true if generating the left list, otherwise false
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   135
 */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   136
static void GenerateReplaceVehList(Window *w, bool draw_left)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   137
{
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   138
	Player *p = GetPlayer(_local_player);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   139
	EngineID e;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   140
	EngineID selected_engine = INVALID_ENGINE;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   141
	byte type = w->window_number;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   142
	byte i = draw_left ? 0 : 1;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   143
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   144
	EngineList *list = &WP(w, replaceveh_d).list[i];
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   145
	EngList_RemoveAll(list);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   146
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   147
	FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   148
		if (type == VEH_Train && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   149
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   150
		if (draw_left) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   151
			/* Skip drawing the engines we don't have any of and haven't set for replacement */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   152
			if (p->num_engines[e] == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e) == INVALID_ENGINE) continue;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   153
		} else {
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   154
			/* This is for engines we can replace to and they should depend on what we selected to replace from */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   155
			if (!IsEngineBuildable(e, type, _local_player)) continue; // we need to be able to build the engine
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   156
			if (!EnginesGotCargoInCommon(e, WP(w, replaceveh_d).sel_engine[0])) continue; // the engines needs to be able to carry the same cargo
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   157
			if (e == WP(w, replaceveh_d).sel_engine[0]) continue; // we can't replace an engine into itself (that would be autorenew)
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   158
		}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   159
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   160
		EngList_Add(list, e);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   161
		if (e == WP(w, replaceveh_d).sel_engine[i]) selected_engine = e; // The selected engine is still in the list
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   162
	}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   163
	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)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   164
}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   165
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   166
/** Generate the lists
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   167
 * @param w Window containing the lists
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   168
 */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   169
static void GenerateLists(Window *w)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   170
{
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   171
	EngineID e = WP(w, replaceveh_d).sel_engine[0];
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   172
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   173
	if (WP(w, replaceveh_d).update_left == true) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   174
		/* We need to rebuild the left list */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   175
		GenerateReplaceVehList(w, true);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   176
		SetVScrollCount(w, EngList_Count(&WP(w, replaceveh_d).list[0]));
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   177
		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) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   178
			WP(w, replaceveh_d).sel_engine[0] = WP(w, replaceveh_d).list[0][0];
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   179
		}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   180
	}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   181
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   182
	if (WP(w, replaceveh_d).update_right || e != WP(w, replaceveh_d).sel_engine[0]) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   183
		/* Either we got a request to rebuild the right list or the left list selected a different engine */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   184
		if (WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   185
			/* Always empty the right list when nothing is selected in the left list */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   186
			EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   187
			WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   188
		} else {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   189
			GenerateReplaceVehList(w, false);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   190
			SetVScroll2Count(w, EngList_Count(&WP(w, replaceveh_d).list[1]));
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   191
			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) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   192
				WP(w, replaceveh_d).sel_engine[1] = WP(w, replaceveh_d).list[1][0];
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   193
			}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   194
		}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   195
	}
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   196
	/* Reset the flags about needed updates */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   197
	WP(w, replaceveh_d).update_left  = false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   198
	WP(w, replaceveh_d).update_right = false;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   199
	WP(w, replaceveh_d).init_lists   = false;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   200
}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   201
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   202
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   203
void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count);
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   204
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   205
static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   206
{
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   207
	/* Strings for the pulldown menu */
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   208
	static const StringID _vehicle_type_names[] = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   209
		STR_019F_TRAIN,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   210
		STR_019C_ROAD_VEHICLE,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   211
		STR_019E_SHIP,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   212
		STR_019D_AIRCRAFT
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   213
	};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   214
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   215
	switch (e->event) {
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   216
		case WE_CREATE:
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   217
			WP(w, replaceveh_d).wagon_btnstate = true; // start with locomotives (all other vehicles will not read this bool)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   218
			EngList_Create(&WP(w, replaceveh_d).list[0]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   219
			EngList_Create(&WP(w, replaceveh_d).list[1]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   220
			WP(w, replaceveh_d).update_left   = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   221
			WP(w, replaceveh_d).update_right  = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   222
			WP(w, replaceveh_d).init_lists    = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   223
			WP(w, replaceveh_d).sel_engine[0] = INVALID_ENGINE;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   224
			WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   225
			break;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   226
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   227
		case WE_PAINT: {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   228
			if (WP(w, replaceveh_d).update_left || WP(w, replaceveh_d).update_right) GenerateLists(w);
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   229
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   230
			Player *p = GetPlayer(_local_player);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   231
			EngineID selected_id[2];
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   232
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   233
			selected_id[0] = WP(w, replaceveh_d).sel_engine[0];
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   234
			selected_id[1] = WP(w, replaceveh_d).sel_engine[1];
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   235
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   236
			/* Disable the "Start Replacing" button if:
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   237
			 *    Either list is empty
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   238
			 * or The selected replacement engine has a replacement (to prevent loops)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   239
			 * or The right list (new replacement) has the existing replacement vehicle selected */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   240
			SetWindowWidgetDisabledState(w, 4,
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   241
										 selected_id[0] == INVALID_ENGINE ||
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   242
										 selected_id[1] == INVALID_ENGINE ||
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   243
										 EngineReplacementForPlayer(p, selected_id[1]) != INVALID_ENGINE ||
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   244
										 EngineReplacementForPlayer(p, selected_id[0]) == selected_id[1]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   245
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   246
			/* Disable the "Stop Replacing" button if:
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   247
			 *   The left list (existing vehicle) is empty
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   248
			 *   or The selected vehicle has no replacement set up */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   249
			SetWindowWidgetDisabledState(w, 6,
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   250
										 selected_id[0] == INVALID_ENGINE ||
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   251
										 !EngineHasReplacementForPlayer(p, selected_id[0]));
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   252
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   253
			/* now the actual drawing of the window itself takes place */
6206
67358999d80d (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: 6195
diff changeset
   254
			SetDParam(0, _vehicle_type_names[w->window_number]);
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   255
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   256
			if (w->window_number == VEH_Train) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   257
				/* set on/off for renew_keep_length */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   258
				SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   259
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   260
				/* set wagon/engine button */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   261
				SetDParam(2, WP(w, replaceveh_d).wagon_btnstate ? STR_ENGINES : STR_WAGONS);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   262
			}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   263
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   264
			w->widget[13].color = _player_colors[_local_player]; // sets the colour of that art thing
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   265
			w->widget[16].color = _player_colors[_local_player]; // sets the colour of that art thing
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   266
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   267
			w->DrawWidgets();
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   268
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   269
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   270
			if (w->window_number == VEH_Train) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   271
				/* Draw the selected railtype in the pulldown menu */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   272
				RailType railtype = _railtype_selected_in_replace_gui;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   273
				DrawString(157, w->widget[14].top + 1, _rail_types_list[railtype], 0x10);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   274
			}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   275
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   276
			/* sets up the string for the vehicle that is being replaced to */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   277
			if (selected_id[0] != INVALID_ENGINE) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   278
				if (!EngineHasReplacementForPlayer(p, selected_id[0])) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   279
					SetDParam(0, STR_NOT_REPLACING);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   280
				} else {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   281
					SetDParam(0, GetCustomEngineName(EngineReplacementForPlayer(p, selected_id[0])));
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   282
				}
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   283
			} else {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   284
				SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   285
			}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   286
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   287
			DrawString(145, w->widget[5].top + 1, STR_02BD, 0x10);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   288
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   289
			/* Draw the lists */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   290
			for(byte i = 0; i < 2; i++) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   291
				uint16 x        = i == 0 ? 2 : 230; // at what X offset
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   292
				EngineList list = WP(w, replaceveh_d).list[i]; // which list to draw
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   293
				EngineID start  = i == 0 ? w->vscroll.pos : w->vscroll2.pos; // what is the offset for the start (scrolling)
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   294
				EngineID end    = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list));
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   295
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   296
				/* Do the actual drawing */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   297
				DrawEngineList(w->window_number, x, 15, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   298
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   299
				/* Also draw the details if an engine is selected */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   300
				if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   301
					const Widget *wi = &w->widget[i == 0 ? 3 : 11];
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   302
					DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, WP(w, replaceveh_d).sel_engine[i]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   303
				}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   304
			}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   305
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   306
		} break;   // end of paint
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   307
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   308
		case WE_CLICK: {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   309
			switch (e->we.click.widget) {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   310
				case 12:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   311
					WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   312
					WP(w, replaceveh_d).update_left = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   313
					WP(w, replaceveh_d).init_lists  = true;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6206
diff changeset
   314
					w->SetDirty();
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   315
					break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   316
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   317
				case 14:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   318
				case 15: /* Railtype selection dropdown menu */
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   319
					w->ShowDropDownMenu(_rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   320
					break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   321
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   322
				case 17: /* toggle renew_keep_length */
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   323
					DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   324
					break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   325
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   326
				case 4: { /* Start replacing */
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   327
					EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   328
					EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   329
					DoCommandP(0, 3, veh_from + (veh_to << 16), NULL, CMD_SET_AUTOREPLACE);
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   330
				} break;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   331
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   332
				case 6: { /* Stop replacing */
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   333
					EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   334
					DoCommandP(0, 3, veh_from + (INVALID_ENGINE << 16), NULL, CMD_SET_AUTOREPLACE);
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   335
				} break;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   336
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   337
				case 7:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   338
				case 9: {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   339
					uint i = (e->we.click.pt.y - 14) / w->resize.step_height;
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   340
					uint16 click_scroll_pos = e->we.click.widget == 7 ? w->vscroll.pos : w->vscroll2.pos;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   341
					uint16 click_scroll_cap = e->we.click.widget == 7 ? w->vscroll.cap : w->vscroll2.cap;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   342
					byte click_side         = e->we.click.widget == 7 ? 0 : 1;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   343
					uint16 engine_count     = EngList_Count(&WP(w, replaceveh_d).list[click_side]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   344
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   345
					if (i < click_scroll_cap) {
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   346
						i += click_scroll_pos;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   347
						EngineID e = engine_count > i ? WP(w, replaceveh_d).list[click_side][i] : INVALID_ENGINE;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   348
						if (e == WP(w, replaceveh_d).sel_engine[click_side]) break; // we clicked the one we already selected
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   349
						WP(w, replaceveh_d).sel_engine[click_side] = e;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   350
						if (click_side == 0) {
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   351
							WP(w, replaceveh_d).update_right = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   352
							WP(w, replaceveh_d).init_lists   = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   353
						}
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6206
diff changeset
   354
						w->SetDirty();
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   355
						}
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   356
					break;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   357
					}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   358
			}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   359
			break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   360
		}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   361
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   362
		case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   363
			RailType temp = (RailType)e->we.dropdown.index;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   364
			if (temp == _railtype_selected_in_replace_gui) break; // we didn't select a new one. No need to change anything
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   365
			_railtype_selected_in_replace_gui = temp;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   366
			/* Reset scrollbar positions */
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   367
			w->vscroll.pos  = 0;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   368
			w->vscroll2.pos = 0;
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   369
			/* Rebuild the lists */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   370
			WP(w, replaceveh_d).update_left  = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   371
			WP(w, replaceveh_d).update_right = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   372
			WP(w, replaceveh_d).init_lists   = true;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6206
diff changeset
   373
			w->SetDirty();
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   374
		} break;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   375
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   376
		case WE_RESIZE:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   377
			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   378
			w->vscroll2.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   379
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   380
			w->widget[7].data = (w->vscroll.cap  << 8) + 1;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   381
			w->widget[9].data = (w->vscroll2.cap << 8) + 1;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   382
			break;
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   383
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   384
		case WE_INVALIDATE_DATA:
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   385
			if (_rebuild_left_list) WP(w, replaceveh_d).update_left = true;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   386
			if (_rebuild_right_list) WP(w, replaceveh_d).update_right = true;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6206
diff changeset
   387
			w->SetDirty();
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   388
			break;
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   389
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   390
		case WE_DESTROY:
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   391
			EngList_RemoveAll(&WP(w, replaceveh_d).list[0]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   392
			EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   393
		break;
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   394
	}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   395
}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   396
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   397
static const Widget _replace_rail_vehicle_widgets[] = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   398
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,       STR_018B_CLOSE_WINDOW},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   399
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   400
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,       STR_STICKY_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   401
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   227, 0x0,            STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   402
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   240,   251, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   403
{      WWT_PANEL,     RESIZE_TB,    14,   139,   316,   228,   239, 0x0,            STR_REPLACE_HELP_REPLACE_INFO_TAB},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   404
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   240,   251, STR_REPLACE_VEHICLES_STOP,  STR_REPLACE_HELP_STOP_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   405
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,          STR_REPLACE_HELP_LEFT_ARRAY},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   406
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   407
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,          STR_REPLACE_HELP_RIGHT_ARRAY},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   408
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   409
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   227, 0x0,            STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   410
// train specific stuff
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   411
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   228,   239, STR_REPLACE_ENGINE_WAGON_SELECT,       STR_REPLACE_ENGINE_WAGON_SELECT_HELP},  // widget 12
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   412
{      WWT_PANEL,     RESIZE_TB,    14,   139,   153,   240,   251, 0x0,            STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   413
{      WWT_PANEL,     RESIZE_TB,    14,   154,   277,   240,   251, 0x0,            STR_REPLACE_HELP_RAILTYPE},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   414
{    WWT_TEXTBTN,     RESIZE_TB,    14,   278,   289,   240,   251, STR_0225,       STR_REPLACE_HELP_RAILTYPE},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   415
{      WWT_PANEL,     RESIZE_TB,    14,   290,   305,   240,   251, 0x0,            STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   416
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   317,   455,   228,   239, STR_REPLACE_REMOVE_WAGON,       STR_REPLACE_REMOVE_WAGON_HELP},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   417
// end of train specific stuff
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   418
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   240,   251, STR_NULL,       STR_RESIZE_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   419
{   WIDGETS_END},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   420
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   421
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   422
static const Widget _replace_road_vehicle_widgets[] = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   423
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   424
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   425
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   426
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   217, 0x0,                         STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   427
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   218,   229, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   428
{      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   218,   229, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   429
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   218,   229, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   430
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,                       STR_REPLACE_HELP_LEFT_ARRAY},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   431
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   432
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,                       STR_REPLACE_HELP_RIGHT_ARRAY},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   433
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   434
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   217, 0x0,                         STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   435
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   218,   229, STR_NULL,                    STR_RESIZE_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   436
{   WIDGETS_END},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   437
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   438
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   439
static const Widget _replace_ship_aircraft_vehicle_widgets[] = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   440
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   441
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   442
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   443
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   110,   201, 0x0,                         STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   444
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   202,   213, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   445
{      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   202,   213, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   446
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   202,   213, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   447
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   109, 0x401,                       STR_REPLACE_HELP_LEFT_ARRAY},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   448
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   449
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   109, 0x401,                       STR_REPLACE_HELP_RIGHT_ARRAY},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   450
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   451
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   110,   201, 0x0,                         STR_NULL},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   452
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   202,   213, STR_NULL,                    STR_RESIZE_BUTTON},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   453
{   WIDGETS_END},
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   454
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   455
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   456
static const WindowDesc _replace_rail_vehicle_desc = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   457
	WDP_AUTO, WDP_AUTO, 456, 252,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6119
diff changeset
   458
	WC_REPLACE_VEHICLE, WC_NONE,
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   459
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   460
	_replace_rail_vehicle_widgets,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   461
	ReplaceVehicleWndProc
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   462
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   463
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   464
static const WindowDesc _replace_road_vehicle_desc = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   465
	WDP_AUTO, WDP_AUTO, 456, 230,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6119
diff changeset
   466
	WC_REPLACE_VEHICLE, WC_NONE,
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   467
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   468
	_replace_road_vehicle_widgets,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   469
	ReplaceVehicleWndProc
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   470
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   471
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   472
static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   473
	WDP_AUTO, WDP_AUTO, 456, 214,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6119
diff changeset
   474
	WC_REPLACE_VEHICLE, WC_NONE,
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   475
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   476
	_replace_ship_aircraft_vehicle_widgets,
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   477
	ReplaceVehicleWndProc
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   478
};
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   479
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   480
6060
8388a1bcb7c8 (svn r8371) -Codechange: [autoreplace GUI] moved the autoreplace GUI to a file of it's own
bjarni
parents: 6059
diff changeset
   481
void ShowReplaceVehicleWindow(byte vehicletype)
6059
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   482
{
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   483
	Window *w;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   484
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   485
	DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   486
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   487
	switch (vehicletype) {
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   488
		case VEH_Train:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   489
			w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   490
			w->vscroll.cap  = 8;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   491
			w->resize.step_height = 14;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   492
			WP(w, replaceveh_d).wagon_btnstate = true;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   493
			break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   494
		case VEH_Road:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   495
			w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   496
			w->vscroll.cap  = 8;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   497
			w->resize.step_height = 14;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   498
			break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   499
		case VEH_Ship:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   500
		case VEH_Aircraft:
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   501
			w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   502
			w->vscroll.cap  = 4;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   503
			w->resize.step_height = 24;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   504
			break;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   505
		default: return;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   506
	}
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   507
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   508
	w->caption_color = _local_player;
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   509
	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
14d457867d5e (svn r8370) -Revert (r8363): the autoreplace GUI move cleared the file history
bjarni
parents: 6052
diff changeset
   510
}