From ac016eae5e3841edd6a3ecfd00fcfdea2520e134 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 18 Aug 2017 01:49:03 +0100 Subject: [PATCH] Add client setting to enable shared order group window for single vehicles --- src/lang/english.txt | 2 ++ src/order_cmd.cpp | 14 +++++++++----- src/order_gui.cpp | 2 +- src/settings.cpp | 11 +++++++++++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 10 ++++++++++ src/timetable_gui.cpp | 4 ++-- src/vehicle.cpp | 5 +++-- src/vehicle_gui.cpp | 3 +++ 10 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 00e8518dd9..14f6cfa6cd 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1397,6 +1397,8 @@ STR_CONFIG_SETTING_OSK_ACTIVATION_SINGLE_CLICK :Single click (i STR_CONFIG_SETTING_SHOW_VEHICLE_ROUTE_STEPS :Show the vehicle's route steps: {STRING2} STR_CONFIG_SETTING_SHOW_VEHICLE_LIST_COMPANY_COLOUR :Mark other companies' vehicles in lists with their company colour: {STRING2} STR_CONFIG_SETTING_SHOW_VEHICLE_LIST_COMPANY_COLOUR_HELPTEXT :Vehicles in a vehicle list window which are owned by a different company than the owner of the vehicle list are marked with a coloured square in the vehicle's company colour. +STR_CONFIG_SETTING_ENABLE_SINGLE_VEH_SHARED_ORDER_GUI :Enable single vehicles in shared order group window: {STRING2} +STR_CONFIG_SETTING_ENABLE_SINGLE_VEH_SHARED_ORDER_GUI_HELPTEXT :Allow using the shared order group window with single vehicles, without shared orders. STR_CONFIG_SETTING_VIEWPORT_MAP_SCAN_SURROUNDINGS :Scan surroundings (better for high zoom out levels): {STRING2} STR_CONFIG_SETTING_VIEWPORT_MAP_SHOW_SLOPES :Show slopes: {STRING2} diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 6f1f1090d0..510bc34ab9 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -37,6 +37,7 @@ #include "cheat_type.h" #include "viewport_func.h" #include "order_cmd.h" +#include "vehiclelist.h" #include "table/strings.h" @@ -1909,7 +1910,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 for (const auto& slot : src->orders.list->GetScheduledDispatch()) { dst->orders.list->AddScheduledDispatch(slot); } - + Date start_date; uint16 start_full_date_fract; SchdispatchConvertToFullDateFract( @@ -2157,10 +2158,13 @@ void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indic /* Remove ourself from the shared order list. */ v->RemoveFromShared(); v->orders.list = NULL; - } else if (v->orders.list != NULL) { - /* Remove the orders */ - v->orders.list->FreeChain(keep_orderlist); - if (!keep_orderlist) v->orders.list = NULL; + } else { + DeleteWindowById(GetWindowClassForVehicleType(v->type), VehicleListIdentifier(VL_SHARED_ORDERS, v->type, v->owner, v->index).Pack()); + if (v->orders.list != NULL) { + /* Remove the orders */ + v->orders.list->FreeChain(keep_orderlist); + if (!keep_orderlist) v->orders.list = NULL; + } } if (reset_order_indices) { diff --git a/src/order_gui.cpp b/src/order_gui.cpp index a2f0056015..95b5a96ad5 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1658,7 +1658,7 @@ public: } /* Disable list of vehicles with the same shared orders if there is no list */ - this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders); + this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !(shared_orders || _settings_client.gui.enable_single_veh_shared_order_gui)); this->GetWidget(WID_O_SEL_OCCUPANCY)->SetDisplayedPlane(IsWidgetLowered(WID_O_OCCUPANCY_TOGGLE) ? 0 : SZSP_NONE); diff --git a/src/settings.cpp b/src/settings.cpp index 59ece2a8e9..c7ecefab2c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1169,6 +1169,17 @@ static bool SimulatedWormholeSignalsChanged(int32 p1) return true; } +static bool EnableSingleVehSharedOrderGuiChanged(int32) +{ + for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) { + InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0); + } + SetWindowClassesDirty(WC_VEHICLE_TIMETABLE); + InvalidateWindowClassesData(WC_VEHICLE_ORDERS, 0); + + return true; +} + /** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */ static void ValidateSettings() { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 4800f9cffc..563f62c40b 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1599,6 +1599,7 @@ static SettingsContainer &GetSettingsTree() interface->Add(new SettingEntry("gui.show_vehicle_group_in_details")); interface->Add(new SettingEntry("gui.show_vehicle_list_company_colour")); interface->Add(new SettingEntry("gui.show_adv_tracerestrict_features")); + interface->Add(new SettingEntry("gui.enable_single_veh_shared_order_gui")); } SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS)); diff --git a/src/settings_type.h b/src/settings_type.h index 39f6269e74..b88b0bcc56 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -176,6 +176,7 @@ struct GUISettings { uint8 osk_activation; ///< Mouse gesture to trigger the OSK. bool show_vehicle_route_steps; ///< when a window related to a specific vehicle is focused, show route steps bool show_vehicle_list_company_colour; ///< show the company colour of vehicles which have an owner different to the owner of the vehicle list + bool enable_single_veh_shared_order_gui; ///< enable showing a single vehicle in the shared order GUI window uint16 console_backlog_timeout; ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity. uint16 console_backlog_length; ///< the minimum amount of items in the console backlog before items will be removed. diff --git a/src/table/settings.ini b/src/table/settings.ini index 5358123e6e..ad18f97fcf 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -45,6 +45,7 @@ static bool MaxVehiclesChanged(int32 p1); static bool ImprovedBreakdownsSettingChanged(int32 p1); static bool DayLengthChanged(int32 p1); static bool SimulatedWormholeSignalsChanged(int32 p1); +static bool EnableSingleVehSharedOrderGuiChanged(int32 p1); #ifdef ENABLE_NETWORK static bool UpdateClientName(int32 p1); @@ -4089,6 +4090,15 @@ strhelp = STR_CONFIG_SETTING_SHOW_ADV_TRACE_RESTRICT_FEATURES_HELPTEXT proc = RedrawScreen cat = SC_EXPERT +[SDTC_BOOL] +var = gui.enable_single_veh_shared_order_gui +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = false +str = STR_CONFIG_SETTING_ENABLE_SINGLE_VEH_SHARED_ORDER_GUI +strhelp = STR_CONFIG_SETTING_ENABLE_SINGLE_VEH_SHARED_ORDER_GUI_HELPTEXT +proc = EnableSingleVehSharedOrderGuiChanged +cat = SC_EXPERT + ; For the dedicated build we'll enable dates in logs by default. [SDTC_BOOL] ifdef = DEDICATED diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 9deb1c06a2..7dad64ef87 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -356,7 +356,7 @@ struct TimetableWindow : Window { this->SetWidgetDisabledState(WID_VT_CLEAR_TIME, disable || HasBit(v->vehicle_flags, VF_AUTOMATE_TIMETABLE)); this->SetWidgetDisabledState(WID_VT_CHANGE_SPEED, disable_speed); this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed); - this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !v->IsOrderListShared()); + this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !(v->IsOrderListShared() || _settings_client.gui.enable_single_veh_shared_order_gui)); this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders.list == NULL || HasBit(v->vehicle_flags, VF_TIMETABLE_SEPARATION) || HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH)); this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders.list == NULL); @@ -380,7 +380,7 @@ struct TimetableWindow : Window { this->SetWidgetLoweredState(WID_VT_AUTOMATE, HasBit(v->vehicle_flags, VF_AUTOMATE_TIMETABLE)); this->SetWidgetLoweredState(WID_VT_AUTO_SEPARATION, HasBit(v->vehicle_flags, VF_TIMETABLE_SEPARATION)); this->SetWidgetLoweredState(WID_VT_SCHEDULED_DISPATCH, HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH)); - + this->SetWidgetDisabledState(WID_VT_SCHEDULED_DISPATCH, v->orders.list == NULL); this->DrawWidgets(); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 65b6745ef6..68dfb4fb18 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3346,10 +3346,11 @@ void Vehicle::RemoveFromShared() if (this->next_shared != NULL) this->next_shared->previous_shared = this->previous_shared; - if (this->orders.list->GetNumVehicles() == 1) { + if (this->orders.list->GetNumVehicles() == 1) InvalidateVehicleOrder(this->FirstShared(), 0); + + if (this->orders.list->GetNumVehicles() == 1 && !_settings_client.gui.enable_single_veh_shared_order_gui) { /* When there is only one vehicle, remove the shared order list window. */ DeleteWindowById(GetWindowClassForVehicleType(this->type), vli.Pack()); - InvalidateVehicleOrder(this->FirstShared(), 0); } else if (were_first) { /* If we were the first one, update to the new first one. * Note: FirstShared() is already the new first */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 8e22829fbc..7e3b93aacb 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1923,6 +1923,9 @@ public: if (data == 0) { /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */ this->vehicles.ForceRebuild(); + if (this->vli.type == VL_SHARED_ORDERS && !_settings_client.gui.enable_single_veh_shared_order_gui && this->vehicles.Length() == 1) { + delete this; + } } else { this->vehicles.ForceResort(); }