src/depot_gui.cpp
author rubidium
Sat, 12 Jan 2008 14:10:35 +0000
changeset 8750 fdd6054e7bae
parent 8733 9e2d2a2619ff
child 8760 ce0891c412ce
permissions -rw-r--r--
(svn r11818) -Codechange: split player.h into smaller pieces.
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     1
/* $Id$ */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     2
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6451
diff changeset
     3
/** @file depot_gui.cpp */
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6369
diff changeset
     4
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     5
#include "stdafx.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     6
#include "openttd.h"
4654
71048359c6ac (svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents: 4653
diff changeset
     7
#include "train.h"
71048359c6ac (svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents: 4653
diff changeset
     8
#include "roadveh.h"
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     9
#include "ship.h"
4653
091f530bae28 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
    10
#include "aircraft.h"
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    11
#include "table/strings.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    12
#include "table/sprites.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    13
#include "gui.h"
8603
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8578
diff changeset
    14
#include "textbuf_gui.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8640
diff changeset
    15
#include "viewport_func.h"
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8640
diff changeset
    16
#include "gfx_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    17
#include "command_func.h"
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    18
#include "depot.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    19
#include "vehicle_gui.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    20
#include "station_map.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    21
#include "newgrf_engine.h"
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    22
#include "spritecache.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8603
diff changeset
    23
#include "strings_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8617
diff changeset
    24
#include "window_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8627
diff changeset
    25
#include "vehicle_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    26
#include "player_func.h"
4649
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    27
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    28
/*
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    29
 * Since all depot window sizes aren't the same, we need to modify sizes a little.
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    30
 * It's done with the following arrays of widget indexes. Each of them tells if a widget side should be moved and in what direction.
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    31
 * How long they should be moved and for what window types are controlled in ShowDepotWindow()
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    32
 */
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    33
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    34
/* Names of the widgets. Keep them in the same order as in the widget array */
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    35
enum DepotWindowWidgets {
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    36
	DEPOT_WIDGET_CLOSEBOX = 0,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    37
	DEPOT_WIDGET_CAPTION,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    38
	DEPOT_WIDGET_STICKY,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    39
	DEPOT_WIDGET_SELL,
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
    40
	DEPOT_WIDGET_SELL_CHAIN,
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    41
	DEPOT_WIDGET_SELL_ALL,
4699
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    42
	DEPOT_WIDGET_AUTOREPLACE,
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    43
	DEPOT_WIDGET_MATRIX,
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6369
diff changeset
    44
	DEPOT_WIDGET_V_SCROLL, ///< Vertical scrollbar
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6369
diff changeset
    45
	DEPOT_WIDGET_H_SCROLL, ///< Horizontal scrollbar
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    46
	DEPOT_WIDGET_BUILD,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    47
	DEPOT_WIDGET_CLONE,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    48
	DEPOT_WIDGET_LOCATION,
4681
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
    49
	DEPOT_WIDGET_VEHICLE_LIST,
4699
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    50
	DEPOT_WIDGET_STOP_ALL,
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    51
	DEPOT_WIDGET_START_ALL,
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    52
	DEPOT_WIDGET_RESIZE,
4649
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    53
};
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    54
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    55
/* Widget array for all depot windows.
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    56
 * If a widget is needed in some windows only (like train specific), add it for all windows
4702
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4699
diff changeset
    57
 * and use HideWindowWidget in ShowDepotWindow() to remove it in the windows where it should not be
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    58
 * Keep the widget numbers in sync with the enum or really bad stuff will happen!!! */
4649
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    59
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    60
/* When adding widgets, place them as you would place them for the ship depot and define how you want it to move in widget_moves[]
4650
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    61
 * If you want a widget for one window only, set it to be hidden in ShowDepotWindow() for the windows where you don't want it
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    62
 * NOTE: the train only widgets are moved/resized in ShowDepotWindow() so they follow certain other widgets if they are moved to ensure that they stick together.
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    63
 *    Changing the size of those here will not have an effect at all. It should be done in ShowDepotWindow()
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    64
 */
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    65
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    66
/*
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    67
 * Some of the widgets are placed outside the window (negative coordinates).
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    68
 * The reason is that they are placed relatively to the matrix and the matrix is just one pixel (in 0, 14).
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    69
 * The matrix and the rest of the window will be resized when the size of the boxes is set and then all the widgets will be inside the window.
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    70
 */
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    71
static const Widget _depot_widgets[] = {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    72
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW},            // DEPOT_WIDGET_CLOSEBOX
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    73
	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,    23,     0,    13, 0x0,                 STR_018C_WINDOW_TITLE_DRAG_THIS},  // DEPOT_WIDGET_CAPTION
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    74
	{  WWT_STICKYBOX,     RESIZE_LR,    14,    24,    35,     0,    13, 0x0,                 STR_STICKY_BUTTON},                // DEPOT_WIDGET_STICKY
4640
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
    75
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4935
diff changeset
    76
	/* Widgets are set up run-time */
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    77
	{     WWT_IMGBTN,    RESIZE_LRB,    14,     1,    23,    14,   -32, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_SELL
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    78
	{     WWT_IMGBTN,   RESIZE_LRTB,    14,     1,    23,   -55,   -32, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    79
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,     1,    23,   -31,    -9, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_SELL_ALL
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    80
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,     1,    23,    -8,    14, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_AUTOREPLACE
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    81
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    82
	{     WWT_MATRIX,     RESIZE_RB,    14,     0,     0,    14,    14, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_MATRIX
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    83
	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,    24,    35,    14,    14, 0x0,                 STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_V_SCROLL
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    84
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    85
	{ WWT_HSCROLLBAR,    RESIZE_RTB,    14,     0,     0,     3,    14, 0x0,                 STR_HSCROLL_BAR_SCROLLS_LIST},     // DEPOT_WIDGET_H_SCROLL, trains only
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    86
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    87
	/* The buttons in the bottom of the window. left and right is not important as they are later resized to be equal in size
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    88
	 * This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0            */
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    89
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,     0,    15,    26, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_BUILD
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    90
	{    WWT_TEXTBTN,     RESIZE_TB,    14,     0,     0,    15,    26, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_CLONE
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    91
	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,     0,   -12,    15,    26, STR_00E4_LOCATION,   STR_NULL},                         // DEPOT_WIDGET_LOCATION
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    92
	{ WWT_PUSHTXTBTN,   RESIZE_LRTB,    14,   -11,     0,    15,    26, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_VEHICLE_LIST
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    93
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,     1,    11,    15,    26, SPR_FLAG_VEH_STOPPED,STR_NULL},                         // DEPOT_WIDGET_STOP_ALL
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    94
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,    12,    23,    15,    26, SPR_FLAG_VEH_RUNNING,STR_NULL},                         // DEPOT_WIDGET_START_ALL
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
    95
	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,    24,    35,    15,    26, 0x0,                 STR_RESIZE_BUTTON},                // DEPOT_WIDGET_RESIZE
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    96
	{   WIDGETS_END},
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    97
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    98
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    99
static void DepotWndProc(Window *w, WindowEvent *e);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   100
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   101
static const WindowDesc _train_depot_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   102
	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6075
diff changeset
   103
	WC_VEHICLE_DEPOT, WC_NONE,
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   104
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   105
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   106
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   107
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   108
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   109
static const WindowDesc _road_depot_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   110
	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6075
diff changeset
   111
	WC_VEHICLE_DEPOT, WC_NONE,
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   112
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   113
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   114
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   115
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   116
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   117
static const WindowDesc _ship_depot_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   118
	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6075
diff changeset
   119
	WC_VEHICLE_DEPOT, WC_NONE,
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   120
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   121
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   122
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   123
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   124
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   125
static const WindowDesc _aircraft_depot_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   126
	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6075
diff changeset
   127
	WC_VEHICLE_DEPOT, WC_NONE,
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   128
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   129
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   130
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   131
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   132
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   133
extern int WagonLengthToPixels(int len);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   134
7974
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   135
/**
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   136
 * This is the Callback method after the cloning attempt of a vehicle
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   137
 * @param success indicates completion (or not) of the operation
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   138
 * @param tile unused
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   139
 * @param p1 unused
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   140
 * @param p2 unused
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   141
 */
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   142
void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   143
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   144
	if (!success) return;
7974
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   145
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   146
	Vehicle *v = GetVehicle(_new_vehicle_id);
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7837
diff changeset
   147
7982
539e32cc37ce (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7975
diff changeset
   148
	ShowVehicleViewWindow(v);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   149
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   150
5670
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   151
static void DepotSellAllConfirmationCallback(Window *w, bool confirmed)
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   152
{
5670
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   153
	if (confirmed) {
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   154
		TileIndex tile = w->window_number;
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   155
		byte vehtype = WP(w, depot_d).type;
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   156
		DoCommandP(tile, vehtype, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES);
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   157
	}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   158
}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   159
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   160
const Sprite *GetAircraftSprite(EngineID engine);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   161
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   162
/** Draw a vehicle in the depot window in the box with the top left corner at x,y
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   163
 * @param *w Window to draw in
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   164
 * @param *v Vehicle to draw
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   165
 * @param x Left side of the box to draw in
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   166
 * @param y Top of the box to draw in
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   167
 */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   168
static void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y)
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   169
{
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   170
	byte diff_x = 0, diff_y = 0;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   171
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   172
	int sprite_y = y + w->resize.step_height - GetVehicleListHeight(v->type);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   173
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   174
	switch (v->type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   175
		case VEH_TRAIN:
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8627
diff changeset
   176
			DrawTrainImage(v, x + 21, sprite_y, WP(w, depot_d).sel, w->hscroll.cap + 4, w->hscroll.pos);
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   177
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   178
			/* Number of wagons relative to a standard length wagon (rounded up) */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   179
			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
   180
			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   181
			break;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   182
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8627
diff changeset
   183
		case VEH_ROAD:     DrawRoadVehImage( v, x + 24, sprite_y, WP(w, depot_d).sel, 1); break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   184
		case VEH_SHIP:     DrawShipImage(    v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   185
		case VEH_AIRCRAFT: {
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7353
diff changeset
   186
			const Sprite *spr = GetSprite(v->GetImage(DIR_W));
6369
7a8bf7c010bd (svn r8770) -Fix r8661: corrected some aircraft sprite placement issues in the depot window
bjarni
parents: 6223
diff changeset
   187
			DrawAircraftImage(v, x + 12,
7a8bf7c010bd (svn r8770) -Fix r8661: corrected some aircraft sprite placement issues in the depot window
bjarni
parents: 6223
diff changeset
   188
							  y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
7a8bf7c010bd (svn r8770) -Fix r8661: corrected some aircraft sprite placement issues in the depot window
bjarni
parents: 6223
diff changeset
   189
							  WP(w, depot_d).sel);
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   190
		} break;
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   191
		default: NOT_REACHED();
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   192
	}
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   193
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   194
	if (w->resize.step_height == 14) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   195
		/* VEH_TRAIN and VEH_ROAD, which are low */
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   196
		diff_x = 15;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   197
	} else {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   198
		/* VEH_SHIP and VEH_AIRCRAFT, which are tall */
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   199
		diff_y = 12;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   200
	}
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   201
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5852
diff changeset
   202
	DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y);
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   203
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   204
	SetDParam(0, v->unitnumber);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
   205
	DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING);
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   206
}
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   207
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   208
static void DrawDepotWindow(Window *w)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   209
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   210
	Vehicle **vl = WP(w, depot_d).vehicle_list;
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   211
	TileIndex tile = w->window_number;
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   212
	int x, y, i, maxval;
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   213
	uint16 hnum;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   214
	uint16 num = WP(w, depot_d).engine_count;
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   215
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   216
	/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   217
	uint16 rows_in_display   = w->widget[DEPOT_WIDGET_MATRIX].data >> 8;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   218
	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   219
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   220
	/* setup disabled buttons */
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   221
	w->SetWidgetsDisabledState(!IsTileOwner(tile, _local_player),
4758
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   222
		DEPOT_WIDGET_STOP_ALL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   223
		DEPOT_WIDGET_START_ALL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   224
		DEPOT_WIDGET_SELL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   225
		DEPOT_WIDGET_SELL_CHAIN,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   226
		DEPOT_WIDGET_SELL_ALL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   227
		DEPOT_WIDGET_BUILD,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   228
		DEPOT_WIDGET_CLONE,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   229
		DEPOT_WIDGET_AUTOREPLACE,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   230
		WIDGET_LIST_END);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   231
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   232
	/* determine amount of items for scroller */
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   233
	if (WP(w, depot_d).type == VEH_TRAIN) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   234
		hnum = 8;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   235
		for (num = 0; num < WP(w, depot_d).engine_count; num++) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   236
			const Vehicle *v = vl[num];
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   237
			hnum = max(hnum, v->u.rail.cached_total_length);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   238
		}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   239
		/* Always have 1 empty row, so people can change the setting of the train */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   240
		SetVScrollCount(w, WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count + 1);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   241
		SetHScrollCount(w, WagonLengthToPixels(hnum));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   242
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   243
		SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   244
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   245
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   246
	/* locate the depot struct */
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   247
	if (WP(w, depot_d).type == VEH_AIRCRAFT) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   248
		SetDParam(0, GetStationIndex(tile)); // Airport name
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   249
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   250
		Depot *depot = GetDepotByTile(tile);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   251
		assert(depot != NULL);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   252
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   253
		SetDParam(0, depot->town_index);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   254
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   255
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   256
	DrawWindowWidgets(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   257
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   258
	num = w->vscroll.pos * boxes_in_each_row;
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   259
	maxval = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row));
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   260
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   261
	for (x = 2, y = 15; num < maxval; y += w->resize.step_height, x = 2) { // Draw the rows
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   262
		byte i;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   263
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   264
		for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += w->resize.step_width) {
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   265
			/* Draw all vehicles in the current row */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   266
			const Vehicle *v = vl[num];
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   267
			DrawVehicleInDepot(w, v, x, y);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   268
		}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   269
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   270
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   271
	maxval = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   272
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   273
	/* draw the train wagons, that do not have an engine in front */
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5835
diff changeset
   274
	for (; num < maxval; num++, y += 14) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   275
		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   276
		const Vehicle *u;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   277
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8627
diff changeset
   278
		DrawTrainImage(v, x + 50, y, WP(w, depot_d).sel, w->hscroll.cap - 29, 0);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
   279
		DrawString(x, y + 2, STR_8816, TC_FROMSTRING);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   280
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   281
		/*Draw the train counter */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   282
		i = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   283
		u = v;
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7982
diff changeset
   284
		do i++; while ((u = u->Next()) != NULL); // Determine length of train
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   285
		SetDParam(0, i);                      // Set the counter
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
   286
		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   287
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   288
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   289
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6505
diff changeset
   290
