depot_gui.c
author KUDr
Sat, 30 Dec 2006 18:25:01 +0000
branchcustombridgeheads
changeset 5609 ec38986d2c8e
parent 5269 3f3eead5ace2
child 5623 ef2a8a524a95
permissions -rw-r--r--
(svn r7655) [cbh] - Fix: [YAPF] another assert (on opposite cbh when it contained choice). Now it is possible to reach choice when exiting wormhole. So the wormhole cost must be taken into consideration when starting new YAPF node.
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     1
/* $Id$ */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     2
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     3
#include "stdafx.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     4
#include "openttd.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     5
#include "functions.h"
4654
71048359c6ac (svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents: 4653
diff changeset
     6
#include "train.h"
71048359c6ac (svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents: 4653
diff changeset
     7
#include "roadveh.h"
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
     8
#include "ship.h"
4653
091f530bae28 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
     9
#include "aircraft.h"
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    10
#include "table/strings.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    11
#include "table/sprites.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    12
#include "gui.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    13
#include "gfx.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    14
#include "vehicle.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    15
#include "viewport.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    16
#include "command.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    17
#include "depot.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    18
#include "vehicle_gui.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    19
#include "station_map.h"
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    20
#include "newgrf_engine.h"
4649
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    21
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    22
/*
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    23
 * Since all depot window sizes aren't the same, we need to modify sizes a little.
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    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.
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    25
 * How long they should be moved and for what window types are controlled in ShowDepotWindow()
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    26
 */
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    27
4646
c6f774de4f6f (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
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
    29
enum DepotWindowWidgets {
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    30
	DEPOT_WIDGET_CLOSEBOX = 0,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    31
	DEPOT_WIDGET_CAPTION,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    32
	DEPOT_WIDGET_STICKY,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    33
	DEPOT_WIDGET_SELL,
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
    34
	DEPOT_WIDGET_SELL_CHAIN,
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    35
	DEPOT_WIDGET_SELL_ALL,
4699
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    36
	DEPOT_WIDGET_AUTOREPLACE,
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    37
	DEPOT_WIDGET_MATRIX,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    38
	DEPOT_WIDGET_V_SCROLL, // Vertical scrollbar
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    39
	DEPOT_WIDGET_H_SCROLL, // Horizontal scrollbar
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    40
	DEPOT_WIDGET_BUILD,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    41
	DEPOT_WIDGET_CLONE,
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    42
	DEPOT_WIDGET_LOCATION,
4681
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
    43
	DEPOT_WIDGET_VEHICLE_LIST,
4699
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    44
	DEPOT_WIDGET_STOP_ALL,
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    45
	DEPOT_WIDGET_START_ALL,
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
    46
	DEPOT_WIDGET_RESIZE,
4649
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    47
};
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    48
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    49
/* Widget array for all depot windows.
8abe4f10b94b (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
5179f9adc5b3 (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
8abe4f10b94b (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
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    53
eced6da682cb (svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents: 4646
diff changeset
    54
/* When adding widgets, place them as you would place them for the ship depot and define how you want it to move in widget_moves[]
4650
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    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
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    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.
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    57
 *    Changing the size of those here will not have an effect at all. It should be done in ShowDepotWindow()
1a39612a6291 (svn r6526) -Codechange: [depot window] the train only widgets are now resized depending on the size of other widgets
bjarni
parents: 4649
diff changeset
    58
 */
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    59
static const Widget _depot_widgets[] = {
8abe4f10b94b (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
8abe4f10b94b (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
8abe4f10b94b (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
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
    63
4938
074f734a91ca (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
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    65
	{     WWT_IMGBTN,    RESIZE_LRB,    14,   270,   292,    14,    37, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_SELL
5269
3f3eead5ace2 (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
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    67
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   270,   292,    38,    60, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_SELL_ALL
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    68
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   270,   292,    61,    83, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_AUTOREPLACE
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    69
4659
2f99f35d5813 (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
2f99f35d5813 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    72
5269
3f3eead5ace2 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    74
8abe4f10b94b (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
8abe4f10b94b (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
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    77
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,    85,    84,    95, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_BUILD
4968
6cfec8858f17 (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
3f3eead5ace2 (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
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
    80
	{ WWT_PUSHTXTBTN,   RESIZE_LRTB,    14,   258,   269,    84,    95, 0x0,                 STR_NULL},                         // DEPOT_WIDGET_VEHICLE_LIST
4699
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    81
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   270,   280,    84,    95, SPR_FLAG_VEH_STOPPED,STR_NULL},                         // DEPOT_WIDGET_STOP_ALL
1f2d7bc70d0c (svn r6609) - Move the mass stop/start buttons of the depot window to the bottom row, to match all other vehicle list windows, and make it look a bit neater, (Suggested by skidd13)
peter1138
parents: 4690
diff changeset
    82
	{ WWT_PUSHIMGBTN,   RESIZE_LRTB,    14,   281,   292,    84,    95, SPR_FLAG_VEH_RUNNING,STR_NULL},                         // DEPOT_WIDGET_START_ALL
4659
2f99f35d5813 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    84
	{   WIDGETS_END},
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    85
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    86
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    87
static void DepotWndProc(Window *w, WindowEvent *e);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    88
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    89
static const WindowDesc _train_depot_desc = {
5269
3f3eead5ace2 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    91
	WC_VEHICLE_DEPOT,0,
8abe4f10b94b (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,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    93
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    94
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    95
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    96
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    97
static const WindowDesc _road_depot_desc = {
5269
3f3eead5ace2 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
    99
	WC_VEHICLE_DEPOT,0,
8abe4f10b94b (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,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   101
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   102
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   103
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   104
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   105
static const WindowDesc _ship_depot_desc = {
5269
3f3eead5ace2 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   107
	WC_VEHICLE_DEPOT,0,
8abe4f10b94b (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,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   109
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   110
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   111
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   112
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   113
static const WindowDesc _aircraft_depot_desc = {
5269
3f3eead5ace2 (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
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   115
	WC_VEHICLE_DEPOT,0,
8abe4f10b94b (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,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   117
	_depot_widgets,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   118
	DepotWndProc
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   119
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   120
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   121
extern int WagonLengthToPixels(int len);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   122
8abe4f10b94b (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)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   124
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   125
	if (!success) return;
4653
091f530bae28 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   126
	switch(GetVehicle(p1)->type) {
091f530bae28 (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;
091f530bae28 (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;
091f530bae28 (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;
091f530bae28 (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;
091f530bae28 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4652
diff changeset
   131
	}
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   132
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   133
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   134
static inline void ShowVehicleViewWindow(const Vehicle *v)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   135
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   136
	switch (v->type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   137
		case VEH_Train:    ShowTrainViewWindow(v);    break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   138
		case VEH_Road:     ShowRoadVehViewWindow(v);  break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   139
		case VEH_Ship:     ShowShipViewWindow(v);     break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   140
		case VEH_Aircraft: ShowAircraftViewWindow(v); break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   141
		default: NOT_REACHED();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   142
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   143
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   144
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   145
static void DepotSellAllWndProc(Window *w, WindowEvent *e)
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   146
{
4670
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   147
	TileIndex tile = w->window_number;
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   148
	byte vehicle_type = WP(w, depot_d).type;
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   149
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   150
	switch (e->event) {
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   151
		case WE_PAINT:
4670
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   152
			if (vehicle_type == VEH_Aircraft) {
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   153
				SetDParam(0, GetStationIndex(tile)); // Airport name
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   154
			} else {
4670
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   155
				Depot *depot = GetDepotByTile(tile);
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   156
				assert(depot != NULL);
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   157
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   158
				SetDParam(0, depot->town_index);
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   159
			}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   160
			DrawWindowWidgets(w);
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   161
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   162
			DrawStringCentered(150, 25, STR_DEPOT_SELL_ALL_VEHICLE_CONFIRM, 0);
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   163
			DrawStringCentered(150, 38, STR_ARE_YOU_SURE, 0);
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   164
			break;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   165
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   166
		case WE_CLICK:
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   167
			switch (e->we.click.widget) {
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   168
				case 4:
4670
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   169
					DoCommandP(tile, vehicle_type, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES);
5125
60b21cf18b50 (svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents: 5071
diff changeset
   170
					/* Fallthrough */
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   171
				case 3:
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   172
					DeleteWindow(w);
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   173
					break;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   174
			}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   175
			break;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   176
	}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   177
}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   178
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   179
static const Widget _depot_sell_all_widgets[] = {
4670
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   180
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,        STR_018B_CLOSE_WINDOW},
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   181
	{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   299,     0,    13, 0x0,             STR_018C_WINDOW_TITLE_DRAG_THIS},
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   182
	{      WWT_PANEL,   RESIZE_NONE,    14,     0,   299,    14,    71, 0x0,             STR_NULL},
4686
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   183
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    85,   144,    52,    63, STR_012E_CANCEL, STR_NULL},
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   184
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   155,   214,    52,    63, STR_SELL,        STR_NULL},
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   185
	{   WIDGETS_END},
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   186
};
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   187
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   188
static const WindowDesc _depot_sell_all_desc = {
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   189
	WDP_CENTER, WDP_CENTER, 300, 72,
4745
21632cc267bb (svn r6657) -Change: [depot window] sell all vehicles in depot confirm window now opens on top of depot window instead of in the middle of the screen
bjarni
parents: 4740
diff changeset
   190
	WC_DEPOT_SELL_ALL, WC_VEHICLE_DEPOT,
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   191
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   192
	_depot_sell_all_widgets,
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   193
	DepotSellAllWndProc
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   194
};
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   195
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   196
static void ShowDepotSellAllWindow(TileIndex tile, byte type)
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   197
{
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5070
diff changeset
   198
	Window *w = AllocateWindowDescFront(&_depot_sell_all_desc, tile);
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   199
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   200
	if (w != NULL) {
4670
279aa8ca7a71 (svn r6567) -Fix r6542: [depot window] solved an issue where the confimation window sometimes failed to close (spotted by MacLir)
bjarni
parents: 4668
diff changeset
   201
		w->caption_color = GetTileOwner(tile);
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   202
		WP(w, depot_d).type = type;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   203
		switch (type) {
4686
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   204
			case VEH_Train:
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   205
				w->widget[1].data     = STR_8800_TRAIN_DEPOT;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   206
				w->widget[3].tooltips = STR_DEPOT_SELL_ALL_CANCEL_TRAIN_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   207
				w->widget[4].tooltips = STR_DEPOT_SELL_ALL_TRAIN_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   208
				break;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   209
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   210
			case VEH_Road:
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   211
				w->widget[1].data     = STR_9003_ROAD_VEHICLE_DEPOT;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   212
				w->widget[3].tooltips = STR_DEPOT_SELL_ALL_CANCEL_ROADVEH_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   213
				w->widget[4].tooltips = STR_DEPOT_SELL_ALL_ROADVEH_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   214
				break;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   215
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   216
			case VEH_Ship:
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   217
				w->widget[1].data     = STR_9803_SHIP_DEPOT;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   218
				w->widget[3].tooltips = STR_DEPOT_SELL_ALL_CANCEL_SHIP_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   219
				w->widget[4].tooltips = STR_DEPOT_SELL_ALL_SHIP_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   220
				break;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   221
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   222
			case VEH_Aircraft:
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   223
				w->widget[1].data     = STR_A002_AIRCRAFT_HANGAR;
4686
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   224
				w->widget[3].tooltips = STR_DEPOT_SELL_ALL_CANCEL_AIRCRAFT_TIP;
4f4ac8a1445b (svn r6591) -Codechange: changed strings that used the word "depot" into one for each vehicle type
bjarni
parents: 4681
diff changeset
   225
				w->widget[4].tooltips = STR_DEPOT_SELL_ALL_AIRCRAFT_TIP;
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   226
				break;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   227
		}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   228
	}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   229
}
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   230
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   231
/** Draw a vehicle in the depot window in the box with the top left corner at x,y
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   232
 * @param *w Window to draw in
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   233
 * @param *v Vehicle to draw
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   234
 * @param x Left side of the box to draw in
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   235
 * @param y Top of the box to draw in
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   236
 */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   237
static void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y)
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   238
{
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   239
	byte diff_x = 0, diff_y = 0;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   240
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   241
	switch (v->type) {
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   242
		case VEH_Train:
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   243
			DrawTrainImage(v, x + 21, y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   244
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   245
			/* Number of wagons relative to a standard length wagon (rounded up) */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   246
			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   247
			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   248
			break;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   249
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   250
		case VEH_Road:     DrawRoadVehImage( v, x + 24, y, WP(w, depot_d).sel); break;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   251
		case VEH_Ship:     DrawShipImage(    v, x + 19, y, WP(w, depot_d).sel); break;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   252
		case VEH_Aircraft: DrawAircraftImage(v, x + 12, y, WP(w, depot_d).sel); break;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   253
		default: NOT_REACHED();
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   254
	}
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   255
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   256
	if (w->resize.step_height == 14) {
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   257
		/* VEH_Train and VEH_Road, which are low */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   258
		diff_x = 15;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   259
	} else {
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   260
		/* VEH_Ship and VEH_Aircraft, which are tall */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   261
		diff_y = 12;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   262
	}
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   263
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   264
	DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x + diff_x, y + diff_y);
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   265
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   266
	SetDParam(0, v->unitnumber);
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   267
	DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   268
}
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   269
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   270
static void DrawDepotWindow(Window *w)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   271
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   272
	Vehicle **vl = WP(w, depot_d).vehicle_list;
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   273
	TileIndex tile = w->window_number;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   274
	int x, y, i, hnum, max;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   275
	uint16 num = WP(w, depot_d).engine_count;
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   276
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   277
	/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   278
	uint16 rows_in_display   = w->widget[DEPOT_WIDGET_MATRIX].data >> 8;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   279
	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   280
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   281
	/* setup disabled buttons */
4758
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   282
	SetWindowWidgetsDisabledState(w, !IsTileOwner(tile, _local_player),
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   283
		DEPOT_WIDGET_STOP_ALL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   284
		DEPOT_WIDGET_START_ALL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   285
		DEPOT_WIDGET_SELL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   286
		DEPOT_WIDGET_SELL_CHAIN,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   287
		DEPOT_WIDGET_SELL_ALL,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   288
		DEPOT_WIDGET_BUILD,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   289
		DEPOT_WIDGET_CLONE,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   290
		DEPOT_WIDGET_AUTOREPLACE,
c955385b5432 (svn r6672) -Codechange: [depot & vehicle windows] applied SetWindowWidgetsDisabledState() and SetWindowWidgetsHiddenState() to depot and vehicle windows
bjarni
parents: 4754
diff changeset
   291
		WIDGET_LIST_END);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   292
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   293
	/* determine amount of items for scroller */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   294
	if (WP(w, depot_d).type == VEH_Train) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   295
		hnum = 8;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   296
		for (num = 0; num < WP(w, depot_d).engine_count; num++) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   297
			const Vehicle *v = vl[num];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   298
			hnum = maxu(hnum, v->u.rail.cached_total_length);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   299
		}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   300
		/* Always have 1 empty row, so people can change the setting of the train */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   301
		SetVScrollCount(w, WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count + 1);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   302
		SetHScrollCount(w, WagonLengthToPixels(hnum));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   303
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   304
		SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   305
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   306
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   307
	/* locate the depot struct */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   308
	if (WP(w, depot_d).type == VEH_Aircraft) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   309
		SetDParam(0, GetStationIndex(tile)); // Airport name
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   310
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   311
		Depot *depot = GetDepotByTile(tile);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   312
		assert(depot != NULL);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   313
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   314
		SetDParam(0, depot->town_index);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   315
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   316
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   317
	DrawWindowWidgets(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   318
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   319
	num = w->vscroll.pos * boxes_in_each_row;
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   320
	max = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row));
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   321
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   322
	for (x = 2, y = 15; num < max; y += w->resize.step_height, x = 2) { // Draw the rows
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   323
		byte i;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   324
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   325
		for (i = 0; i < boxes_in_each_row && num < max; i++, num++, x += w->resize.step_width) {
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   326
			/* Draw all vehicles in the current row */
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   327
			const Vehicle *v = vl[num];
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   328
			DrawVehicleInDepot(w, v, x, y);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   329
		}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   330
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   331
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   332
	max = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   333
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   334
	/* draw the train wagons, that do not have an engine in front */
4754
0f3a6a6e0a16 (svn r6668) -Codechange: [depot window] simplified the engine drawing loop in the depot window
bjarni
parents: 4745
diff changeset
   335
	for (; num < max; num++, y += 14) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   336
		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   337
		const Vehicle *u;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   338
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   339
		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   340
		DrawString(x, y + 2, STR_8816, 0);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   341
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   342
		/*Draw the train counter */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   343
		i = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   344
		u = v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   345
		do i++; while ( (u=u->next) != NULL); // Determine length of train
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   346
		SetDParam(0, i);                      // Set the counter
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   347
		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   348
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   349
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   350
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   351
typedef struct GetDepotVehiclePtData {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   352
	Vehicle *head;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   353
	Vehicle *wagon;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   354
} GetDepotVehiclePtData;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   355
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   356
enum {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   357
	MODE_ERROR        =  1,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   358
	MODE_DRAG_VEHICLE =  0,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   359
	MODE_SHOW_VEHICLE = -1,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   360
	MODE_START_STOP   = -2,
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   361
};
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   362
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   363
static int GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh, GetDepotVehiclePtData *d)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   364
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   365
	Vehicle **vl = WP(w, depot_d).vehicle_list;
4641
acaeea0a1795 (svn r6516) -Fix r6513: killed warnings about two variables being used uninitialized
bjarni
parents: 4640
diff changeset
   366
	uint xt, row, xm = 0, ym = 0;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   367
	int pos, skip = 0;
4759
4cc941b61b07 (svn r6673) -Codechange: [depot window] replaced a piece of code to calculate max number of vehicles in a row with a simple read of the matrix grid
bjarni
parents: 4758
diff changeset
   368
	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   369
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   370
	if (WP(w, depot_d).type == VEH_Train) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   371
		xt = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   372
		x -= 23;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   373
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   374
		xt = x / w->resize.step_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   375
		xm = x % w->resize.step_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   376
		if (xt >= w->hscroll.cap) return MODE_ERROR;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   377
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   378
		ym = (y - 14) % w->resize.step_height;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   379
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   380
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   381
	row = (y - 14) / w->resize.step_height;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   382
	if (row >= w->vscroll.cap) return MODE_ERROR;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   383
4759
4cc941b61b07 (svn r6673) -Codechange: [depot window] replaced a piece of code to calculate max number of vehicles in a row with a simple read of the matrix grid
bjarni
parents: 4758
diff changeset
   384
	pos = ((row + w->vscroll.pos) * boxes_in_each_row) + xt;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   385
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   386
	if (WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count <= pos) {
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   387
		if (WP(w, depot_d).type == VEH_Train) {
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   388
			d->head  = NULL;
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   389
			d->wagon = NULL;
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   390
			return MODE_DRAG_VEHICLE;
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   391
		} else {
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   392
			return MODE_ERROR; // empty block, so no vehicle is selected
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   393
		}
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   394
	}
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   395
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   396
	if (WP(w, depot_d).engine_count > pos) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   397
		*veh = vl[pos];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   398
		skip = w->hscroll.pos;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   399
	} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   400
		vl = WP(w, depot_d).wagon_list;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   401
		pos -= WP(w, depot_d).engine_count;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   402
		*veh = vl[pos];
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   403
		/* free wagons don't have an initial loco. */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   404
		x -= _traininfo_vehicle_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   405
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   406
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   407
	switch (WP(w, depot_d).type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   408
		case VEH_Train: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   409
			Vehicle *v = *veh;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   410
			d->head = d->wagon = v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   411
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   412
			/* either pressed the flag or the number, but only when it's a loco */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   413
			if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   414
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   415
			skip = (skip * 8) / _traininfo_vehicle_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   416
			x = (x * 8) / _traininfo_vehicle_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   417
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   418
			/* Skip vehicles that are scrolled off the list */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   419
			x += skip;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   420
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   421
			/* find the vehicle in this row that was clicked */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   422
			while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->next;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   423
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   424
			/* if an articulated part was selected, find its parent */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   425
			while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   426
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   427
			d->wagon = v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   428
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   429
			return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   430
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   431
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   432
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   433
		case VEH_Road:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   434
			if (xm >= 24) return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   435
			if (xm <= 16) return MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   436
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   437
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   438
		case VEH_Ship:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   439
			if (xm >= 19) return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   440
			if (ym <= 10) return MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   441
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   442
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   443
		case VEH_Aircraft:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   444
			if (xm >= 12) return MODE_DRAG_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   445
			if (ym <= 12) return MODE_SHOW_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   446
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   447
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   448
		default: NOT_REACHED();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   449
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   450
	return MODE_START_STOP;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   451
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   452
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   453
static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   454
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   455
	Vehicle *v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   456
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   457
	v = GetVehicle(sel);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   458
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   459
	if (v == wagon) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   460
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   461
	if (wagon == NULL) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   462
		if (head != NULL) wagon = GetLastVehicleInChain(head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   463
	} else  {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   464
		wagon = GetPrevVehicleInChain(wagon);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   465
		if (wagon == NULL) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   466
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   467
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   468
	if (wagon == v) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   469
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   470
	DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   471
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   472
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   473
static void DepotClick(Window *w, int x, int y)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   474
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   475
	GetDepotVehiclePtData gdvp;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   476
	Vehicle *v = NULL;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   477
	int mode = GetVehicleFromDepotWndPt(w, x, y, &v, &gdvp);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   478
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   479
	/* share / copy orders */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   480
	if (_thd.place_mode && mode <= 0) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   481
		_place_clicked_vehicle = (WP(w, depot_d).type == VEH_Train ? gdvp.head : v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   482
		return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   483
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   484
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   485
	if (WP(w, depot_d).type == VEH_Train) v = gdvp.wagon;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   486
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   487
	switch (mode) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   488
		case MODE_ERROR: // invalid
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   489
			return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   490
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   491
		case MODE_DRAG_VEHICLE: { // start dragging of vehicle
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   492
			VehicleID sel = WP(w, depot_d).sel;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   493
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   494
			if (WP(w, depot_d).type == VEH_Train && sel != INVALID_VEHICLE) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   495
				WP(w,depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   496
				TrainDepotMoveVehicle(v, sel, gdvp.head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   497
			} else if (v != NULL) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   498
				int image;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   499
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   500
				switch (WP(w, depot_d).type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   501
					case VEH_Train:    image = GetTrainImage(v, DIR_W);    break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   502
					case VEH_Road:     image = GetRoadVehImage(v, DIR_W);  break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   503
					case VEH_Ship:     image = GetShipImage(v, DIR_W);     break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   504
					case VEH_Aircraft: image = GetAircraftImage(v, DIR_W); break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   505
					default: NOT_REACHED(); image = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   506
				}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   507
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   508
				WP(w, depot_d).sel = v->index;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   509
				SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   510
				SetObjectToPlaceWnd(GetVehiclePalette(v) | image, 4, w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   511
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   512
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   513
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   514
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   515
		case MODE_SHOW_VEHICLE: // show info window
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   516
			ShowVehicleViewWindow(v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   517
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   518
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   519
		case MODE_START_STOP: { // click start/stop flag
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   520
			uint command;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   521
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   522
			switch (WP(w, depot_d).type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   523
				case VEH_Train:    command = CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN);          break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   524
				case VEH_Road:     command = CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   525
				case VEH_Ship:     command = CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP);            break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   526
				case VEH_Aircraft: command = CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT);    break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   527
				default: NOT_REACHED(); command = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   528
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   529
			DoCommandP(v->tile, v->index, 0, NULL, command);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   530
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   531
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   532
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   533
		default: NOT_REACHED();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   534
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   535
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   536
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   537
/**
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   538
 * Clones a vehicle
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   539
 * @param *v is the original vehicle to clone
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   540
 * @param *w is the window of the depot where the clone is build
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   541
 */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   542
static void HandleCloneVehClick(const Vehicle *v, const Window *w)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   543
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   544
	uint error_str;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   545
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   546
	if (v == NULL) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   547
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   548
	if (v->type == VEH_Train && !IsFrontEngine(v)) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   549
		v = GetFirstVehicleInChain(v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   550
		/* Do nothing when clicking on a train in depot with no loc attached */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   551
		if (!IsFrontEngine(v)) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   552
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   553
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   554
	switch (v->type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   555
		case VEH_Train:    error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   556
		case VEH_Road:     error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE);     break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   557
		case VEH_Ship:     error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP);             break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   558
		case VEH_Aircraft: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT);         break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   559
		default: return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   560
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   561
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   562
	DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   563
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   564
	ResetObjectToPlace();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   565
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   566
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   567
static void ClonePlaceObj(const Window *w)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   568
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   569
	const Vehicle *v = CheckMouseOverVehicle();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   570
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   571
	if (v != NULL) HandleCloneVehClick(v, w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   572
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   573
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   574
static void ResizeDepotButtons(Window *w)
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   575
{
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   576
	/* We got the widget moved around. Now we will make some widgets to fill the gap between some widgets in equal sizes */
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   577
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   578
	/* Make the buttons in the bottom equal in size */
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   579
	w->widget[DEPOT_WIDGET_BUILD].right    = w->widget[DEPOT_WIDGET_LOCATION].right / 3;
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   580
	w->widget[DEPOT_WIDGET_LOCATION].left  = w->widget[DEPOT_WIDGET_BUILD].right * 2;
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   581
	w->widget[DEPOT_WIDGET_CLONE].left     = w->widget[DEPOT_WIDGET_BUILD].right + 1;
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   582
	w->widget[DEPOT_WIDGET_CLONE].right    = w->widget[DEPOT_WIDGET_LOCATION].left - 1;
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   583
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   584
	if (WP(w, depot_d).type == VEH_Train) {
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   585
		/* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size.
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   586
		* This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason                                                  */
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   587
		w->widget[DEPOT_WIDGET_SELL_CHAIN].top    = ((w->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - w->widget[DEPOT_WIDGET_SELL].top) / 2) + w->widget[DEPOT_WIDGET_SELL].top;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   588
		w->widget[DEPOT_WIDGET_SELL].bottom     = w->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1;
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   589
	}
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   590
}
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   591
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   592
/* Function to set up vehicle specific sprites and strings
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   593
 * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   594
 * Vehicle specific text/sprites, that's in a widget, that's only shown for one vehicle type (like sell whole train) is set in the widget array
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   595
 */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   596
static void SetupStringsForDepotWindow(Window *w, byte type)
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   597
{
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   598
	switch (type) {
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   599
		case VEH_Train:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   600
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_8800_TRAIN_DEPOT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   601
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   602
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_DEPOT_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   603
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   604
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   605
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   606
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   607
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_8815_NEW_VEHICLES;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   608
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_8840_BUILD_NEW_TRAIN_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   609
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   610
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_TRAIN_DEPOT_INFO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   611
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   612
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   613
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   614
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   615
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   616
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   617
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   618
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   619
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   620
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   621
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   622
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   623
		case VEH_Road:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   624
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_9003_ROAD_VEHICLE_DEPOT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   625
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   626
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_DEPOT_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   627
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   628
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   629
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_9022_VEHICLES_CLICK_ON_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   630
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   631
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_9004_NEW_VEHICLES;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   632
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_9023_BUILD_NEW_ROAD_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   633
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_ROAD_VEHICLE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   634
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   635
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   636
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   637
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   638
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   639
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   640
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   641
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   642
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_ROADVEH;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   643
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_ROADVEH;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   644
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   645
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   646
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   647
		case VEH_Ship:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   648
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_9803_SHIP_DEPOT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   649
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   650
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_DEPOT_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   651
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   652
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   653
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_981F_SHIPS_CLICK_ON_SHIP_FOR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   654
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   655
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_9804_NEW_SHIPS;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   656
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_9820_BUILD_NEW_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   657
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   658
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_SHIP_DEPOT_INFO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   659
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   660
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   661
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   662
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   663
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   664
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   665
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   666
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   667
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   668
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   669
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   670
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   671
		case VEH_Aircraft:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   672
			w->widget[DEPOT_WIDGET_CAPTION].data      = STR_A002_AIRCRAFT_HANGAR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   673
			w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   674
			w->widget[DEPOT_WIDGET_START_ALL].tooltips=	STR_MASS_START_HANGAR_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   675
			w->widget[DEPOT_WIDGET_SELL].tooltips     = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   676
			w->widget[DEPOT_WIDGET_SELL_ALL].tooltips =	STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   677
			w->widget[DEPOT_WIDGET_MATRIX].tooltips   = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   678
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   679
			w->widget[DEPOT_WIDGET_BUILD].data        = STR_A003_NEW_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   680
			w->widget[DEPOT_WIDGET_BUILD].tooltips    = STR_A022_BUILD_NEW_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   681
			w->widget[DEPOT_WIDGET_CLONE].data        = STR_CLONE_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   682
			w->widget[DEPOT_WIDGET_CLONE].tooltips    = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   683
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   684
			w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   685
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   686
			w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   687
			w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   688
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   689
			/* Sprites */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   690
			w->widget[DEPOT_WIDGET_SELL].data        = SPR_SELL_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   691
			w->widget[DEPOT_WIDGET_SELL_ALL].data    = SPR_SELL_ALL_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   692
			w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   693
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   694
	}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   695
}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   696
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   697
static void CreateDepotListWindow(Window *w, byte type)
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   698
{
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   699
	WP(w, depot_d).type = type;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   700
	_backup_orders_tile = 0;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   701
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   702
	/* Resize the window according to the vehicle type */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   703
	switch (type) {
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   704
		default: NOT_REACHED();
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   705
		case VEH_Train:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   706
			w->vscroll.cap = 6;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   707
			w->hscroll.cap = 10 * 29;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   708
			w->resize.step_width = 1;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   709
			ResizeWindow(w, 56, 26);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   710
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   711
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   712
		case VEH_Road:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   713
			w->vscroll.cap = 5;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   714
			w->hscroll.cap = 5;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   715
			w->resize.step_width = 56;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   716
			ResizeWindow(w, 10, 0);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   717
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   718
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   719
		case VEH_Ship:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   720
			w->vscroll.cap = 3;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   721
			w->hscroll.cap = 3;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   722
			w->resize.step_width = 90;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   723
			ResizeWindow(w, 0, 2);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   724
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   725
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   726
		case VEH_Aircraft:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   727
			w->vscroll.cap = 3;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   728
			w->hscroll.cap = 4;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   729
			w->resize.step_width = 74;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   730
			ResizeWindow(w, 26, 2);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   731
			break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   732
	}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   733
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   734
	/* Set the minimum window size to the current window size */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   735
	w->resize.width = w->width;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   736
	w->resize.height = w->height;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   737
	w->resize.step_height = GetVehicleListHeight(type);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   738
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   739
	SetupStringsForDepotWindow(w, type);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   740
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   741
	w->widget[DEPOT_WIDGET_MATRIX].data =
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   742
		(w->vscroll.cap * 0x100) // number of rows to draw on the background
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   743
		+ (type == VEH_Train ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   744
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   745
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   746
	SetWindowWidgetsHiddenState(w, type != VEH_Train,
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   747
		DEPOT_WIDGET_H_SCROLL,
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   748
		DEPOT_WIDGET_SELL_CHAIN,
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   749
		WIDGET_LIST_END);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   750
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   751
	/* The train depot has a horizontal scroller, make the matrix that much shorter to fit */
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   752
	if (type == VEH_Train) w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   753
	ResizeDepotButtons(w);
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   754
}
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   755
4740
e562a2cde601 (svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
bjarni
parents: 4739
diff changeset
   756
void DepotSortList(Vehicle **v, uint16 length);
e562a2cde601 (svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
bjarni
parents: 4739
diff changeset
   757
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   758
static void DepotWndProc(Window *w, WindowEvent *e)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   759
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   760
	switch (e->event) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   761
		case WE_CREATE:
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   762
			WP(w, depot_d).sel = INVALID_VEHICLE;
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   763
			WP(w, depot_d).vehicle_list  = NULL;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   764
			WP(w, depot_d).wagon_list    = NULL;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   765
			WP(w, depot_d).engine_count  = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   766
			WP(w, depot_d).wagon_count   = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   767
			WP(w, depot_d).generate_list = true;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   768
			break;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   769
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   770
		case WE_INVALIDATE_DATA:
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   771
			WP(w, depot_d).generate_list = true;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   772
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   773
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   774
		case WE_PAINT:
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   775
			if (WP(w, depot_d).generate_list) {
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   776
				/* Generate the vehicle list
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   777
				 * It's ok to use the wagon pointers for non-trains as they will be ignored */
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   778
				BuildDepotVehicleList(WP(w, depot_d).type, w->window_number,
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   779
					&WP(w, depot_d).vehicle_list, &WP(w, depot_d).engine_list_length, &WP(w, depot_d).engine_count,
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   780
					&WP(w, depot_d).wagon_list,   &WP(w, depot_d).wagon_list_length,  &WP(w, depot_d).wagon_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   781
				WP(w, depot_d).generate_list = false;
4740
e562a2cde601 (svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
bjarni
parents: 4739
diff changeset
   782
				DepotSortList(WP(w, depot_d).vehicle_list, WP(w, depot_d).engine_count);
4763
cd72f1d9f4a6 (svn r6677) -Codechange r6651: [depot window] disabled the check for the correct cache in the depot window
bjarni
parents: 4762
diff changeset
   783
//#ifndef NDEBUG
cd72f1d9f4a6 (svn r6677) -Codechange r6651: [depot window] disabled the check for the correct cache in the depot window
bjarni
parents: 4762
diff changeset
   784
#if 0
cd72f1d9f4a6 (svn r6677) -Codechange r6651: [depot window] disabled the check for the correct cache in the depot window
bjarni
parents: 4762
diff changeset
   785
/* We disabled this check for now, but will keep it to quickly make this test again later (if we change some code) */
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   786
			} else {
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   787
				/* Here we got a piece of code, that only checks if we got a different number of vehicles in the depot list and the number of vehicles actually being in the depot.
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   788
				 * IF they aren't the same, then WE_INVALIDATE_DATA should have been called somewhere, but it wasn't and we got a bug
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   789
				 * Since this is a time consuming check and not nice to memory fragmentation, it may not stay for long, but it's a good way to check this
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   790
				 * We can turn it on/off by switching between #ifndef NDEBUG and #if 0 */
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   791
				Vehicle **engines = NULL, **wagons = NULL;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   792
				uint16 engine_count = 0, engine_length = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   793
				uint16 wagon_count  = 0, wagon_length  = 0;
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   794
				BuildDepotVehicleList(WP(w, depot_d).type, w->window_number, &engines, &engine_length, &engine_count,
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   795
									  &wagons,  &wagon_length,  &wagon_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   796
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   797
				assert(engine_count == WP(w, depot_d).engine_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   798
				assert(wagon_count == WP(w, depot_d).wagon_count);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   799
				free((void*)engines);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   800
				free((void*)wagons);
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   801
#endif
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4733
diff changeset
   802
			}
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   803
			DrawDepotWindow(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   804
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   805
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   806
		case WE_CLICK:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   807
			switch (e->we.click.widget) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   808
				case DEPOT_WIDGET_MATRIX: // List
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   809
					DepotClick(w, e->we.click.pt.x, e->we.click.pt.y);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   810
					break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   811
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   812
				case DEPOT_WIDGET_BUILD: // Build vehicle
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   813
					ResetObjectToPlace();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   814
					switch (WP(w, depot_d).type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   815
						case VEH_Train:    ShowBuildTrainWindow(w->window_number);    break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   816
						case VEH_Road:     ShowBuildRoadVehWindow(w->window_number);  break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   817
						case VEH_Ship:     ShowBuildShipWindow(w->window_number);     break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents: 4797
diff changeset
   818
						case VEH_Aircraft:
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents: 4797
diff changeset
   819
							ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents: 4797
diff changeset
   820
							break;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   821
					default: NOT_REACHED();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   822
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   823
					break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   824
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   825
				case DEPOT_WIDGET_CLONE: // Clone button
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   826
					InvalidateWidget(w, DEPOT_WIDGET_CLONE);
4733
6f69ecf19282 (svn r6645) -Fix(r6631): Forgot two click_state occurences
belugas
parents: 4719
diff changeset
   827
					ToggleWidgetLoweredState(w, DEPOT_WIDGET_CLONE);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   828
4733
6f69ecf19282 (svn r6645) -Fix(r6631): Forgot two click_state occurences
belugas
parents: 4719
diff changeset
   829
					if (IsWindowWidgetLowered(w, DEPOT_WIDGET_CLONE)) {
4935
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   830
						static const CursorID clone_icons[] = {
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   831
							SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   832
							SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   833
						};
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   834
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   835
						_place_clicked_vehicle = NULL;
4935
aa0721b7ae79 (svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents: 4800
diff changeset
   836
						SetObjectToPlaceWnd(clone_icons[WP(w, depot_d).type - VEH_Train], VHM_RECT, w);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   837
					} else {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   838
						ResetObjectToPlace();
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   839
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   840
						break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   841
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   842
				case DEPOT_WIDGET_LOCATION: ScrollMainWindowToTile(w->window_number); break;
4640
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   843
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   844
				case DEPOT_WIDGET_STOP_ALL:
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   845
				case DEPOT_WIDGET_START_ALL:
4762
58d2f43ebdda (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4759
diff changeset
   846
					DoCommandP(w->window_number, 0, WP(w, depot_d).type | (e->we.click.widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP);
4640
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   847
					break;
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4638
diff changeset
   848
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   849
				case DEPOT_WIDGET_SELL_ALL:
4690
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   850
					/* Only open the confimation window if there are anything to sell */
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   851
					if (WP(w, depot_d).engine_count != 0 || WP(w, depot_d).wagon_count != 0) {
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   852
						ShowDepotSellAllWindow(w->window_number, WP(w, depot_d).type);
7b255dae6815 (svn r6595) -Fix r6542: [depot window] clicking sell all in a depot with no vehicles will now do nothing at all (instead of opening the confination window) (spotted by glx)
bjarni
parents: 4688
diff changeset
   853
					}
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   854
					break;
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   855
4681
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   856
				case DEPOT_WIDGET_VEHICLE_LIST:
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   857
					ShowVehDepotOrders(GetTileOwner(w->window_number), WP(w, depot_d).type, w->window_number);
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   858
					break;
7d7a89b32dd0 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4670
diff changeset
   859
4662
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   860
				case DEPOT_WIDGET_AUTOREPLACE:
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   861
					DoCommandP(w->window_number, WP(w, depot_d).type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE);
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   862
					break;
a20121e5442b (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
   863
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   864
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   865
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   866
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   867
		case WE_PLACE_OBJ: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   868
			ClonePlaceObj(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   869
		} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   870
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   871
		case WE_ABORT_PLACE_OBJ: {
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   872
			RaiseWindowWidget(w, DEPOT_WIDGET_CLONE);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   873
			InvalidateWidget(w, DEPOT_WIDGET_CLONE);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   874
		} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   875
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   876
			/* check if a vehicle in a depot was clicked.. */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   877
		case WE_MOUSELOOP: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   878
			const Vehicle *v = _place_clicked_vehicle;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   879
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   880
			/* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   881
			if (v != NULL && IsWindowWidgetLowered(w, DEPOT_WIDGET_CLONE)) {
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   882
				_place_clicked_vehicle = NULL;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   883
				HandleCloneVehClick(v, w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   884
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   885
		} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   886
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   887
		case WE_DESTROY:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   888
			DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   889
			free((void*)WP(w, depot_d).vehicle_list);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   890
			free((void*)WP(w, depot_d).wagon_list);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   891
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   892
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   893
		case WE_DRAGDROP:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   894
			switch (e->we.click.widget) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   895
				case DEPOT_WIDGET_MATRIX: {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   896
					Vehicle *v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   897
					VehicleID sel = WP(w, depot_d).sel;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   898
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   899
					WP(w, depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   900
					SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   901
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   902
					if (WP(w, depot_d).type == VEH_Train) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   903
						GetDepotVehiclePtData gdvp;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   904
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   905
						if (GetVehicleFromDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE &&
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   906
							sel != INVALID_VEHICLE) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   907
							if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   908
								DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   909
							} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   910
								TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   911
							} else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   912
								ShowTrainViewWindow(gdvp.head);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   913
							}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   914
						}
4663
2e01fabb902f (svn r6554) -Fix r6513: [depot window] fixed a bug where moving rail vehicles from one line to another could fail under certain conditions
bjarni
parents: 4662
diff changeset
   915
					} else if (GetVehicleFromDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v, NULL) == MODE_DRAG_VEHICLE &&
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   916
						v != NULL &&
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   917
						sel == v->index) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   918
						ShowVehicleViewWindow(v);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   919
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   920
				} break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   921
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   922
				case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   923
					if (!IsWindowWidgetDisabled(w, DEPOT_WIDGET_SELL) &&
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   924
						WP(w, depot_d).sel != INVALID_VEHICLE) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   925
						Vehicle *v;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   926
						uint command;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   927
						int sell_cmd;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   928
						bool is_engine;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   929
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   930
						if (IsWindowWidgetDisabled(w, e->we.click.widget)) return;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   931
						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   932
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   933
						HandleButtonClick(w, e->we.click.widget);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   934
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   935
						v = GetVehicle(WP(w, depot_d).sel);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   936
						WP(w, depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   937
						SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   938
4659
2f99f35d5813 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4654
diff changeset
   939
						sell_cmd = (v->type == VEH_Train && (e->we.click.widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   940
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   941
						is_engine = (!(v->type == VEH_Train && !IsFrontEngine(v)));
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   942
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   943
						if (is_engine) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   944
							_backup_orders_tile = v->tile;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   945
							BackupVehicleOrders(v, _backup_orders_data);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   946
						}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   947
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   948
						switch (v->type) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   949
							case VEH_Train:    command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   950
							case VEH_Road:     command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE);       break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   951
							case VEH_Ship:     command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP);                   break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   952
							case VEH_Aircraft: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT);           break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   953
							default: NOT_REACHED(); command = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   954
						}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   955
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   956
						if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   957
					}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   958
					break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   959
				default:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   960
					WP(w, depot_d).sel = INVALID_VEHICLE;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   961
					SetWindowDirty(w);
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   962
			}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   963
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   964
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   965
		case WE_RESIZE:
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   966
			w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   967
			w->hscroll.cap += e->we.sizing.diff.x / (int)w->resize.step_width;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   968
			w->widget[DEPOT_WIDGET_MATRIX].data = (w->vscroll.cap << 8) + (WP(w, depot_d).type == VEH_Train ? 1 : w->hscroll.cap);
4646
c6f774de4f6f (svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents: 4644
diff changeset
   969
			ResizeDepotButtons(w);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   970
			break;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   971
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   972
}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   973
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   974
/** Opens a depot window
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   975
 * @param tile The tile where the depot/hangar is located
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   976
 * @param type The type of vehicles in the depot
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   977
 */
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   978
void ShowDepotWindow(TileIndex tile, byte type)
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   979
{
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   980
	Window *w;
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   981
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   982
	switch (type) {
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   983
		default: NOT_REACHED();
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   984
		case VEH_Train:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   985
			w = AllocateWindowDescFront(&_train_depot_desc, tile); break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   986
		case VEH_Road:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   987
			w = AllocateWindowDescFront(&_road_depot_desc, tile); break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   988
		case VEH_Ship:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   989
			w = AllocateWindowDescFront(&_ship_depot_desc, tile); break;
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   990
		case VEH_Aircraft:
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   991
			w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break;
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   992
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   993
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   994
	if (w != NULL) {
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   995
		w->caption_color = GetTileOwner(tile);
5269
3f3eead5ace2 (svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents: 5265
diff changeset
   996
		CreateDepotListWindow(w, type);
4638
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   997
	}
8abe4f10b94b (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff changeset
   998
}
5255
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
   999
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1000
/** Removes the highlight of a vehicle in a depot window
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1001
 * @param *v Vehicle to remove all highlights from
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1002
 */
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1003
void DeleteDepotHighlightOfVehicle(const Vehicle *v)
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1004
{
5265
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1005
	Window *w;
5255
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1006
5260
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
  1007
	/* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
  1008
	 * If that is the case, we can skip looping though the windows and save time                                */
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
  1009
	if (_special_mouse_mode != WSM_DRAGDROP) return;
6d1a560dd028 (svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents: 5256
diff changeset
  1010
5265
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1011
	w = FindWindowById(WC_VEHICLE_DEPOT, v->tile);
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1012
	if (w != NULL) {
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1013
		WP(w, depot_d).sel = INVALID_VEHICLE;
a15469628808 (svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents: 5260
diff changeset
  1014
		ResetObjectToPlace();
5255
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1015
	}
b8445fda3fe2 (svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents: 5125
diff changeset
  1016
}