author | truebrain |
Thu, 12 Jun 2008 21:07:25 +0000 | |
branch | noai |
changeset 10943 | 5f5a5dd407d8 |
parent 10776 | 07203fc29812 |
permissions | -rw-r--r-- |
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 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
3 |
/** @file depot_gui.cpp The GUI for depots. */ |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6369
diff
changeset
|
4 |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
6 |
#include "openttd.h" |
4654
71048359c6ac
(svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents:
4653
diff
changeset
|
7 |
#include "train.h" |
71048359c6ac
(svn r6530) -Fix r6529: added missing header file (oops)
bjarni
parents:
4653
diff
changeset
|
8 |
#include "roadveh.h" |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
9 |
#include "ship.h" |
4653
091f530bae28
(svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents:
4652
diff
changeset
|
10 |
#include "aircraft.h" |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
11 |
#include "gui.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
12 |
#include "textbuf_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "gfx_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "command_func.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
9869
diff
changeset
|
16 |
#include "depot_base.h" |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
17 |
#include "vehicle_gui.h" |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
18 |
#include "station_map.h" |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
19 |
#include "newgrf_engine.h" |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
20 |
#include "spritecache.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
21 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
22 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
23 |
#include "vehicle_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
24 |
#include "player_func.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9732
diff
changeset
|
25 |
#include "order_func.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
9869
diff
changeset
|
26 |
#include "depot_base.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
27 |
#include "tilehighlight_func.h" |
10645 | 28 |
#include "window_gui.h" |
10776 | 29 |
#include "vehiclelist.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
30 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
31 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
32 |
#include "table/sprites.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
|
33 |
|
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
|
34 |
/* |
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
|
35 |
* 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
|
36 |
* 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
|
37 |
* 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
|
38 |
*/ |
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
|
39 |
|
4646
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
40 |
/* 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
|
41 |
enum DepotWindowWidgets { |
4646
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
42 |
DEPOT_WIDGET_CLOSEBOX = 0, |
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
43 |
DEPOT_WIDGET_CAPTION, |
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
44 |
DEPOT_WIDGET_STICKY, |
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
45 |
DEPOT_WIDGET_SELL, |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4654
diff
changeset
|
46 |
DEPOT_WIDGET_SELL_CHAIN, |
4646
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
47 |
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
|
48 |
DEPOT_WIDGET_AUTOREPLACE, |
4646
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
49 |
DEPOT_WIDGET_MATRIX, |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6369
diff
changeset
|
50 |
DEPOT_WIDGET_V_SCROLL, ///< Vertical scrollbar |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6369
diff
changeset
|
51 |
DEPOT_WIDGET_H_SCROLL, ///< Horizontal scrollbar |
4646
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
52 |
DEPOT_WIDGET_BUILD, |
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
53 |
DEPOT_WIDGET_CLONE, |
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
DEPOT_WIDGET_START_ALL, |
4646
c6f774de4f6f
(svn r6522) -Feature: [depot window] the buttons are now "scaled" resized
bjarni
parents:
4644
diff
changeset
|
58 |
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
|
59 |
}; |
eced6da682cb
(svn r6525) -Codechange r6513: altered how to control how to move widgets around in the window. Hopefully it's a bit easier to understand now
bjarni
parents:
4646
diff
changeset
|
60 |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
61 |
/* Widget array for all depot windows. |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
62 |
* 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
|
63 |
* 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
|
64 |
* 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
|
65 |
|
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
|
66 |
/* 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
|
67 |
* 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
|
68 |
* 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
|
69 |
* 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
|
70 |
*/ |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
71 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
72 |
/* |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
73 |
* Some of the widgets are placed outside the window (negative coordinates). |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
74 |
* The reason is that they are placed relatively to the matrix and the matrix is just one pixel (in 0, 14). |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
75 |
* The matrix and the rest of the window will be resized when the size of the boxes is set and then all the widgets will be inside the window. |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
76 |
*/ |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
77 |
static const Widget _depot_widgets[] = { |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
78 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // DEPOT_WIDGET_CLOSEBOX |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
79 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 23, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS}, // DEPOT_WIDGET_CAPTION |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
80 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 24, 35, 0, 13, 0x0, STR_STICKY_BUTTON}, // DEPOT_WIDGET_STICKY |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4638
diff
changeset
|
81 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4935
diff
changeset
|
82 |
/* Widgets are set up run-time */ |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
83 |
{ WWT_IMGBTN, RESIZE_LRB, 14, 1, 23, 14, -32, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
84 |
{ WWT_IMGBTN, RESIZE_LRTB, 14, 1, 23, -55, -32, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
85 |
{ WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 1, 23, -31, -9, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL_ALL |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
86 |
{ WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 1, 23, -8, 14, 0x0, STR_NULL}, // DEPOT_WIDGET_AUTOREPLACE |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
87 |
|
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
88 |
{ WWT_MATRIX, RESIZE_RB, 14, 0, 0, 14, 14, 0x0, STR_NULL}, // DEPOT_WIDGET_MATRIX |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
89 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 24, 35, 14, 14, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_V_SCROLL |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
90 |
|
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
91 |
{ WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 0, 3, 14, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_H_SCROLL, trains only |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
92 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
93 |
/* 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
|
94 |
* This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0 */ |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
95 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_BUILD |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
96 |
{ WWT_TEXTBTN, RESIZE_TB, 14, 0, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_CLONE |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
97 |
{ WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, -12, 15, 26, STR_00E4_LOCATION, STR_NULL}, // DEPOT_WIDGET_LOCATION |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
98 |
{ WWT_PUSHTXTBTN, RESIZE_LRTB, 14, -11, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_VEHICLE_LIST |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
99 |
{ WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 1, 11, 15, 26, SPR_FLAG_VEH_STOPPED,STR_NULL}, // DEPOT_WIDGET_STOP_ALL |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
100 |
{ WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 12, 23, 15, 26, SPR_FLAG_VEH_RUNNING,STR_NULL}, // DEPOT_WIDGET_START_ALL |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
101 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 24, 35, 15, 26, 0x0, STR_RESIZE_BUTTON}, // DEPOT_WIDGET_RESIZE |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
102 |
{ WIDGETS_END}, |
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 |
|
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
105 |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
106 |
static const WindowDesc _train_depot_desc = { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
107 |
WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6075
diff
changeset
|
108 |
WC_VEHICLE_DEPOT, WC_NONE, |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
109 |
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
|
110 |
_depot_widgets, |
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 _road_depot_desc = { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
114 |
WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6075
diff
changeset
|
115 |
WC_VEHICLE_DEPOT, WC_NONE, |
4638
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 |
}; |
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 |
static const WindowDesc _ship_depot_desc = { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
121 |
WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6075
diff
changeset
|
122 |
WC_VEHICLE_DEPOT, WC_NONE, |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
123 |
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
|
124 |
_depot_widgets, |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
125 |
}; |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
126 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
127 |
static const WindowDesc _aircraft_depot_desc = { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
128 |
WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
6075
diff
changeset
|
129 |
WC_VEHICLE_DEPOT, WC_NONE, |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
130 |
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
|
131 |
_depot_widgets, |
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 |
extern int WagonLengthToPixels(int len); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
135 |
extern void DepotSortList(VehicleList *list); |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
136 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
137 |
/** |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
138 |
* This is the Callback method after the cloning attempt of a vehicle |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
139 |
* @param success indicates completion (or not) of the operation |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
140 |
* @param tile unused |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
141 |
* @param p1 unused |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
142 |
* @param p2 unused |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
143 |
*/ |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
144 |
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
|
145 |
{ |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
146 |
if (!success) return; |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
147 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
148 |
const Vehicle *v = GetVehicle(_new_vehicle_id); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
149 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
150 |
ShowVehicleViewWindow(v); |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
151 |
} |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
152 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
153 |
static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Vehicle *head) |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
154 |
{ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
155 |
const Vehicle *v = GetVehicle(sel); |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
156 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
157 |
if (v == wagon) return; |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
158 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
159 |
if (wagon == NULL) { |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
160 |
if (head != NULL) wagon = GetLastVehicleInChain(head); |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
161 |
} else { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
162 |
wagon = wagon->Previous(); |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
163 |
if (wagon == NULL) return; |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
164 |
} |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
165 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
166 |
if (wagon == v) return; |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
167 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
168 |
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
|
169 |
} |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
170 |
|
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
171 |
/* Array to hold the block sizes |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
172 |
* First part is the vehicle type, while the last is 0 = x, 1 = y */ |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
173 |
uint _block_sizes[4][2]; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
174 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
175 |
/* Array to hold the default resize capacities |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
176 |
* First part is the vehicle type, while the last is 0 = x, 1 = y */ |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
177 |
const uint _resize_cap[][2] = { |
9574 | 178 |
/* VEH_TRAIN */ {6, 10 * 29}, |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
179 |
/* VEH_ROAD */ {5, 5}, |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
180 |
/* VEH_SHIP */ {3, 3}, |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
181 |
/* VEH_AIRCRAFT */ {3, 4}, |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
182 |
}; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
183 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
184 |
static void ResizeDefaultWindowSizeForTrains() |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
185 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
186 |
_block_sizes[VEH_TRAIN][0] = 1; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
187 |
_block_sizes[VEH_TRAIN][1] = GetVehicleListHeight(VEH_TRAIN); |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
188 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
189 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
190 |
static void ResizeDefaultWindowSizeForRoadVehicles() |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
191 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
192 |
_block_sizes[VEH_ROAD][0] = 56; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
193 |
_block_sizes[VEH_ROAD][1] = GetVehicleListHeight(VEH_ROAD); |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
194 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
195 |
|
9624 | 196 |
static void ResizeDefaultWindowSize(VehicleType type) |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
197 |
{ |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
198 |
uint max_width = 0; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
199 |
uint max_height = 0; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
200 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
201 |
const Engine *e; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
202 |
FOR_ALL_ENGINES_OF_TYPE(e, type) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
203 |
EngineID eid = e->index; |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
204 |
uint x, y; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
205 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
206 |
switch (type) { |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
207 |
default: NOT_REACHED(); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
208 |
case VEH_SHIP: GetShipSpriteSize( eid, x, y); break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
209 |
case VEH_AIRCRAFT: GetAircraftSpriteSize(eid, x, y); break; |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
210 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
211 |
if (x > max_width) max_width = x; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
212 |
if (y > max_height) max_height = y; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
213 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
214 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
215 |
switch (type) { |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
216 |
default: NOT_REACHED(); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
217 |
case VEH_SHIP: |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
218 |
_block_sizes[VEH_SHIP][0] = max(90U, max_width + 20); // we need 20 pixels from the right edge to the sprite |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
219 |
break; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
220 |
case VEH_AIRCRAFT: |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
221 |
_block_sizes[VEH_AIRCRAFT][0] = max(74U, max_width); |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
222 |
break; |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
223 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
224 |
_block_sizes[type][1] = max(GetVehicleListHeight(type), max_height); |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
225 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
226 |
|
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
227 |
/* Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
228 |
* We will only need to call this once for each game */ |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
229 |
void InitDepotWindowBlockSizes() |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
230 |
{ |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
231 |
ResizeDefaultWindowSizeForTrains(); |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
232 |
ResizeDefaultWindowSizeForRoadVehicles(); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
233 |
ResizeDefaultWindowSize(VEH_SHIP); |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
234 |
ResizeDefaultWindowSize(VEH_AIRCRAFT); |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
235 |
} |
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
236 |
|
10645 | 237 |
static void DepotSellAllConfirmationCallback(Window *w, bool confirmed); |
238 |
const Sprite *GetAircraftSprite(EngineID engine); |
|
5269
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
239 |
|
10645 | 240 |
struct DepotWindow : Window { |
241 |
VehicleID sel; |
|
242 |
VehicleType type; |
|
243 |
bool generate_list; |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
244 |
VehicleList vehicle_list; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
245 |
VehicleList wagon_list; |
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
246 |
|
10645 | 247 |
DepotWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
248 |
{ |
|
249 |
this->sel = INVALID_VEHICLE; |
|
250 |
this->generate_list = true; |
|
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6206
diff
changeset
|
251 |
|
10645 | 252 |
this->FindWindowPlacementAndResize(desc); |
5269
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
253 |
} |
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
254 |
|
10645 | 255 |
~DepotWindow() |
256 |
{ |
|
257 |
DeleteWindowById(WC_BUILD_VEHICLE, this->window_number); |
|
258 |
} |
|
5269
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
259 |
|
10645 | 260 |
/** Draw a vehicle in the depot window in the box with the top left corner at x,y |
261 |
* @param *w Window to draw in |
|
262 |
* @param *v Vehicle to draw |
|
263 |
* @param x Left side of the box to draw in |
|
264 |
* @param y Top of the box to draw in |
|
265 |
*/ |
|
266 |
void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y) |
|
267 |
{ |
|
268 |
byte diff_x = 0, diff_y = 0; |
|
5269
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
269 |
|
10645 | 270 |
int sprite_y = y + this->resize.step_height - GetVehicleListHeight(v->type); |
271 |
||
272 |
switch (v->type) { |
|
273 |
case VEH_TRAIN: |
|
274 |
DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos); |
|
275 |
||
276 |
/* Number of wagons relative to a standard length wagon (rounded up) */ |
|
277 |
SetDParam(0, (v->u.rail.cached_total_length + 7) / 8); |
|
278 |
DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter |
|
279 |
break; |
|
280 |
||
281 |
case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, this->sel, 1); break; |
|
282 |
case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, this->sel); break; |
|
283 |
case VEH_AIRCRAFT: { |
|
284 |
const Sprite *spr = GetSprite(v->GetImage(DIR_W)); |
|
285 |
DrawAircraftImage(v, x + 12, |
|
286 |
y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset |
|
287 |
this->sel); |
|
288 |
} break; |
|
289 |
default: NOT_REACHED(); |
|
290 |
} |
|
291 |
||
292 |
if (this->resize.step_height == 14) { |
|
293 |
/* VEH_TRAIN and VEH_ROAD, which are low */ |
|
294 |
diff_x = 15; |
|
295 |
} else { |
|
296 |
/* VEH_SHIP and VEH_AIRCRAFT, which are tall */ |
|
297 |
diff_y = 12; |
|
298 |
} |
|
299 |
||
300 |
DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y); |
|
301 |
||
302 |
SetDParam(0, v->unitnumber); |
|
303 |
DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING); |
|
304 |
} |
|
305 |
||
306 |
void DrawDepotWindow(Window *w) |
|
307 |
{ |
|
308 |
TileIndex tile = this->window_number; |
|
309 |
int x, y, i, maxval; |
|
310 |
uint16 hnum; |
|
311 |
||
312 |
/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */ |
|
313 |
uint16 rows_in_display = this->widget[DEPOT_WIDGET_MATRIX].data >> 8; |
|
314 |
uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; |
|
315 |
||
316 |
/* setup disabled buttons */ |
|
317 |
this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_player), |
|
318 |
DEPOT_WIDGET_STOP_ALL, |
|
319 |
DEPOT_WIDGET_START_ALL, |
|
320 |
DEPOT_WIDGET_SELL, |
|
321 |
DEPOT_WIDGET_SELL_CHAIN, |
|
322 |
DEPOT_WIDGET_SELL_ALL, |
|
323 |
DEPOT_WIDGET_BUILD, |
|
324 |
DEPOT_WIDGET_CLONE, |
|
325 |
DEPOT_WIDGET_AUTOREPLACE, |
|
326 |
WIDGET_LIST_END); |
|
327 |
||
328 |
/* determine amount of items for scroller */ |
|
329 |
if (this->type == VEH_TRAIN) { |
|
330 |
hnum = 8; |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
331 |
for (uint num = 0; num < this->vehicle_list.Length(); num++) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
332 |
const Vehicle *v = this->vehicle_list[num]; |
10645 | 333 |
hnum = max(hnum, v->u.rail.cached_total_length); |
334 |
} |
|
335 |
/* Always have 1 empty row, so people can change the setting of the train */ |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
336 |
SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1); |
10645 | 337 |
SetHScrollCount(w, WagonLengthToPixels(hnum)); |
338 |
} else { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
339 |
SetVScrollCount(w, (this->vehicle_list.Length() + this->hscroll.cap - 1) / this->hscroll.cap); |
10645 | 340 |
} |
341 |
||
342 |
/* locate the depot struct */ |
|
343 |
if (this->type == VEH_AIRCRAFT) { |
|
344 |
SetDParam(0, GetStationIndex(tile)); // Airport name |
|
345 |
} else { |
|
346 |
Depot *depot = GetDepotByTile(tile); |
|
347 |
assert(depot != NULL); |
|
348 |
||
349 |
SetDParam(0, depot->town_index); |
|
350 |
} |
|
351 |
||
352 |
w->DrawWidgets(); |
|
353 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
354 |
uint16 num = this->vscroll.pos * boxes_in_each_row; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
355 |
maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row)); |
10645 | 356 |
|
357 |
for (x = 2, y = 15; num < maxval; y += this->resize.step_height, x = 2) { // Draw the rows |
|
358 |
byte i; |
|
359 |
||
360 |
for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) { |
|
361 |
/* Draw all vehicles in the current row */ |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
362 |
const Vehicle *v = this->vehicle_list[num]; |
10645 | 363 |
DrawVehicleInDepot(w, v, x, y); |
364 |
} |
|
365 |
} |
|
366 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
367 |
maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); |
10645 | 368 |
|
369 |
/* draw the train wagons, that do not have an engine in front */ |
|
370 |
for (; num < maxval; num++, y += 14) { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
371 |
const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()]; |
10645 | 372 |
const Vehicle *u; |
373 |
||
374 |
DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0); |
|
375 |
DrawString(x, y + 2, STR_8816, TC_FROMSTRING); |
|
376 |
||
377 |
/*Draw the train counter */ |
|
378 |
i = 0; |
|
379 |
u = v; |
|
380 |
do i++; while ((u = u->Next()) != NULL); // Determine length of train |
|
381 |
SetDParam(0, i); // Set the counter |
|
382 |
DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
struct GetDepotVehiclePtData { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
387 |
const Vehicle *head; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
388 |
const Vehicle *wagon; |
10645 | 389 |
}; |
390 |
||
391 |
enum DepotGUIAction { |
|
392 |
MODE_ERROR, |
|
393 |
MODE_DRAG_VEHICLE, |
|
394 |
MODE_SHOW_VEHICLE, |
|
395 |
MODE_START_STOP, |
|
396 |
}; |
|
397 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
398 |
DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const |
10645 | 399 |
{ |
400 |
uint xt, row, xm = 0, ym = 0; |
|
401 |
int pos, skip = 0; |
|
402 |
uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; |
|
403 |
||
404 |
if (this->type == VEH_TRAIN) { |
|
405 |
xt = 0; |
|
406 |
x -= 23; |
|
407 |
} else { |
|
408 |
xt = x / this->resize.step_width; |
|
409 |
xm = x % this->resize.step_width; |
|
410 |
if (xt >= this->hscroll.cap) return MODE_ERROR; |
|
411 |
||
412 |
ym = (y - 14) % this->resize.step_height; |
|
413 |
} |
|
414 |
||
415 |
row = (y - 14) / this->resize.step_height; |
|
416 |
if (row >= this->vscroll.cap) return MODE_ERROR; |
|
417 |
||
418 |
pos = ((row + this->vscroll.pos) * boxes_in_each_row) + xt; |
|
419 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
420 |
if ((int)(this->vehicle_list.Length() + this->wagon_list.Length()) <= pos) { |
10645 | 421 |
if (this->type == VEH_TRAIN) { |
422 |
d->head = NULL; |
|
423 |
d->wagon = NULL; |
|
424 |
return MODE_DRAG_VEHICLE; |
|
425 |
} else { |
|
426 |
return MODE_ERROR; // empty block, so no vehicle is selected |
|
427 |
} |
|
428 |
} |
|
429 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
430 |
if ((int)this->vehicle_list.Length() > pos) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
431 |
*veh = this->vehicle_list[pos]; |
10645 | 432 |
skip = this->hscroll.pos; |
433 |
} else { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
434 |
pos -= this->vehicle_list.Length(); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
435 |
*veh = this->wagon_list[pos]; |
10645 | 436 |
/* free wagons don't have an initial loco. */ |
437 |
x -= _traininfo_vehicle_width; |
|
438 |
} |
|
439 |
||
440 |
switch (this->type) { |
|
441 |
case VEH_TRAIN: { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
442 |
const Vehicle *v = *veh; |
10645 | 443 |
d->head = d->wagon = v; |
444 |
||
445 |
/* either pressed the flag or the number, but only when it's a loco */ |
|
446 |
if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE; |
|
447 |
||
448 |
skip = (skip * 8) / _traininfo_vehicle_width; |
|
449 |
x = (x * 8) / _traininfo_vehicle_width; |
|
450 |
||
451 |
/* Skip vehicles that are scrolled off the list */ |
|
452 |
x += skip; |
|
453 |
||
454 |
/* find the vehicle in this row that was clicked */ |
|
455 |
while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next(); |
|
456 |
||
457 |
/* if an articulated part was selected, find its parent */ |
|
458 |
while (v != NULL && IsArticulatedPart(v)) v = v->Previous(); |
|
459 |
||
460 |
d->wagon = v; |
|
461 |
||
462 |
return MODE_DRAG_VEHICLE; |
|
463 |
} |
|
464 |
break; |
|
465 |
||
466 |
case VEH_ROAD: |
|
467 |
if (xm >= 24) return MODE_DRAG_VEHICLE; |
|
468 |
if (xm <= 16) return MODE_SHOW_VEHICLE; |
|
469 |
break; |
|
470 |
||
471 |
case VEH_SHIP: |
|
472 |
if (xm >= 19) return MODE_DRAG_VEHICLE; |
|
473 |
if (ym <= 10) return MODE_SHOW_VEHICLE; |
|
474 |
break; |
|
475 |
||
476 |
case VEH_AIRCRAFT: |
|
477 |
if (xm >= 12) return MODE_DRAG_VEHICLE; |
|
478 |
if (ym <= 12) return MODE_SHOW_VEHICLE; |
|
479 |
break; |
|
480 |
||
481 |
default: NOT_REACHED(); |
|
482 |
} |
|
483 |
return MODE_START_STOP; |
|
484 |
} |
|
485 |
||
486 |
void DepotClick(int x, int y) |
|
487 |
{ |
|
488 |
GetDepotVehiclePtData gdvp = { NULL, NULL }; |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
489 |
const Vehicle *v = NULL; |
10645 | 490 |
DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp); |
491 |
||
492 |
/* share / copy orders */ |
|
493 |
if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) { |
|
494 |
_place_clicked_vehicle = (this->type == VEH_TRAIN ? gdvp.head : v); |
|
495 |
return; |
|
496 |
} |
|
497 |
||
498 |
if (this->type == VEH_TRAIN) v = gdvp.wagon; |
|
499 |
||
500 |
switch (mode) { |
|
501 |
case MODE_ERROR: // invalid |
|
502 |
return; |
|
503 |
||
504 |
case MODE_DRAG_VEHICLE: { // start dragging of vehicle |
|
505 |
VehicleID sel = this->sel; |
|
506 |
||
507 |
if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) { |
|
508 |
this->sel = INVALID_VEHICLE; |
|
509 |
TrainDepotMoveVehicle(v, sel, gdvp.head); |
|
510 |
} else if (v != NULL) { |
|
511 |
int image = v->GetImage(DIR_W); |
|
512 |
||
513 |
this->sel = v->index; |
|
514 |
this->SetDirty(); |
|
515 |
SetObjectToPlaceWnd(image, GetVehiclePalette(v), VHM_DRAG, this); |
|
516 |
_cursor.vehchain = _ctrl_pressed; |
|
517 |
} |
|
518 |
} break; |
|
519 |
||
520 |
case MODE_SHOW_VEHICLE: // show info window |
|
521 |
ShowVehicleViewWindow(v); |
|
522 |
break; |
|
523 |
||
524 |
case MODE_START_STOP: { // click start/stop flag |
|
525 |
uint command; |
|
526 |
||
527 |
switch (this->type) { |
|
528 |
case VEH_TRAIN: command = CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN); break; |
|
529 |
case VEH_ROAD: command = CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break; |
|
530 |
case VEH_SHIP: command = CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP); break; |
|
531 |
case VEH_AIRCRAFT: command = CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT); break; |
|
532 |
default: NOT_REACHED(); command = 0; |
|
533 |
} |
|
534 |
DoCommandP(v->tile, v->index, 0, NULL, command); |
|
535 |
} break; |
|
536 |
||
537 |
default: NOT_REACHED(); |
|
538 |
} |
|
539 |
} |
|
540 |
||
541 |
/** |
|
542 |
* Clones a vehicle |
|
543 |
* @param *v is the original vehicle to clone |
|
544 |
* @param *w is the window of the depot where the clone is build |
|
545 |
*/ |
|
546 |
void HandleCloneVehClick(const Vehicle *v, const Window *w) |
|
547 |
{ |
|
548 |
uint error_str; |
|
549 |
||
550 |
if (v == NULL) return; |
|
551 |
||
552 |
if (!v->IsPrimaryVehicle()) { |
|
553 |
v = v->First(); |
|
554 |
/* Do nothing when clicking on a train in depot with no loc attached */ |
|
555 |
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) return; |
|
556 |
} |
|
557 |
||
558 |
switch (v->type) { |
|
559 |
case VEH_TRAIN: error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break; |
|
560 |
case VEH_ROAD: error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE); break; |
|
561 |
case VEH_SHIP: error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP); break; |
|
562 |
case VEH_AIRCRAFT: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT); break; |
|
563 |
default: return; |
|
564 |
} |
|
565 |
||
566 |
DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str); |
|
567 |
||
568 |
ResetObjectToPlace(); |
|
569 |
} |
|
570 |
||
571 |
void ResizeDepotButtons(Window *w) |
|
572 |
{ |
|
573 |
ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION); |
|
574 |
||
575 |
if (this->type == VEH_TRAIN) { |
|
576 |
/* 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. |
|
577 |
* This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason */ |
|
578 |
this->widget[DEPOT_WIDGET_SELL_CHAIN].top = ((this->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - this->widget[DEPOT_WIDGET_SELL].top) / 2) + this->widget[DEPOT_WIDGET_SELL].top; |
|
579 |
this->widget[DEPOT_WIDGET_SELL].bottom = this->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1; |
|
580 |
} |
|
581 |
} |
|
582 |
||
583 |
/* Function to set up vehicle specific sprites and strings |
|
584 |
* Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites |
|
585 |
* 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 |
|
586 |
*/ |
|
587 |
void SetupStringsForDepotWindow(VehicleType type) |
|
588 |
{ |
|
589 |
switch (type) { |
|
590 |
default: NOT_REACHED(); |
|
591 |
||
592 |
case VEH_TRAIN: |
|
593 |
this->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; |
|
594 |
this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; |
|
595 |
this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP; |
|
596 |
this->widget[DEPOT_WIDGET_SELL].tooltips = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE; |
|
597 |
this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP; |
|
598 |
this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR; |
|
599 |
||
600 |
this->widget[DEPOT_WIDGET_BUILD].data = STR_8815_NEW_VEHICLES; |
|
601 |
this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_8840_BUILD_NEW_TRAIN_VEHICLE; |
|
602 |
this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_TRAIN; |
|
603 |
this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_TRAIN_DEPOT_INFO; |
|
604 |
||
605 |
this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN; |
|
606 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN; |
|
607 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP; |
|
608 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP; |
|
609 |
||
610 |
/* Sprites */ |
|
611 |
this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_TRAIN; |
|
612 |
this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_TRAIN; |
|
613 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN; |
|
614 |
break; |
|
615 |
||
616 |
case VEH_ROAD: |
|
617 |
this->widget[DEPOT_WIDGET_CAPTION].data = STR_9003_ROAD_VEHICLE_DEPOT; |
|
618 |
this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP; |
|
619 |
this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP; |
|
620 |
this->widget[DEPOT_WIDGET_SELL].tooltips = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE; |
|
621 |
this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP; |
|
622 |
this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_9022_VEHICLES_CLICK_ON_VEHICLE; |
|
623 |
||
624 |
this->widget[DEPOT_WIDGET_BUILD].data = STR_9004_NEW_VEHICLES; |
|
625 |
this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9023_BUILD_NEW_ROAD_VEHICLE; |
|
626 |
this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_ROAD_VEHICLE; |
|
627 |
this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO; |
|
628 |
||
629 |
this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD; |
|
630 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY; |
|
631 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP; |
|
632 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP; |
|
633 |
||
634 |
/* Sprites */ |
|
635 |
this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_ROADVEH; |
|
636 |
this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_ROADVEH; |
|
637 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH; |
|
638 |
break; |
|
639 |
||
640 |
case VEH_SHIP: |
|
641 |
this->widget[DEPOT_WIDGET_CAPTION].data = STR_9803_SHIP_DEPOT; |
|
642 |
this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP; |
|
643 |
this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP; |
|
644 |
this->widget[DEPOT_WIDGET_SELL].tooltips = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL; |
|
645 |
this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP; |
|
646 |
this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_981F_SHIPS_CLICK_ON_SHIP_FOR; |
|
647 |
||
648 |
this->widget[DEPOT_WIDGET_BUILD].data = STR_9804_NEW_SHIPS; |
|
649 |
this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9820_BUILD_NEW_SHIP; |
|
650 |
this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_SHIP; |
|
651 |
this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_SHIP_DEPOT_INFO; |
|
652 |
||
653 |
this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP; |
|
654 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP; |
|
655 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP; |
|
656 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP; |
|
657 |
||
658 |
/* Sprites */ |
|
659 |
this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_SHIP; |
|
660 |
this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_SHIP; |
|
661 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP; |
|
662 |
break; |
|
663 |
||
664 |
case VEH_AIRCRAFT: |
|
665 |
this->widget[DEPOT_WIDGET_CAPTION].data = STR_A002_AIRCRAFT_HANGAR; |
|
666 |
this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP; |
|
667 |
this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP; |
|
668 |
this->widget[DEPOT_WIDGET_SELL].tooltips = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO; |
|
669 |
this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP; |
|
670 |
this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT; |
|
671 |
||
672 |
this->widget[DEPOT_WIDGET_BUILD].data = STR_A003_NEW_AIRCRAFT; |
|
673 |
this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_A022_BUILD_NEW_AIRCRAFT; |
|
674 |
this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT; |
|
675 |
this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW; |
|
676 |
||
677 |
this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR; |
|
678 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE; |
|
679 |
this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP; |
|
680 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP; |
|
681 |
||
682 |
/* Sprites */ |
|
683 |
this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_AIRCRAFT; |
|
684 |
this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_AIRCRAFT; |
|
685 |
this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; |
|
686 |
break; |
|
687 |
} |
|
688 |
} |
|
689 |
||
690 |
void CreateDepotListWindow(VehicleType type) |
|
691 |
{ |
|
692 |
this->type = type; |
|
693 |
_backup_orders_tile = 0; |
|
694 |
||
695 |
assert(IsPlayerBuildableVehicleType(type)); // ensure that we make the call with a valid type |
|
696 |
||
697 |
/* Resize the window according to the vehicle type */ |
|
698 |
||
699 |
/* Set the number of blocks in each direction */ |
|
700 |
this->vscroll.cap = _resize_cap[type][0]; |
|
701 |
this->hscroll.cap = _resize_cap[type][1]; |
|
702 |
||
703 |
/* Set the block size */ |
|
704 |
this->resize.step_width = _block_sizes[type][0]; |
|
705 |
this->resize.step_height = _block_sizes[type][1]; |
|
706 |
||
707 |
/* Enlarge the window to fit with the selected number of blocks of the selected size */ |
|
708 |
ResizeWindow(this, |
|
709 |
_block_sizes[type][0] * this->hscroll.cap, |
|
710 |
_block_sizes[type][1] * this->vscroll.cap); |
|
711 |
||
712 |
if (type == VEH_TRAIN) { |
|
713 |
/* Make space for the horizontal scrollbar vertically, and the unit |
|
714 |
* number, flag, and length counter horizontally. */ |
|
715 |
ResizeWindow(this, 36, 12); |
|
716 |
/* substract the newly added space from the matrix since it was meant for the scrollbar */ |
|
717 |
this->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; |
|
718 |
} |
|
719 |
||
720 |
/* Set the minimum window size to the current window size */ |
|
721 |
this->resize.width = this->width; |
|
722 |
this->resize.height = this->height; |
|
723 |
||
724 |
this->SetupStringsForDepotWindow(type); |
|
725 |
||
726 |
this->widget[DEPOT_WIDGET_MATRIX].data = |
|
727 |
(this->vscroll.cap * 0x100) // number of rows to draw on the background |
|
728 |
+ (type == VEH_TRAIN ? 1 : this->hscroll.cap); // number of boxes in each row. Trains always have just one |
|
5269
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
729 |
|
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
730 |
|
10645 | 731 |
this->SetWidgetsHiddenState(type != VEH_TRAIN, |
732 |
DEPOT_WIDGET_H_SCROLL, |
|
733 |
DEPOT_WIDGET_SELL_CHAIN, |
|
734 |
WIDGET_LIST_END); |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
735 |
|
10645 | 736 |
ResizeDepotButtons(this); |
737 |
} |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
738 |
|
10645 | 739 |
virtual void OnInvalidateData(int data) |
740 |
{ |
|
741 |
this->generate_list = true; |
|
742 |
} |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
743 |
|
10645 | 744 |
virtual void OnPaint() |
745 |
{ |
|
746 |
if (this->generate_list) { |
|
747 |
/* Generate the vehicle list |
|
748 |
* It's ok to use the wagon pointers for non-trains as they will be ignored */ |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
749 |
BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list); |
10645 | 750 |
this->generate_list = false; |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
751 |
DepotSortList(&this->vehicle_list); |
10645 | 752 |
} |
753 |
DrawDepotWindow(this); |
|
754 |
} |
|
4935
aa0721b7ae79
(svn r6922) -Feature: Add proper cloning sprites and cursors, different for each vehicle. Big thanks
Darkvater
parents:
4800
diff
changeset
|
755 |
|
10645 | 756 |
virtual void OnClick(Point pt, int widget) |
757 |
{ |
|
758 |
switch (widget) { |
|
759 |
case DEPOT_WIDGET_MATRIX: // List |
|
760 |
this->DepotClick(pt.x, pt.y); |
|
761 |
break; |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
762 |
|
10645 | 763 |
case DEPOT_WIDGET_BUILD: // Build vehicle |
764 |
ResetObjectToPlace(); |
|
765 |
ShowBuildVehicleWindow(this->window_number, this->type); |
|
766 |
break; |
|
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4638
diff
changeset
|
767 |
|
10645 | 768 |
case DEPOT_WIDGET_CLONE: // Clone button |
769 |
this->InvalidateWidget(DEPOT_WIDGET_CLONE); |
|
770 |
this->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE); |
|
771 |
||
772 |
if (this->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { |
|
773 |
static const CursorID clone_icons[] = { |
|
774 |
SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH, |
|
775 |
SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE |
|
776 |
}; |
|
777 |
||
778 |
_place_clicked_vehicle = NULL; |
|
779 |
SetObjectToPlaceWnd(clone_icons[this->type], PAL_NONE, VHM_RECT, this); |
|
780 |
} else { |
|
781 |
ResetObjectToPlace(); |
|
782 |
} |
|
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4638
diff
changeset
|
783 |
break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4638
diff
changeset
|
784 |
|
10645 | 785 |
case DEPOT_WIDGET_LOCATION: |
786 |
if (_ctrl_pressed) { |
|
787 |
ShowExtraViewPortWindow(this->window_number); |
|
788 |
} else { |
|
789 |
ScrollMainWindowToTile(this->window_number); |
|
790 |
} |
|
791 |
break; |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
792 |
|
10645 | 793 |
case DEPOT_WIDGET_STOP_ALL: |
794 |
case DEPOT_WIDGET_START_ALL: |
|
795 |
DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP); |
|
796 |
break; |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
797 |
|
10645 | 798 |
case DEPOT_WIDGET_SELL_ALL: |
799 |
/* Only open the confimation window if there are anything to sell */ |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
800 |
if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) { |
10645 | 801 |
static const StringID confirm_captions[] = { |
802 |
STR_8800_TRAIN_DEPOT, |
|
803 |
STR_9003_ROAD_VEHICLE_DEPOT, |
|
804 |
STR_9803_SHIP_DEPOT, |
|
805 |
STR_A002_AIRCRAFT_HANGAR |
|
806 |
}; |
|
807 |
TileIndex tile = this->window_number; |
|
808 |
byte vehtype = this->type; |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
809 |
|
10645 | 810 |
SetDParam(0, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index); |
811 |
ShowQuery( |
|
812 |
confirm_captions[vehtype], |
|
813 |
STR_DEPOT_SELL_CONFIRMATION_TEXT, |
|
814 |
this, |
|
815 |
DepotSellAllConfirmationCallback |
|
816 |
); |
|
817 |
} |
|
818 |
break; |
|
819 |
||
820 |
case DEPOT_WIDGET_VEHICLE_LIST: |
|
821 |
ShowVehicleListWindow(GetTileOwner(this->window_number), this->type, (TileIndex)this->window_number); |
|
822 |
break; |
|
823 |
||
824 |
case DEPOT_WIDGET_AUTOREPLACE: |
|
825 |
DoCommandP(this->window_number, this->type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE); |
|
826 |
break; |
|
827 |
||
828 |
} |
|
829 |
} |
|
830 |
||
831 |
virtual void OnPlaceObject(Point pt, TileIndex tile) |
|
832 |
{ |
|
833 |
const Vehicle *v = CheckMouseOverVehicle(); |
|
834 |
||
835 |
if (v != NULL) HandleCloneVehClick(v, this); |
|
836 |
} |
|
837 |
||
838 |
virtual void OnPlaceObjectAbort() |
|
839 |
{ |
|
840 |
/* abort clone */ |
|
841 |
this->RaiseWidget(DEPOT_WIDGET_CLONE); |
|
842 |
this->InvalidateWidget(DEPOT_WIDGET_CLONE); |
|
843 |
||
844 |
/* abort drag & drop */ |
|
845 |
this->sel = INVALID_VEHICLE; |
|
846 |
this->InvalidateWidget(DEPOT_WIDGET_MATRIX); |
|
847 |
}; |
|
848 |
||
849 |
/* check if a vehicle in a depot was clicked.. */ |
|
850 |
virtual void OnMouseLoop() |
|
851 |
{ |
|
852 |
const Vehicle *v = _place_clicked_vehicle; |
|
853 |
||
854 |
/* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */ |
|
855 |
if (v != NULL && this->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { |
|
856 |
_place_clicked_vehicle = NULL; |
|
857 |
HandleCloneVehClick(v, this); |
|
858 |
} |
|
859 |
} |
|
860 |
||
861 |
virtual void OnDragDrop(Point pt, int widget) |
|
862 |
{ |
|
863 |
switch (widget) { |
|
864 |
case DEPOT_WIDGET_MATRIX: { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
865 |
const Vehicle *v = NULL; |
10645 | 866 |
VehicleID sel = this->sel; |
867 |
||
868 |
this->sel = INVALID_VEHICLE; |
|
869 |
this->SetDirty(); |
|
870 |
||
871 |
if (this->type == VEH_TRAIN) { |
|
872 |
GetDepotVehiclePtData gdvp = { NULL, NULL }; |
|
873 |
||
874 |
if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && |
|
875 |
sel != INVALID_VEHICLE) { |
|
876 |
if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) { |
|
877 |
DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN)); |
|
878 |
} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { |
|
879 |
TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); |
|
880 |
} else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) { |
|
881 |
ShowVehicleViewWindow(gdvp.head); |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
882 |
} |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
883 |
} |
10645 | 884 |
} else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, NULL) == MODE_DRAG_VEHICLE && |
885 |
v != NULL && |
|
886 |
sel == v->index) { |
|
887 |
ShowVehicleViewWindow(v); |
|
888 |
} |
|
889 |
} break; |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
890 |
|
10645 | 891 |
case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN: |
892 |
if (!this->IsWidgetDisabled(DEPOT_WIDGET_SELL) && |
|
893 |
this->sel != INVALID_VEHICLE) { |
|
894 |
uint command; |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
895 |
|
10645 | 896 |
if (this->IsWidgetDisabled(widget)) return; |
897 |
if (this->sel == INVALID_VEHICLE) return; |
|
898 |
||
899 |
this->HandleButtonClick(widget); |
|
900 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
901 |
const Vehicle *v = GetVehicle(this->sel); |
10645 | 902 |
this->sel = INVALID_VEHICLE; |
903 |
this->SetDirty(); |
|
904 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
905 |
int sell_cmd = (v->type == VEH_TRAIN && (widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0; |
10645 | 906 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
907 |
bool is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v))); |
10645 | 908 |
|
909 |
if (is_engine) { |
|
910 |
_backup_orders_tile = v->tile; |
|
911 |
BackupVehicleOrders(v); |
|
912 |
} |
|
913 |
||
914 |
switch (v->type) { |
|
915 |
case VEH_TRAIN: command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break; |
|
916 |
case VEH_ROAD: command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE); break; |
|
917 |
case VEH_SHIP: command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP); break; |
|
918 |
case VEH_AIRCRAFT: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT); break; |
|
919 |
default: NOT_REACHED(); command = 0; |
|
920 |
} |
|
921 |
||
922 |
if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0; |
|
923 |
} |
|
924 |
break; |
|
925 |
default: |
|
926 |
this->sel = INVALID_VEHICLE; |
|
927 |
this->SetDirty(); |
|
928 |
} |
|
929 |
_cursor.vehchain = false; |
|
930 |
} |
|
931 |
||
932 |
virtual void OnResize(Point new_size, Point delta) |
|
933 |
{ |
|
934 |
this->vscroll.cap += delta.y / (int)this->resize.step_height; |
|
935 |
this->hscroll.cap += delta.x / (int)this->resize.step_width; |
|
936 |
this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap); |
|
937 |
ResizeDepotButtons(this); |
|
938 |
} |
|
939 |
||
940 |
virtual EventState OnCTRLStateChange() |
|
941 |
{ |
|
942 |
if (this->sel != INVALID_VEHICLE) { |
|
943 |
_cursor.vehchain = _ctrl_pressed; |
|
944 |
this->InvalidateWidget(DEPOT_WIDGET_MATRIX); |
|
945 |
} |
|
946 |
||
947 |
return ES_HANDLED; |
|
948 |
} |
|
949 |
}; |
|
950 |
||
951 |
static void DepotSellAllConfirmationCallback(Window *win, bool confirmed) |
|
952 |
{ |
|
953 |
if (confirmed) { |
|
954 |
DepotWindow *w = (DepotWindow*)win; |
|
955 |
TileIndex tile = w->window_number; |
|
956 |
byte vehtype = w->type; |
|
957 |
DoCommandP(tile, vehtype, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES); |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
958 |
} |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
959 |
} |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
960 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
961 |
/** Opens a depot window |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
962 |
* @param tile The tile where the depot/hangar is located |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
963 |
* @param type The type of vehicles in the depot |
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
964 |
*/ |
9624 | 965 |
void ShowDepotWindow(TileIndex tile, VehicleType type) |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
966 |
{ |
10645 | 967 |
DepotWindow *w; |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
968 |
|
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
969 |
switch (type) { |
5269
3f3eead5ace2
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
Darkvater
parents:
5265
diff
changeset
|
970 |
default: NOT_REACHED(); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
971 |
case VEH_TRAIN: |
10645 | 972 |
w = AllocateWindowDescFront<DepotWindow>(&_train_depot_desc, tile); break; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
973 |
case VEH_ROAD: |
10645 | 974 |
w = AllocateWindowDescFront<DepotWindow>(&_road_depot_desc, tile); break; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
975 |
case VEH_SHIP: |
10645 | 976 |
w = AllocateWindowDescFront<DepotWindow>(&_ship_depot_desc, tile); break; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
977 |
case VEH_AIRCRAFT: |
10645 | 978 |
w = AllocateWindowDescFront<DepotWindow>(&_aircraft_depot_desc, tile); break; |
4638
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 |
|
10645 | 981 |
if (w == NULL) return; |
982 |
||
983 |
w->caption_color = GetTileOwner(tile); |
|
984 |
w->CreateDepotListWindow(type); |
|
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
diff
changeset
|
985 |
} |
5255
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
986 |
|
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
987 |
/** Removes the highlight of a vehicle in a depot window |
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
988 |
* @param *v Vehicle to remove all highlights from |
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
989 |
*/ |
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
990 |
void DeleteDepotHighlightOfVehicle(const Vehicle *v) |
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
991 |
{ |
10645 | 992 |
DepotWindow *w; |
5255
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
993 |
|
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
|
994 |
/* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either |
10645 | 995 |
* If that is the case, we can skip looping though the windows and save time |
996 |
*/ |
|
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
|
997 |
if (_special_mouse_mode != WSM_DRAGDROP) return; |
6d1a560dd028
(svn r7390) -Codechange r7386: only loop though the windows to find a depot window to unhighlight a vehicle in if there is a vehicle on the mouse pointer
bjarni
parents:
5256
diff
changeset
|
998 |
|
10645 | 999 |
w = dynamic_cast<DepotWindow*>(FindWindowById(WC_VEHICLE_DEPOT, v->tile)); |
5265
a15469628808
(svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents:
5260
diff
changeset
|
1000 |
if (w != NULL) { |
10645 | 1001 |
w->sel = INVALID_VEHICLE; |
5265
a15469628808
(svn r7403) -Codechange (r7386, r7385): Use available functions to find a window instead of doing
Darkvater
parents:
5260
diff
changeset
|
1002 |
ResetObjectToPlace(); |
5255
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
1003 |
} |
b8445fda3fe2
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
bjarni
parents:
5125
diff
changeset
|
1004 |
} |