struct GetDepotVehiclePtData {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   291
	Vehicle *head;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   292
	Vehicle *wagon;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6505
diff changeset
   293
};
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   294
8453
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   295
enum DepotGUIAction {
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   296
	MODE_ERROR,
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   297
	MODE_DRAG_VEHICLE,
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   298
	MODE_SHOW_VEHICLE,
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   299
	MODE_START_STOP,
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   300
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   301
8453
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   302
static DepotGUIAction GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh, GetDepotVehiclePtData *d)
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   303
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   304
	Vehicle **vl = WP(w, depot_d).vehicle_list;
4641
acaeea0a1795 (svn r6516) -Fix r6513: killed warnings about two variables being used uninitialized
bjarni
parents: 4640
diff changeset
   305
	uint xt, row, xm = 0, ym = 0;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   306
	int pos, skip = 0;
4759
4cc941b61b07 (svn r6673) -Codechange: [depot window] replaced a piece of code to calculate max number of vehicles in a row with a simple read of the matrix grid
bjarni
parents: 4758
diff changeset
   307
	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   308
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   309
	if (WP(w, depot_d).type == VEH_TRAIN) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   310
		xt = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   311
		x -= 23;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   312
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   313
		xt = x / w->resize.step_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   314
		xm = x % w->resize.step_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   315
		if (xt >= w->hscroll.cap) return MODE_ERROR;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   316
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   317
		ym = (y - 14) % w->resize.step_height;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   318
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   319
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   320
	row = (y - 14) / w->resize.step_height;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   321
	if (row >= w->vscroll.cap) return MODE_ERROR;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   322
