src/depot_gui.cpp
author bjarni
Mon, 22 Jan 2007 00:26:46 +0000
changeset 5783 e207986ffe71
parent 5779 a694ce1457bb
child 5786 9bbd2d7f2a30
permissions -rw-r--r--
(svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
-Codechange: the build ship window is merged into build_vehicle_gui.cpp
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
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     3
#include "stdafx.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     4
#include "openttd.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     5
#include "functions.h"
4654
113ca7bde069 (svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents: 4653
diff changeset
     6
#include "train.h"
113ca7bde069 (svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents: 4653
diff changeset
     7
#include "roadveh.h"
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     8
#include "ship.h"
4653
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
     9
#include "aircraft.h"
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    10
#include "table/strings.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    11
#include "table/sprites.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    12
#include "gui.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    13
#include "gfx.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    14
#include "vehicle.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    15
#include "viewport.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    16
#include "command.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    17
#include "depot.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    18
#include "vehicle_gui.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    19
#include "station_map.h"
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    20
#include "newgrf_engine.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
    21
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
    22
/*
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
    23
 * 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
    24
 * 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
    25
 * 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
    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
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    28
/* 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
    29
enum DepotWindowWidgets {
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    30
	DEPOT_WIDGET_CLOSEBOX = 0,
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    31
	DEPOT_WIDGET_CAPTION,
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    32
	DEPOT_WIDGET_STICKY,
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    33
	DEPOT_WIDGET_SELL,
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
    34
	DEPOT_WIDGET_SELL_CHAIN,
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    35
	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
    36
	DEPOT_WIDGET_AUTOREPLACE,
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    37
	DEPOT_WIDGET_MATRIX,
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    38
	DEPOT_WIDGET_V_SCROLL, // Vertical scrollbar
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    39
	DEPOT_WIDGET_H_SCROLL, // Horizontal scrollbar
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    40
	DEPOT_WIDGET_BUILD,
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    41
	DEPOT_WIDGET_CLONE,
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    42
	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
    43
	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
    44
	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
    45
	DEPOT_WIDGET_START_ALL,
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    46
	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
    47
};
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
    48
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    49
/* Widget array for all depot windows.
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    50
 * 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
    51
 * 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
    52
 * 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
    53
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
    54
/* 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
    55
 * 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
    56
 * 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
    57
 *    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
    58
 */
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    59
static const Widget _depot_widgets[] = {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    60
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW},            // DEPOT_WIDGET_CLOSEBOX
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    61
	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   292,     0,    13, 0x0,                 STR_018C_WINDOW_TITLE_DRAG_THIS},  // DEPOT_WIDGET_CAPTION
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    62
	{  WWT_STICKYBOX,     RESIZE_LR,    14,   293,   304,     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
    63
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4935
diff changeset
    64
	/* Widgets are set up run-time */
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
    65
	{     WWT_IMGBTN,    RESIZE_LRB,    14,   270,   292,    14,    37, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_SELL
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    66
	{     WWT_IMGBTN,   RESIZE_LRTB,    14,   270,   292,    14,    37, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only
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
    67
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   270,   292,    38,    60, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_SELL_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
    68
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   270,   292,    61,    83, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_AUTOREPLACE
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    69
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
    70
	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   269,    14,    83, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_MATRIX
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
    71
	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   293,   304,    14,    83, 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
    72
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    73
	{ WWT_HSCROLLBAR,    RESIZE_RTB,    14,     0,   269,    72,    83, 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
    74
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    75
	/* 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
    76
	 * This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0            */
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
    77
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,    85,    84,    95, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_BUILD
4968
59dcd41ce2d0 (svn r6971) -Fix r6961: WWT_NODISTXTBTN buttons were normal buttons not push buttons
glx
parents: 4963
diff changeset
    78
	{    WWT_TEXTBTN,     RESIZE_TB,    14,    86,   170,    84,    95, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_CLONE
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    79
	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   171,   257,    84,    95, STR_00E4_LOCATION,   STR_NULL},                         // 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
    80
	{ WWT_PUSHTXTBTN,   RESIZE_LRTB,    14,   258,   269,    84,    95, 0x0,                 STR_NULL},                         // 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
    81
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   270,   280,    84,    95, SPR_FLAG_VEH_STOPPED,STR_NULL},                         // 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
    82
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   281,   292,    84,    95, SPR_FLAG_VEH_RUNNING,STR_NULL},                         // DEPOT_WIDGET_START_ALL
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
    83
	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   293,   304,    84,    95, 0x0,                 STR_RESIZE_BUTTON},                // DEPOT_WIDGET_RESIZE
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    84
	{   WIDGETS_END},
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
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    87
static void DepotWndProc(Window *w, WindowEvent *e);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    88
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    89
static const WindowDesc _train_depot_desc = {
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    90
	WDP_AUTO, WDP_AUTO, 305, 96,
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    91
	WC_VEHICLE_DEPOT,0,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    92
	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
    93
	_depot_widgets,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    94
	DepotWndProc
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    95
};
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
static const WindowDesc _road_depot_desc = {
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    98
	WDP_AUTO, WDP_AUTO, 305, 96,
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    99
	WC_VEHICLE_DEPOT,0,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   100
	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
   101
	_depot_widgets,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   102
	DepotWndProc
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   103
};
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   104
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   105
static const WindowDesc _ship_depot_desc = {
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   106
	WDP_AUTO, WDP_AUTO, 305, 96,
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   107
	WC_VEHICLE_DEPOT,0,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   108
	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
   109
	_depot_widgets,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   110
	DepotWndProc
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   111
};
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   112
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   113
static const WindowDesc _aircraft_depot_desc = {
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   114
	WDP_AUTO, WDP_AUTO, 305, 96,
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   115
	WC_VEHICLE_DEPOT,0,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   116
	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
   117
	_depot_widgets,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   118
	DepotWndProc
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   119
};
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   120
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   121
extern int WagonLengthToPixels(int len);
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
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
   124
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   125
	if (!success) return;
4653
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   126
	switch(GetVehicle(p1)->type) {
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   127
		case VEH_Train:    CcCloneTrain(   true, tile, p1, p2); break;
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   128
		case VEH_Road:     CcCloneRoadVeh( true, tile, p1, p2); break;
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   129
		case VEH_Ship:     CcCloneShip(    true, tile, p1, p2); break;
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   130
		case VEH_Aircraft: CcCloneAircraft(true, tile, p1, p2); break;
9f72ab9dc4a7 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   131
	}
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   132
}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   133
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   134
static inline void ShowVehicleViewWindow(const Vehicle *v)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   135
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   136
	switch (v->type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   137
		case VEH_Train:    ShowTrainViewWindow(v);    break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   138
		case VEH_Road:     ShowRoadVehViewWindow(v);  break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   139
		case VEH_Ship:     ShowShipViewWindow(v);     break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   140
		case VEH_Aircraft: ShowAircraftViewWindow(v); break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   141
		default: NOT_REACHED();
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
}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   144
5419
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   145
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
   146
{
5419
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   147
	if (confirmed) {
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   148
		TileIndex tile = w->window_number;
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   149
		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
   150
		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
   151
	}
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   152
}
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   153
4754
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   154
/** 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
   155
 * @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
   156
 * @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
   157
 * @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
   158
 * @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
   159
 */
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   160
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
   161
{
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   162
	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
   163
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   164
	switch (v->type) {
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   165
		case VEH_Train:
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   166
			DrawTrainImage(v, x + 21, y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   167
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   168
			/* 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
   169
			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   170
			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   171
			break;
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   172
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   173
		case VEH_Road:     DrawRoadVehImage( v, x + 24, y, WP(w, depot_d).sel); break;
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   174
		case VEH_Ship:     DrawShipImage(    v, x + 19, y, WP(w, depot_d).sel); break;
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   175
		case VEH_Aircraft: DrawAircraftImage(v, x + 12, y, WP(w, depot_d).sel); break;
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   176
		default: NOT_REACHED();
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   177
	}
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   178
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   179
	if (w->resize.step_height == 14) {
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   180
		/* VEH_Train and VEH_Road, which are low */
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   181
		diff_x = 15;
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   182
	} else {
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   183
		/* VEH_Ship and VEH_Aircraft, which are tall */
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   184
		diff_y = 12;
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   185
	}
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   186
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   187
	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
   188
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   189
	SetDParam(0, v->unitnumber);
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   190
	DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
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
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   193
static void DrawDepotWindow(Window *w)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   194
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   195
	Vehicle **vl = WP(w, depot_d).vehicle_list;
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   196
	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
   197
	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
   198
	uint16 hnum;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   199
	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
   200
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   201
	/* 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
   202
	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
   203
	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
   204
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   205
	/* setup disabled buttons */
4758
090cf0f1b35e (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   206
	SetWindowWidgetsDisabledState(w, !IsTileOwner(tile, _local_player),
090cf0f1b35e (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   207
		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
   208
		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
   209
		DEPOT_WIDGET_SELL,
090cf0f1b35e (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   210
		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
   211
		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
   212
		DEPOT_WIDGET_BUILD,
090cf0f1b35e (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   213
		DEPOT_WIDGET_CLONE,
090cf0f1b35e (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   214
		DEPOT_WIDGET_AUTOREPLACE,
090cf0f1b35e (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   215
		WIDGET_LIST_END);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   216
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   217
	/* determine amount of items for scroller */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   218
	if (WP(w, depot_d).type == VEH_Train) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   219
		hnum = 8;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   220
		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
   221
			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
   222
			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
   223
		}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   224
		/* 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
   225
		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
   226
		SetHScrollCount(w, WagonLengthToPixels(hnum));
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   227
	} else {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   228
		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
   229
	}
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
	/* locate the depot struct */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   232
	if (WP(w, depot_d).type == VEH_Aircraft) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   233
		SetDParam(0, GetStationIndex(tile)); // Airport name
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   234
	} else {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   235
		Depot *depot = GetDepotByTile(tile);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   236
		assert(depot != NULL);
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
		SetDParam(0, depot->town_index);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   239
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   240
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   241
	DrawWindowWidgets(w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   242
4754
26ddeca70f94 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   243
	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
   244
	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
   245
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
   246
	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
   247
		byte i;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   248
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
   249
		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
   250
			/* 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
   251
			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
   252
			DrawVehicleInDepot(w, v, x, y);
4638
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
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
   256
	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
   257
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   258
	/* 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
   259
	for (; num < maxval; num++, y += 14) {
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   260
		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
   261
		const Vehicle *u;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   262
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   263
		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   264
		DrawString(x, y + 2, STR_8816, 0);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   265
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   266
		/*Draw the train counter */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   267
		i = 0;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   268
		u = v;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   269
		do i++; while ( (u=u->next) != NULL); // Determine length of train
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   270
		SetDParam(0, i);                      // Set the counter
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   271
		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   272
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   273
}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   274
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   275
typedef struct GetDepotVehiclePtData {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   276
	Vehicle *head;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   277
	Vehicle *wagon;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   278
} GetDepotVehiclePtData;
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
enum {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   281
	MODE_ERROR        =  1,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   282
	MODE_DRAG_VEHICLE =  0,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   283
	MODE_SHOW_VEHICLE = -1,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   284
	MODE_START_STOP   = -2,
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   285
};
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
static int GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh, GetDepotVehiclePtData *d)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   288
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   289
	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
   290
	uint xt, row, xm = 0, ym = 0;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   291
	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
   292
	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
   293
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   294
	if (WP(w, depot_d).type == VEH_Train) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   295
		xt = 0;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   296
		x -= 23;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   297
	} else {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   298
		xt = x / w->resize.step_width;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   299
		xm = x % w->resize.step_width;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   300
		if (xt >= w->hscroll.cap) return MODE_ERROR;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   301
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   302
		ym = (y - 14) % w->resize.step_height;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   303
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   304
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   305
	row = (y - 14) / w->resize.step_height;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   306
	if (row >= w->vscroll.cap) return MODE_ERROR;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   307
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
   308
	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
   309
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
   310
	if (WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count <= pos) {
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
   311
		if (WP(w, depot_d).type == VEH_Train) {
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
   312
			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
   313
			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
   314
			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
   315
		} 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
   316
			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
   317
		}
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
   318
	}
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   319
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   320
	if (WP(w, depot_d).engine_count > pos) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   321
		*veh = vl[pos];
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   322
		skip = w->hscroll.pos;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   323
	} else {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   324
		vl = WP(w, depot_d).wagon_list;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   325
		pos -= WP(w, depot_d).engine_count;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   326
		*veh = vl[pos];
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   327
		/* free wagons don't have an initial loco. */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   328
		x -= _traininfo_vehicle_width;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   329
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   330
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   331
	switch (WP(w, depot_d).type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   332
		case VEH_Train: {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   333
			Vehicle *v = *veh;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   334
			d->head = d->wagon = v;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   335
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   336
			/* 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
   337
			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
   338
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   339
			skip = (skip * 8) / _traininfo_vehicle_width;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   340
			x = (x * 8) / _traininfo_vehicle_width;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   341
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   342
			/* Skip vehicles that are scrolled off the list */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   343
			x += skip;
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
			/* find the vehicle in this row that was clicked */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   346
			while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->next;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   347
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   348
			/* if an articulated part was selected, find its parent */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   349
			while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   350
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   351
			d->wagon = v;
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
			return MODE_DRAG_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   354
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   355
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   356
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   357
		case VEH_Road:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   358
			if (xm >= 24) return MODE_DRAG_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   359
			if (xm <= 16) return MODE_SHOW_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   360
			break;
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
		case VEH_Ship:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   363
			if (xm >= 19) return MODE_DRAG_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   364
			if (ym <= 10) return MODE_SHOW_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   365
			break;
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
		case VEH_Aircraft:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   368
			if (xm >= 12) return MODE_DRAG_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   369
			if (ym <= 12) return MODE_SHOW_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   370
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   371
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   372
		default: NOT_REACHED();
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   373
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   374
	return MODE_START_STOP;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   375
}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   376
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   377
static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   378
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   379
	Vehicle *v;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   380
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   381
	v = GetVehicle(sel);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   382
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   383
	if (v == wagon) return;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   384
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   385
	if (wagon == NULL) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   386
		if (head != NULL) wagon = GetLastVehicleInChain(head);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   387
	} else  {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   388
		wagon = GetPrevVehicleInChain(wagon);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   389
		if (wagon == NULL) return;
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
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   392
	if (wagon == v) return;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   393
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   394
	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
   395
}
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
static void DepotClick(Window *w, int x, int y)
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
	GetDepotVehiclePtData gdvp;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   400
	Vehicle *v = NULL;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   401
	int mode = GetVehicleFromDepotWndPt(w, x, y, &v, &gdvp);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   402
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   403
	/* share / copy orders */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   404
	if (_thd.place_mode && mode <= 0) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   405
		_place_clicked_vehicle = (WP(w, depot_d).type == VEH_Train ? gdvp.head : v);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   406
		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
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   409
	if (WP(w, depot_d).type == VEH_Train) v = gdvp.wagon;
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
	switch (mode) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   412
		case MODE_ERROR: // invalid
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   413
			return;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   414
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   415
		case MODE_DRAG_VEHICLE: { // start dragging of vehicle
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   416
			VehicleID sel = WP(w, depot_d).sel;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   417
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   418
			if (WP(w, depot_d).type == VEH_Train && sel != INVALID_VEHICLE) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   419
				WP(w,depot_d).sel = INVALID_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   420
				TrainDepotMoveVehicle(v, sel, gdvp.head);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   421
			} else if (v != NULL) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   422
				int image;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   423
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   424
				switch (WP(w, depot_d).type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   425
					case VEH_Train:    image = GetTrainImage(v, DIR_W);    break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   426
					case VEH_Road:     image = GetRoadVehImage(v, DIR_W);  break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   427
					case VEH_Ship:     image = GetShipImage(v, DIR_W);     break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   428
					case VEH_Aircraft: image = GetAircraftImage(v, DIR_W); break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   429
					default: NOT_REACHED(); image = 0;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   430
				}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   431
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   432
				WP(w, depot_d).sel = v->index;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   433
				SetWindowDirty(w);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   434
				SetObjectToPlaceWnd(image, GetVehiclePalette(v), 4, w);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   435
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   436
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   437
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   438
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   439
		case MODE_SHOW_VEHICLE: // show info window
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   440
			ShowVehicleViewWindow(v);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   441
			break;
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
		case MODE_START_STOP: { // click start/stop flag
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   444
			uint command;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   445
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   446
			switch (WP(w, depot_d).type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   447
				case VEH_Train:    command = CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN);          break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   448
				case VEH_Road:     command = CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   449
				case VEH_Ship:     command = CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP);            break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   450
				case VEH_Aircraft: command = CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT);    break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   451
				default: NOT_REACHED(); command = 0;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   452
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   453
			DoCommandP(v->tile, v->index, 0, NULL, command);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   454
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   455
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   456
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   457
		default: NOT_REACHED();
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
}
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
/**
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   462
 * Clones a vehicle
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   463
 * @param *v is the original vehicle to clone
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   464
 * @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
   465
 */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   466
static void HandleCloneVehClick(const Vehicle *v, const Window *w)
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
	uint error_str;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   469
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   470
	if (v == NULL) return;
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
	if (v->type == VEH_Train && !IsFrontEngine(v)) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   473
		v = GetFirstVehicleInChain(v);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   474
		/* Do nothing when clicking on a train in depot with no loc attached */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   475
		if (!IsFrontEngine(v)) return;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   476
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   477
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   478
	switch (v->type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   479
		case VEH_Train:    error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   480
		case VEH_Road:     error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE);     break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   481
		case VEH_Ship:     error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP);             break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   482
		case VEH_Aircraft: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT);         break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   483
		default: return;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   484
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   485
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   486
	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
   487
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   488
	ResetObjectToPlace();
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   489
}
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
static void ClonePlaceObj(const Window *w)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   492
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   493
	const Vehicle *v = CheckMouseOverVehicle();
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   494
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   495
	if (v != NULL) HandleCloneVehClick(v, w);
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
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   498
static void ResizeDepotButtons(Window *w)
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   499
{
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   500
	/* We got the widget moved around. Now we will make some widgets to fill the gap between some widgets in equal sizes */
4646
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   501
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   502
	/* Make the buttons in the bottom equal in size */
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   503
	w->widget[DEPOT_WIDGET_BUILD].right    = w->widget[DEPOT_WIDGET_LOCATION].right / 3;
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   504
	w->widget[DEPOT_WIDGET_LOCATION].left  = w->widget[DEPOT_WIDGET_BUILD].right * 2;
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   505
	w->widget[DEPOT_WIDGET_CLONE].left     = w->widget[DEPOT_WIDGET_BUILD].right + 1;
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   506
	w->widget[DEPOT_WIDGET_CLONE].right    = w->widget[DEPOT_WIDGET_LOCATION].left - 1;
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   507
d3d73ee03bbc (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
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) {
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   523
		case VEH_Train:
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   526
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_DEPOT_TRAIN_TIP;
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   528
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP;
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
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   547
		case VEH_Road:
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   550
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_DEPOT_ROADVEH_TIP;
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   552
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP;
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
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   571
		case VEH_Ship:
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   574
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_DEPOT_SHIP_TIP;
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   576
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP;
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
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   595
		case VEH_Aircraft:
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   598
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_HANGAR_TIP;
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;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   600
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP;
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
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   621
static void CreateDepotListWindow(Window *w, byte type)
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   622
{
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   623
	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
   624
	_backup_orders_tile = 0;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   625
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   626
	/* Resize the window according to the vehicle type */
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   627
	switch (type) {
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   628
		default: NOT_REACHED();
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   629
		case VEH_Train:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   630
			w->vscroll.cap = 6;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   631
			w->hscroll.cap = 10 * 29;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   632
			w->resize.step_width = 1;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   633
			ResizeWindow(w, 56, 26);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   634
			break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   635
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   636
		case VEH_Road:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   637
			w->vscroll.cap = 5;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   638
			w->hscroll.cap = 5;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   639
			w->resize.step_width = 56;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   640
			ResizeWindow(w, 10, 0);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   641
			break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   642
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   643
		case VEH_Ship:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   644
			w->vscroll.cap = 3;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   645
			w->hscroll.cap = 3;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   646
			w->resize.step_width = 90;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   647
			ResizeWindow(w, 0, 2);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   648
			break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   649
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   650
		case VEH_Aircraft:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   651
			w->vscroll.cap = 3;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   652
			w->hscroll.cap = 4;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   653
			w->resize.step_width = 74;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   654
			ResizeWindow(w, 26, 2);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   655
			break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   656
	}
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   657
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   658
	/* Set the minimum window size to the current window size */
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   659
	w->resize.width = w->width;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   660
	w->resize.height = w->height;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   661
	w->resize.step_height = GetVehicleListHeight(type);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   662
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   663
	SetupStringsForDepotWindow(w, type);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   664
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   665
	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
   666
		(w->vscroll.cap * 0x100) // number of rows to draw on the background
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   667
		+ (type == VEH_Train ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   668
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   669
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   670
	SetWindowWidgetsHiddenState(w, type != VEH_Train,
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   671
		DEPOT_WIDGET_H_SCROLL,
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   672
		DEPOT_WIDGET_SELL_CHAIN,
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   673
		WIDGET_LIST_END);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   674
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   675
	/* The train depot has a horizontal scroller, make the matrix that much shorter to fit */
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   676
	if (type == VEH_Train) w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   677
	ResizeDepotButtons(w);
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   678
}
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   679
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
   680
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
   681
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   682
static void DepotWndProc(Window *w, WindowEvent *e)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   683
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   684
	switch (e->event) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   685
		case WE_CREATE:
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   686
			WP(w, depot_d).sel = INVALID_VEHICLE;
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   687
			WP(w, depot_d).vehicle_list  = NULL;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   688
			WP(w, depot_d).wagon_list    = NULL;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   689
			WP(w, depot_d).engine_count  = 0;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   690
			WP(w, depot_d).wagon_count   = 0;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   691
			WP(w, depot_d).generate_list = true;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   692
			break;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   693
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   694
		case WE_INVALIDATE_DATA:
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   695
			WP(w, depot_d).generate_list = true;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   696
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   697
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   698
		case WE_PAINT:
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   699
			if (WP(w, depot_d).generate_list) {
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   700
				/* Generate the vehicle list
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   701
				 * 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
   702
				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
   703
					&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
   704
					&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
   705
				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
   706
				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
   707
//#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
   708
#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
   709
/* 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
   710
			} else {
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   711
				/* 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
   712
				 * 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
   713
				 * 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
   714
				 * 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
   715
				Vehicle **engines = NULL, **wagons = NULL;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   716
				uint16 engine_count = 0, engine_length = 0;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   717
				uint16 wagon_count  = 0, wagon_length  = 0;
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   718
				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
   719
									  &wagons,  &wagon_length,  &wagon_count);
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   720
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   721
				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
   722
				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
   723
				free((void*)engines);
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   724
				free((void*)wagons);
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   725
#endif
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   726
			}
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   727
			DrawDepotWindow(w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   728
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   729
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   730
		case WE_CLICK:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   731
			switch (e->we.click.widget) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   732
				case DEPOT_WIDGET_MATRIX: // List
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   733
					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
   734
					break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   735
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   736
				case DEPOT_WIDGET_BUILD: // Build vehicle
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   737
					ResetObjectToPlace();
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   738
					switch (WP(w, depot_d).type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   739
						case VEH_Road:     ShowBuildRoadVehWindow(w->window_number);  break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5779
diff changeset
   740
						case VEH_Ship:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5745
diff changeset
   741
						case VEH_Train:
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents: 4797
diff changeset
   742
						case VEH_Aircraft:
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents: 4797
diff changeset
   743
							ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents: 4797
diff changeset
   744
							break;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   745
					default: NOT_REACHED();
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   746
					}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   747
					break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   748
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   749
				case DEPOT_WIDGET_CLONE: // Clone button
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   750
					InvalidateWidget(w, DEPOT_WIDGET_CLONE);
4733
7405f1da28f1 (svn r6645) -Fix(r6631): Forgot two click_state occurences
belugas
parents: 4719
diff changeset
   751
					ToggleWidgetLoweredState(w, DEPOT_WIDGET_CLONE);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   752
4733
7405f1da28f1 (svn r6645) -Fix(r6631): Forgot two click_state occurences
belugas
parents: 4719
diff changeset
   753
					if (IsWindowWidgetLowered(w, 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
   754
						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
   755
							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
   756
							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
   757
						};
1eeda247f1ea (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   758
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   759
						_place_clicked_vehicle = NULL;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5601
diff changeset
   760
						SetObjectToPlaceWnd(clone_icons[WP(w, depot_d).type - VEH_Train], PAL_NONE, VHM_RECT, w);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   761
					} else {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   762
						ResetObjectToPlace();
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   763
					}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   764
						break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   765
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   766
				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
   767
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   768
				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
   769
				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
   770
					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
   771
					break;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   772
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   773
				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
   774
					/* 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
   775
					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
   776
						static const StringID confirm_captions[] = {
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   777
							STR_8800_TRAIN_DEPOT,
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   778
							STR_9003_ROAD_VEHICLE_DEPOT,
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   779
							STR_9803_SHIP_DEPOT,
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   780
							STR_A002_AIRCRAFT_HANGAR
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   781
						};
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   782
						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
   783
						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
   784
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   785
						SetDParam(0, (vehtype == VEH_Aircraft) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index);
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   786
						ShowQuery(
5460
dd591800bf3f (svn r7726) -Fix (r7622, FS#497): segmentation fault on pressing the 'sell all airplanes'.
rubidium
parents: 5419
diff changeset
   787
							confirm_captions[vehtype - VEH_Train],
5419
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   788
							STR_DEPOT_SELL_CONFIRMATION_TEXT,
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   789
							w,
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   790
							DepotSellAllConfirmationCallback
a3d7068578bd (svn r7622) -Codechange: Convert some more windows to ShowQuery. This includes the depot
Darkvater
parents: 5269
diff changeset
   791
						);
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
   792
					}
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   793
					break;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   794
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
   795
				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
   796
					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
   797
					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
   798
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   799
				case DEPOT_WIDGET_AUTOREPLACE:
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   800
					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
   801
					break;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   802
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   803
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   804
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   805
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   806
		case WE_PLACE_OBJ: {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   807
			ClonePlaceObj(w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   808
		} break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   809
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   810
		case WE_ABORT_PLACE_OBJ: {
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   811
			RaiseWindowWidget(w, DEPOT_WIDGET_CLONE);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   812
			InvalidateWidget(w, DEPOT_WIDGET_CLONE);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   813
		} break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   814
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   815
			/* check if a vehicle in a depot was clicked.. */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   816
		case WE_MOUSELOOP: {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   817
			const Vehicle *v = _place_clicked_vehicle;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   818
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   819
			/* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   820
			if (v != NULL && IsWindowWidgetLowered(w, DEPOT_WIDGET_CLONE)) {
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   821
				_place_clicked_vehicle = NULL;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   822
				HandleCloneVehClick(v, w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   823
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   824
		} break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   825
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   826
		case WE_DESTROY:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   827
			DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   828
			free((void*)WP(w, depot_d).vehicle_list);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   829
			free((void*)WP(w, depot_d).wagon_list);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   830
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   831
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   832
		case WE_DRAGDROP:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   833
			switch (e->we.click.widget) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   834
				case DEPOT_WIDGET_MATRIX: {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   835
					Vehicle *v;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   836
					VehicleID sel = WP(w, depot_d).sel;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   837
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   838
					WP(w, depot_d).sel = INVALID_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   839
					SetWindowDirty(w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   840
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   841
					if (WP(w, depot_d).type == VEH_Train) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   842
						GetDepotVehiclePtData gdvp;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   843
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
   844
						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
   845
							sel != INVALID_VEHICLE) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   846
							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
   847
								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
   848
							} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   849
								TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   850
							} else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   851
								ShowTrainViewWindow(gdvp.head);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   852
							}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   853
						}
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
   854
					} 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
   855
						v != NULL &&
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   856
						sel == v->index) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   857
						ShowVehicleViewWindow(v);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   858
					}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   859
				} break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   860
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   861
				case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   862
					if (!IsWindowWidgetDisabled(w, DEPOT_WIDGET_SELL) &&
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   863
						WP(w, depot_d).sel != INVALID_VEHICLE) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   864
						Vehicle *v;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   865
						uint command;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   866
						int sell_cmd;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   867
						bool is_engine;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   868
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   869
						if (IsWindowWidgetDisabled(w, e->we.click.widget)) return;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   870
						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
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
						HandleButtonClick(w, e->we.click.widget);
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
						v = GetVehicle(WP(w, depot_d).sel);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   875
						WP(w, depot_d).sel = INVALID_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   876
						SetWindowDirty(w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   877
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   878
						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
   879
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   880
						is_engine = (!(v->type == VEH_Train && !IsFrontEngine(v)));
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   881
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   882
						if (is_engine) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   883
							_backup_orders_tile = v->tile;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   884
							BackupVehicleOrders(v, _backup_orders_data);
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
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   887
						switch (v->type) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   888
							case VEH_Train:    command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   889
							case VEH_Road:     command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE);       break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   890
							case VEH_Ship:     command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP);                   break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   891
							case VEH_Aircraft: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT);           break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   892
							default: NOT_REACHED(); command = 0;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   893
						}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   894
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   895
						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
   896
					}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   897
					break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   898
				default:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   899
					WP(w, depot_d).sel = INVALID_VEHICLE;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   900
					SetWindowDirty(w);
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   901
			}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   902
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   903
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   904
		case WE_RESIZE:
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   905
			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
   906
			w->hscroll.cap += e->we.sizing.diff.x / (int)w->resize.step_width;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   907
			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
   908
			ResizeDepotButtons(w);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   909
			break;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   910
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   911
}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   912
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   913
/** Opens a depot window
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   914
 * @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
   915
 * @param type The type of vehicles in the depot
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   916
 */
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   917
void ShowDepotWindow(TileIndex tile, byte type)
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   918
{
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   919
	Window *w;
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   920
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   921
	switch (type) {
5269
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   922
		default: NOT_REACHED();
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   923
		case VEH_Train:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   924
			w = AllocateWindowDescFront(&_train_depot_desc, tile); break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   925
		case VEH_Road:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   926
			w = AllocateWindowDescFront(&_road_depot_desc, tile); break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   927
		case VEH_Ship:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   928
			w = AllocateWindowDescFront(&_ship_depot_desc, tile); break;
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   929
		case VEH_Aircraft:
4b50973b21f6 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   930
			w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break;
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   931
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   932
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   933
	if (w != NULL) {
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   934
		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
   935
		CreateDepotListWindow(w, type);
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   936
	}
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   937
}
5255
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   938
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   939
/** 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
   940
 * @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
   941
 */
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   942
void DeleteDepotHighlightOfVehicle(const Vehicle *v)
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   943
{
5265
8fe8701184ac (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
   944
	Window *w;
5255
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   945
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
   946
	/* 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
   947
	 * 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
   948
	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
   949
5265
8fe8701184ac (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
   950
	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
   951
	if (w != NULL) {
8fe8701184ac (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
   952
		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
   953
		ResetObjectToPlace();
5255
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   954
	}
b693a9941b8c (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   955
}