summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-28 23:05:03 +0000
committerbjarni <bjarni@openttd.org>2006-09-28 23:05:03 +0000
commit4ccdb0686f3b401199efc975e8ce9f75bbcde0d7 (patch)
treeb9c5f2fcf23245015608eafaccdf02f62b94eda6
parent1ae8aa4b809c3ddff032e2f3de7317490efa5235 (diff)
downloadopenttd-4ccdb0686f3b401199efc975e8ce9f75bbcde0d7.tar.xz
(svn r6562) -Codechange: merged the vehicle list window widget arrays
It made no sense to maintain 8 nearly identically arrays when a single one can do the job Also made the two buttons always use half of the bottom width each, even when resizing
-rw-r--r--aircraft_gui.c76
-rw-r--r--depot_gui.c64
-rw-r--r--gui.h8
-rw-r--r--main_gui.c17
-rw-r--r--misc_gui.c20
-rw-r--r--order_gui.c9
-rw-r--r--resize_window_widgets.h31
-rw-r--r--roadveh_gui.c75
-rw-r--r--ship_gui.c77
-rw-r--r--station_gui.c9
-rw-r--r--train_gui.c75
-rw-r--r--vehicle_gui.c210
-rw-r--r--vehicle_gui.h3
13 files changed, 275 insertions, 399 deletions
diff --git a/aircraft_gui.c b/aircraft_gui.c
index cc1894f27..8b503bd3c 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -602,79 +602,3 @@ void DrawSmallOrderListAircraft(const Vehicle *v, int x, int y)
}
}
}
-
-
-static const Widget _player_aircraft_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS },
-{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON },
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP },
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP },
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP },
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL },
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x401, STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT },
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST },
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 124, 170, 181, STR_SEND_TO_HANGARS, STR_SEND_TO_HANGARS_TIP },
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 125, 247, 170, 181, STR_REPLACE_VEHICLES, STR_REPLACE_HELP },
-{ WWT_PANEL, RESIZE_RTB, 14, 248, 247, 170, 181, 0x0, STR_NULL },
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON },
-{ WIDGETS_END},
-};
-
-static const Widget _other_player_aircraft_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS },
-{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON },
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP },
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP },
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP },
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL },
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x401, STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT },
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST },
-{ WWT_PANEL, RESIZE_RTB, 14, 0, 247, 170, 181, 0x0, STR_NULL },
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON },
-{ WIDGETS_END},
-};
-
-static const WindowDesc _player_aircraft_desc = {
- -1, -1, 260, 182,
- WC_AIRCRAFT_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _player_aircraft_widgets,
- PlayerVehWndProc
-};
-
-static const WindowDesc _other_player_aircraft_desc = {
- -1, -1, 260, 182,
- WC_AIRCRAFT_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _other_player_aircraft_widgets,
- PlayerVehWndProc
-};
-
-void ShowPlayerAircraftLocal(PlayerID player, StationID station, OrderID order, bool show_shared)
-{
- Window *w;
-
- if (show_shared) {
- w = AllocateWindowDescFront(&_player_aircraft_desc, (order << 16) | (VEH_Aircraft << 11) | VLW_SHARED_ORDERS | player);
- } else {
- uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST;
- if (player == _local_player) {
- w = AllocateWindowDescFront(&_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | VLW_flag | player);
- } else {
- w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | VLW_flag | player);
- }
- }
-}
-
-void ShowPlayerAircraft(PlayerID player, StationID station)
-{
- ShowPlayerAircraftLocal(player, station, INVALID_ORDER, false);
-}
-
-void ShowVehWithSharedOrdersAircraft(Vehicle *v)
-{
- if (v->orders == NULL) return; // no shared list to show
- ShowPlayerAircraftLocal(v->owner, INVALID_STATION, v->orders->index, true);
-}
diff --git a/depot_gui.c b/depot_gui.c
index 405c6df02..6c254c11f 100644
--- a/depot_gui.c
+++ b/depot_gui.c
@@ -18,23 +18,7 @@
#include "vehicle_gui.h"
#include "station_map.h"
#include "newgrf_engine.h"
-
-enum {
- WIDGET_DEPOT_MOVE_NONE = 0 << 0,
- WIDGET_DEPOT_MOVE_RIGHT = 1 << 0,
- WIDGET_DEPOT_MOVE_LEFT = 1 << 1,
- WIDGET_DEPOT_MOVE_TOP = 1 << 2,
- WIDGET_DEPOT_MOVE_BOTTOM = 1 << 3,
-
- DEPOT_MOVE_NONE = WIDGET_DEPOT_MOVE_NONE,
- DEPOT_STRETCH_RIGHT = WIDGET_DEPOT_MOVE_RIGHT,
- DEPOT_MOVE_RIGHT = WIDGET_DEPOT_MOVE_RIGHT | WIDGET_DEPOT_MOVE_LEFT,
- DEPOT_STRETCH_DOWN = WIDGET_DEPOT_MOVE_BOTTOM,
- DEPOT_MOVE_DOWN = WIDGET_DEPOT_MOVE_BOTTOM | WIDGET_DEPOT_MOVE_TOP,
- DEPOT_STRETCH_DOWN_RIGHT = DEPOT_STRETCH_DOWN | DEPOT_STRETCH_RIGHT,
- DEPOT_MOVE_DOWN_RIGHT = DEPOT_MOVE_RIGHT | DEPOT_MOVE_DOWN,
- DEPOT_MOVE_RIGHT_STRETCH_DOWN = DEPOT_MOVE_RIGHT | DEPOT_STRETCH_DOWN,
-};
+#include "resize_window_widgets.h"
/*
* Since all depot window sizes aren't the same, we need to modify sizes a little.
@@ -65,22 +49,22 @@ typedef enum DepotWindowWidgets {
/* Define how to move each widget. The order is important */
static const byte widget_moves[] = {
- DEPOT_MOVE_NONE, // DEPOT_WIDGET_CLOSEBOX
- DEPOT_STRETCH_RIGHT, // DEPOT_WIDGET_CAPTION
- DEPOT_MOVE_RIGHT, // DEPOT_WIDGET_STICKY
- DEPOT_MOVE_RIGHT, // DEPOT_WIDGET_STOP_ALL
- DEPOT_MOVE_RIGHT, // DEPOT_WIDGET_START_ALL
- DEPOT_MOVE_RIGHT, // DEPOT_WIDGET_SELL
- DEPOT_MOVE_NONE, // DEPOT_WIDGET_SELL_CHAIN
- DEPOT_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_SELL_ALL
- DEPOT_STRETCH_DOWN_RIGHT, // DEPOT_WIDGET_MATRIX
- DEPOT_MOVE_RIGHT_STRETCH_DOWN, // DEPOT_WIDGET_V_SCROLL
- DEPOT_MOVE_NONE, // DEPOT_WIDGET_H_SCROLL
- DEPOT_MOVE_DOWN, // DEPOT_WIDGET_BUILD
- DEPOT_MOVE_DOWN, // DEPOT_WIDGET_CLONE
- DEPOT_MOVE_DOWN, // DEPOT_WIDGET_LOCATION
- DEPOT_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_AUTOREPLACE
- DEPOT_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_RESIZE
+ WIDGET_MOVE_NONE, // DEPOT_WIDGET_CLOSEBOX
+ WIDGET_STRETCH_RIGHT, // DEPOT_WIDGET_CAPTION
+ WIDGET_MOVE_RIGHT, // DEPOT_WIDGET_STICKY
+ WIDGET_MOVE_RIGHT, // DEPOT_WIDGET_STOP_ALL
+ WIDGET_MOVE_RIGHT, // DEPOT_WIDGET_START_ALL
+ WIDGET_MOVE_RIGHT, // DEPOT_WIDGET_SELL
+ WIDGET_MOVE_NONE, // DEPOT_WIDGET_SELL_CHAIN
+ WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_SELL_ALL
+ WIDGET_STRETCH_DOWN_RIGHT, // DEPOT_WIDGET_MATRIX
+ WIDGET_MOVE_RIGHT_STRETCH_DOWN, // DEPOT_WIDGET_V_SCROLL
+ WIDGET_MOVE_NONE, // DEPOT_WIDGET_H_SCROLL
+ WIDGET_MOVE_DOWN, // DEPOT_WIDGET_BUILD
+ WIDGET_MOVE_DOWN, // DEPOT_WIDGET_CLONE
+ WIDGET_MOVE_DOWN, // DEPOT_WIDGET_LOCATION
+ WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_AUTOREPLACE
+ WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_RESIZE
};
/* Widget array for all depot windows.
@@ -906,18 +890,8 @@ void ShowDepotWindow(TileIndex tile, byte type)
SETBIT(w->hidden_state, DEPOT_WIDGET_SELL_CHAIN);
}
- /* Move the widgets to their right locations
- * Note: it's signed values so negative will make the widget move left and not right, or up instead of down */
- {
- byte i;
-
- for (i = 0; i < lengthof(widget_moves); i++) {
- if (widget_moves[i] & WIDGET_DEPOT_MOVE_LEFT) w->widget[i].left += horizontal;
- if (widget_moves[i] & WIDGET_DEPOT_MOVE_RIGHT) w->widget[i].right += horizontal;
- if (widget_moves[i] & WIDGET_DEPOT_MOVE_TOP) w->widget[i].top += vertical;
- if (widget_moves[i] & WIDGET_DEPOT_MOVE_BOTTOM) w->widget[i].bottom += vertical;
- }
- }
+ /* Move the widgets to their right locations */
+ ResizeWindowWidgets(w, widget_moves, lengthof(widget_moves), horizontal, vertical);
if (type == VEH_Train) {
/* Now we move the train only widgets so they are placed correctly
diff --git a/gui.h b/gui.h
index 69be6c848..bc74bccd3 100644
--- a/gui.h
+++ b/gui.h
@@ -40,28 +40,20 @@ void ShowBuildRailToolbar(RailType railtype, int button);
void PlaceProc_BuyLand(TileIndex tile);
/* train_gui.c */
-void ShowPlayerTrains(PlayerID player, StationID station);
void ShowTrainViewWindow(const Vehicle *v);
void ShowOrdersWindow(const Vehicle *v);
-void ShowVehWithSharedOrdersTrains(Vehicle *v);
/* road_gui.c */
void ShowBuildRoadToolbar(void);
void ShowBuildRoadScenToolbar(void);
-void ShowPlayerRoadVehicles(PlayerID player, StationID station);
-void ShowVehWithSharedOrdersRoadVehicles(Vehicle *v);
void ShowRoadVehViewWindow(const Vehicle *v);
/* dock_gui.c */
void ShowBuildDocksToolbar(void);
-void ShowPlayerShips(PlayerID player, StationID station);
-void ShowVehWithSharedOrdersShips(Vehicle *v);
void ShowShipViewWindow(const Vehicle *v);
/* aircraft_gui.c */
void ShowBuildAirToolbar(void);
-void ShowPlayerAircraft(PlayerID player, StationID station);
-void ShowVehWithSharedOrdersAircraft(Vehicle *v);
/* terraform_gui.c */
void ShowTerraformToolbar(void);
diff --git a/main_gui.c b/main_gui.c
index 9eb0681d8..e8fed0744 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -33,6 +33,7 @@
#include "genworld.h"
#include "settings.h"
#include "date.h"
+#include "vehicle_gui.h"
#include "network_data.h"
#include "network_client.h"
@@ -268,22 +269,22 @@ static void MenuClickIndustry(int index)
static void MenuClickShowTrains(int index)
{
- ShowPlayerTrains(index, INVALID_STATION);
+ ShowVehicleListWindow(index, INVALID_STATION, VEH_Train);
}
static void MenuClickShowRoad(int index)
{
- ShowPlayerRoadVehicles(index, INVALID_STATION);
+ ShowVehicleListWindow(index, INVALID_STATION, VEH_Road);
}
static void MenuClickShowShips(int index)
{
- ShowPlayerShips(index, INVALID_STATION);
+ ShowVehicleListWindow(index, INVALID_STATION, VEH_Ship);
}
static void MenuClickShowAir(int index)
{
- ShowPlayerAircraft(index, INVALID_STATION);
+ ShowVehicleListWindow(index, INVALID_STATION, VEH_Aircraft);
}
static void MenuClickBuildRail(int index)
@@ -1792,10 +1793,10 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
case WKC_F10:ShowOperatingProfitGraph(); break;
case WKC_F11: ShowCompanyLeagueTable(); break;
case WKC_F12: ShowBuildIndustryWindow(); break;
- case WKC_SHIFT | WKC_F1: ShowPlayerTrains(local, INVALID_STATION); break;
- case WKC_SHIFT | WKC_F2: ShowPlayerRoadVehicles(local, INVALID_STATION); break;
- case WKC_SHIFT | WKC_F3: ShowPlayerShips(local, INVALID_STATION); break;
- case WKC_SHIFT | WKC_F4: ShowPlayerAircraft(local, INVALID_STATION); break;
+ case WKC_SHIFT | WKC_F1: ShowVehicleListWindow(local, INVALID_STATION, VEH_Train); break;
+ case WKC_SHIFT | WKC_F2: ShowVehicleListWindow(local, INVALID_STATION, VEH_Road); break;
+ case WKC_SHIFT | WKC_F3: ShowVehicleListWindow(local, INVALID_STATION, VEH_Ship); break;
+ case WKC_SHIFT | WKC_F4: ShowVehicleListWindow(local, INVALID_STATION, VEH_Aircraft); break;
case WKC_SHIFT | WKC_F5: ToolbarZoomInClick(w); break;
case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(w); break;
case WKC_SHIFT | WKC_F7: ShowBuildRailToolbar(_last_built_railtype,-1); break;
diff --git a/misc_gui.c b/misc_gui.c
index 3654e6fc2..315bab533 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -30,6 +30,7 @@
#include "tgp.h"
#include "settings.h"
#include "date.h"
+#include "resize_window_widgets.h"
#include "fios.h"
/* Variables to display file lists */
@@ -1867,3 +1868,22 @@ void ShowCheatWindow(void)
if (w != NULL) SetWindowDirty(w);
}
+
+/** Resize the widgets in a window
+ * @param *w Window to resize in
+ * @param *resizearray Bytearray of the same length as the window contains widgets. Each byte tells how to move the widget of the same index using the flags in resize_window_widgets.h
+ * @param length Length of the bytearray
+ * @param horizontal Tells how far to the right the widgets should be moved (note: negative moves left)
+ * @param vertical Tells how far down the widgets should be moved (note: negative moves up)
+*/
+void ResizeWindowWidgets(Window *w, const byte *resizearray, byte length, byte horizontal, byte vertical)
+{
+ byte i;
+
+ for (i = 0; i < length; i++) {
+ if (resizearray[i] & WIDGET_DEFINE_MOVE_LEFT) w->widget[i].left += horizontal;
+ if (resizearray[i] & WIDGET_DEFINE_MOVE_RIGHT) w->widget[i].right += horizontal;
+ if (resizearray[i] & WIDGET_DEFINE_MOVE_TOP) w->widget[i].top += vertical;
+ if (resizearray[i] & WIDGET_DEFINE_MOVE_BOTTOM) w->widget[i].bottom += vertical;
+ }
+}
diff --git a/order_gui.c b/order_gui.c
index 2bcf0ed76..c1b262a72 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -21,6 +21,7 @@
#include "waypoint.h"
#include "train.h"
#include "water_map.h"
+#include "vehicle_gui.h"
static int OrderGetSel(const Window *w)
{
@@ -463,13 +464,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
OrderClick_Transfer(w, v);
break;
case 11: /* Vehicle with same shared Orders button */
- switch (v->type) {
- case VEH_Train: ShowVehWithSharedOrdersTrains(v); break;
- case VEH_Road: ShowVehWithSharedOrdersRoadVehicles(v); break;
- case VEH_Ship: ShowVehWithSharedOrdersShips(v); break;
- case VEH_Aircraft: ShowVehWithSharedOrdersAircraft(v); break;
- default: NOT_REACHED(); break;
- }
+ ShowVehWithSharedOrders(v, v->type);
break;
}
} break;
diff --git a/resize_window_widgets.h b/resize_window_widgets.h
new file mode 100644
index 000000000..a593e45b0
--- /dev/null
+++ b/resize_window_widgets.h
@@ -0,0 +1,31 @@
+/* $Id$ */
+
+/** @file resize_window_widgets.h */
+
+
+#ifndef RESIZE_WINDOW_WIDGET_H
+#define RESIZE_WINDOW_WIDGET_H
+#include "stdafx.h"
+#include "window.h"
+
+enum {
+ WIDGET_DEFINE_MOVE_NONE = 0 << 0,
+ WIDGET_DEFINE_MOVE_RIGHT = 1 << 0,
+ WIDGET_DEFINE_MOVE_LEFT = 1 << 1,
+ WIDGET_DEFINE_MOVE_TOP = 1 << 2,
+ WIDGET_DEFINE_MOVE_BOTTOM = 1 << 3,
+
+ WIDGET_MOVE_NONE = WIDGET_DEFINE_MOVE_NONE,
+ WIDGET_STRETCH_RIGHT = WIDGET_DEFINE_MOVE_RIGHT,
+ WIDGET_MOVE_RIGHT = WIDGET_DEFINE_MOVE_RIGHT | WIDGET_DEFINE_MOVE_LEFT,
+ WIDGET_STRETCH_DOWN = WIDGET_DEFINE_MOVE_BOTTOM,
+ WIDGET_MOVE_DOWN = WIDGET_DEFINE_MOVE_BOTTOM | WIDGET_DEFINE_MOVE_TOP,
+ WIDGET_STRETCH_DOWN_RIGHT = WIDGET_STRETCH_DOWN | WIDGET_STRETCH_RIGHT,
+ WIDGET_MOVE_DOWN_RIGHT = WIDGET_MOVE_RIGHT | WIDGET_MOVE_DOWN,
+ WIDGET_MOVE_RIGHT_STRETCH_DOWN = WIDGET_MOVE_RIGHT | WIDGET_STRETCH_DOWN,
+ WIDGET_MOVE_DOWN_STRETCH_RIGHT = WIDGET_MOVE_DOWN | WIDGET_STRETCH_RIGHT,
+};
+
+void ResizeWindowWidgets(Window *w, const byte *resizearray, byte length, byte horizontal, byte vertical);
+
+#endif
diff --git a/roadveh_gui.c b/roadveh_gui.c
index 61bab84e4..01c8f459e 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -535,78 +535,3 @@ void ShowBuildRoadVehWindow(TileIndex tile)
}
}
-static const Widget _player_roadveh_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 207, 0x701, STR_901A_ROAD_VEHICLES_CLICK_ON},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 124, 208, 219, STR_SEND_TO_DEPOTS, STR_SEND_TO_DEPOTS_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 125, 247, 208, 219, STR_REPLACE_VEHICLES, STR_REPLACE_HELP},
-{ WWT_PANEL, RESIZE_RTB, 14, 248, 247, 208, 219, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 208, 219, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const Widget _other_player_roadveh_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 207, 0x701, STR_901A_ROAD_VEHICLES_CLICK_ON},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PANEL, RESIZE_RTB, 14, 0, 247, 208, 219, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 208, 219, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const WindowDesc _player_roadveh_desc = {
- -1, -1, 260, 220,
- WC_ROADVEH_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _player_roadveh_widgets,
- PlayerVehWndProc
-};
-
-static const WindowDesc _other_player_roadveh_desc = {
- -1, -1, 260, 220,
- WC_ROADVEH_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _other_player_roadveh_widgets,
- PlayerVehWndProc
-};
-
-
-static void ShowPlayerRoadVehiclesLocal(PlayerID player, StationID station, OrderID order, bool show_shared)
-{
- Window *w;
-
- if (show_shared) {
- w = AllocateWindowDescFront(&_player_roadveh_desc, (order << 16) | (VEH_Road << 11) | VLW_SHARED_ORDERS | player);
- } else {
- uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST;
- if (player == _local_player) {
- w = AllocateWindowDescFront(&_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | VLW_flag | player);
- } else {
- w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | VLW_flag | player);
- }
- }
-}
-
-void ShowPlayerRoadVehicles(PlayerID player, StationID station)
-{
- ShowPlayerRoadVehiclesLocal(player, station, 0, false);
-}
-
-void ShowVehWithSharedOrdersRoadVehicles(Vehicle *v)
-{
- if (v->orders == NULL) return; // no shared list to show
- ShowPlayerRoadVehiclesLocal(v->owner, INVALID_STATION, v->orders->index, true);
-}
diff --git a/ship_gui.c b/ship_gui.c
index 8d80d9a48..bf1114d1c 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -548,80 +548,3 @@ void DrawSmallOrderListShip(const Vehicle *v, int x, int y)
}
}
}
-
-
-static const Widget _player_ships_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 124, 170, 181, STR_SEND_TO_DEPOTS, STR_SEND_TO_DEPOTS_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 125, 247, 170, 181, STR_REPLACE_VEHICLES, STR_REPLACE_HELP},
-{ WWT_PANEL, RESIZE_RTB, 14, 248, 247, 170, 181, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const Widget _other_player_ships_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PANEL, RESIZE_RTB, 14, 0, 247, 170, 181, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const WindowDesc _player_ships_desc = {
- -1, -1, 260, 182,
- WC_SHIPS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _player_ships_widgets,
- PlayerVehWndProc
-};
-
-static const WindowDesc _other_player_ships_desc = {
- -1, -1, 260, 182,
- WC_SHIPS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _other_player_ships_widgets,
- PlayerVehWndProc
-};
-
-
-static void ShowPlayerShipsLocal(PlayerID player, StationID station, OrderID order, bool show_shared)
-{
- Window *w;
-
- if (show_shared) {
- w = AllocateWindowDescFront(&_player_ships_desc, (order << 16) | (VEH_Ship << 11) | VLW_SHARED_ORDERS | player);
- } else {
- uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST;
- if (player == _local_player) {
- w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | (VEH_Ship << 11) | VLW_flag | player);
- } else {
- w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | (VEH_Ship << 11) | VLW_flag | player);
- }
- }
-}
-
-void ShowPlayerShips(PlayerID player, StationID station)
-{
- ShowPlayerShipsLocal(player, station, 0, false);
-}
-
-void ShowVehWithSharedOrdersShips(Vehicle *v)
-{
- if (v->orders == NULL) return; // no shared list to show
- ShowPlayerShipsLocal(v->owner, INVALID_STATION, v->orders->index, true);
-}
diff --git a/station_gui.c b/station_gui.c
index a7d9b1143..4c4dad665 100644
--- a/station_gui.c
+++ b/station_gui.c
@@ -17,6 +17,7 @@
#include "variables.h"
#include "vehicle_gui.h"
#include "date.h"
+#include "vehicle.h"
typedef int CDECL StationSortListingTypeFunction(const void*, const void*);
@@ -679,13 +680,13 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
case 10: { /* Show a list of scheduled trains to this station */
const Station *st = GetStation(w->window_number);
- ShowPlayerTrains(st->owner, w->window_number);
+ ShowVehicleListWindow(st->owner, w->window_number, VEH_Train);
break;
}
case 11: { /* Show a list of scheduled road-vehicles to this station */
const Station *st = GetStation(w->window_number);
- ShowPlayerRoadVehicles(st->owner, w->window_number);
+ ShowVehicleListWindow(st->owner, w->window_number, VEH_Road);
break;
}
@@ -693,7 +694,7 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
const Station *st = GetStation(w->window_number);
/* Since oilrigs have no owners, show the scheduled aircraft of current player */
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
- ShowPlayerAircraft(owner, w->window_number);
+ ShowVehicleListWindow(owner, w->window_number, VEH_Aircraft);
break;
}
@@ -701,7 +702,7 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
const Station *st = GetStation(w->window_number);
/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
- ShowPlayerShips(owner, w->window_number);
+ ShowVehicleListWindow(owner, w->window_number, VEH_Ship);
break;
}
}
diff --git a/train_gui.c b/train_gui.c
index aba29e187..5f3e7b93f 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -873,78 +873,3 @@ static void ShowTrainDetailsWindow(const Vehicle *v)
WP(w,traindetails_d).tab = 0;
}
-
-static const Widget _player_trains_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 324, 14, 25, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 156, 208, 219, STR_SEND_TO_DEPOTS, STR_SEND_TO_DEPOTS_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 157, 312, 208, 219, STR_REPLACE_VEHICLES, STR_REPLACE_HELP},
-{ WWT_PANEL, RESIZE_RTB, 14, 313, 312, 208, 219, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const Widget _other_player_trains_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 324, 14, 25, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PANEL, RESIZE_RTB, 14, 0, 312, 208, 219, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const WindowDesc _player_trains_desc = {
- -1, -1, 325, 220,
- WC_TRAINS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _player_trains_widgets,
- PlayerVehWndProc
-};
-
-static const WindowDesc _other_player_trains_desc = {
- -1, -1, 325, 220,
- WC_TRAINS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _other_player_trains_widgets,
- PlayerVehWndProc
-};
-
-static void ShowPlayerTrainsLocal(PlayerID player, StationID station, OrderID order, bool show_shared)
-{
- Window *w;
-
- if (show_shared) {
- w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | (VEH_Train << 11) | VLW_SHARED_ORDERS | player);
- } else {
- uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST;
- if (player == _local_player) {
- w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | (VEH_Train << 11) | VLW_flag | player);
- } else {
- w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | (VEH_Train << 11) | VLW_flag | player);
- }
- }
-}
-
-void ShowPlayerTrains(PlayerID player, StationID station)
-{
- ShowPlayerTrainsLocal(player, station, INVALID_ORDER, false);
-}
-
-void ShowVehWithSharedOrdersTrains(Vehicle *v)
-{
- if (v->orders == NULL) return; // no shared list to show
- ShowPlayerTrainsLocal(v->owner, INVALID_STATION, v->orders->index, true);
-}
diff --git a/vehicle_gui.c b/vehicle_gui.c
index b7ff5d186..de4a2497c 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -27,6 +27,7 @@
#include "aircraft.h"
#include "roadveh.h"
#include "depot.h"
+#include "resize_window_widgets.h"
typedef struct Sorting {
Listing aircraft;
@@ -1210,26 +1211,125 @@ enum {
PLY_WND_PRC__SIZE_OF_ROW_BIG = 36,
};
+typedef enum VehicleListWindowWidgets {
+ VLW_WIDGET_CLOSEBOX = 0,
+ VLW_WIDGET_CAPTION,
+ VLW_WIDGET_STICKY,
+ VLW_WIDGET_SORT_ORDER,
+ VLW_WIDGET_SORT_BY_TEXT,
+ VLW_WIDGET_SORT_BY_PULLDOWN,
+ VLW_WIDGET_EMPTY_SPACE_TOP_RIGHT,
+ VLW_WIDGET_LIST,
+ VLW_WIDGET_SCROLLBAR,
+ VLW_WIDGET_OTHER_PLAYER_FILLER,
+ VLW_WIDGET_SEND_TO_DEPOT,
+ VLW_WIDGET_AUTOREPLACE,
+ VLW_WIDGET_RESIZE,
+} VehicleListWindowWidget;
+
+static const byte vehicle_list_widget_moves[] = {
+ WIDGET_MOVE_NONE, // VLW_WIDGET_CLOSEBOX
+ WIDGET_STRETCH_RIGHT, // VLW_WIDGET_CAPTION
+ WIDGET_MOVE_RIGHT, // VLW_WIDGET_STICKY
+ WIDGET_MOVE_NONE, // VLW_WIDGET_SORT_ORDER
+ WIDGET_MOVE_NONE, // VLW_WIDGET_SORT_BY_TEXT
+ WIDGET_MOVE_NONE, // VLW_WIDGET_SORT_BY_PULLDOWN
+ WIDGET_STRETCH_RIGHT, // VLW_WIDGET_EMPTY_SPACE_TOP_RIGHT
+ WIDGET_STRETCH_DOWN_RIGHT, // VLW_WIDGET_LIST
+ WIDGET_MOVE_RIGHT_STRETCH_DOWN, // VLW_WIDGET_SCROLLBAR
+ WIDGET_MOVE_DOWN_STRETCH_RIGHT, // VLW_WIDGET_OTHER_PLAYER_FILLER
+ WIDGET_MOVE_DOWN, // VLW_WIDGET_SEND_TO_DEPOT
+ WIDGET_MOVE_DOWN, // VLW_WIDGET_AUTOREPLACE
+ WIDGET_MOVE_DOWN_RIGHT, // VLW_WIDGET_RESIZE
+};
+
+static const Widget _vehicle_list_widgets[] = {
+ { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
+ { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS},
+ { WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
+ { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
+ { WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
+ { WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
+ { WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
+ { WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x0, STR_NULL},
+ { WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
+ { WWT_PANEL, RESIZE_RTB, 14, 0, 247, 170, 181, 0x0, STR_NULL},
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 124, 170, 181, STR_SEND_TO_DEPOTS, STR_SEND_TO_DEPOTS_TIP},
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 125, 247, 170, 181, STR_REPLACE_VEHICLES, STR_REPLACE_HELP},
+ { WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON},
+ { WIDGETS_END},
+};
+
+/* Resize the bottom row of buttons to make them equal in size when resizing */
+static void ResizeVehicleListWidgets(Window *w)
+{
+ w->widget[VLW_WIDGET_AUTOREPLACE].right = w->widget[VLW_WIDGET_RESIZE].left - 1;
+ w->widget[VLW_WIDGET_SEND_TO_DEPOT].right = w->widget[VLW_WIDGET_AUTOREPLACE].right / 2;
+ w->widget[VLW_WIDGET_AUTOREPLACE].left = w->widget[VLW_WIDGET_SEND_TO_DEPOT].right;
+}
+
static void CreateVehicleListWindow(Window *w)
{
vehiclelist_d *vl = &WP(w, vehiclelist_d);
uint16 window_type = w->window_number & VLW_MASK;
+ PlayerID player = GB(w->window_number, 0, 8);
+
vl->vehicle_type = GB(w->window_number, 11, 5);
- w->caption_color = GB(w->window_number, 0, 8); // PlayerID
+ w->caption_color = player;
+
+ /* Hide the widgets that we will not use in this window
+ * Some windows contains actions only fit for the owner */
+ if (player == _local_player) {
+ SETBIT(w->hidden_state, VLW_WIDGET_OTHER_PLAYER_FILLER);
+ } else {
+ SETBIT(w->hidden_state, VLW_WIDGET_SEND_TO_DEPOT);
+ SETBIT(w->hidden_state, VLW_WIDGET_AUTOREPLACE);
+ }
/* Set up the window widgets */
+ switch (vl->vehicle_type) {
+ case VEH_Train:
+ w->widget[VLW_WIDGET_LIST].tooltips = STR_883D_TRAINS_CLICK_ON_TRAIN_FOR;
+ break;
+
+ case VEH_Road:
+ w->widget[VLW_WIDGET_LIST].tooltips = STR_901A_ROAD_VEHICLES_CLICK_ON;
+ break;
+
+ case VEH_Ship:
+ w->widget[VLW_WIDGET_LIST].tooltips = STR_9823_SHIPS_CLICK_ON_SHIP_FOR;
+ break;
+
+ case VEH_Aircraft:
+ w->widget[VLW_WIDGET_CAPTION].data = STR_A009_AIRCRAFT;
+ w->widget[VLW_WIDGET_LIST].tooltips = STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT;
+ /* Aircraft uses hangars, not depots, so we will apply the hangar strings */
+ w->widget[VLW_WIDGET_SEND_TO_DEPOT].data = STR_SEND_TO_HANGARS;
+ w->widget[VLW_WIDGET_SEND_TO_DEPOT].tooltips = STR_SEND_TO_HANGARS_TIP;
+ break;
+
+ default: NOT_REACHED(); break;
+ }
+
switch (window_type) {
case VLW_SHARED_ORDERS:
- w->widget[1].data = STR_VEH_WITH_SHARED_ORDERS_LIST;
+ w->widget[VLW_WIDGET_CAPTION].data = STR_VEH_WITH_SHARED_ORDERS_LIST;
break;
case VLW_STANDARD: /* Company Name - standard widget setup */
+ switch (vl->vehicle_type) {
+ case VEH_Train: w->widget[VLW_WIDGET_CAPTION].data = STR_881B_TRAINS; break;
+ case VEH_Road: w->widget[VLW_WIDGET_CAPTION].data = STR_9001_ROAD_VEHICLES; break;
+ case VEH_Ship: w->widget[VLW_WIDGET_CAPTION].data = STR_9805_SHIPS; break;
+ case VEH_Aircraft: w->widget[VLW_WIDGET_CAPTION].data = STR_A009_AIRCRAFT; break;
+ default: NOT_REACHED(); break;
+ }
break;
case VLW_STATION_LIST: /* Station Name */
switch (vl->vehicle_type) {
- case VEH_Train: w->widget[1].data = STR_SCHEDULED_TRAINS; break;
- case VEH_Road: w->widget[1].data = STR_SCHEDULED_ROAD_VEHICLES; break;
- case VEH_Ship: w->widget[1].data = STR_SCHEDULED_SHIPS; break;
- case VEH_Aircraft: w->widget[1].data = STR_SCHEDULED_AIRCRAFT; break;
+ case VEH_Train: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_TRAINS; break;
+ case VEH_Road: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_ROAD_VEHICLES; break;
+ case VEH_Ship: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_SHIPS; break;
+ case VEH_Aircraft: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_AIRCRAFT; break;
default: NOT_REACHED(); break;
}
break;
@@ -1254,7 +1354,7 @@ static void CreateVehicleListWindow(Window *w)
default: NOT_REACHED();
}
- w->widget[7].data = (w->vscroll.cap << 8) + 1;
+ w->widget[VLW_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
/* Set up sorting. Make the window-specific _sorting variable
* point to the correct global _sorting struct so we are freed
@@ -1272,6 +1372,12 @@ static void CreateVehicleListWindow(Window *w)
vl->sort_list = NULL;
vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
+ /* Resize the widgets to fit the window size.
+ * Aircraft and ships already got the right size widgets */
+ if (w->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_SMALL) {
+ ResizeWindowWidgets(w, vehicle_list_widget_moves, lengthof(vehicle_list_widget_moves), vl->vehicle_type == VEH_Train ? 65 : 0, 38);
+ ResizeVehicleListWidgets(w);
+ }
}
static void DrawVehicleListWindow(Window *w)
@@ -1305,15 +1411,15 @@ static void DrawVehicleListWindow(Window *w)
case VLW_STANDARD: /* Company Name */
SetDParam(0, p->name_1);
- SetDParam(1, p->name_2);
- SetDParam(2, w->vscroll.count);
- break;
+ SetDParam(1, p->name_2);
+ SetDParam(2, w->vscroll.count);
+ break;
- case VLW_STATION_LIST: /* Station Name */
- SetDParam(0, station);
- SetDParam(1, w->vscroll.count);
- break;
- default: NOT_REACHED(); break;
+ case VLW_STATION_LIST: /* Station Name */
+ SetDParam(0, station);
+ SetDParam(1, w->vscroll.count);
+ break;
+ default: NOT_REACHED(); break;
}
DrawWindowWidgets(w);
@@ -1411,17 +1517,17 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
switch (e->we.click.widget) {
- case 3: /* Flip sorting method ascending/descending */
+ case VLW_WIDGET_SORT_ORDER: /* Flip sorting method ascending/descending */
vl->l.flags ^= VL_DESC;
vl->l.flags |= VL_RESORT;
vl->_sorting->order = !!(vl->l.flags & VL_DESC);
SetWindowDirty(w);
break;
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, 5, 0, 0);
+ case VLW_WIDGET_SORT_BY_TEXT: case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */
+ ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, 0);
return;
- case 7: { /* Matrix to show vehicles */
+ case VLW_WIDGET_LIST: { /* Matrix to show vehicles */
uint32 id_v = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / w->resize.step_height;
const Vehicle *v;
@@ -1442,15 +1548,13 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
}
} break;
- case 9: // Left button
- if ((PlayerID)w->caption_color != _local_player) break;
-
+ case VLW_WIDGET_SEND_TO_DEPOT: // Left button
assert(vl->l.list_length != 0);
DoCommandP(0, GB(w->window_number, 16, 16) /* StationID or OrderID (depending on VLW). Nomatter which one it is, it's needed here */,
(w->window_number & VLW_MASK) | DEPOT_MASS_SEND | (_ctrl_pressed ? DEPOT_SERVICE : 0), NULL, CMD_SEND_TO_DEPOT(vl->vehicle_type));
break;
- case 10: // Right button
+ case VLW_WIDGET_AUTOREPLACE: // Right button
ShowReplaceVehicleWindow(vl->vehicle_type);
break;
}
@@ -1485,7 +1589,65 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
case WE_RESIZE: /* Update the scroll + matrix */
if (vl->vehicle_type == VEH_Train) w->hscroll.cap += e->we.sizing.diff.x;
w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
- w->widget[7].data = (w->vscroll.cap << 8) + 1;
+ w->widget[VLW_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
+ ResizeVehicleListWidgets(w);
break;
}
}
+
+static const WindowDesc _player_vehicle_list_large_desc = {
+ -1, -1, 260, 182,
+ WC_SHIPS_LIST,0,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
+ _vehicle_list_widgets,
+ PlayerVehWndProc
+};
+
+static const WindowDesc _player_vehicle_list_train_desc = {
+ -1, -1, 325, 220,
+ WC_TRAINS_LIST,0,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
+ _vehicle_list_widgets,
+ PlayerVehWndProc
+};
+
+static const WindowDesc _player_vehicle_list_road_veh_desc = {
+ -1, -1, 260, 220,
+ WC_TRAINS_LIST,0,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
+ _vehicle_list_widgets,
+ PlayerVehWndProc
+};
+
+static void ShowVehicleListWindowLocal(PlayerID player, byte vehicle_type, StationID station, OrderID order, bool show_shared)
+{
+ Window *w;
+ WindowNumber num = (vehicle_type << 11) | player;
+
+ if (show_shared) {
+ num |= (order << 16) | VLW_SHARED_ORDERS;
+ } else if (station == INVALID_STATION) {
+ num |= VLW_STANDARD;
+ } else {
+ num |= (station << 16) | VLW_STATION_LIST;
+ }
+
+ if (vehicle_type == VEH_Train) {
+ w = AllocateWindowDescFront(&_player_vehicle_list_train_desc, num);
+ } else if (vehicle_type == VEH_Road) {
+ w = AllocateWindowDescFront(&_player_vehicle_list_road_veh_desc, num);
+ } else {
+ w = AllocateWindowDescFront(&_player_vehicle_list_large_desc, num);
+ }
+}
+
+void ShowVehicleListWindow(PlayerID player, StationID station, byte vehicle_type)
+{
+ ShowVehicleListWindowLocal(player, vehicle_type, station, INVALID_ORDER, false);
+}
+
+void ShowVehWithSharedOrders(Vehicle *v, byte vehicle_type)
+{
+ if (v->orders == NULL) return; // no shared list to show
+ ShowVehicleListWindowLocal(v->owner, vehicle_type, INVALID_STATION, v->orders->index, true);
+} \ No newline at end of file
diff --git a/vehicle_gui.h b/vehicle_gui.h
index 4a30a9518..8bcba82fd 100644
--- a/vehicle_gui.h
+++ b/vehicle_gui.h
@@ -52,4 +52,7 @@ void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
int ShowAdditionalText(int x, int y, int w, EngineID engine);
+void ShowVehicleListWindow(PlayerID player, StationID station, byte vehicle_type);
+void ShowVehWithSharedOrders(Vehicle *v, byte vehicle_type);
+
#endif /* VEHICLE_GUI_H */