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