4759
4cc941b61b07 (svn r6673) -Codechange: [depot window] replaced a piece of code to calculate max number of vehicles in a row with a simple read of the matrix grid
bjarni
parents: 4758
diff changeset
   323
	pos = ((row + w->vscroll.pos) * boxes_in_each_row) + xt;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   324
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   325
	if (WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count <= pos) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   326
		if (WP(w, depot_d).type == VEH_TRAIN) {
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   327
			d->head  = NULL;
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   328
			d->wagon = NULL;
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   329
			return MODE_DRAG_VEHICLE;
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   330
		} else {
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   331
			return MODE_ERROR; // empty block, so no vehicle is selected
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   332
		}
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   333
	}
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   334
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   335
	if (WP(w, depot_d).engine_count > pos) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   336
		*veh = vl[pos];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   337
		skip = w->hscroll.pos;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   338
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   339
		vl = WP(w, depot_d).wagon_list;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   340
		pos -= WP(w, depot_d).engine_count;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   341
		*veh = vl[pos];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   342
		/* free wagons don't have an initial loco. */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   343
		x -= _traininfo_vehicle_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   344
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   345
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   346
	switch (WP(w, depot_d).type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   347
		case VEH_TRAIN: {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   348
			Vehicle *v = *veh;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   349
			d->head = d->wagon = v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   350
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   351
			/* either pressed the flag or the number, but only when it's a loco */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   352
			if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   353
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   354
			skip = (skip * 8) / _traininfo_vehicle_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   355
			x = (x * 8) / _traininfo_vehicle_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   356
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   357
			/* Skip vehicles that are scrolled off the list */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   358
			x += skip;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   359
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   360
			/* find the vehicle in this row that was clicked */
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7982
diff changeset
   361
			while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next();
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   362
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   363
			/* if an articulated part was selected, find its parent */
7993
76b0eb3e19c9 (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7988
diff changeset
   364
			while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   365
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   366
			d->wagon = v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   367
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   368
			return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   369
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   370
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   371
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   372
		case VEH_ROAD:
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   373
			if (xm >= 24) return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   374
			if (xm <= 16) return MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   375
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   376
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   377
		case VEH_SHIP:
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   378
			if (xm >= 19) return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   379
			if (ym <= 10) return MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   380
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   381
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   382
		case VEH_AIRCRAFT:
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   383
			if (xm >= 12) return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   384
			if (ym <= 12) return MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   385
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   386
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   387
		default: NOT_REACHED();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   388
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   389
	return MODE_START_STOP;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   390
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   391
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   392
static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   393
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   394
	Vehicle *v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   395
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   396
	v = GetVehicle(sel);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   397
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   398
	if (v == wagon) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   399
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   400
	if (wagon == NULL) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   401
		if (head != NULL) wagon = GetLastVehicleInChain(head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   402
	} else  {
7993
76b0eb3e19c9 (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7988
diff changeset
   403
		wagon = wagon->Previous();
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   404
		if (wagon == NULL) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   405
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   406
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   407
	if (wagon == v) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   408
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   409
	DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   410
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   411
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   412
static void DepotClick(Window *w, int x, int y)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   413
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   414
	GetDepotVehiclePtData gdvp;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   415
	Vehicle *v = NULL;
8453
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   416
	DepotGUIAction mode = GetVehicleFromDepotWndPt(w, x, y, &v, &gdvp);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   417
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   418
	/* share / copy orders */
8453
0410aa90bfdf (svn r11513) -Codechange: enumerize some depot GUI actions
smatz
parents: 8414
diff changeset
   419
	if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   420
		_place_clicked_vehicle = (WP(w, depot_d).type == VEH_TRAIN ? gdvp.head : v);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   421
		return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   422
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   423
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   424
	if (WP(w, depot_d).type == VEH_TRAIN) v = gdvp.wagon;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   425
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   426
	switch (mode) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   427
		case MODE_ERROR: // invalid
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   428
			return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   429
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   430
		case MODE_DRAG_VEHICLE: { // start dragging of vehicle
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   431
			VehicleID sel = WP(w, depot_d).sel;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   432
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   433
			if (WP(w, depot_d).type == VEH_TRAIN && sel != INVALID_VEHICLE) {
8578
55218950ce2d (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8532
diff changeset
   434
				WP(w, depot_d).sel = INVALID_VEHICLE;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   435
				TrainDepotMoveVehicle(v, sel, gdvp.head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   436
			} else if (v != NULL) {
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7353
diff changeset
   437
				int image = v->GetImage(DIR_W);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   438
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   439
				WP(w, depot_d).sel = v->index;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   440
				SetWindowDirty(w);
8385
aedd7656cfd1 (svn r11440) -Codechange: replace magic numbers with enumified WindowHighlightMode constants. Patch by SmatZ.
rubidium
parents: 8320
diff changeset
   441
				SetObjectToPlaceWnd(image, GetVehiclePalette(v), VHM_DRAG, w);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   442
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   443
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   444
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   445
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   446
		case MODE_SHOW_VEHICLE: // show info window
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   447
			ShowVehicleViewWindow(v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   448
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   449
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   450
		case MODE_START_STOP: { // click start/stop flag
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   451
			uint command;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   452
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   453
			switch (WP(w, depot_d).type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   454
				case VEH_TRAIN:    command = CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN);          break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   455
				case VEH_ROAD:     command = CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   456
				case VEH_SHIP:     command = CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP);            break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   457
				case VEH_AIRCRAFT: command = CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT);    break;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   458
				default: NOT_REACHED(); command = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   459
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   460
			DoCommandP(v->tile, v->index, 0, NULL, command);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   461
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   462
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   463
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   464
		default: NOT_REACHED();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   465
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   466
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   467
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   468
/**
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   469
 * Clones a vehicle
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   470
 * @param *v is the original vehicle to clone
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   471
 * @param *w is the window of the depot where the clone is build
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   472
 */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   473
static void HandleCloneVehClick(const Vehicle *v, const Window *w)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   474
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   475
	uint error_str;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   476
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   477
	if (v == NULL) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   478
8044
72c3e2bc6429 (svn r11068) -Codechange: remove Vehicle::HasFront as all vehicles have the Vehicle::first pointer correctly set.
rubidium
parents: 7993
diff changeset
   479
	if (!v->IsPrimaryVehicle()) {
7993
76b0eb3e19c9 (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7988
diff changeset
   480
		v = v->First();
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   481
		/* Do nothing when clicking on a train in depot with no loc attached */
7269
c7f39d91255e (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 7134
diff changeset
   482
		if (v->type == VEH_TRAIN && !IsFrontEngine(v)) return;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   483
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   484
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   485
	switch (v->type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   486
		case VEH_TRAIN:    error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   487
		case VEH_ROAD:     error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE);     break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   488
		case VEH_SHIP:     error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP);             break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   489
		case VEH_AIRCRAFT: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT);         break;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   490
		default: return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   491
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   492
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   493
	DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   494
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   495
	ResetObjectToPlace();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   496
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   497
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   498
static void ClonePlaceObj(const Window *w)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   499
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   500
	const Vehicle *v = CheckMouseOverVehicle();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   501
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   502
	if (v != NULL) HandleCloneVehClick(v, w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   503
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   504
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   505
static void ResizeDepotButtons(Window *w)
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   506
{
6075
33cdb35f9af5 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 6073
diff changeset
   507
	ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION);
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   508
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   509
	if (WP(w, depot_d).type == VEH_TRAIN) {
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   510
		/* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size.
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   511
		* This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason                                                  */
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   512
		w->widget[DEPOT_WIDGET_SELL_CHAIN].top    = ((w->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - w->widget[DEPOT_WIDGET_SELL].top) / 2) + w->widget[DEPOT_WIDGET_SELL].top;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   513
		w->widget[DEPOT_WIDGET_SELL].bottom     = w->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1;
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   514
	}
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   515
}
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   516
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   517
/* Function to set up vehicle specific sprites and strings
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   518
 * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   519
 * Vehicle specific text/sprites, that's in a widget, that's only shown for one vehicle type (like sell whole train) is set in the widget array
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   520
 */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   521
static void SetupStringsForDepotWindow(Window *w, byte type)
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   522
{
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   523
	switch (type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   524
		case VEH_TRAIN:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   525
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_8800_TRAIN_DEPOT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   526
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   527
			w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   528
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   529
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   530
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   531
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   532
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_8815_NEW_VEHICLES;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   533
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_8840_BUILD_NEW_TRAIN_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   534
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   535
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_TRAIN_DEPOT_INFO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   536
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   537
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   538
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   539
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   540
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   541
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   542
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   543
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   544
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   545
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   546
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   547
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   548
		case VEH_ROAD:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   549
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_9003_ROAD_VEHICLE_DEPOT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   550
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   551
			w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   552
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   553
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   554
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_9022_VEHICLES_CLICK_ON_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   555
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   556
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_9004_NEW_VEHICLES;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   557
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_9023_BUILD_NEW_ROAD_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   558
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_ROAD_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   559
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   560
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   561
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   562
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   563
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   564
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   565
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   566
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   567
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_ROADVEH;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   568
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_ROADVEH;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   569
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   570
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   571
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   572
		case VEH_SHIP:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   573
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_9803_SHIP_DEPOT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   574
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   575
			w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   576
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   577
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   578
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_981F_SHIPS_CLICK_ON_SHIP_FOR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   579
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   580
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_9804_NEW_SHIPS;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   581
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_9820_BUILD_NEW_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   582
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   583
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_SHIP_DEPOT_INFO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   584
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   585
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   586
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   587
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   588
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   589
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   590
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   591
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   592
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   593
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   594
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   595
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   596
		case VEH_AIRCRAFT:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   597
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_A002_AIRCRAFT_HANGAR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   598
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   599
			w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   600
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6897
diff changeset
   601
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   602
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   603
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   604
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_A003_NEW_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   605
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_A022_BUILD_NEW_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   606
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   607
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   608
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   609
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   610
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   611
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   612
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   613
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   614
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   615
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   616
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   617
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   618
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   619
	}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   620
}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   621
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   622
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   623
/* Array to hold the block sizes
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   624
 * First part is the vehicle type, while the last is 0 = x, 1 = y */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   625
uint _block_sizes[4][2];
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   626
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   627
/* Array to hold the default resize capacities
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   628
* First part is the vehicle type, while the last is 0 = x, 1 = y */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   629
const uint _resize_cap[][2] = {
6897
dcee0e80200b (svn r9531) -Fix (r8661) [FS#692]: The scroll settings were wrong for trains as only a part
maedhros
parents: 6585
diff changeset
   630
/* VEH_TRAIN */    {6, 10 * 29},
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   631
/* VEH_ROAD */     {5, 5},
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   632
/* VEH_SHIP */     {3, 3},
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   633
/* VEH_AIRCRAFT */ {3, 4},
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   634
};
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   635
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   636
static void ResizeDefaultWindowSizeForTrains()
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   637
{
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   638
	_block_sizes[VEH_TRAIN][0] = 1;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   639
	_block_sizes[VEH_TRAIN][1] = GetVehicleListHeight(VEH_TRAIN);
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   640
}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   641
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   642
static void ResizeDefaultWindowSizeForRoadVehicles()
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   643
{
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   644
	_block_sizes[VEH_ROAD][0] = 56;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   645
	_block_sizes[VEH_ROAD][1] = GetVehicleListHeight(VEH_ROAD);
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   646
}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   647
7134
c5a90dd41166 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 7117
diff changeset
   648
static void ResizeDefaultWindowSize(VehicleType type)
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   649
{
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   650
	EngineID engine;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   651
	uint max_width  = 0;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   652
	uint max_height = 0;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   653
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   654
	FOR_ALL_ENGINEIDS_OF_TYPE(engine, type) {
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   655
		uint x, y;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   656
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   657
		switch (type) {
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   658
			default: NOT_REACHED();
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   659
			case VEH_SHIP:     GetShipSpriteSize(    engine, x, y); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   660
			case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y); break;
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   661
		}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   662
		if (x > max_width)  max_width  = x;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   663
		if (y > max_height) max_height = y;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   664
	}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   665
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   666
	switch (type) {
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   667
		default: NOT_REACHED();
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   668
		case VEH_SHIP:
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   669
			_block_sizes[VEH_SHIP][0] = max(90U, max_width + 20); // we need 20 pixels from the right edge to the sprite
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   670
			break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   671
		case VEH_AIRCRAFT:
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   672
			_block_sizes[VEH_AIRCRAFT][0] = max(74U, max_width);
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   673
			break;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   674
	}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   675
	_block_sizes[type][1] = max(GetVehicleListHeight(type), max_height);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   676
}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   677
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   678
/* Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   679
 * We will only need to call this once for each game */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   680
void InitDepotWindowBlockSizes()
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   681
{
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   682
	ResizeDefaultWindowSizeForTrains();
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   683
	ResizeDefaultWindowSizeForRoadVehicles();
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   684
	ResizeDefaultWindowSize(VEH_SHIP);
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   685
	ResizeDefaultWindowSize(VEH_AIRCRAFT);
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   686
}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   687
7134
c5a90dd41166 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 7117
diff changeset
   688
static void CreateDepotListWindow(Window *w, VehicleType type)
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   689
{
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   690
	WP(w, depot_d).type = type;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   691
	_backup_orders_tile = 0;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   692
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   693
	assert(IsPlayerBuildableVehicleType(type)); // ensure that we make the call with a valid type
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   694
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   695
	/* Resize the window according to the vehicle type */
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   696
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   697
	/* Set the number of blocks in each direction */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   698
	w->vscroll.cap = _resize_cap[type][0];
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   699
	w->hscroll.cap = _resize_cap[type][1];
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   700
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   701
	/* Set the block size */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   702
	w->resize.step_width  = _block_sizes[type][0];
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   703
	w->resize.step_height = _block_sizes[type][1];
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   704
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   705
	/* Enlarge the window to fit with the selected number of blocks of the selected size */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   706
	ResizeWindow(w,
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   707
				 _block_sizes[type][0] * w->hscroll.cap,
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   708
				 _block_sizes[type][1] * w->vscroll.cap);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   709
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   710
	if (type == VEH_TRAIN) {
6897
dcee0e80200b (svn r9531) -Fix (r8661) [FS#692]: The scroll settings were wrong for trains as only a part
maedhros
parents: 6585
diff changeset
   711
		/* Make space for the horizontal scrollbar vertically, and the unit
dcee0e80200b (svn r9531) -Fix (r8661) [FS#692]: The scroll settings were wrong for trains as only a part
maedhros
parents: 6585
diff changeset
   712
		 * number, flag, and length counter horizontally. */
dcee0e80200b (svn r9531) -Fix (r8661) [FS#692]: The scroll settings were wrong for trains as only a part
maedhros
parents: 6585
diff changeset
   713
		ResizeWindow(w, 36, 12);
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   714
		/* substract the newly added space from the matrix since it was meant for the scrollbar */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   715
		w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   716
	}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   717
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   718
	/* Set the minimum window size to the current window size */
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6206
diff changeset
   719
	w->resize.width  = w->width;
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   720
	w->resize.height = w->height;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   721
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   722
	SetupStringsForDepotWindow(w, type);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   723
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   724
	w->widget[DEPOT_WIDGET_MATRIX].data =
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   725
		(w->vscroll.cap * 0x100) // number of rows to draw on the background
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   726
		+ (type == VEH_TRAIN ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   727
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   728
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   729
	w->SetWidgetsHiddenState(type != VEH_TRAIN,
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   730
		DEPOT_WIDGET_H_SCROLL,
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   731
		DEPOT_WIDGET_SELL_CHAIN,
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   732
		WIDGET_LIST_END);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   733
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   734
	ResizeDepotButtons(w);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   735
}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   736
4740
e562a2cde601 (svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
bjarni
parents: 4739
diff changeset
   737
void DepotSortList(Vehicle **v, uint16 length);
e562a2cde601 (svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
bjarni
parents: 4739
diff changeset
   738
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   739
static void DepotWndProc(Window *w, WindowEvent *e)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   740
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   741
	switch (e->event) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   742
		case WE_CREATE:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   743
			WP(w, depot_d).sel = INVALID_VEHICLE;
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   744
			WP(w, depot_d).vehicle_list  = NULL;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   745
			WP(w, depot_d).wagon_list    = NULL;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   746
			WP(w, depot_d).engine_count  = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   747
			WP(w, depot_d).wagon_count   = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   748
			WP(w, depot_d).generate_list = true;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   749
			break;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   750
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   751
		case WE_INVALIDATE_DATA:
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   752
			WP(w, depot_d).generate_list = true;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   753
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   754
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   755
		case WE_PAINT:
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   756
			if (WP(w, depot_d).generate_list) {
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   757
				/* Generate the vehicle list
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   758
				 * It's ok to use the wagon pointers for non-trains as they will be ignored */
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   759
				BuildDepotVehicleList(WP(w, depot_d).type, w->window_number,
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   760
					&WP(w, depot_d).vehicle_list, &WP(w, depot_d).engine_list_length, &WP(w, depot_d).engine_count,
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   761
					&WP(w, depot_d).wagon_list,   &WP(w, depot_d).wagon_list_length,  &WP(w, depot_d).wagon_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   762
				WP(w, depot_d).generate_list = false;
4740
e562a2cde601 (svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
bjarni
parents: 4739
diff changeset
   763
				DepotSortList(WP(w, depot_d).vehicle_list, WP(w, depot_d).engine_count);
4763
cd72f1d9f4a6 (svn r6677) -Codechange r6651: [depot window] disabled the check for the correct cache in the depot window
bjarni
parents: 4762
diff changeset
   764
//#ifndef NDEBUG
cd72f1d9f4a6 (svn r6677) -Codechange r6651: [depot window] disabled the check for the correct cache in the depot window
bjarni
parents: 4762
diff changeset
   765
#if 0
cd72f1d9f4a6 (svn r6677) -Codechange r6651: [depot window] disabled the check for the correct cache in the depot window
bjarni
parents: 4762
diff changeset
   766
/* We disabled this check for now, but will keep it to quickly make this test again later (if we change some code) */
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   767
			} else {
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   768
				/* Here we got a piece of code, that only checks if we got a different number of vehicles in the depot list and the number of vehicles actually being in the depot.
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   769
				 * IF they aren't the same, then WE_INVALIDATE_DATA should have been called somewhere, but it wasn't and we got a bug
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   770
				 * Since this is a time consuming check and not nice to memory fragmentation, it may not stay for long, but it's a good way to check this
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   771
				 * We can turn it on/off by switching between #ifndef NDEBUG and #if 0 */
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   772
				Vehicle **engines = NULL, **wagons = NULL;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   773
				uint16 engine_count = 0, engine_length = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   774
				uint16 wagon_count  = 0, wagon_length  = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   775
				BuildDepotVehicleList(WP(w, depot_d).type, w->window_number, &engines, &engine_length, &engine_count,
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   776
									  &wagons,  &wagon_length,  &wagon_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   777
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   778
				assert(engine_count == WP(w, depot_d).engine_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   779
				assert(wagon_count == WP(w, depot_d).wagon_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   780
				free((void*)engines);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   781
				free((void*)wagons);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   782
#endif
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   783
			}
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   784
			DrawDepotWindow(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   785
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   786
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   787
		case WE_CLICK:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   788
			switch (e->we.click.widget) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   789
				case DEPOT_WIDGET_MATRIX: // List
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   790
					DepotClick(w, e->we.click.pt.x, e->we.click.pt.y);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   791
					break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   792
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   793
				case DEPOT_WIDGET_BUILD: // Build vehicle
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   794
					ResetObjectToPlace();
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6034
diff changeset
   795
					ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   796
					break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   797
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   798
				case DEPOT_WIDGET_CLONE: // Clone button
8524
baf4ab1ba18d (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8493
diff changeset
   799
					w->InvalidateWidget(DEPOT_WIDGET_CLONE);
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   800
					w->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   801
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   802
					if (w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) {
4935
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   803
						static const CursorID clone_icons[] = {
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   804
							SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   805
							SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   806
						};
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   807
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   808
						_place_clicked_vehicle = NULL;
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: 6144
diff changeset
   809
						SetObjectToPlaceWnd(clone_icons[WP(w, depot_d).type], PAL_NONE, VHM_RECT, w);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   810
					} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   811
						ResetObjectToPlace();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   812
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   813
						break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   814
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   815
				case DEPOT_WIDGET_LOCATION: ScrollMainWindowToTile(w->window_number); break;
4640
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   816
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   817
				case DEPOT_WIDGET_STOP_ALL:
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   818
				case DEPOT_WIDGET_START_ALL:
4762
58d2f43ebdda (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4759
diff changeset
   819
					DoCommandP(w->window_number, 0, WP(w, depot_d).type | (e->we.click.widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP);
4640
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   820
					break;
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   821
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   822
				case DEPOT_WIDGET_SELL_ALL:
4690
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   823
					/* Only open the confimation window if there are anything to sell */
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   824
					if (WP(w, depot_d).engine_count != 0 || WP(w, depot_d).wagon_count != 0) {
5670
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   825
						static const StringID confirm_captions[] = {
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   826
							STR_8800_TRAIN_DEPOT,
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   827
							STR_9003_ROAD_VEHICLE_DEPOT,
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   828
							STR_9803_SHIP_DEPOT,
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   829
							STR_A002_AIRCRAFT_HANGAR
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   830
						};
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   831
						TileIndex tile = w->window_number;
5711
c466a5cc386e (svn r7726) -Fix (r7622, FS#497): segmentation fault on pressing the 'sell all airplanes'.
rubidium
parents: 5670
diff changeset
   832
						byte vehtype = WP(w, depot_d).type;
5670
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   833
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   834
						SetDParam(0, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index);
5670
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   835
						ShowQuery(
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: 6144
diff changeset
   836
							confirm_captions[vehtype],
5670
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   837
							STR_DEPOT_SELL_CONFIRMATION_TEXT,
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   838
							w,
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   839
							DepotSellAllConfirmationCallback
c6dcca763ebb (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   840
						);
4690
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   841
					}
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   842
					break;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   843
4681
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   844
				case DEPOT_WIDGET_VEHICLE_LIST:
5996
d4b66530ded4 (svn r8293) -Codechange: overloaded ShowVehicleListWindow() so it can open all types of vehicle lists (depending on arguments)
bjarni
parents: 5919
diff changeset
   845
					ShowVehicleListWindow(GetTileOwner(w->window_number), WP(w, depot_d).type, (TileIndex)w->window_number);
4681
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   846
					break;
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   847
4662
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   848
				case DEPOT_WIDGET_AUTOREPLACE:
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   849
					DoCommandP(w->window_number, WP(w, depot_d).type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE);
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   850
					break;
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   851
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   852
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   853
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   854
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   855
		case WE_PLACE_OBJ: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   856
			ClonePlaceObj(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   857
		} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   858
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   859
		case WE_ABORT_PLACE_OBJ: {
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   860
			w->RaiseWidget(DEPOT_WIDGET_CLONE);
8524
baf4ab1ba18d (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8493
diff changeset
   861
			w->InvalidateWidget(DEPOT_WIDGET_CLONE);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   862
		} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   863
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   864
			/* check if a vehicle in a depot was clicked.. */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   865
		case WE_MOUSELOOP: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   866
			const Vehicle *v = _place_clicked_vehicle;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   867
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   868
			/* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   869
			if (v != NULL && w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   870
				_place_clicked_vehicle = NULL;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   871
				HandleCloneVehClick(v, w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   872
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   873
		} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   874
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   875
		case WE_DESTROY:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   876
			DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   877
			free((void*)WP(w, depot_d).vehicle_list);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   878
			free((void*)WP(w, depot_d).wagon_list);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   879
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   880
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   881
		case WE_DRAGDROP:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   882
			switch (e->we.click.widget) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   883
				case DEPOT_WIDGET_MATRIX: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   884
					Vehicle *v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   885
					VehicleID sel = WP(w, depot_d).sel;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   886
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   887
					WP(w, depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   888
					SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   889
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   890
					if (WP(w, depot_d).type == VEH_TRAIN) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   891
						GetDepotVehiclePtData gdvp;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   892
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   893
						if (GetVehicleFromDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE &&
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   894
							sel != INVALID_VEHICLE) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   895
							if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   896
								DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   897
							} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   898
								TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   899
							} else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) {
7982
539e32cc37ce (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7975
diff changeset
   900
								ShowVehicleViewWindow(gdvp.head);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   901
							}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   902
						}
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   903
					} else if (GetVehicleFromDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v, NULL) == MODE_DRAG_VEHICLE &&
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   904
						v != NULL &&
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   905
						sel == v->index) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   906
						ShowVehicleViewWindow(v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   907
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   908
				} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   909
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   910
				case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   911
					if (!w->IsWidgetDisabled(DEPOT_WIDGET_SELL) &&
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   912
						WP(w, depot_d).sel != INVALID_VEHICLE) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   913
						Vehicle *v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   914
						uint command;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   915
						int sell_cmd;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   916
						bool is_engine;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   917
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8453
diff changeset
   918
						if (w->IsWidgetDisabled(e->we.click.widget)) return;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   919
						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   920
8532
3099f32f9bfd (svn r11596) -Codechange: Use the Window member HandleButtonClick and remove its now useless counterpart function
belugas
parents: 8524
diff changeset
   921
						w->HandleButtonClick(e->we.click.widget);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   922
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   923
						v = GetVehicle(WP(w, depot_d).sel);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   924
						WP(w, depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   925
						SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   926
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   927
						sell_cmd = (v->type == VEH_TRAIN && (e->we.click.widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   928
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   929
						is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v)));
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   930
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   931
						if (is_engine) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   932
							_backup_orders_tile = v->tile;
8149
eb78fb69096f (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 8044
diff changeset
   933
							BackupVehicleOrders(v);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   934
						}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   935
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   936
						switch (v->type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   937
							case VEH_TRAIN:    command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   938
							case VEH_ROAD:     command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE);       break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   939
							case VEH_SHIP:     command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP);                   break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   940
							case VEH_AIRCRAFT: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT);           break;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   941
							default: NOT_REACHED(); command = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   942
						}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   943
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   944
						if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   945
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   946
					break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   947
				default:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   948
					WP(w, depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   949
					SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   950
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   951
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   952
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   953
		case WE_RESIZE:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   954
			w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   955
			w->hscroll.cap += e->we.sizing.diff.x / (int)w->resize.step_width;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   956
			w->widget[DEPOT_WIDGET_MATRIX].data = (w->vscroll.cap << 8) + (WP(w, depot_d).type == VEH_TRAIN ? 1 : w->hscroll.cap);
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   957
			ResizeDepotButtons(w);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   958
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   959
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   960
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   961
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   962
/** Opens a depot window
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   963
 * @param tile The tile where the depot/hangar is located
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   964
 * @param type The type of vehicles in the depot
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   965
 */
7134
c5a90dd41166 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 7117
diff changeset
   966
void ShowDepotWindow(TileIndex tile, VehicleType type)
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   967
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   968
	Window *w;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   969
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   970
	switch (type) {
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   971
		default: NOT_REACHED();
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   972
		case VEH_TRAIN:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   973
			w = AllocateWindowDescFront(&_train_depot_desc, tile); break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   974
		case VEH_ROAD:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   975
			w = AllocateWindowDescFront(&_road_depot_desc, tile); break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   976
		case VEH_SHIP:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   977
			w = AllocateWindowDescFront(&_ship_depot_desc, tile); break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
   978
		case VEH_AIRCRAFT:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   979
			w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   980
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   981
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   982
	if (w != NULL) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   983
		w->caption_color = GetTileOwner(tile);
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   984
		CreateDepotListWindow(w, type);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   985
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   986
}
5255
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   987
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   988
/** Removes the highlight of a vehicle in a depot window
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   989
 * @param *v Vehicle to remove all highlights from
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   990
 */
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   991
void DeleteDepotHighlightOfVehicle(const Vehicle *v)
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   992
{
5265
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
   993
	Window *w;
5255
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   994
5260
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
   995
	/* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
   996
	 * If that is the case, we can skip looping though the windows and save time                                */
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
   997
	if (_special_mouse_mode != WSM_DRAGDROP) return;
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
   998
5265
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
   999
	w = FindWindowById(WC_VEHICLE_DEPOT, v->tile);
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1000
	if (w != NULL) {
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1001
		WP(w, depot_d).sel = INVALID_VEHICLE;
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1002
		ResetObjectToPlace();
5255
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1003
	}
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1004
}