diff options
author | Darkvater <darkvater@openttd.org> | 2006-12-07 00:51:20 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-12-07 00:51:20 +0000 |
commit | a518ecbabb65c86b43b7aa4adf968ea3ee68e8a2 (patch) | |
tree | 6e7008b954ce4626822fcb96dad9f6467e534b51 | |
parent | cf385cccf3585299391aa73fad4f49a79bc88f55 (diff) | |
download | openttd-a518ecbabb65c86b43b7aa4adf968ea3ee68e8a2.tar.xz |
(svn r7410) -Codechange/Fix: Remove useless and unfollowable programmatic-resize, and implement it
in a sane way. Correctly specify resize flags for windows and only manually change the
widgets that the resize system cannot handle (eg centering). This changes r6562, and
probably some other commits
-rw-r--r-- | depot_gui.c | 405 | ||||
-rw-r--r-- | misc_gui.c | 20 | ||||
-rw-r--r-- | openttd.vcproj | 3 | ||||
-rw-r--r-- | openttd_vs80.vcproj | 4 | ||||
-rw-r--r-- | resize_window_widgets.h | 31 | ||||
-rw-r--r-- | vehicle_gui.c | 63 |
6 files changed, 212 insertions, 314 deletions
diff --git a/depot_gui.c b/depot_gui.c index 5dac5cc6d..2ce1096f3 100644 --- a/depot_gui.c +++ b/depot_gui.c @@ -18,7 +18,6 @@ #include "vehicle_gui.h" #include "station_map.h" #include "newgrf_engine.h" -#include "resize_window_widgets.h" /* * Since all depot window sizes aren't the same, we need to modify sizes a little. @@ -27,7 +26,7 @@ */ /* Names of the widgets. Keep them in the same order as in the widget array */ -typedef enum DepotWindowWidgets { +enum DepotWindowWidgets { DEPOT_WIDGET_CLOSEBOX = 0, DEPOT_WIDGET_CAPTION, DEPOT_WIDGET_STICKY, @@ -45,28 +44,6 @@ typedef enum DepotWindowWidgets { DEPOT_WIDGET_STOP_ALL, DEPOT_WIDGET_START_ALL, DEPOT_WIDGET_RESIZE, - DEPOT_WIDGET_LAST, // used to assert if DepotWindowWidgets and widget_moves got different lengths. Due to this usage, it needs to be last -} DepotWindowWidget; - -/* Define how to move each widget. The order is important */ -static const byte widget_moves[] = { - WIDGET_MOVE_NONE, // DEPOT_WIDGET_CLOSEBOX - WIDGET_STRETCH_RIGHT, // DEPOT_WIDGET_CAPTION - WIDGET_MOVE_RIGHT, // DEPOT_WIDGET_STICKY - WIDGET_MOVE_RIGHT_STRETCH_DOWN, // DEPOT_WIDGET_SELL - WIDGET_MOVE_NONE, // DEPOT_WIDGET_SELL_CHAIN - WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_SELL_ALL - WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_AUTOREPLACE - 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_VEHICLE_LIST - WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_STOP_ALL - WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_START_ALL - WIDGET_MOVE_DOWN_RIGHT, // DEPOT_WIDGET_RESIZE }; /* Widget array for all depot windows. @@ -86,20 +63,20 @@ static const Widget _depot_widgets[] = { /* Widgets are set up run-time */ { WWT_IMGBTN, RESIZE_LRB, 14, 270, 292, 14, 37, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL - { WWT_IMGBTN, RESIZE_LRTB, 14, 326, 348, 0, 0, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only + { WWT_IMGBTN, RESIZE_LRTB, 14, 270, 292, 14, 37, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 270, 292, 38, 60, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL_ALL { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 270, 292, 61, 83, 0x0, STR_NULL}, // DEPOT_WIDGET_AUTOREPLACE { WWT_MATRIX, RESIZE_RB, 14, 0, 269, 14, 83, 0x0, STR_NULL}, // DEPOT_WIDGET_MATRIX { WWT_SCROLLBAR, RESIZE_LRB, 14, 293, 304, 14, 83, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_V_SCROLL - { WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 325, 98, 109, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_H_SCROLL, trains only + { WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 269, 72, 83, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_H_SCROLL, trains only /* The buttons in the bottom of the window. left and right is not important as they are later resized to be equal in size * This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0 */ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 85, 84, 95, 0x0, STR_NULL}, // DEPOT_WIDGET_BUILD { WWT_TEXTBTN, RESIZE_TB, 14, 86, 170, 84, 95, 0x0, STR_NULL}, // DEPOT_WIDGET_CLONE - { WWT_PUSHTXTBTN, RESIZE_TB, 14, 171, 257, 84, 95, STR_00E4_LOCATION, STR_NULL}, // DEPOT_WIDGET_LOCATION + { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 171, 257, 84, 95, STR_00E4_LOCATION, STR_NULL}, // DEPOT_WIDGET_LOCATION { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 258, 269, 84, 95, 0x0, STR_NULL}, // DEPOT_WIDGET_VEHICLE_LIST { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 270, 280, 84, 95, SPR_FLAG_VEH_STOPPED,STR_NULL}, // DEPOT_WIDGET_STOP_ALL { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 281, 292, 84, 95, SPR_FLAG_VEH_RUNNING,STR_NULL}, // DEPOT_WIDGET_START_ALL @@ -110,7 +87,7 @@ static const Widget _depot_widgets[] = { static void DepotWndProc(Window *w, WindowEvent *e); static const WindowDesc _train_depot_desc = { - WDP_AUTO, WDP_AUTO, 361, 122, + WDP_AUTO, WDP_AUTO, 305, 96, WC_VEHICLE_DEPOT,0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _depot_widgets, @@ -118,7 +95,7 @@ static const WindowDesc _train_depot_desc = { }; static const WindowDesc _road_depot_desc = { - WDP_AUTO, WDP_AUTO, 315, 96, + WDP_AUTO, WDP_AUTO, 305, 96, WC_VEHICLE_DEPOT,0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _depot_widgets, @@ -126,7 +103,7 @@ static const WindowDesc _road_depot_desc = { }; static const WindowDesc _ship_depot_desc = { - WDP_AUTO, WDP_AUTO, 305, 98, + WDP_AUTO, WDP_AUTO, 305, 96, WC_VEHICLE_DEPOT,0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _depot_widgets, @@ -134,7 +111,7 @@ static const WindowDesc _ship_depot_desc = { }; static const WindowDesc _aircraft_depot_desc = { - WDP_AUTO, WDP_AUTO, 331, 98, + WDP_AUTO, WDP_AUTO, 305, 96, WC_VEHICLE_DEPOT,0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _depot_widgets, @@ -596,10 +573,9 @@ static void ClonePlaceObj(const Window *w) static void ResizeDepotButtons(Window *w) { - /* We got the widget moved around. Now we will make some widgets to fill the gab between some widgets in equal sizes */ + /* We got the widget moved around. Now we will make some widgets to fill the gap between some widgets in equal sizes */ /* Make the buttons in the bottom equal in size */ - w->widget[DEPOT_WIDGET_LOCATION].right = w->widget[DEPOT_WIDGET_VEHICLE_LIST].left - 1; w->widget[DEPOT_WIDGET_BUILD].right = w->widget[DEPOT_WIDGET_LOCATION].right / 3; w->widget[DEPOT_WIDGET_LOCATION].left = w->widget[DEPOT_WIDGET_BUILD].right * 2; w->widget[DEPOT_WIDGET_CLONE].left = w->widget[DEPOT_WIDGET_BUILD].right + 1; @@ -608,18 +584,182 @@ static void ResizeDepotButtons(Window *w) if (WP(w, depot_d).type == VEH_Train) { /* 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. * This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason */ - w->widget[DEPOT_WIDGET_SELL_CHAIN].bottom = w->widget[DEPOT_WIDGET_SELL_ALL].top - 1; w->widget[DEPOT_WIDGET_SELL_CHAIN].top = ((w->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - w->widget[DEPOT_WIDGET_SELL].top) / 2) + w->widget[DEPOT_WIDGET_SELL].top; w->widget[DEPOT_WIDGET_SELL].bottom = w->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1; } } +/* Function to set up vehicle specific sprites and strings + * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites + * 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 + */ +static void SetupStringsForDepotWindow(Window *w, byte type) +{ + switch (type) { + case VEH_Train: + w->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; + w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; + w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP; + w->widget[DEPOT_WIDGET_SELL].tooltips = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE; + w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP; + w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR; + + w->widget[DEPOT_WIDGET_BUILD].data = STR_8815_NEW_VEHICLES; + w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_8840_BUILD_NEW_TRAIN_VEHICLE; + w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_TRAIN; + w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_TRAIN_DEPOT_INFO; + + w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP; + w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP; + + /* Sprites */ + w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_TRAIN; + w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_TRAIN; + w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN; + break; + + case VEH_Road: + w->widget[DEPOT_WIDGET_CAPTION].data = STR_9003_ROAD_VEHICLE_DEPOT; + w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP; + w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP; + w->widget[DEPOT_WIDGET_SELL].tooltips = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE; + w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP; + w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_9022_VEHICLES_CLICK_ON_VEHICLE; + + w->widget[DEPOT_WIDGET_BUILD].data = STR_9004_NEW_VEHICLES; + w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9023_BUILD_NEW_ROAD_VEHICLE; + w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_ROAD_VEHICLE; + w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO; + + w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP; + w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP; + + /* Sprites */ + w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_ROADVEH; + w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_ROADVEH; + w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH; + break; + + case VEH_Ship: + w->widget[DEPOT_WIDGET_CAPTION].data = STR_9803_SHIP_DEPOT; + w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP; + w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP; + w->widget[DEPOT_WIDGET_SELL].tooltips = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL; + w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP; + w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_981F_SHIPS_CLICK_ON_SHIP_FOR; + + w->widget[DEPOT_WIDGET_BUILD].data = STR_9804_NEW_SHIPS; + w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9820_BUILD_NEW_SHIP; + w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_SHIP; + w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_SHIP_DEPOT_INFO; + + w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP; + w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP; + + /* Sprites */ + w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_SHIP; + w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_SHIP; + w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP; + break; + + case VEH_Aircraft: + w->widget[DEPOT_WIDGET_CAPTION].data = STR_A002_AIRCRAFT_HANGAR; + w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP; + w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP; + w->widget[DEPOT_WIDGET_SELL].tooltips = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO; + w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP; + w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT; + + w->widget[DEPOT_WIDGET_BUILD].data = STR_A003_NEW_AIRCRAFT; + w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_A022_BUILD_NEW_AIRCRAFT; + w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT; + w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW; + + w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE; + w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP; + w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP; + + /* Sprites */ + w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_AIRCRAFT; + w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_AIRCRAFT; + w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; + break; + } +} + +static void CreateDepotListWindow(Window *w, byte type) +{ + WP(w, depot_d).type = type; + _backup_orders_tile = 0; + + /* Resize the window according to the vehicle type */ + switch (type) { + default: NOT_REACHED(); + case VEH_Train: + w->vscroll.cap = 6; + w->hscroll.cap = 10 * 29; + w->resize.step_width = 1; + ResizeWindow(w, 56, 26); + break; + + case VEH_Road: + w->vscroll.cap = 5; + w->hscroll.cap = 5; + w->resize.step_width = 56; + ResizeWindow(w, 10, 0); + break; + + case VEH_Ship: + w->vscroll.cap = 3; + w->hscroll.cap = 3; + w->resize.step_width = 90; + ResizeWindow(w, 0, 2); + break; + + case VEH_Aircraft: + w->vscroll.cap = 3; + w->hscroll.cap = 4; + w->resize.step_width = 74; + ResizeWindow(w, 26, 2); + break; + } + + /* Set the minimum window size to the current window size */ + w->resize.width = w->width; + w->resize.height = w->height; + w->resize.step_height = GetVehicleListHeight(type); + + SetupStringsForDepotWindow(w, type); + + w->widget[DEPOT_WIDGET_MATRIX].data = + (w->vscroll.cap * 0x100) // number of rows to draw on the background + + (type == VEH_Train ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one + + + SetWindowWidgetsHiddenState(w, type != VEH_Train, + DEPOT_WIDGET_H_SCROLL, + DEPOT_WIDGET_SELL_CHAIN, + WIDGET_LIST_END); + + /* The train depot has a horizontal scroller, make the matrix that much shorter to fit */ + if (type == VEH_Train) w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; + ResizeDepotButtons(w); +} + void DepotSortList(Vehicle **v, uint16 length); static void DepotWndProc(Window *w, WindowEvent *e) { switch (e->event) { case WE_CREATE: + WP(w, depot_d).sel = INVALID_VEHICLE; WP(w, depot_d).vehicle_list = NULL; WP(w, depot_d).wagon_list = NULL; WP(w, depot_d).engine_count = 0; @@ -831,111 +971,6 @@ static void DepotWndProc(Window *w, WindowEvent *e) } } -/* Function to set up vehicle specific sprites and strings - * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites - * 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 - */ -static void SetupStringsForDepotWindow(Window *w, byte type) -{ - switch (type) { - case VEH_Train: - w->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; - w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; - w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP; - w->widget[DEPOT_WIDGET_SELL].tooltips = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE; - w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP; - w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR; - - w->widget[DEPOT_WIDGET_BUILD].data = STR_8815_NEW_VEHICLES; - w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_8840_BUILD_NEW_TRAIN_VEHICLE; - w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_TRAIN; - w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_TRAIN_DEPOT_INFO; - - w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP; - w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP; - - /* Sprites */ - w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_TRAIN; - w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_TRAIN; - w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN; - break; - - case VEH_Road: - w->widget[DEPOT_WIDGET_CAPTION].data = STR_9003_ROAD_VEHICLE_DEPOT; - w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP; - w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP; - w->widget[DEPOT_WIDGET_SELL].tooltips = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE; - w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP; - w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_9022_VEHICLES_CLICK_ON_VEHICLE; - - w->widget[DEPOT_WIDGET_BUILD].data = STR_9004_NEW_VEHICLES; - w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9023_BUILD_NEW_ROAD_VEHICLE; - w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_ROAD_VEHICLE; - w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO; - - w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP; - w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP; - - /* Sprites */ - w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_ROADVEH; - w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_ROADVEH; - w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH; - break; - - case VEH_Ship: - w->widget[DEPOT_WIDGET_CAPTION].data = STR_9803_SHIP_DEPOT; - w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP; - w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP; - w->widget[DEPOT_WIDGET_SELL].tooltips = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL; - w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP; - w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_981F_SHIPS_CLICK_ON_SHIP_FOR; - - w->widget[DEPOT_WIDGET_BUILD].data = STR_9804_NEW_SHIPS; - w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9820_BUILD_NEW_SHIP; - w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_SHIP; - w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_SHIP_DEPOT_INFO; - - w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP; - w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP; - - /* Sprites */ - w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_SHIP; - w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_SHIP; - w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP; - break; - - case VEH_Aircraft: - w->widget[DEPOT_WIDGET_CAPTION].data = STR_A002_AIRCRAFT_HANGAR; - w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP; - w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP; - w->widget[DEPOT_WIDGET_SELL].tooltips = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO; - w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP; - w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT; - - w->widget[DEPOT_WIDGET_BUILD].data = STR_A003_NEW_AIRCRAFT; - w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_A022_BUILD_NEW_AIRCRAFT; - w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT; - w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW; - - w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE; - w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP; - w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP; - - /* Sprites */ - w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_AIRCRAFT; - w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_AIRCRAFT; - w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; - break; - } -} - /** Opens a depot window * @param tile The tile where the depot/hangar is located * @param type The type of vehicles in the depot @@ -944,93 +979,21 @@ void ShowDepotWindow(TileIndex tile, byte type) { Window *w; - /* First we ensure that the widget counts are equal in all 3 lists to prevent bad stuff from happening */ - assert(lengthof(widget_moves) == lengthof(_depot_widgets) - 1); // we should not count WIDGETS_END - assert(lengthof(widget_moves) == DEPOT_WIDGET_LAST); - switch (type) { - case VEH_Train: w = AllocateWindowDescFront(&_train_depot_desc, tile); break; - case VEH_Road: w = AllocateWindowDescFront(&_road_depot_desc, tile); break; - case VEH_Ship: w = AllocateWindowDescFront(&_ship_depot_desc, tile); break; - case VEH_Aircraft: w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break; - default: NOT_REACHED(); w = NULL; + default: NOT_REACHED(); + case VEH_Train: + w = AllocateWindowDescFront(&_train_depot_desc, tile); break; + case VEH_Road: + w = AllocateWindowDescFront(&_road_depot_desc, tile); break; + case VEH_Ship: + w = AllocateWindowDescFront(&_ship_depot_desc, tile); break; + case VEH_Aircraft: + w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break; } if (w != NULL) { - int16 horizontal = 0, vertical = 0; w->caption_color = GetTileOwner(tile); - WP(w, depot_d).type = type; - WP(w, depot_d).sel = INVALID_VEHICLE; - _backup_orders_tile = 0; - - /* Resize the window according to the vehicle type */ - switch (type) { - case VEH_Train: - horizontal = 56; - vertical = 26; - w->vscroll.cap = 6; - w->hscroll.cap = 10 * 29; - w->resize.step_width = 1; - break; - - case VEH_Road: - horizontal = 10; - w->vscroll.cap = 5; - w->hscroll.cap = 5; - w->resize.step_width = 56; - break; - - case VEH_Ship: - vertical = 2; - w->vscroll.cap = 3; - w->hscroll.cap = 3; - w->resize.step_width = 90; - break; - - case VEH_Aircraft: - horizontal = 26; - vertical = 2; - w->vscroll.cap = 3; - w->hscroll.cap = 4; - w->resize.step_width = 74; - break; - - default: NOT_REACHED(); - } - - w->resize.step_height = GetVehicleListHeight(type); - - SetupStringsForDepotWindow(w, type); - - w->widget[DEPOT_WIDGET_MATRIX].data = - (w->vscroll.cap * 0x100) // number of rows to draw on the background - + (type == VEH_Train ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one - - - SetWindowWidgetsHiddenState(w, type != VEH_Train, - DEPOT_WIDGET_H_SCROLL, - DEPOT_WIDGET_SELL_CHAIN, - WIDGET_LIST_END); - - /* 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 - * Doing it here will ensure that they move if the widget they are placed on top of/aligned to are moved */ - - /* DEPOT_WIDGET_H_SCROLL is placed in the lowest part of DEPOT_WIDGET_MATRIX */ - w->widget[DEPOT_WIDGET_H_SCROLL].left = w->widget[DEPOT_WIDGET_MATRIX].left; - w->widget[DEPOT_WIDGET_H_SCROLL].right = w->widget[DEPOT_WIDGET_MATRIX].right; - w->widget[DEPOT_WIDGET_H_SCROLL].bottom = w->widget[DEPOT_WIDGET_MATRIX].bottom; - w->widget[DEPOT_WIDGET_H_SCROLL].top = w->widget[DEPOT_WIDGET_MATRIX].bottom - 11; - w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; - - /* DEPOT_WIDGET_SELL_CHAIN is under DEPOT_WIDGET_SELL. They got the same left and right and height is controlled in ResizeDepotButtons() */ - w->widget[DEPOT_WIDGET_SELL_CHAIN].left = w->widget[DEPOT_WIDGET_SELL].left; - w->widget[DEPOT_WIDGET_SELL_CHAIN].right = w->widget[DEPOT_WIDGET_SELL].right; - } - ResizeDepotButtons(w); + CreateDepotListWindow(w, type); } } diff --git a/misc_gui.c b/misc_gui.c index 1e06a95d8..82a6bf944 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -30,7 +30,6 @@ #include "tgp.h" #include "settings.h" #include "date.h" -#include "resize_window_widgets.h" #include "fios.h" /* Variables to display file lists */ @@ -1858,22 +1857,3 @@ void ShowCheatWindow(void) DeleteWindowById(WC_CHEATS, 0); AllocateWindowDesc(&_cheats_desc); } - -/** 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, int16 length, byte horizontal, int16 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/openttd.vcproj b/openttd.vcproj index c624e6bc5..c044a60ee 100644 --- a/openttd.vcproj +++ b/openttd.vcproj @@ -626,9 +626,6 @@ RelativePath=".\rail.h"> </File> <File - RelativePath=".\resize_window_widgets.h"> - </File> - <File RelativePath=".\saveload.h"> </File> <File diff --git a/openttd_vs80.vcproj b/openttd_vs80.vcproj index 20757a8d5..0998558fc 100644 --- a/openttd_vs80.vcproj +++ b/openttd_vs80.vcproj @@ -1132,10 +1132,6 @@ > </File> <File - RelativePath=".\resize_window_widgets.h" - > - </File> - <File RelativePath=".\road.h" > </File> diff --git a/resize_window_widgets.h b/resize_window_widgets.h deleted file mode 100644 index 047d0d45b..000000000 --- a/resize_window_widgets.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $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, int16 length, byte horizontal, int16 vertical); - -#endif diff --git a/vehicle_gui.c b/vehicle_gui.c index 0fef61104..13f0786dc 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -27,7 +27,6 @@ #include "aircraft.h" #include "roadveh.h" #include "depot.h" -#include "resize_window_widgets.h" typedef struct Sorting { Listing aircraft; @@ -1390,7 +1389,7 @@ enum { PLY_WND_PRC__SIZE_OF_ROW_BIG = 36, }; -typedef enum VehicleListWindowWidgets { +enum VehicleListWindowWidgets { VLW_WIDGET_CLOSEBOX = 0, VLW_WIDGET_CAPTION, VLW_WIDGET_STICKY, @@ -1406,24 +1405,6 @@ typedef enum VehicleListWindowWidgets { VLW_WIDGET_STOP_ALL, VLW_WIDGET_START_ALL, 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_STOP_ALL - WIDGET_MOVE_DOWN_RIGHT, // VLW_WIDGET_START_ALL - WIDGET_MOVE_DOWN_RIGHT, // VLW_WIDGET_RESIZE }; static const Widget _vehicle_list_widgets[] = { @@ -1438,7 +1419,7 @@ static const Widget _vehicle_list_widgets[] = { { 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_NULL}, - { WWT_PUSHTXTBTN, RESIZE_TB, 14, 125, 247, 170, 181, STR_REPLACE_VEHICLES, STR_REPLACE_HELP}, + { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 125, 223, 170, 181, STR_REPLACE_VEHICLES, STR_REPLACE_HELP}, { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 224, 235, 170, 181, SPR_FLAG_VEH_STOPPED, STR_MASS_STOP_LIST_TIP}, { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 236, 247, 170, 181, SPR_FLAG_VEH_RUNNING, STR_MASS_START_LIST_TIP}, { WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON}, @@ -1448,7 +1429,6 @@ static const Widget _vehicle_list_widgets[] = { /* 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_STOP_ALL].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 + 1; } @@ -1572,13 +1552,6 @@ static void CreateVehicleListWindow(Window *w) vl->l.sort_type = vl->_sorting->criteria; 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 DrawSmallOrderList(const Vehicle *v, int x, int y) @@ -1827,7 +1800,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) } static const WindowDesc _player_vehicle_list_train_desc = { - WDP_AUTO, WDP_AUTO, 325, 220, + WDP_AUTO, WDP_AUTO, 260, 182, WC_TRAINS_LIST, 0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _vehicle_list_widgets, @@ -1835,7 +1808,7 @@ static const WindowDesc _player_vehicle_list_train_desc = { }; static const WindowDesc _player_vehicle_list_road_veh_desc = { - WDP_AUTO, WDP_AUTO, 260, 220, + WDP_AUTO, WDP_AUTO, 260, 182, WC_ROADVEH_LIST,0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _vehicle_list_widgets, @@ -1876,12 +1849,32 @@ static void ShowVehicleListWindowLocal(PlayerID player, byte vehicle_type, Stati num |= (station << 16) | VLW_STATION_LIST; } + /* The vehicle list windows have been unified. Just some strings need + * to be changed which happens in the WE_CREATE event and resizing + * some of the windows to the correct size */ switch (vehicle_type) { - case VEH_Train: w = AllocateWindowDescFront(&_player_vehicle_list_train_desc, num); break; - case VEH_Road: w = AllocateWindowDescFront(&_player_vehicle_list_road_veh_desc, num); break; - case VEH_Ship: w = AllocateWindowDescFront(&_player_vehicle_list_ship_desc, num); break; - case VEH_Aircraft: w = AllocateWindowDescFront(&_player_vehicle_list_aircraft_desc, num); break; default: NOT_REACHED(); + case VEH_Train: + w = AllocateWindowDescFront(&_player_vehicle_list_train_desc, num); + if (w != NULL) ResizeWindow(w, 65, 38); + break; + case VEH_Road: + w = AllocateWindowDescFront(&_player_vehicle_list_road_veh_desc, num); + if (w != NULL) ResizeWindow(w, 0, 38); + break; + case VEH_Ship: + w = AllocateWindowDescFront(&_player_vehicle_list_ship_desc, num); + break; + case VEH_Aircraft: + w = AllocateWindowDescFront(&_player_vehicle_list_aircraft_desc, num); + break; + } + + if (w != NULL) { + ResizeVehicleListWidgets(w); + /* Set the minimum window size to the current window size */ + w->resize.width = w->width; + w->resize.height = w->height; } } |