From ba05d5b8fc68e88966330662398d02569bf5e9f2 Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Fri, 18 Feb 2022 02:04:54 +0000 Subject: [PATCH 1/8] Refactor features, overlays, and junction options They were all entangled hence somewhat larger than expected commit. --- TLM/TLM/Lifecycle/TMPELifecycle.cs | 4 + TLM/TLM/Manager/Impl/LaneArrowManager.cs | 2 +- TLM/TLM/Manager/Impl/OptionsManager.cs | 232 ++++++++++--- TLM/TLM/Patch/_RoadBaseAI/UpdateLanesPatch.cs | 2 +- TLM/TLM/State/Options.cs | 108 +----- TLM/TLM/State/OptionsTabs/GameplayTab.cs | 2 +- TLM/TLM/State/OptionsTabs/GeneralTab.cs | 7 +- .../OptionsTabs/GeneralTab_DebugGroup.cs | 4 +- TLM/TLM/State/OptionsTabs/MaintenanceTab.cs | 253 +------------- .../MaintenanceTab_FeaturesGroup.cs | 107 ++++++ TLM/TLM/State/OptionsTabs/OverlaysTab.cs | 304 +---------------- .../OptionsTabs/OverlaysTab_OverlaysGroup.cs | 133 ++++++++ TLM/TLM/State/OptionsTabs/PoliciesTab.cs | 313 +----------------- .../PoliciesTab_AtJunctionsGroup.cs | 118 +++++++ TLM/TLM/TLM.csproj | 3 + TLM/TLM/UI/Helpers/CheckboxOption.cs | 202 ++++++----- .../UI/Helpers/SerializableUIOptionBase.cs | 7 +- TLM/TLM/Util/VersionUtil.cs | 21 +- 18 files changed, 724 insertions(+), 1098 deletions(-) create mode 100644 TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs create mode 100644 TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs create mode 100644 TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs diff --git a/TLM/TLM/Lifecycle/TMPELifecycle.cs b/TLM/TLM/Lifecycle/TMPELifecycle.cs index 139168c75..92fe82fe5 100644 --- a/TLM/TLM/Lifecycle/TMPELifecycle.cs +++ b/TLM/TLM/Lifecycle/TMPELifecycle.cs @@ -64,8 +64,12 @@ public static bool InGameOrEditor() => public static AppMode? AppMode => SimulationManager.instance.m_ManagersWrapper.loading?.currentMode; + // throws null ref if used from main menu public static SimulationManager.UpdateMode UpdateMode => SimulationManager.instance.m_metaData.m_updateMode; + + // throws null ref if used form main menu public static LoadMode Mode => (LoadMode)UpdateMode; + public static string Scene => SceneManager.GetActiveScene().name; /// diff --git a/TLM/TLM/Manager/Impl/LaneArrowManager.cs b/TLM/TLM/Manager/Impl/LaneArrowManager.cs index 71333c3f2..d71794189 100644 --- a/TLM/TLM/Manager/Impl/LaneArrowManager.cs +++ b/TLM/TLM/Manager/Impl/LaneArrowManager.cs @@ -219,7 +219,7 @@ private void ApplyFlags() { public override void OnLevelLoading() { base.OnLevelLoading(); - if (PoliciesTab.DedicatedTurningLanes) { + if (Options.DedicatedTurningLanes) { // update dedicated turning lanes after patch has been applied. UpdateDedicatedTurningLanePolicy(false); } diff --git a/TLM/TLM/Manager/Impl/OptionsManager.cs b/TLM/TLM/Manager/Impl/OptionsManager.cs index 0bb457662..54f150247 100644 --- a/TLM/TLM/Manager/Impl/OptionsManager.cs +++ b/TLM/TLM/Manager/Impl/OptionsManager.cs @@ -9,26 +9,20 @@ namespace TrafficManager.Manager.Impl { using JetBrains.Annotations; using TrafficManager.Util; using System.Reflection; + using TrafficManager.UI; + using TrafficManager.UI.Textures; public class OptionsManager : AbstractCustomManager, IOptionsManager { + // TODO I contain ugly code public static OptionsManager Instance = new OptionsManager(); - protected override void InternalPrintDebugInfo() { - base.InternalPrintDebugInfo(); - Log.NotImpl("InternalPrintDebugInfo for OptionsManager"); - } - - /// - /// Converts value to SimulationAccuracy - /// - /// Old value - /// SimulationAccuracy value - private static SimulationAccuracy ConvertToSimulationAccuracy(byte value) { - return SimulationAccuracy.MaxValue - value; - } + // See: OnAfterLoadData() and related methods + private static bool _needUpdateRoutingManager = false; + private static bool _needUpdateDedicatedTurningLanes = false; + private static bool _needUpdateJunctionRestrictionsManager = false; /// /// API method for external mods to get option values by name. @@ -55,6 +49,50 @@ public bool TryGetOptionByName(string optionName, out TVal value) { return true; } + public bool MayPublishSegmentChanges() => + Options.instantEffects && + TMPELifecycle.InGameOrEditor() && + !TMPELifecycle.Instance.Deserializing; + + /// + /// Loading options may trigger multiple calls to certain methods. To de-spam + /// invocations, the methods are skipped during loading and a bool is set + /// so that we can invoke those methods just once after loading has completed. + /// + public override void OnAfterLoadData() { + base.OnAfterLoadData(); + Log.Info("OptionsManger.OnAfterLoadData() checking for queued method calls"); + + if (_needUpdateRoutingManager) { + _needUpdateRoutingManager = false; + UpdateRoutingManager(); + } + + if (_needUpdateDedicatedTurningLanes) { + _needUpdateDedicatedTurningLanes = false; + UpdateDedicatedTurningLanes(); + } + + if (_needUpdateJunctionRestrictionsManager) { + _needUpdateJunctionRestrictionsManager = false; + UpdateJunctionRestrictionsManager(); + } + } + + protected override void InternalPrintDebugInfo() { + base.InternalPrintDebugInfo(); + Log.NotImpl("InternalPrintDebugInfo for OptionsManager"); + } + + /// + /// Converts value to SimulationAccuracy + /// + /// Old value + /// SimulationAccuracy value + private static SimulationAccuracy ConvertToSimulationAccuracy(byte value) { + return SimulationAccuracy.MaxValue - value; + } + /// /// Converts SimulationAccuracy to SimulationAccuracy /// @@ -64,11 +102,6 @@ private static byte ConvertFromSimulationAccuracy(SimulationAccuracy value) { return (byte)(SimulationAccuracy.MaxValue - value); } - public bool MayPublishSegmentChanges() { - return Options.instantEffects && TMPELifecycle.InGameOrEditor() && - !TMPELifecycle.Instance.Deserializing; - } - // Takes a bool from data and sets it in `out result` private static bool LoadBool([NotNull] byte[] data, uint idx, bool defaultVal = false) { if (data.Length > idx) { @@ -98,6 +131,12 @@ private static void ToCheckbox([NotNull] byte[] data, uint idx, ILegacySerializa opt.Load(defaultVal ? (byte)1 : (byte)0); } + /// + /// Restores the mod options based on supplied . + /// + /// Byte array obtained from the savegame. + /// Returns true if successful, otherwise false. + /// Applies default values if the data for an option does not exist. public bool LoadData(byte[] data) { try { Options.Available = false; @@ -107,35 +146,35 @@ public bool LoadData(byte[] data) { GeneralTab.SetSimulationAccuracy(ConvertToSimulationAccuracy(LoadByte(data, idx: 0))); // skip Options.setLaneChangingRandomization(options[1]); GameplayTab.SetRecklessDrivers(LoadByte(data, idx: 2)); - PoliciesTab.SetRelaxedBusses(LoadBool(data, idx: 3)); - OverlaysTab.SetNodesOverlay(LoadBool(data, idx: 4)); - PoliciesTab.SetMayEnterBlockedJunctions(LoadBool(data, idx: 5)); + ToCheckbox(data, idx: 3, PoliciesTab_AtJunctionsGroup.RelaxedBusses, true); + ToCheckbox(data, idx: 4, OverlaysTab_OverlaysGroup.NodesOverlay, false); + ToCheckbox(data, idx: 5, PoliciesTab_AtJunctionsGroup.AllowEnterBlockedJunctions, false); GameplayTab.SetAdvancedAi(LoadBool(data, idx: 6)); PoliciesTab.SetHighwayRules(LoadBool(data, idx: 7)); - OverlaysTab.SetPrioritySignsOverlay(LoadBool(data, idx: 8)); - OverlaysTab.SetTimedLightsOverlay(LoadBool(data, idx: 9)); - OverlaysTab.SetSpeedLimitsOverlay(LoadBool(data, idx: 10)); - OverlaysTab.SetVehicleRestrictionsOverlay(LoadBool(data, idx: 11)); + ToCheckbox(data, idx: 8, OverlaysTab_OverlaysGroup.PrioritySignsOverlay, false); + ToCheckbox(data, idx: 9, OverlaysTab_OverlaysGroup.TimedLightsOverlay, false); + ToCheckbox(data, idx: 10, OverlaysTab_OverlaysGroup.SpeedLimitsOverlay, false); + ToCheckbox(data, idx: 11, OverlaysTab_OverlaysGroup.VehicleRestrictionsOverlay, false); GameplayTab.SetStrongerRoadConditionEffects(LoadBool(data, idx: 12)); - PoliciesTab.SetAllowUTurns(LoadBool(data, idx: 13)); - PoliciesTab.SetAllowLaneChangesWhileGoingStraight(LoadBool(data, idx: 14)); + ToCheckbox(data, idx: 13, PoliciesTab_AtJunctionsGroup.AllowUTurns, false); + ToCheckbox(data, idx: 14, PoliciesTab_AtJunctionsGroup.AllowLaneChangesWhileGoingStraight, true); GameplayTab.SetDisableDespawning(!LoadBool(data, idx: 15)); // inverted // skip Options.setDynamicPathRecalculation(data[16] == (byte)1); - OverlaysTab.SetConnectedLanesOverlay(LoadBool(data, idx: 17)); - PoliciesTab.SetPrioritySignsEnabled(LoadBool(data, idx: 18)); - PoliciesTab.SetTimedLightsEnabled(LoadBool(data, idx: 19)); - MaintenanceTab.SetCustomSpeedLimitsEnabled(LoadBool(data, idx: 20)); - MaintenanceTab.SetVehicleRestrictionsEnabled(LoadBool(data, idx: 21)); - MaintenanceTab.SetLaneConnectorEnabled(LoadBool(data, idx: 22)); - OverlaysTab.SetJunctionRestrictionsOverlay(LoadBool(data, idx: 23)); - MaintenanceTab.SetJunctionRestrictionsEnabled(LoadBool(data, idx: 24)); + ToCheckbox(data, idx: 17, OverlaysTab_OverlaysGroup.ConnectedLanesOverlay, false); + ToCheckbox(data, idx: 18, MaintenanceTab_FeaturesGroup.PrioritySignsEnabled, true); + ToCheckbox(data, idx: 19, MaintenanceTab_FeaturesGroup.TimedLightsEnabled, true); + ToCheckbox(data, idx: 20, MaintenanceTab_FeaturesGroup.CustomSpeedLimitsEnabled, true); + ToCheckbox(data, idx: 21, MaintenanceTab_FeaturesGroup.VehicleRestrictionsEnabled, true); + ToCheckbox(data, idx: 22, MaintenanceTab_FeaturesGroup.LaneConnectorEnabled, true); + ToCheckbox(data, idx: 23, OverlaysTab_OverlaysGroup.JunctionRestrictionsOverlay, false); + ToCheckbox(data, idx: 24, MaintenanceTab_FeaturesGroup.JunctionRestrictionsEnabled, true); GameplayTab.SetProhibitPocketCars(LoadBool(data, idx: 25)); PoliciesTab.SetPreferOuterLane(LoadBool(data, idx: 26)); GameplayTab.SetIndividualDrivingStyle(LoadBool(data, idx: 27)); PoliciesTab.SetEvacBussesMayIgnoreRules(LoadBool(data, idx: 28)); GeneralTab.SetInstantEffects(LoadBool(data, idx: 29)); - MaintenanceTab.SetParkingRestrictionsEnabled(LoadBool(data, idx: 30)); - OverlaysTab.SetParkingRestrictionsOverlay(LoadBool(data, idx: 31)); + ToCheckbox(data, idx: 30, MaintenanceTab_FeaturesGroup.ParkingRestrictionsEnabled, true); + ToCheckbox(data, idx: 31, OverlaysTab_OverlaysGroup.ParkingRestrictionsOverlay, false); PoliciesTab.SetBanRegularTrafficOnBusLanes(LoadBool(data, idx: 32)); MaintenanceTab.SetShowPathFindStats(LoadBool(data, idx: 33)); GameplayTab.SetDLSPercentage(LoadByte(data, idx: 34)); @@ -151,12 +190,12 @@ public bool LoadData(byte[] data) { } } - PoliciesTab.SetTrafficLightPriorityRules(LoadBool(data, idx: 36)); + ToCheckbox(data, idx: 36, PoliciesTab_AtJunctionsGroup.TrafficLightPriorityRules, false); GameplayTab.SetRealisticPublicTransport(LoadBool(data, idx: 37)); - MaintenanceTab.SetTurnOnRedEnabled(LoadBool(data, idx: 38)); - PoliciesTab.SetAllowNearTurnOnRed(LoadBool(data, idx: 39)); - PoliciesTab.SetAllowFarTurnOnRed(LoadBool(data, idx: 40)); - PoliciesTab.SetAddTrafficLightsIfApplicable(LoadBool(data, idx: 41)); + ToCheckbox(data, idx: 38, MaintenanceTab_FeaturesGroup.TurnOnRedEnabled, true); + ToCheckbox(data, idx: 39, PoliciesTab_AtJunctionsGroup.AllowNearTurnOnRed, false); + ToCheckbox(data, idx: 40, PoliciesTab_AtJunctionsGroup.AllowFarTurnOnRed, false); + ToCheckbox(data, idx: 41, PoliciesTab_AtJunctionsGroup.AutomaticallyAddTrafficLightsIfApplicable, true); ToCheckbox(data, idx: 42, OptionsMassEditTab.RoundAboutQuickFix_StayInLaneMainR, true); ToCheckbox(data, idx: 43, OptionsMassEditTab.RoundAboutQuickFix_StayInLaneNearRabout, true); @@ -176,26 +215,28 @@ public bool LoadData(byte[] data) { ToCheckbox(data, idx: 55, OptionsMassEditTab.RoundAboutQuickFix_ParkingBanYieldR); ToCheckbox(data, idx: 56, PoliciesTab.NoDoubleCrossings); - ToCheckbox(data, idx: 57, PoliciesTab.DedicatedTurningLanes); + ToCheckbox(data, idx: 57, PoliciesTab_AtJunctionsGroup.DedicatedTurningLanes); Options.SavegamePathfinderEdition = LoadByte(data, idx: 58, defaultVal: 0); - ToCheckbox(data, idx: 59, OverlaysTab.ShowDefaultSpeedSubIcon, false); + ToCheckbox(data, idx: 59, OverlaysTab_OverlaysGroup.ShowDefaultSpeedSubIcon, false); Options.Available = true; - return true; } catch (Exception ex) { ex.LogException(); - // even though there was error, the options are now available for querying Options.Available = true; - return false; } } + /// + /// Compiles mod options in to a byte array for storage in savegame. + /// + /// Current success state of SaveData operation. + /// Returns true if successful, otherwise false. public byte[] SaveData(ref bool success) { // Remember to update this when adding new options (lastIdx + 1) @@ -217,7 +258,7 @@ public byte[] SaveData(ref bool success) { save[12] = (byte)(Options.strongerRoadConditionEffects ? 1 : 0); save[13] = (byte)(Options.allowUTurns ? 1 : 0); save[14] = (byte)(Options.allowLaneChangesWhileGoingStraight ? 1 : 0); - save[15] = (byte)(Options.disableDespawning ? 0 : 1); + save[15] = (byte)(!Options.disableDespawning ? 1 : 0); // inverted save[16] = 0; // Options.IsDynamicPathRecalculationActive save[17] = (byte)(Options.connectedLanesOverlay ? 1 : 0); save[18] = (byte)(Options.prioritySignsEnabled ? 1 : 0); @@ -263,11 +304,11 @@ public byte[] SaveData(ref bool success) { save[55] = OptionsMassEditTab.RoundAboutQuickFix_ParkingBanYieldR.Save(); save[56] = PoliciesTab.NoDoubleCrossings.Save(); - save[57] = PoliciesTab.DedicatedTurningLanes.Save(); + save[57] = PoliciesTab_AtJunctionsGroup.DedicatedTurningLanes.Save(); - save[58] = (byte)Options.SavegamePathfinderEdition; + save[58] = Options.SavegamePathfinderEdition; - save[59] = OverlaysTab.ShowDefaultSpeedSubIcon.Save(); + save[59] = OverlaysTab_OverlaysGroup.ShowDefaultSpeedSubIcon.Save(); return save; } @@ -276,5 +317,94 @@ public byte[] SaveData(ref bool success) { return save; // try and salvage some of the settings } } + + /// + /// Triggers a rebuild of the main menu (toolbar), adding/removing buttons + /// where applicable, and refreshing all translated text. Very slow. + /// + internal static void RebuildMenu() { + if (TMPELifecycle.Instance.Deserializing || ModUI.Instance == null) { + Log._Debug("OptionsManager.RebuildMenu() - Ignoring; Deserialising or ModUI is null"); + return; + } + + Log.Info("OptionsManager.RebuildMenu()"); + ModUI.Instance.RebuildMenu(); + + // TM:PE main button also needs to be updated + if (ModUI.Instance.MainMenuButton != null) { + ModUI.Instance.MainMenuButton.UpdateButtonSkinAndTooltip(); + } + + RoadUI.Instance.ReloadTexturesWithTranslation(); + TrafficLightTextures.Instance.ReloadTexturesWithTranslation(); + TMPELifecycle.Instance.TranslationDatabase.ReloadTutorialTranslations(); + TMPELifecycle.Instance.TranslationDatabase.ReloadGuideTranslations(); + } + + /// + /// When options which affect subtools or overlays are toggled, + /// all subtools are reinitialised to ensure they reflect the change. + /// + internal static void ReinitialiseSubTools() { + if (TMPELifecycle.Instance.Deserializing || ModUI.Instance == null) { + Log._Debug("OptionsManager.ReinitialiseSubTools() - Ignoring; Deserialising or ModUI is null"); + return; + } + + Log.Info("OptionsManager.ReinitialiseSubTools()"); + ModUI.GetTrafficManagerTool()?.InitializeSubTools(); + } + + /// + /// When junction restriction policies are toggled, all junctions + /// need to reflect the new default settings. + /// + internal static void UpdateJunctionRestrictionsManager() { + if (TMPELifecycle.Instance.Deserializing) { + Log._Debug("Options.UpdateJunctionRestrictionsManager() - Waiting for deserialisation"); + _needUpdateJunctionRestrictionsManager = true; + return; + } + + if (TMPELifecycle.InGameOrEditor()) { + Log.Info("OptionsManager.UpdateJunctionRestrictionsManager()"); + JunctionRestrictionsManager.Instance.UpdateAllDefaults(); + } + } + + /// + /// When dedicated turning lane policy is toggled, all junctions + /// need to be checked and updated if necessary. + /// + internal static void UpdateDedicatedTurningLanes() { + if (TMPELifecycle.Instance.Deserializing) { + Log._Debug("Options.UpdateDedicatedTurningLanes() - Waiting for deserialisation"); + _needUpdateDedicatedTurningLanes = true; + return; + } + + if (TMPELifecycle.InGameOrEditor()) { + Log.Info("OptionsManager.UpdateDedicatedTurningLanes()"); + LaneArrowManager.Instance.UpdateDedicatedTurningLanePolicy(true); + } + } + + /// + /// When lane routing feature activation is toggled, all junctions + /// need to be updated to reflect the change. + /// + internal static void UpdateRoutingManager() { + if (TMPELifecycle.Instance.Deserializing) { + Log._Debug("OptionsManager.UpdateRoutingManager() - Waiting for deserialisation"); + _needUpdateRoutingManager = true; + return; + } + + if (TMPELifecycle.InGameOrEditor()) { + Log.Info("OptionsManager.UpdateRoutingManager()"); + RoutingManager.Instance.RequestFullRecalculation(); + } + } } } diff --git a/TLM/TLM/Patch/_RoadBaseAI/UpdateLanesPatch.cs b/TLM/TLM/Patch/_RoadBaseAI/UpdateLanesPatch.cs index bd14c3c44..32e2a4b26 100644 --- a/TLM/TLM/Patch/_RoadBaseAI/UpdateLanesPatch.cs +++ b/TLM/TLM/Patch/_RoadBaseAI/UpdateLanesPatch.cs @@ -14,7 +14,7 @@ public class UpdateLanesPatch { /// [UsedImplicitly] static void Postfix(ushort segmentID) { - if (PoliciesTab.DedicatedTurningLanes) { + if (Options.DedicatedTurningLanes) { BuiltIn(segmentID); } diff --git a/TLM/TLM/State/Options.cs b/TLM/TLM/State/Options.cs index 14a48a4f9..1169d891e 100644 --- a/TLM/TLM/State/Options.cs +++ b/TLM/TLM/State/Options.cs @@ -13,10 +13,9 @@ namespace TrafficManager.State { using System; using JetBrains.Annotations; using UI.Textures; + using TrafficManager.Manager.Impl; public class Options : MonoBehaviour { - private const int CHECKBOX_LABEL_MAX_WIDTH = 695; - private const int CHECKBOX_LABEL_MAX_WIDTH_INDENTED = 680; #if DEBUG private static List debugSwitchFields = new List(); private static List debugValueFields = new List(); @@ -39,7 +38,7 @@ public enum PersistTo { /// /// /// Is set true after options are loaded via . - /// Is set false while options are being saved, and also when level unloads. + /// Is set false while options are being loaded, and also when level unloads. /// public static bool Available = false; @@ -61,24 +60,14 @@ public enum PersistTo { public static bool junctionRestrictionsOverlay; public static bool connectedLanesOverlay; #if QUEUEDSTATS - #if DEBUG - public static bool showPathFindStats = true; - #else - public static bool showPathFindStats = false; - #endif + public static bool showPathFindStats = VersionUtil.IS_DEBUG; #endif -#if DEBUG public static bool nodesOverlay; public static bool vehicleOverlay; public static bool citizenOverlay; public static bool buildingOverlay; -#else - public static bool nodesOverlay = false; - public static bool vehicleOverlay = false; - public static bool citizenOverlay = false; - public static bool buildingOverlay = false; -#endif + public static bool allowEnterBlockedJunctions; public static bool allowUTurns; public static bool allowNearTurnOnRed; @@ -91,28 +80,26 @@ public enum PersistTo { public static bool realisticPublicTransport; public static byte altLaneSelectionRatio; public static bool highwayRules; - public static bool automaticallyAddTrafficLightsIfApplicable = true; + public static bool automaticallyAddTrafficLightsIfApplicable; public static bool NoDoubleCrossings; public static bool DedicatedTurningLanes; -#if DEBUG - public static bool showLanes = true; -#else - public static bool showLanes = false; -#endif + + public static bool showLanes = VersionUtil.IS_DEBUG; + public static bool strongerRoadConditionEffects; public static bool parkingAI; public static bool disableDespawning; public static bool preferOuterLane; //public static byte publicTransportUsage = 1; - public static bool prioritySignsEnabled = true; - public static bool timedLightsEnabled = true; - public static bool customSpeedLimitsEnabled = true; - public static bool vehicleRestrictionsEnabled = true; - public static bool parkingRestrictionsEnabled = true; - public static bool junctionRestrictionsEnabled = true; - public static bool turnOnRedEnabled = true; - public static bool laneConnectorEnabled = true; + public static bool prioritySignsEnabled; + public static bool timedLightsEnabled; + public static bool customSpeedLimitsEnabled; + public static bool vehicleRestrictionsEnabled; + public static bool parkingRestrictionsEnabled; + public static bool junctionRestrictionsEnabled; + public static bool turnOnRedEnabled; + public static bool laneConnectorEnabled; [UsedImplicitly] public static bool scanForKnownIncompatibleModsEnabled = true; @@ -143,31 +130,9 @@ public enum PersistTo { public static bool showDefaultSpeedSubIcon; - /// - /// Invoked on options change to refresh the main menu and possibly update the labels for - /// a new language. Takes a second, very slow. - /// - internal static void RebuildMenu() { - if (ModUI.Instance != null) { - Log.Info("Rebuilding the TM:PE menu..."); - ModUI.Instance.RebuildMenu(); - - // TM:PE main button also needs to be uidated - if (ModUI.Instance.MainMenuButton != null) { - ModUI.Instance.MainMenuButton.UpdateButtonSkinAndTooltip(); - } - - RoadUI.Instance.ReloadTexturesWithTranslation(); - TrafficLightTextures.Instance.ReloadTexturesWithTranslation(); - TMPELifecycle.Instance.TranslationDatabase.ReloadTutorialTranslations(); - TMPELifecycle.Instance.TranslationDatabase.ReloadGuideTranslations(); - } else { - Log._Debug("Rebuilding the TM:PE menu: ignored, ModUI is null"); - } - } - public static void MakeSettings(UIHelper helper) { - Log.Info("Options.MakeSettings: Adding UI to mod options tabs"); + Log.Info("Options.MakeSettings() - Adding UI to mod options tabs"); + try { ExtUITabstrip tabStrip = ExtUITabstrip.Create(helper); GeneralTab.MakeSettings_General(tabStrip); @@ -182,43 +147,6 @@ public static void MakeSettings(UIHelper helper) { } } - internal static void Indent(UIComponent component) { - UILabel label = component.Find("Label"); - - if (label != null) { - label.padding = new RectOffset(22, 0, 0, 0); - } - - UISprite check = component.Find("Unchecked"); - - if (check != null) { - check.relativePosition += new Vector3(22.0f, 0); - } - } - - /// - /// Allows long checkbox label text to wrap and adds padding to checkbox - /// - /// Checkbox instance - /// Is checkbox indented - public static void AllowTextWrap(UICheckBox checkBox, bool indented = false) { - UILabel label = checkBox.label; - bool requireTextWrap; - int maxWidth = indented ? CHECKBOX_LABEL_MAX_WIDTH_INDENTED : CHECKBOX_LABEL_MAX_WIDTH; - using (UIFontRenderer renderer = label.ObtainRenderer()) { - Vector2 size = renderer.MeasureString(label.text); - requireTextWrap = size.x > maxWidth; - } - label.autoSize = false; - label.wordWrap = true; - label.verticalAlignment = UIVerticalAlignment.Middle; - label.textAlignment = UIHorizontalAlignment.Left; - label.size = new Vector2(maxWidth, requireTextWrap ? 40 : 20); - if (requireTextWrap) { - checkBox.height = 42; // set new height + top/bottom 1px padding - } - } - /// /// If the game is not loaded and warn is true, will display a warning about options being /// local to each savegame. diff --git a/TLM/TLM/State/OptionsTabs/GameplayTab.cs b/TLM/TLM/State/OptionsTabs/GameplayTab.cs index 9641f0789..03acaebc9 100644 --- a/TLM/TLM/State/OptionsTabs/GameplayTab.cs +++ b/TLM/TLM/State/OptionsTabs/GameplayTab.cs @@ -88,7 +88,7 @@ internal static void MakeSettings_Gameplay(ExtUITabstrip tabStrip) { Translation.Options.Get("Gameplay.Checkbox:No excessive transfers"), Options.realisticPublicTransport, OnRealisticPublicTransportChanged) as UICheckBox; - Options.AllowTextWrap(_realisticPublicTransportToggle); + CheckboxOption.AllowTextWrap(_realisticPublicTransportToggle); } private static void OnRecklessDriversChanged(int newRecklessDrivers) { diff --git a/TLM/TLM/State/OptionsTabs/GeneralTab.cs b/TLM/TLM/State/OptionsTabs/GeneralTab.cs index 82940895c..46a4e04be 100644 --- a/TLM/TLM/State/OptionsTabs/GeneralTab.cs +++ b/TLM/TLM/State/OptionsTabs/GeneralTab.cs @@ -16,6 +16,7 @@ namespace TrafficManager.State { using TrafficManager.State.ConfigData; using TrafficManager.UI.Textures; using UI.WhatsNew; + using TrafficManager.Manager.Impl; public static class GeneralTab { private static UICheckBox _instantEffectsToggle; @@ -172,7 +173,7 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) { text: Translation.ModConflicts.Get("Checkbox:Ignore disabled mods"), defaultValue: GlobalConfig.Instance.Main.IgnoreDisabledMods, eventCallback: OnIgnoreDisabledModsChanged) as UICheckBox; - Options.Indent(_ignoreDisabledModsToggle); + CheckboxOption.IndentUI(_ignoreDisabledModsToggle); _showCompatibilityCheckErrorToggle = group.AddCheckbox( T("General.Checkbox:Notify me about TM:PE startup conflicts"), @@ -214,14 +215,14 @@ private static void OnLanguageChanged(int newLanguageIndex) { // TODO: Move this to the owner class and implement IObserver Translation.SetCurrentLanguageToGameLanguage(); - Options.RebuildMenu(); + OptionsManager.RebuildMenu(); } else if (newLanguageIndex - 1 < Translation.AvailableLanguageCodes.Count) { string newLang = Translation.AvailableLanguageCodes[newLanguageIndex - 1]; GlobalConfig.Instance.LanguageCode = newLang; GlobalConfig.WriteConfig(); // TODO: Move this to the owner class and implement IObserver Translation.SetCurrentLanguageToTMPELanguage(); - Options.RebuildMenu(); + OptionsManager.RebuildMenu(); } else { Log.Warning($"Options.onLanguageChanged: Invalid language index: {newLanguageIndex}"); return; diff --git a/TLM/TLM/State/OptionsTabs/GeneralTab_DebugGroup.cs b/TLM/TLM/State/OptionsTabs/GeneralTab_DebugGroup.cs index 2b85f7f95..5ac9055fc 100644 --- a/TLM/TLM/State/OptionsTabs/GeneralTab_DebugGroup.cs +++ b/TLM/TLM/State/OptionsTabs/GeneralTab_DebugGroup.cs @@ -21,9 +21,7 @@ public static class GeneralTab_DebugGroup { static GeneralTab_DebugGroup() { try { - DebugCheckboxA.PropagatesTrueTo = new () { - { DebugCheckboxB }, - }; + DebugCheckboxA.PropagateTrueTo(DebugCheckboxB); } catch (Exception ex) { ex.LogException(); diff --git a/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs b/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs index ade1b64d2..ebd85c239 100644 --- a/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs +++ b/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs @@ -33,16 +33,6 @@ public static class MaintenanceTab { private static UICheckBox _showPathFindStatsToggle; #endif - private static UICheckBox _enableCustomSpeedLimitsToggle; - private static UICheckBox _enableVehicleRestrictionsToggle; - private static UICheckBox _enableParkingRestrictionsToggle; - private static UICheckBox _enableJunctionRestrictionsToggle; - private static UICheckBox _turnOnRedEnabledToggle; - private static UICheckBox _enableLaneConnectorToggle; - - internal static UICheckBox EnablePrioritySignsToggle; - internal static UICheckBox EnableTimedLightsToggle; - private static string T(string text) { return Translation.Options.Get(text); } @@ -77,57 +67,9 @@ internal static void MakeSettings_Maintenance(ExtUITabstrip tabStrip) { OnShowPathFindStatsChanged) as UICheckBox; #endif - var featureGroup = - panelHelper.AddGroup(T("Maintenance.Group:Activated features")) as UIHelper; - EnablePrioritySignsToggle = featureGroup.AddCheckbox( - T("Checkbox:Priority signs"), - Options.prioritySignsEnabled, - OnPrioritySignsEnabledChanged) as UICheckBox; - EnableTimedLightsToggle = featureGroup.AddCheckbox( - T("Checkbox:Timed traffic lights"), - Options.timedLightsEnabled, - OnTimedLightsEnabledChanged) as UICheckBox; - _enableCustomSpeedLimitsToggle = featureGroup.AddCheckbox( - T("Checkbox:Speed limits"), - Options.customSpeedLimitsEnabled, - OnCustomSpeedLimitsEnabledChanged) as UICheckBox; - _enableVehicleRestrictionsToggle = featureGroup.AddCheckbox( - T("Checkbox:Vehicle restrictions"), - Options.vehicleRestrictionsEnabled, - OnVehicleRestrictionsEnabledChanged) as - UICheckBox; - _enableParkingRestrictionsToggle = featureGroup.AddCheckbox( - T("Checkbox:Parking restrictions"), - Options.parkingRestrictionsEnabled, - OnParkingRestrictionsEnabledChanged) as - UICheckBox; - _enableJunctionRestrictionsToggle = featureGroup.AddCheckbox( - T("Checkbox:Junction restrictions"), - Options.junctionRestrictionsEnabled, - OnJunctionRestrictionsEnabledChanged) as - UICheckBox; - _turnOnRedEnabledToggle = featureGroup.AddCheckbox( - T("Maintenance.Checkbox:Turn on red"), - Options.turnOnRedEnabled, - OnTurnOnRedEnabledChanged) as UICheckBox; - _enableLaneConnectorToggle = featureGroup.AddCheckbox( - T("Maintenance.Checkbox:Lane connector"), - Options.laneConnectorEnabled, - OnLaneConnectorEnabledChanged) as UICheckBox; - - Options.Indent(_turnOnRedEnabledToggle); + MaintenanceTab_FeaturesGroup.AddUI(panelHelper); MaintenanceTab_DespawnGroup.AddUI(panelHelper); - - // TODO [issue ##959] remove when TTL is implemented in asset editor. - bool inEditor = TMPELifecycle.InGameOrEditor() - && TMPELifecycle.AppMode != AppMode.Game; - if (inEditor) { - EnableTimedLightsToggle.isChecked = false; - EnableTimedLightsToggle.isEnabled = false; - // since this is temprory I don't want to go through the trouble of creating translation key. - EnableTimedLightsToggle.tooltip = "TTL is not yet supported in asset editor"; - } } private static void onClickResetStuckEntities() { @@ -181,201 +123,10 @@ private static void OnShowPathFindStatsChanged(bool newVal) { Log._Debug($"Show path-find stats changed to {newVal}"); Options.showPathFindStats = newVal; - Options.RebuildMenu(); + OptionsManager.RebuildMenu(); } #endif - private static void OnPrioritySignsEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - Options.prioritySignsEnabled = val; - Options.RebuildMenu(); - - if (!val) { - OverlaysTab.SetPrioritySignsOverlay(false); - PoliciesTab.SetTrafficLightPriorityRules(false); - } - } - - private static void OnTimedLightsEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - Options.timedLightsEnabled = val; - Options.RebuildMenu(); - - if (!val) { - OverlaysTab.SetTimedLightsOverlay(false); - PoliciesTab.SetTrafficLightPriorityRules(false); - } - } - - private static void OnCustomSpeedLimitsEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - Options.customSpeedLimitsEnabled = val; - Options.RebuildMenu(); - - if (!val) { - OverlaysTab.SetSpeedLimitsOverlay(false); - } - } - - private static void OnVehicleRestrictionsEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - Options.vehicleRestrictionsEnabled = val; - Options.RebuildMenu(); - - if (!val) { - OverlaysTab.SetVehicleRestrictionsOverlay(false); - } - } - - private static void OnParkingRestrictionsEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - Options.parkingRestrictionsEnabled = val; - Options.RebuildMenu(); - - if (!val) { - OverlaysTab.SetParkingRestrictionsOverlay(false); - } - } - - private static void OnJunctionRestrictionsEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - Options.junctionRestrictionsEnabled = val; - Options.RebuildMenu(); - - if (!val) { - PoliciesTab.SetAllowUTurns(false); - PoliciesTab.SetAllowEnterBlockedJunctions(false); - PoliciesTab.SetAllowLaneChangesWhileGoingStraight(false); - SetTurnOnRedEnabled(false); - OverlaysTab.SetJunctionRestrictionsOverlay(false); - } - } - - private static void OnTurnOnRedEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - SetTurnOnRedEnabled(val); - } - - private static void OnLaneConnectorEnabledChanged(bool val) { - if (!Options.IsGameLoaded()) { - return; - } - - bool changed = val != Options.laneConnectorEnabled; - - if (!changed) { - return; - } - - Options.laneConnectorEnabled = val; - Options.RebuildMenu(); - - RoutingManager.Instance.RequestFullRecalculation(); - - if (!val) { - OverlaysTab.SetConnectedLanesOverlay(false); - } - } - - public static void SetCustomSpeedLimitsEnabled(bool newValue) { - Options.customSpeedLimitsEnabled = newValue; - Options.RebuildMenu(); - - if (_enableCustomSpeedLimitsToggle != null) { - _enableCustomSpeedLimitsToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetSpeedLimitsOverlay(false); - } - } - - public static void SetVehicleRestrictionsEnabled(bool newValue) { - Options.vehicleRestrictionsEnabled = newValue; - Options.RebuildMenu(); - - if (_enableVehicleRestrictionsToggle != null) { - _enableVehicleRestrictionsToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetVehicleRestrictionsOverlay(false); - } - } - - public static void SetParkingRestrictionsEnabled(bool newValue) { - Options.parkingRestrictionsEnabled = newValue; - Options.RebuildMenu(); - - if (_enableParkingRestrictionsToggle != null) { - _enableParkingRestrictionsToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetParkingRestrictionsOverlay(false); - } - } - - public static void SetJunctionRestrictionsEnabled(bool newValue) { - Options.junctionRestrictionsEnabled = newValue; - Options.RebuildMenu(); - - if (_enableJunctionRestrictionsToggle != null) { - _enableJunctionRestrictionsToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetJunctionRestrictionsOverlay(false); - } - } - - public static void SetTurnOnRedEnabled(bool newValue) { - Options.turnOnRedEnabled = newValue; - - if (_turnOnRedEnabledToggle != null) { - _turnOnRedEnabledToggle.isChecked = newValue; - } - - if (!newValue) { - PoliciesTab.SetAllowNearTurnOnRed(false); - PoliciesTab.SetAllowFarTurnOnRed(false); - } - } - - public static void SetLaneConnectorEnabled(bool newValue) { - Options.laneConnectorEnabled = newValue; - Options.RebuildMenu(); - - if (_enableLaneConnectorToggle != null) { - _enableLaneConnectorToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetConnectedLanesOverlay(false); - } - } - #if QUEUEDSTATS public static void SetShowPathFindStats(bool value) { Options.showPathFindStats = value; diff --git a/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs b/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs new file mode 100644 index 000000000..e484a93e0 --- /dev/null +++ b/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs @@ -0,0 +1,107 @@ +namespace TrafficManager.State { + using ICities; + using System; + using TrafficManager.Lifecycle; + using TrafficManager.Manager.Impl; + using TrafficManager.UI; + using TrafficManager.UI.Helpers; + using TrafficManager.Util; + + public static class MaintenanceTab_FeaturesGroup { + + public static CheckboxOption PrioritySignsEnabled = + new (nameof(Options.prioritySignsEnabled), Options.PersistTo.Savegame) { + Label = "Checkbox:Priority signs", + Handler = OnFeatureAvailabilityChanged, + }; + public static CheckboxOption TimedLightsEnabled = + new (nameof(Options.timedLightsEnabled), Options.PersistTo.Savegame) { + Label = "Checkbox:Timed traffic lights", + Validator = NotInEditorValidator, + Handler = OnFeatureAvailabilityChanged, + }; + public static CheckboxOption CustomSpeedLimitsEnabled = + new (nameof(Options.customSpeedLimitsEnabled), Options.PersistTo.Savegame) { + Label = "Checkbox:Speed limits", + Handler = OnFeatureAvailabilityChanged, + }; + public static CheckboxOption VehicleRestrictionsEnabled = + new (nameof(Options.vehicleRestrictionsEnabled), Options.PersistTo.Savegame) { + Label = "Checkbox:Vehicle restrictions", + Handler = OnFeatureAvailabilityChanged, + }; + public static CheckboxOption ParkingRestrictionsEnabled = + new (nameof(Options.parkingRestrictionsEnabled), Options.PersistTo.Savegame) { + Label = "Checkbox:Parking restrictions", + Handler = OnFeatureAvailabilityChanged, + }; + public static CheckboxOption JunctionRestrictionsEnabled = + new (nameof(Options.junctionRestrictionsEnabled), Options.PersistTo.Savegame) { + Label = "Checkbox:Junction restrictions", + Handler = OnFeatureAvailabilityChanged, + }; + public static CheckboxOption TurnOnRedEnabled = + new (nameof(Options.turnOnRedEnabled), Options.PersistTo.Savegame) { + Label = "Maintenance.Checkbox:Turn on red", + Indent = true, + }; + public static CheckboxOption LaneConnectorEnabled = + new (nameof(Options.laneConnectorEnabled), Options.PersistTo.Savegame) { + Label = "Maintenance.Checkbox:Lane connector", + Handler = OnLaneConnectorEnabledChanged, + }; + + static MaintenanceTab_FeaturesGroup() { + try { + TurnOnRedEnabled + .PropagateTrueTo(JunctionRestrictionsEnabled); + } + catch (Exception ex) { + ex.LogException(); + } + } + + internal static void AddUI(UIHelperBase tab) { + var group = tab.AddGroup(T("Maintenance.Group:Activated features")); + + PrioritySignsEnabled.AddUI(group); + + // TODO [issue #959] remove `if` when TTL is implemented in asset editor. + if (!IsInEditor()) { + TimedLightsEnabled.AddUI(group); + } + + CustomSpeedLimitsEnabled.AddUI(group); + VehicleRestrictionsEnabled.AddUI(group); + ParkingRestrictionsEnabled.AddUI(group); + JunctionRestrictionsEnabled.AddUI(group); + TurnOnRedEnabled.AddUI(group); + LaneConnectorEnabled.AddUI(group); + } + + private static string T(string key) => Translation.Options.Get(key); + + // TODO [issue #959] remove when TTL is implemented in asset editor. + private static bool IsInEditor() => + TMPELifecycle.InGameOrEditor() && + TMPELifecycle.AppMode != AppMode.Game; + + // TODO [issue #959] remove when TTL is implemented in asset editor. + private static bool NotInEditorValidator(bool desired, out bool result) { + if (!IsInEditor()) { + result = desired; + return true; + } + + return result = false; + } + + private static void OnFeatureAvailabilityChanged(bool _) + => OptionsManager.RebuildMenu(); + + private static void OnLaneConnectorEnabledChanged(bool _) { + OptionsManager.RebuildMenu(); + OptionsManager.UpdateRoutingManager(); + } + } +} \ No newline at end of file diff --git a/TLM/TLM/State/OptionsTabs/OverlaysTab.cs b/TLM/TLM/State/OptionsTabs/OverlaysTab.cs index 820e36cff..f57a5c25b 100644 --- a/TLM/TLM/State/OptionsTabs/OverlaysTab.cs +++ b/TLM/TLM/State/OptionsTabs/OverlaysTab.cs @@ -1,310 +1,12 @@ namespace TrafficManager.State { - using ColossalFramework.UI; - using CSUtil.Commons; - using JetBrains.Annotations; using TrafficManager.UI.Helpers; using TrafficManager.UI; public static class OverlaysTab { - private static UICheckBox _prioritySignsOverlayToggle; - private static UICheckBox _timedLightsOverlayToggle; - private static UICheckBox _speedLimitsOverlayToggle; - private static UICheckBox _vehicleRestrictionsOverlayToggle; - private static UICheckBox _parkingRestrictionsOverlayToggle; - private static UICheckBox _junctionRestrictionsOverlayToggle; - private static UICheckBox _connectedLanesOverlayToggle; - private static UICheckBox _nodesOverlayToggle; - private static UICheckBox _vehicleOverlayToggle; - private static UICheckBox _showLanesToggle; -#if DEBUG - [UsedImplicitly] - private static UICheckBox _citizenOverlayToggle; - - [UsedImplicitly] - private static UICheckBox _buildingOverlayToggle; -#endif - - public static CheckboxOption ShowDefaultSpeedSubIcon = - new(nameof(Options.showDefaultSpeedSubIcon), Options.PersistTo.Savegame) { - Label = "Overlays.Checkbox:Show default speed with customised speeds", - Indent = true, - }; - internal static void MakeSettings_Overlays(ExtUITabstrip tabStrip) { - UIHelper panelHelper = tabStrip.AddTabPage(Translation.Options.Get("Tab:Overlays")); - - _prioritySignsOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Checkbox:Priority signs"), - Options.prioritySignsOverlay, - OnPrioritySignsOverlayChanged) as UICheckBox; - _timedLightsOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Checkbox:Timed traffic lights"), - Options.timedLightsOverlay, - OnTimedLightsOverlayChanged) as UICheckBox; - _speedLimitsOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Checkbox:Speed limits"), - Options.speedLimitsOverlay, - OnSpeedLimitsOverlayChanged) as UICheckBox; - ShowDefaultSpeedSubIcon.AddUI(panelHelper); - _vehicleRestrictionsOverlayToggle - = panelHelper.AddCheckbox( - Translation.Options.Get("Checkbox:Vehicle restrictions"), - Options.vehicleRestrictionsOverlay, - OnVehicleRestrictionsOverlayChanged) as UICheckBox; - _parkingRestrictionsOverlayToggle - = panelHelper.AddCheckbox( - Translation.Options.Get("Checkbox:Parking restrictions"), - Options.parkingRestrictionsOverlay, - OnParkingRestrictionsOverlayChanged) as UICheckBox; - _junctionRestrictionsOverlayToggle - = panelHelper.AddCheckbox( - Translation.Options.Get("Checkbox:Junction restrictions"), - Options.junctionRestrictionsOverlay, - OnJunctionRestrictionsOverlayChanged) as UICheckBox; - _connectedLanesOverlayToggle - = panelHelper.AddCheckbox( - Translation.Options.Get("Overlay.Checkbox:Connected lanes"), - Options.connectedLanesOverlay, - OnConnectedLanesOverlayChanged) as UICheckBox; - _nodesOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Overlay.Checkbox:Nodes and segments"), - Options.nodesOverlay, - onNodesOverlayChanged) as UICheckBox; - _showLanesToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Overlay.Checkbox:Lanes"), - Options.showLanes, - onShowLanesChanged) as UICheckBox; -#if DEBUG - _vehicleOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Overlay.Checkbox:Vehicles"), - Options.vehicleOverlay, - onVehicleOverlayChanged) as UICheckBox; - _citizenOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Overlay.Checkbox:Citizens"), - Options.citizenOverlay, - onCitizenOverlayChanged) as UICheckBox; - _buildingOverlayToggle = panelHelper.AddCheckbox( - Translation.Options.Get("Overlay.Checkbox:Buildings"), - Options.buildingOverlay, - onBuildingOverlayChanged) as UICheckBox; -#endif - } - - public static void SetPrioritySignsOverlay(bool newPrioritySignsOverlay) { - Options.prioritySignsOverlay = newPrioritySignsOverlay; - - if (_prioritySignsOverlayToggle != null) { - _prioritySignsOverlayToggle.isChecked = newPrioritySignsOverlay; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetTimedLightsOverlay(bool newTimedLightsOverlay) { - Options.timedLightsOverlay = newTimedLightsOverlay; - - if (_timedLightsOverlayToggle != null) { - _timedLightsOverlayToggle.isChecked = newTimedLightsOverlay; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetSpeedLimitsOverlay(bool newSpeedLimitsOverlay) { - Options.speedLimitsOverlay = newSpeedLimitsOverlay; - - if (_speedLimitsOverlayToggle != null) { - _speedLimitsOverlayToggle.isChecked = newSpeedLimitsOverlay; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetVehicleRestrictionsOverlay(bool newVehicleRestrictionsOverlay) { - Options.vehicleRestrictionsOverlay = newVehicleRestrictionsOverlay; - - if (_vehicleRestrictionsOverlayToggle != null) { - _vehicleRestrictionsOverlayToggle.isChecked = newVehicleRestrictionsOverlay; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetParkingRestrictionsOverlay(bool newParkingRestrictionsOverlay) { - Options.parkingRestrictionsOverlay = newParkingRestrictionsOverlay; - - if (_parkingRestrictionsOverlayToggle != null) { - _parkingRestrictionsOverlayToggle.isChecked = newParkingRestrictionsOverlay; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetJunctionRestrictionsOverlay(bool newValue) { - Options.junctionRestrictionsOverlay = newValue; - - if (_junctionRestrictionsOverlayToggle != null) { - _junctionRestrictionsOverlayToggle.isChecked = newValue; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetConnectedLanesOverlay(bool newValue) { - Options.connectedLanesOverlay = newValue; - - if (_connectedLanesOverlayToggle != null) { - _connectedLanesOverlayToggle.isChecked = newValue; - } - } - - public static void SetNodesOverlay(bool newNodesOverlay) { - Options.nodesOverlay = newNodesOverlay; - - if (_nodesOverlayToggle != null) { - _nodesOverlayToggle.isChecked = newNodesOverlay; - } - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetVehicleOverlay(bool newVal) { - Options.vehicleOverlay = newVal; - - if (_vehicleOverlayToggle != null) { - _vehicleOverlayToggle.isChecked = newVal; - } - } - - private static void OnPrioritySignsOverlayChanged(bool newPrioritySignsOverlay) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"prioritySignsOverlay changed to {newPrioritySignsOverlay}"); - Options.prioritySignsOverlay = newPrioritySignsOverlay; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void OnTimedLightsOverlayChanged(bool newTimedLightsOverlay) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"timedLightsOverlay changed to {newTimedLightsOverlay}"); - Options.timedLightsOverlay = newTimedLightsOverlay; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void OnSpeedLimitsOverlayChanged(bool newSpeedLimitsOverlay) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"speedLimitsOverlay changed to {newSpeedLimitsOverlay}"); - Options.speedLimitsOverlay = newSpeedLimitsOverlay; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void OnVehicleRestrictionsOverlayChanged(bool newVehicleRestrictionsOverlay) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"vehicleRestrictionsOverlay changed to {newVehicleRestrictionsOverlay}"); - Options.vehicleRestrictionsOverlay = newVehicleRestrictionsOverlay; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void OnParkingRestrictionsOverlayChanged(bool newParkingRestrictionsOverlay) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"parkingRestrictionsOverlay changed to {newParkingRestrictionsOverlay}"); - Options.parkingRestrictionsOverlay = newParkingRestrictionsOverlay; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void OnJunctionRestrictionsOverlayChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"junctionRestrictionsOverlay changed to {newValue}"); - Options.junctionRestrictionsOverlay = newValue; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void OnConnectedLanesOverlayChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"connectedLanesOverlay changed to {newValue}"); - Options.connectedLanesOverlay = newValue; - - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - private static void onNodesOverlayChanged(bool newNodesOverlay) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"Nodes overlay changed to {newNodesOverlay}"); - Options.nodesOverlay = newNodesOverlay; - } - - private static void onShowLanesChanged(bool newShowLanes) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"Show lanes changed to {newShowLanes}"); - Options.showLanes = newShowLanes; - } - - private static void onVehicleOverlayChanged(bool newVal) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"Vehicle overlay changed to {newVal}"); - Options.vehicleOverlay = newVal; - } - - private static void onCitizenOverlayChanged(bool newVal) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"Citizen overlay changed to {newVal}"); - Options.citizenOverlay = newVal; - } - - private static void onBuildingOverlayChanged(bool newVal) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"Building overlay changed to {newVal}"); - Options.buildingOverlay = newVal; - } - - [UsedImplicitly] - public static void SetShowLanes(bool newShowLanes) { - Options.showLanes = newShowLanes; + var tab = tabStrip.AddTabPage(Translation.Options.Get("Tab:Overlays")); - if (_showLanesToggle != null) { - _showLanesToggle.isChecked = newShowLanes; - } + OverlaysTab_OverlaysGroup.AddUI(tab); } - } // end class + } } diff --git a/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs b/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs new file mode 100644 index 000000000..f44bbc9ad --- /dev/null +++ b/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs @@ -0,0 +1,133 @@ +namespace TrafficManager.State { + using ICities; + using System; + using TrafficManager.Manager.Impl; + using TrafficManager.UI; + using TrafficManager.UI.Helpers; + using TrafficManager.Util; + + public static class OverlaysTab_OverlaysGroup { + + public static CheckboxOption PrioritySignsOverlay = + new (nameof(Options.prioritySignsOverlay), Options.PersistTo.Savegame) { + Label = "Checkbox:Priority signs", + Handler = OnOverlayChanged, + }; + public static CheckboxOption TimedLightsOverlay = + new (nameof(Options.timedLightsOverlay), Options.PersistTo.Savegame) { + Label = "Checkbox:Timed traffic lights", + Handler = OnOverlayChanged, + }; + public static CheckboxOption SpeedLimitsOverlay = + new (nameof(Options.speedLimitsOverlay), Options.PersistTo.Savegame) { + Label = "Checkbox:Speed limits", + Handler = OnOverlayChanged, + }; + public static CheckboxOption ShowDefaultSpeedSubIcon = + new (nameof(Options.showDefaultSpeedSubIcon), Options.PersistTo.Savegame) { + Label = "Overlays.Checkbox:Show default speed with customised speeds", + Indent = true, + }; + public static CheckboxOption VehicleRestrictionsOverlay = + new (nameof(Options.vehicleRestrictionsOverlay), Options.PersistTo.Savegame) { + Label = "Checkbox:Vehicle restrictions", + Handler = OnOverlayChanged, + }; + public static CheckboxOption ParkingRestrictionsOverlay = + new (nameof(Options.parkingRestrictionsOverlay), Options.PersistTo.Savegame) { + Label = "Checkbox:Parking restrictions", + Handler = OnOverlayChanged, + }; + public static CheckboxOption JunctionRestrictionsOverlay = + new (nameof(Options.junctionRestrictionsOverlay), Options.PersistTo.Savegame) { + Label = "Checkbox:Junction restrictions", + Handler = OnOverlayChanged, + }; + public static CheckboxOption ConnectedLanesOverlay = + new (nameof(Options.connectedLanesOverlay), Options.PersistTo.Savegame) { + Label = "Overlay.Checkbox:Connected lanes", + Handler = OnOverlayChanged, + }; + public static CheckboxOption NodesOverlay = + new (nameof(Options.nodesOverlay), Options.PersistTo.Savegame) { + Label = "Overlay.Checkbox:Nodes and segments", + }; + public static CheckboxOption ShowLanes = + new (nameof(Options.showLanes), Options.PersistTo.Savegame) { + Label = "Overlay.Checkbox:Lanes", + }; + public static CheckboxOption VehicleOverlay = + new (nameof(Options.vehicleOverlay), Options.PersistTo.Savegame) { + Label = "Overlay.Checkbox:Vehicles", + Validator = DebugOnlyValidator, + }; + public static CheckboxOption CitizenOverlay = + new (nameof(Options.citizenOverlay), Options.PersistTo.Savegame) { + Label = "Overlay.Checkbox:Citizens", + Validator = DebugOnlyValidator, + }; + public static CheckboxOption BuildingOverlay = + new (nameof(Options.buildingOverlay), Options.PersistTo.Savegame) { + Label = "Overlay.Checkbox:Buildings", + Validator = DebugOnlyValidator, + }; + + static OverlaysTab_OverlaysGroup() { + try { + PrioritySignsOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.PrioritySignsEnabled); + TimedLightsOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.TimedLightsEnabled); + SpeedLimitsOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.CustomSpeedLimitsEnabled); + VehicleRestrictionsOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.VehicleRestrictionsEnabled); + ParkingRestrictionsOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.ParkingRestrictionsEnabled); + JunctionRestrictionsOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.JunctionRestrictionsEnabled); + ConnectedLanesOverlay + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.LaneConnectorEnabled); + } + catch (Exception ex) { + ex.LogException(); + } + } + + internal static void AddUI(UIHelperBase tab) { + + var group = tab.AddGroup(T("Tab:Overlays")); + + PrioritySignsOverlay.AddUI(group); + TimedLightsOverlay.AddUI(group); + SpeedLimitsOverlay.AddUI(group); + ShowDefaultSpeedSubIcon.AddUI(group); + VehicleRestrictionsOverlay.AddUI(group); + ParkingRestrictionsOverlay.AddUI(group); + JunctionRestrictionsOverlay.AddUI(group); + ConnectedLanesOverlay.AddUI(group); + + NodesOverlay.AddUI(group); + ShowLanes.AddUI(group); +#if DEBUG + VehicleOverlay.AddUI(group); + CitizenOverlay.AddUI(group); + BuildingOverlay.AddUI(group); +#endif + } + + private static string T(string key) => Translation.Options.Get(key); + + private static bool DebugOnlyValidator(bool desired, out bool result) { +#if DEBUG + result = desired; + return true; +#else + return result = false; +#endif + } + + private static void OnOverlayChanged(bool _) + => OptionsManager.ReinitialiseSubTools(); + } +} \ No newline at end of file diff --git a/TLM/TLM/State/OptionsTabs/PoliciesTab.cs b/TLM/TLM/State/OptionsTabs/PoliciesTab.cs index abb4146d5..f41e3f163 100644 --- a/TLM/TLM/State/OptionsTabs/PoliciesTab.cs +++ b/TLM/TLM/State/OptionsTabs/PoliciesTab.cs @@ -9,15 +9,6 @@ namespace TrafficManager.State { using static TrafficManager.Util.Shortcuts; public static class PoliciesTab { - private static UICheckBox _relaxedBussesToggle; - private static UICheckBox _allRelaxedToggle; - private static UICheckBox _allowEnterBlockedJunctionsToggle; - private static UICheckBox _allowUTurnsToggle; - private static UICheckBox _allowNearTurnOnRedToggle; - private static UICheckBox _allowFarTurnOnRedToggle; - private static UICheckBox _allowLaneChangesWhileGoingStraightToggle; - private static UICheckBox _trafficLightPriorityRulesToggle; - private static UICheckBox _automaticallyAddTrafficLightsIfApplicableToggle; private static UIDropDown _vehicleRestrictionsAggressionDropdown; private static UICheckBox _banRegularTrafficOnBusLanesToggle; private static UICheckBox _highwayRulesToggle; @@ -30,74 +21,13 @@ public static class PoliciesTab { Handler = JunctionRestrictionsUpdateHandler, }; - public static CheckboxOption DedicatedTurningLanes = - new CheckboxOption(nameof(DedicatedTurningLanes)) { - Label = "VR.Option:Dedicated turning lanes", - Handler = UpdateDedicatedTurningLanePolicyHandler, - }; - static void JunctionRestrictionsUpdateHandler(bool value ) => JunctionRestrictionsManager.Instance.UpdateAllDefaults(); - static void UpdateDedicatedTurningLanePolicyHandler(bool value) => - LaneArrowManager.Instance.UpdateDedicatedTurningLanePolicy(true); - internal static void MakeSettings_VehicleRestrictions(ExtUITabstrip tabStrip) { UIHelper panelHelper = tabStrip.AddTabPage(Translation.Options.Get("Tab:Policies & Restrictions")); - UIHelperBase atJunctionsGroup = panelHelper.AddGroup( - Translation.Options.Get("VR.Group:At junctions")); -#if DEBUG - _allRelaxedToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:All vehicles may ignore lane arrows"), - Options.allRelaxed, - OnAllRelaxedChanged) as UICheckBox; -#endif - _relaxedBussesToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Buses may ignore lane arrows"), - Options.relaxedBusses, - OnRelaxedBussesChanged) as UICheckBox; - _allowEnterBlockedJunctionsToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Vehicles may enter blocked junctions"), - Options.allowEnterBlockedJunctions, - OnAllowEnterBlockedJunctionsChanged) as UICheckBox; - _allowUTurnsToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Vehicles may do u-turns at junctions"), - Options.allowUTurns, - OnAllowUTurnsChanged) as UICheckBox; - _allowNearTurnOnRedToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Vehicles may turn on red"), - Options.allowNearTurnOnRed, - OnAllowNearTurnOnRedChanged) as UICheckBox; - _allowFarTurnOnRedToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Also apply to left/right turns between one-way streets"), - Options.allowFarTurnOnRed, - OnAllowFarTurnOnRedChanged) as UICheckBox; - Options.Indent(_allowFarTurnOnRedToggle); - Options.AllowTextWrap(_allowFarTurnOnRedToggle, indented: true); - _allowLaneChangesWhileGoingStraightToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Vehicles going straight may change lanes at junctions"), - Options.allowLaneChangesWhileGoingStraight, - OnAllowLaneChangesWhileGoingStraightChanged) as UICheckBox; - _trafficLightPriorityRulesToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Vehicles follow priority rules at junctions with timedTL"), - Options.trafficLightPriorityRules, - OnTrafficLightPriorityRulesChanged) as UICheckBox; - Options.AllowTextWrap(_trafficLightPriorityRulesToggle); - _automaticallyAddTrafficLightsIfApplicableToggle - = atJunctionsGroup.AddCheckbox( - Translation.Options.Get("VR.Checkbox:Automatically add traffic lights if applicable"), - Options.automaticallyAddTrafficLightsIfApplicable, - OnAutomaticallyAddTrafficLightsIfApplicableChanged) as UICheckBox; - DedicatedTurningLanes.AddUI(atJunctionsGroup); + PoliciesTab_AtJunctionsGroup.AddUI(panelHelper); UIHelperBase onRoadsGroup = panelHelper.AddGroup(Translation.Options.Get("VR.Group:On roads")); @@ -146,126 +76,6 @@ internal static void MakeSettings_VehicleRestrictions(ExtUITabstrip tabStrip) { OptionsMassEditTab.MakePanel_MassEdit(panelHelper); } - private static void OnAllRelaxedChanged(bool newAllRelaxed) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"All relaxed changed to {newAllRelaxed}"); - Options.allRelaxed = newAllRelaxed; - } - - private static void OnRelaxedBussesChanged(bool newRelaxedBusses) { - if (!Options.IsGameLoaded()) { - return; - } - - Log._Debug($"Relaxed busses changed to {newRelaxedBusses}"); - Options.relaxedBusses = newRelaxedBusses; - } - - private static void OnAllowEnterBlockedJunctionsChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - if (newValue && !Options.junctionRestrictionsEnabled) { - SetAllowEnterBlockedJunctions(false); - return; - } - - Log._Debug($"allowEnterBlockedJunctions changed to {newValue}"); - SetAllowEnterBlockedJunctions(newValue); - } - - private static void OnAllowUTurnsChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - if (newValue && !Options.junctionRestrictionsEnabled) { - SetAllowUTurns(false); - return; - } - - Log._Debug($"allowUTurns changed to {newValue}"); - SetAllowUTurns(newValue); - } - - private static void OnAllowNearTurnOnRedChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - if (newValue && !Options.turnOnRedEnabled) { - SetAllowNearTurnOnRed(false); - SetAllowFarTurnOnRed(false); - return; - } - - Log._Debug($"allowNearTurnOnRed changed to {newValue}"); - SetAllowNearTurnOnRed(newValue); - - if (!newValue) { - SetAllowFarTurnOnRed(false); - } - } - - private static void OnAllowFarTurnOnRedChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - if (newValue && (!Options.turnOnRedEnabled || !Options.allowNearTurnOnRed)) { - SetAllowFarTurnOnRed(false); - return; - } - - Log._Debug($"allowFarTurnOnRed changed to {newValue}"); - SetAllowFarTurnOnRed(newValue); - } - - private static void OnAllowLaneChangesWhileGoingStraightChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - if (newValue && !Options.junctionRestrictionsEnabled) { - SetAllowLaneChangesWhileGoingStraight(false); - return; - } - - Log._Debug($"allowLaneChangesWhileGoingStraight changed to {newValue}"); - SetAllowLaneChangesWhileGoingStraight(newValue); - } - - private static void OnTrafficLightPriorityRulesChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - - if (newValue && !Options.prioritySignsEnabled) { - SetTrafficLightPriorityRules(false); - return; - } - - Log._Debug($"trafficLightPriorityRules changed to {newValue}"); - Options.trafficLightPriorityRules = newValue; - - if (newValue) { - SetPrioritySignsEnabled(true); - SetTimedLightsEnabled(true); - } - } - - private static void OnAutomaticallyAddTrafficLightsIfApplicableChanged(bool newValue) { - if (!Options.IsGameLoaded()) { - return; - } - Log._Debug($"AutomaticallyAddTrafficLightsIfApplicableChanged changed to {newValue}"); - Options.automaticallyAddTrafficLightsIfApplicable = newValue; - } - private static void OnVehicleRestrictionsAggressionChanged(int newValue) { if (!Options.IsGameLoaded()) { return; @@ -284,14 +94,6 @@ public static void SetVehicleRestrictionsAggression(VehicleRestrictionsAggressio } } - public static void SetTrafficLightPriorityRules(bool value) { - Options.trafficLightPriorityRules = value; - - if (_trafficLightPriorityRulesToggle != null) { - _trafficLightPriorityRulesToggle.isChecked = value; - } - } - private static void OnBanRegularTrafficOnBusLanesChanged(bool newValue) { if (!Options.IsGameLoaded()) { return; @@ -301,7 +103,7 @@ private static void OnBanRegularTrafficOnBusLanesChanged(bool newValue) { Options.banRegularTrafficOnBusLanes = newValue; VehicleRestrictionsManager.Instance.ClearCache(); ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - if (DedicatedTurningLanes) { + if (Options.DedicatedTurningLanes) { LaneArrowManager.Instance.UpdateDedicatedTurningLanePolicy(false); } } @@ -340,100 +142,6 @@ private static void OnEvacBussesMayIgnoreRulesChanged(bool value) { Options.evacBussesMayIgnoreRules = value; } - public static void SetAllowEnterBlockedJunctions(bool value) { - Options.allowEnterBlockedJunctions = value; - - if (_allowEnterBlockedJunctionsToggle != null) { - _allowEnterBlockedJunctionsToggle.isChecked = value; - } - - Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults(); - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetPrioritySignsEnabled(bool newValue) { - Options.RebuildMenu(); - Options.prioritySignsEnabled = newValue; - - if (MaintenanceTab.EnablePrioritySignsToggle != null) { - MaintenanceTab.EnablePrioritySignsToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetPrioritySignsOverlay(false); - } - } - - public static void SetTimedLightsEnabled(bool newValue) { - Options.RebuildMenu(); - Options.timedLightsEnabled = newValue; - - if (MaintenanceTab.EnableTimedLightsToggle != null) { - MaintenanceTab.EnableTimedLightsToggle.isChecked = newValue; - } - - if (!newValue) { - OverlaysTab.SetTimedLightsOverlay(false); - } - } - - public static void SetAllowUTurns(bool value) { - Options.allowUTurns = value; - - if (_allowUTurnsToggle != null) { - _allowUTurnsToggle.isChecked = value; - } - - Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults(); - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetAllowNearTurnOnRed(bool newValue) { - Options.allowNearTurnOnRed = newValue; - - if (_allowNearTurnOnRedToggle != null) { - _allowNearTurnOnRedToggle.isChecked = newValue; - } - - Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults(); - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetAllowFarTurnOnRed(bool newValue) { - Options.allowFarTurnOnRed = newValue; - - if (_allowFarTurnOnRedToggle != null) { - _allowFarTurnOnRedToggle.isChecked = newValue; - } - - Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults(); - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetAllowLaneChangesWhileGoingStraight(bool value) { - Options.allowLaneChangesWhileGoingStraight = value; - if (_allowLaneChangesWhileGoingStraightToggle != null) - _allowLaneChangesWhileGoingStraightToggle.isChecked = value; - Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults(); - ModUI.GetTrafficManagerTool()?.InitializeSubTools(); - } - - public static void SetRelaxedBusses(bool newRelaxedBusses) { - Options.relaxedBusses = newRelaxedBusses; - - if (_relaxedBussesToggle != null) { - _relaxedBussesToggle.isChecked = newRelaxedBusses; - } - } - - public static void SetAllRelaxed(bool newAllRelaxed) { - Options.allRelaxed = newAllRelaxed; - - if (_allRelaxedToggle != null) { - _allRelaxedToggle.isChecked = newAllRelaxed; - } - } - public static void SetHighwayRules(bool newHighwayRules) { Options.highwayRules = newHighwayRules; @@ -462,14 +170,6 @@ public static void SetEvacBussesMayIgnoreRules(bool value) { } } - public static void SetMayEnterBlockedJunctions(bool newMayEnterBlockedJunctions) { - Options.allowEnterBlockedJunctions = newMayEnterBlockedJunctions; - - if (_allowEnterBlockedJunctionsToggle != null) { - _allowEnterBlockedJunctionsToggle.isChecked = newMayEnterBlockedJunctions; - } - } - public static void SetBanRegularTrafficOnBusLanes(bool value) { Options.banRegularTrafficOnBusLanes = value; @@ -481,12 +181,5 @@ public static void SetBanRegularTrafficOnBusLanes(bool value) { ModUI.GetTrafficManagerTool()?.InitializeSubTools(); } - public static void SetAddTrafficLightsIfApplicable(bool value) { - Options.automaticallyAddTrafficLightsIfApplicable = value; - - if (_automaticallyAddTrafficLightsIfApplicableToggle != null) { - _automaticallyAddTrafficLightsIfApplicableToggle.isChecked = value; - } - } - } // end class + } } diff --git a/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs b/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs new file mode 100644 index 000000000..f16977ec1 --- /dev/null +++ b/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs @@ -0,0 +1,118 @@ +namespace TrafficManager.State { + using ICities; + using System; + using TrafficManager.Manager.Impl; + using TrafficManager.UI; + using TrafficManager.UI.Helpers; + using TrafficManager.Util; + + public static class PoliciesTab_AtJunctionsGroup { + + public static CheckboxOption AllRelaxed = + new (nameof(Options.allRelaxed), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:All vehicles may ignore lane arrows", + Validator = DebugOnlyValidator, + }; + public static CheckboxOption RelaxedBusses = + new (nameof(Options.relaxedBusses), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Buses may ignore lane arrows", + }; + public static CheckboxOption AllowEnterBlockedJunctions = + new (nameof(Options.allowEnterBlockedJunctions), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Vehicles may enter blocked junctions", + Handler = OnJunctionRestrictionPolicyChanged, + }; + public static CheckboxOption AllowUTurns = + new (nameof(Options.allowUTurns), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Vehicles may do u-turns at junctions", + Handler = OnJunctionRestrictionPolicyChanged, + }; + public static CheckboxOption AllowNearTurnOnRed = + new (nameof(Options.allowNearTurnOnRed), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Vehicles may turn on red", + Handler = OnJunctionRestrictionPolicyChanged, + }; + public static CheckboxOption AllowFarTurnOnRed = + new (nameof(Options.allowFarTurnOnRed), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Also apply to left/right turns between one-way streets", + Indent = true, + Handler = OnJunctionRestrictionPolicyChanged, + }; + public static CheckboxOption AllowLaneChangesWhileGoingStraight = + new (nameof(Options.allowLaneChangesWhileGoingStraight), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Vehicles going straight may change lanes at junctions", + Handler = OnJunctionRestrictionPolicyChanged, + }; + public static CheckboxOption TrafficLightPriorityRules = + new (nameof(Options.trafficLightPriorityRules), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Vehicles follow priority rules at junctions with timedTL", + }; + public static CheckboxOption AutomaticallyAddTrafficLightsIfApplicable = + new (nameof(Options.automaticallyAddTrafficLightsIfApplicable), Options.PersistTo.Savegame) { + Label = "VR.Checkbox:Automatically add traffic lights if applicable", + }; + public static CheckboxOption DedicatedTurningLanes = + new (nameof(DedicatedTurningLanes)) { + Label = "VR.Option:Dedicated turning lanes", + Handler = OnDedicatedTurningLanesChanged, + }; + + static PoliciesTab_AtJunctionsGroup() { + try { + AllowEnterBlockedJunctions + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.JunctionRestrictionsEnabled); + AllowUTurns + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.JunctionRestrictionsEnabled); + AllowNearTurnOnRed + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.TurnOnRedEnabled); + AllowFarTurnOnRed + .PropagateTrueTo(AllowNearTurnOnRed); + AllowLaneChangesWhileGoingStraight + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.JunctionRestrictionsEnabled); + TrafficLightPriorityRules + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.PrioritySignsEnabled) + .PropagateTrueTo(MaintenanceTab_FeaturesGroup.TimedLightsEnabled); + } + catch (Exception ex) { + ex.LogException(); + } + } + + internal static void AddUI(UIHelperBase tab) { + + var group = tab.AddGroup(T("VR.Group:At junctions")); + +#if DEBUG + AllRelaxed.AddUI(group); +#endif + RelaxedBusses.AddUI(group); + AllowEnterBlockedJunctions.AddUI(group); + AllowUTurns.AddUI(group); + AllowNearTurnOnRed.AddUI(group); + AllowFarTurnOnRed.AddUI(group); + AllowLaneChangesWhileGoingStraight.AddUI(group); + TrafficLightPriorityRules.AddUI(group); + AutomaticallyAddTrafficLightsIfApplicable.AddUI(group); + DedicatedTurningLanes.AddUI(group); + } + + private static string T(string key) => Translation.Options.Get(key); + + private static bool DebugOnlyValidator(bool desired, out bool result) { +#if DEBUG + result = desired; + return true; +#else + return result = false; +#endif + } + + private static void OnJunctionRestrictionPolicyChanged(bool _) { + OptionsManager.UpdateJunctionRestrictionsManager(); + OptionsManager.ReinitialiseSubTools(); + } + + private static void OnDedicatedTurningLanesChanged(bool _) + => OptionsManager.UpdateDedicatedTurningLanes(); + } +} \ No newline at end of file diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index f413e0cab..bff206d73 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -148,6 +148,9 @@ + + + diff --git a/TLM/TLM/UI/Helpers/CheckboxOption.cs b/TLM/TLM/UI/Helpers/CheckboxOption.cs index 04268512d..3f5895a38 100644 --- a/TLM/TLM/UI/Helpers/CheckboxOption.cs +++ b/TLM/TLM/UI/Helpers/CheckboxOption.cs @@ -1,14 +1,18 @@ namespace TrafficManager.UI.Helpers { using ICities; using ColossalFramework.UI; - using State; + using TrafficManager.State; using CSUtil.Commons; using System.Collections.Generic; using JetBrains.Annotations; + using UnityEngine; public class CheckboxOption : SerializableUIOptionBase { - [CanBeNull] + private const int CHECKBOX_LABEL_MAX_WIDTH = 695; + private const int CHECKBOX_LABEL_MAX_WIDTH_INDENTED = 680; + private List _propagatesTrueTo; + private List _propagatesFalseTo; public CheckboxOption(string fieldName, Options.PersistTo scope = Options.PersistTo.Savegame) : base(fieldName, scope) { @@ -17,6 +21,8 @@ public CheckboxOption(string fieldName, Options.PersistTo scope = Options.Persis /* Data */ + public delegate bool ValidatorDelegate(bool desired, out bool result); + public event OnCheckChanged OnValueChanged; public OnCheckChanged Handler { @@ -24,55 +30,41 @@ public OnCheckChanged Handler { } /// - /// Optional: If specified, when Value is set true it will propagate that to listed checkboxes. + /// Optional custom validator which intercepts value changes and can inhibit event propagation. /// - [CanBeNull] - public List PropagatesTrueTo { - get => _propagatesTrueTo; - set { - _propagatesTrueTo = value; - Log.Info($"CheckboxOption.PropagatesTrueTo: {nameof(Options)}.{FieldName} will proagate to:"); - - foreach (var requirement in _propagatesTrueTo) { - Log.Info($"- {nameof(Options)}.{requirement.FieldName}"); - - if (requirement.PropagatesFalseTo == null) { - requirement.PropagatesFalseTo = new (); - } - - requirement.PropagatesFalseTo.Add(this); - } - } - } + public ValidatorDelegate Validator { get; set; } /// - /// Optional: If specified, when Value is set false it will propagate that to listed checkboxes. + /// If this checkbox is set true, it will propagate that to the . + /// Chainable. /// - /// Don't need to set directly; it's automatically managed by property. - [CanBeNull] - public List PropagatesFalseTo { get; set; } + /// The checkox to propagate true value to. + /// + /// If target is set false, it will proapagate that back to this checkbox. + /// + public CheckboxOption PropagateTrueTo([NotNull] CheckboxOption target) { + Log.Info($"CheckboxOption.PropagateTrueTo: `{FieldName}` will proagate to `{target.FieldName}`"); - public override void Load(byte data) { - Log.Info($"CheckboxOption.Load: {data} -> {data != 0} -> {nameof(Options)}.{FieldName}"); - Value = data != 0; - } + if (_propagatesTrueTo == null) _propagatesTrueTo = new (); + _propagatesTrueTo.Add(target); - public override byte Save() { - Log.Info($"CheckboxOption.Save: {nameof(Options)}.{FieldName} -> {Value} -> {(Value ? (byte)1 : (byte)0)}"); - return Value ? (byte)1 : (byte)0; + if (target._propagatesFalseTo == null) target._propagatesFalseTo = new(); + target._propagatesFalseTo.Add(this); + + return this; } + public override void Load(byte data) => Value = data != 0; + + public override byte Save() => (byte)(Value ? 1 : 0); + /* UI */ public string Label { - get => _label ?? FieldName; + get => _label ?? $"Checkbox:{FieldName}"; set { _label = value; - if (HasUI) { - _ui.label.text = string.IsNullOrEmpty(value) - ? string.Empty // avoid invalidating UI if already no label - : T(value); - } + UpdateLabel(); } } @@ -80,64 +72,124 @@ public string Tooltip { get => _tooltip; set { _tooltip = value; - if (HasUI) { - _ui.tooltip = IsInScope - ? string.IsNullOrEmpty(value) - ? string.Empty // avoid invalidating UI if already no tooltip - : T(value) - : T(INGAME_ONLY_SETTING); - } + UpdateTooltip(); } } + public bool Indent { get; set; } + public override bool Value { get => base.Value; set { - Log.Info($"CheckboxOption.Value: {nameof(Options)}.{FieldName} changed to {value}"); - - // auto-enable requirements if applicable - if (value && _propagatesTrueTo != null) { - foreach (var requirement in _propagatesTrueTo) { - requirement.Value = true; + if (Validator != null) { + if (Validator(value, out bool result)) { + value = result; + } else { + Log.Info($"CheckboxOption.Value: `{FieldName}` validator rejected value: {value}"); + return; } } - // auto-disable dependents if applicable - if (!value && PropagatesFalseTo != null) { - foreach (var dependent in PropagatesFalseTo) { - dependent.Value = false; - } - } + if (value == base.Value) + return; base.Value = value; - if (HasUI) { - _ui.isChecked = value; - } + + Log.Info($"CheckboxOption.Value: `{FieldName}` changed to {value}"); + + if (value && _propagatesTrueTo != null) + PropagateTo(_propagatesTrueTo, true); + + if (!value && _propagatesFalseTo != null) + PropagateTo(_propagatesFalseTo, false); + + if (HasUI) _ui.isChecked = value; } } - public bool ReadOnlyUI { - get => _readOnlyUI; + public bool ReadOnly { + get => _readOnly; set { - // _readOnlyUI = !IsInScope || value; - if (HasUI) { - _ui.readOnly = _readOnlyUI; - _ui.opacity = _readOnlyUI ? 0.3f : 1f; - } + _readOnly = !IsInScope || value; + UpdateReadOnly(); } } - public bool Indent { get; set; } - public override void AddUI(UIHelperBase container) { _ui = container.AddCheckbox(T(Label), Value, OnValueChanged) as UICheckBox; - if (HasUI && Indent) { - Options.Indent(_ui); + + if (Indent) IndentUI(_ui); + + AllowTextWrap(_ui, Indent); + + UpdateTooltip(); + UpdateReadOnly(); + } + + private void PropagateTo(IList targets, bool value) { + foreach (var target in targets) + target.Value = value; + } + + private void UpdateLabel() { + if (!HasUI) return; + + _ui.label.text = T(Label); + } + + private void UpdateTooltip() { + if (!HasUI) return; + + _ui.tooltip = IsInScope + ? string.IsNullOrEmpty(_tooltip) + ? string.Empty // avoid invalidating UI if already no tooltip + : T(_tooltip) + : T(INGAME_ONLY_SETTING); + } + + private void UpdateReadOnly() { + if (!HasUI) return; + + Log.Info($"CheckboxOption.Value: `{FieldName}` is readonly"); + + var readOnly = !IsInScope || _readOnly; + + _ui.readOnly = readOnly; + _ui.opacity = readOnly ? 0.3f : 1f; + } + + /* UI helper methods */ + + internal static void IndentUI(UIComponent component) { + UILabel label = component.Find("Label"); + + if (label != null) { + label.padding = new RectOffset(22, 0, 0, 0); + } + + UISprite check = component.Find("Unchecked"); + + if (check != null) { + check.relativePosition += new Vector3(22.0f, 0); } - Options.AllowTextWrap(_ui, Indent); - Tooltip = _tooltip; - ReadOnlyUI = _readOnlyUI; } + internal static void AllowTextWrap(UICheckBox checkBox, bool indented = false) { + UILabel label = checkBox.label; + bool requireTextWrap; + int maxWidth = indented ? CHECKBOX_LABEL_MAX_WIDTH_INDENTED : CHECKBOX_LABEL_MAX_WIDTH; + using (UIFontRenderer renderer = label.ObtainRenderer()) { + Vector2 size = renderer.MeasureString(label.text); + requireTextWrap = size.x > maxWidth; + } + label.autoSize = false; + label.wordWrap = true; + label.verticalAlignment = UIVerticalAlignment.Middle; + label.textAlignment = UIHorizontalAlignment.Left; + label.size = new Vector2(maxWidth, requireTextWrap ? 40 : 20); + if (requireTextWrap) { + checkBox.height = 42; // set new height + top/bottom 1px padding + } + } } -} +} \ No newline at end of file diff --git a/TLM/TLM/UI/Helpers/SerializableUIOptionBase.cs b/TLM/TLM/UI/Helpers/SerializableUIOptionBase.cs index 6e068ae18..321c6c826 100644 --- a/TLM/TLM/UI/Helpers/SerializableUIOptionBase.cs +++ b/TLM/TLM/UI/Helpers/SerializableUIOptionBase.cs @@ -7,6 +7,7 @@ namespace TrafficManager.UI.Helpers { using System; using TrafficManager.State; using JetBrains.Annotations; + using TrafficManager.Lifecycle; public abstract class SerializableUIOptionBase : ILegacySerializableOption where TUI : UIComponent { @@ -56,12 +57,12 @@ public virtual TVal Value { /// Returns true if setting can persist in current . /// - /// When false, UI component should be + /// When false, UI component should be /// and should be set to . /// protected bool IsInScope => _scope.IsFlagSet(Options.PersistTo.Global) || - (_scope.IsFlagSet(Options.PersistTo.Savegame) && Options.IsGameLoaded(false)) || + (_scope.IsFlagSet(Options.PersistTo.Savegame) && TMPELifecycle.AppMode != null) || _scope == Options.PersistTo.None; public static implicit operator TVal(SerializableUIOptionBase a) => a.Value; @@ -87,7 +88,7 @@ public void DefaultOnValueChanged(TVal newVal) { protected string _label; protected string _tooltip; - protected bool _readOnlyUI; + protected bool _readOnly; private TranslatorDelegate _translator; public delegate string TranslatorDelegate(string key); diff --git a/TLM/TLM/Util/VersionUtil.cs b/TLM/TLM/Util/VersionUtil.cs index 30790efd2..9de0da19e 100644 --- a/TLM/TLM/Util/VersionUtil.cs +++ b/TLM/TLM/Util/VersionUtil.cs @@ -3,22 +3,27 @@ namespace TrafficManager.Util { using System; using System.Reflection; using TrafficManager.Lifecycle; - using System.Diagnostics.CodeAnalysis; /// /// Much of this stuff will be replaced as part of PR #699. /// - [SuppressMessage("Performance", "HAA0101:Array allocation for params parameter", Justification = "Not performance critical")] - [SuppressMessage("Performance", "HAA0601:Value type to reference type conversion causing boxing allocation", Justification = "Not performance critical")] - [SuppressMessage("Performance", "HAA0302:Display class allocation to capture closure", Justification = "Not performance critical")] public static class VersionUtil { - public const string BRANCH = + #if TEST - "TEST"; + public const string BRANCH = "TEST"; + public const bool IS_DEBUG = false; + public const bool IS_TEST = true; + public const bool IS_STABLE = false; #elif DEBUG - "DEBUG"; + public const string BRANCH = "DEBUG"; + public const bool IS_DEBUG = true; + public const bool IS_TEST = false; + public const bool IS_STABLE = false; #else - "STABLE"; + public const string BRANCH = "STABLE"; + public const bool IS_DEBUG = false; + public const bool IS_TEST = false; + public const bool IS_STABLE = true; #endif /// From dc9c3c47cd15b4c1523a4ac15829a68ac1a50c8b Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Fri, 18 Feb 2022 02:25:12 +0000 Subject: [PATCH 2/8] Simplify checkbox validators Ensure mod options will always be set false if not validated. --- TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs | 8 ++------ TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs | 6 +----- TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs | 6 +----- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs b/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs index e484a93e0..87e4c197d 100644 --- a/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs +++ b/TLM/TLM/State/OptionsTabs/MaintenanceTab_FeaturesGroup.cs @@ -88,12 +88,8 @@ private static bool IsInEditor() => // TODO [issue #959] remove when TTL is implemented in asset editor. private static bool NotInEditorValidator(bool desired, out bool result) { - if (!IsInEditor()) { - result = desired; - return true; - } - - return result = false; + result = !IsInEditor() && desired; + return true; } private static void OnFeatureAvailabilityChanged(bool _) diff --git a/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs b/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs index f44bbc9ad..bfc0c495b 100644 --- a/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs +++ b/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs @@ -119,12 +119,8 @@ internal static void AddUI(UIHelperBase tab) { private static string T(string key) => Translation.Options.Get(key); private static bool DebugOnlyValidator(bool desired, out bool result) { -#if DEBUG - result = desired; + result = VersionUtil.IS_DEBUG && desired; return true; -#else - return result = false; -#endif } private static void OnOverlayChanged(bool _) diff --git a/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs b/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs index f16977ec1..e77b654ca 100644 --- a/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs +++ b/TLM/TLM/State/OptionsTabs/PoliciesTab_AtJunctionsGroup.cs @@ -99,12 +99,8 @@ internal static void AddUI(UIHelperBase tab) { private static string T(string key) => Translation.Options.Get(key); private static bool DebugOnlyValidator(bool desired, out bool result) { -#if DEBUG - result = desired; + result = VersionUtil.IS_DEBUG && desired; return true; -#else - return result = false; -#endif } private static void OnJunctionRestrictionPolicyChanged(bool _) { From 7071de34ef6fb221c3722c6f5b972c4f895b90b3 Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Fri, 18 Feb 2022 10:43:40 +0000 Subject: [PATCH 3/8] Add `ActionButton` class Similar approach to CheckboxOption, but just a button. --- TLM/TLM/UI/Helpers/ActionButton.cs | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 TLM/TLM/UI/Helpers/ActionButton.cs diff --git a/TLM/TLM/UI/Helpers/ActionButton.cs b/TLM/TLM/UI/Helpers/ActionButton.cs new file mode 100644 index 000000000..bb0ec470f --- /dev/null +++ b/TLM/TLM/UI/Helpers/ActionButton.cs @@ -0,0 +1,73 @@ +namespace TrafficManager.UI.Helpers { + using ColossalFramework.UI; + using ICities; + + public class ActionButton { + private string _label; + private string _tooltip; + private bool _readOnly; + + private UIButton _ui; + + public event OnButtonClicked OnClicked; + + public OnButtonClicked Handler { + set => OnClicked += value; + } + + public bool HasUI => _ui != null; + + public string Label { + get => _label; + set { + _label = value; + UpdateLabel(); + } + } + + public string Tooltip { + get => _tooltip; + set { + _tooltip = value; + UpdateTooltip(); + } + } + + public bool ReadOnly { + get => _readOnly; + set { + _readOnly = value; + UpdateReadOnly(); + } + } + + public void AddUI(UIHelperBase container) { + _ui = container.AddButton(T(_label), OnClicked) as UIButton; + + UpdateTooltip(); + UpdateReadOnly(); + } + + private void UpdateLabel() { + if (!HasUI) return; + + _ui.text = T(_label); + } + + private void UpdateTooltip() { + if (!HasUI) return; + + _ui.tooltip = T(_tooltip); + } + + private void UpdateReadOnly() { + if (!HasUI) return; + + _ui.isInteractive = !_readOnly; + _ui.opacity = _readOnly ? 0.3f : 1f; + } + + private string T(string key) + => Translation.Options.Get(key); + } +} From 01dffb6c5c707a9816b593054bccdfa48412a1b2 Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Fri, 18 Feb 2022 10:45:04 +0000 Subject: [PATCH 4/8] Refactor remainder of maintenance tab - Move pathfind stats cb to overlays group - Split maint buttons in to two groups... - Tools group - Config group --- TLM/TLM/Manager/Impl/OptionsManager.cs | 2 +- TLM/TLM/State/OptionsTabs/MaintenanceTab.cs | 129 +----------------- .../OptionsTabs/MaintenanceTab_ConfigGroup.cs | 33 +++++ .../OptionsTabs/MaintenanceTab_ToolsGroup.cs | 59 ++++++++ .../OptionsTabs/OverlaysTab_OverlaysGroup.cs | 21 +++ TLM/TLM/TLM.csproj | 3 + 6 files changed, 123 insertions(+), 124 deletions(-) create mode 100644 TLM/TLM/State/OptionsTabs/MaintenanceTab_ConfigGroup.cs create mode 100644 TLM/TLM/State/OptionsTabs/MaintenanceTab_ToolsGroup.cs diff --git a/TLM/TLM/Manager/Impl/OptionsManager.cs b/TLM/TLM/Manager/Impl/OptionsManager.cs index 54f150247..dae4ca5d5 100644 --- a/TLM/TLM/Manager/Impl/OptionsManager.cs +++ b/TLM/TLM/Manager/Impl/OptionsManager.cs @@ -176,7 +176,7 @@ public bool LoadData(byte[] data) { ToCheckbox(data, idx: 30, MaintenanceTab_FeaturesGroup.ParkingRestrictionsEnabled, true); ToCheckbox(data, idx: 31, OverlaysTab_OverlaysGroup.ParkingRestrictionsOverlay, false); PoliciesTab.SetBanRegularTrafficOnBusLanes(LoadBool(data, idx: 32)); - MaintenanceTab.SetShowPathFindStats(LoadBool(data, idx: 33)); + ToCheckbox(data, idx: 33, OverlaysTab_OverlaysGroup.ShowPathFindStats, VersionUtil.IS_DEBUG); GameplayTab.SetDLSPercentage(LoadByte(data, idx: 34)); if (data.Length > 35) { diff --git a/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs b/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs index ebd85c239..751cd2b51 100644 --- a/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs +++ b/TLM/TLM/State/OptionsTabs/MaintenanceTab.cs @@ -1,139 +1,22 @@ namespace TrafficManager.State { - using ColossalFramework.UI; - using CSUtil.Commons; - using ICities; - using JetBrains.Annotations; - using TrafficManager.Manager.Impl; using TrafficManager.UI.Helpers; using TrafficManager.UI; - using TrafficManager.Lifecycle; - using ColossalFramework; - using System.Collections.Generic; public static class MaintenanceTab { - [UsedImplicitly] - private static UIButton _resetStuckEntitiesBtn; - - [UsedImplicitly] - private static UIButton _removeParkedVehiclesBtn; - - [UsedImplicitly] - private static UIButton _removeAllExistingTrafficLightsBtn; -#if DEBUG - [UsedImplicitly] - private static UIButton _resetSpeedLimitsBtn; -#endif - [UsedImplicitly] - private static UIButton _reloadGlobalConfBtn; - - [UsedImplicitly] - private static UIButton _resetGlobalConfBtn; - -#if QUEUEDSTATS - private static UICheckBox _showPathFindStatsToggle; -#endif - - private static string T(string text) { - return Translation.Options.Get(text); - } internal static void MakeSettings_Maintenance(ExtUITabstrip tabStrip) { - UIHelper panelHelper = tabStrip.AddTabPage(Translation.Options.Get("Tab:Maintenance")); - UIHelperBase maintenanceGroup = panelHelper.AddGroup(T("Tab:Maintenance")); - - _resetStuckEntitiesBtn = maintenanceGroup.AddButton( - T("Maintenance.Button:Reset stuck cims and vehicles"), - onClickResetStuckEntities) as UIButton; - - _removeAllExistingTrafficLightsBtn = maintenanceGroup.AddButton( - T("Maintenance.Button:Remove all existing traffic lights"), - OnClickRemoveAllExistingTrafficLights) as UIButton; -#if DEBUG - _resetSpeedLimitsBtn = maintenanceGroup.AddButton( - T("Maintenance.Button:Reset custom speed limits"), - OnClickResetSpeedLimits) as UIButton; -#endif - _reloadGlobalConfBtn = maintenanceGroup.AddButton( - T("Maintenance.Button:Reload global configuration"), - OnClickReloadGlobalConf) as UIButton; - _resetGlobalConfBtn = maintenanceGroup.AddButton( - T("Maintenance.Button:Reset global configuration"), - OnClickResetGlobalConf) as UIButton; - -#if QUEUEDSTATS - _showPathFindStatsToggle = maintenanceGroup.AddCheckbox( - T("Maintenance.Checkbox:Show path-find stats"), - Options.showPathFindStats, - OnShowPathFindStatsChanged) as UICheckBox; -#endif - - MaintenanceTab_FeaturesGroup.AddUI(panelHelper); - - MaintenanceTab_DespawnGroup.AddUI(panelHelper); - } - private static void onClickResetStuckEntities() { - if (!Options.IsGameLoaded()) { - return; - } + var tab = tabStrip.AddTabPage(T("Tab:Maintenance")); - Singleton.instance.AddAction( - () => { UtilityManager.Instance.ResetStuckEntities(); }); - } - - private static void OnClickRemoveAllExistingTrafficLights() { - if (!Options.IsGameLoaded()) { - return; - } - - ConfirmPanel.ShowModal(T("Maintenance.Dialog.Title:Remove all traffic lights"), - T("Maintenance.Dialog.Text:Remove all traffic lights, Confirmation"), - (_, result) => { - if(result != 1) - { - return; - } - - Log._Debug("Removing all existing Traffic Lights"); - Singleton.instance.AddAction(() => - TrafficLightManager.Instance.RemoveAllExistingTrafficLights()); - }); - } - - private static void OnClickResetSpeedLimits() { - if (!Options.IsGameLoaded()) { - return; - } + MaintenanceTab_ToolsGroup.AddUI(tab); - SpeedLimitManager.Instance.ResetSpeedLimits(); - } - - private static void OnClickReloadGlobalConf() { - GlobalConfig.Reload(); - } + MaintenanceTab_FeaturesGroup.AddUI(tab); - private static void OnClickResetGlobalConf() { - GlobalConfig.Reset(oldConfig: null, resetAll: true); - } - -#if QUEUEDSTATS - private static void OnShowPathFindStatsChanged(bool newVal) { - if (!Options.IsGameLoaded()) - return; + MaintenanceTab_DespawnGroup.AddUI(tab); - Log._Debug($"Show path-find stats changed to {newVal}"); - Options.showPathFindStats = newVal; - OptionsManager.RebuildMenu(); + MaintenanceTab_ConfigGroup.AddUI(tab); } -#endif -#if QUEUEDSTATS - public static void SetShowPathFindStats(bool value) { - Options.showPathFindStats = value; - if (_showPathFindStatsToggle != null) { - _showPathFindStatsToggle.isChecked = value; - } - } -#endif + private static string T(string key) => Translation.Options.Get(key); } } diff --git a/TLM/TLM/State/OptionsTabs/MaintenanceTab_ConfigGroup.cs b/TLM/TLM/State/OptionsTabs/MaintenanceTab_ConfigGroup.cs new file mode 100644 index 000000000..18dbf0878 --- /dev/null +++ b/TLM/TLM/State/OptionsTabs/MaintenanceTab_ConfigGroup.cs @@ -0,0 +1,33 @@ +namespace TrafficManager.State { + using ICities; + using TrafficManager.UI; + using TrafficManager.UI.Helpers; + + public static class MaintenanceTab_ConfigGroup { + + public static ActionButton ReloadGlobalConfig = new() { + Label = "Maintenance.Button:Reload global configuration", + Handler = OnReloadGlobalConfigClicked, + }; + public static ActionButton ResetGlobalConfig = new() { + Label = "Maintenance.Button:Reset global configuration", + Handler = OnResetGlobalConfigClicked, + }; + + internal static void AddUI(UIHelperBase tab) { + + var group = tab.AddGroup(T("Group:Configuration")); + + ReloadGlobalConfig.AddUI(group); + ResetGlobalConfig.AddUI(group); + } + + private static string T(string key) => Translation.Options.Get(key); + + private static void OnReloadGlobalConfigClicked() + => GlobalConfig.Reload(); + + private static void OnResetGlobalConfigClicked() + => GlobalConfig.Reset(oldConfig: null, resetAll: true); + } +} \ No newline at end of file diff --git a/TLM/TLM/State/OptionsTabs/MaintenanceTab_ToolsGroup.cs b/TLM/TLM/State/OptionsTabs/MaintenanceTab_ToolsGroup.cs new file mode 100644 index 000000000..986a2be01 --- /dev/null +++ b/TLM/TLM/State/OptionsTabs/MaintenanceTab_ToolsGroup.cs @@ -0,0 +1,59 @@ +namespace TrafficManager.State { + using ColossalFramework; + using ICities; + using TrafficManager.Lifecycle; + using TrafficManager.Manager.Impl; + using TrafficManager.UI; + using TrafficManager.UI.Helpers; + + public static class MaintenanceTab_ToolsGroup { + + public static ActionButton ResetStuckEntities = new() { + Label = "Maintenance.Button:Reset stuck cims and vehicles", + Handler = OnResetStuckEntitiesClicked, + }; + public static ActionButton RemoveTrafficLights = new() { + Label = "Maintenance.Button:Remove all existing traffic lights", + Handler = OnRemoveTrafficLightsClicked, + }; + public static ActionButton ResetSpeedLimits = new() { + Label = "Maintenance.Button:Reset custom speed limits", + Handler = OnResetSpeedLimitsClicked, + }; + + internal static void AddUI(UIHelperBase tab) { + if (!TMPELifecycle.InGameOrEditor()) + return; + + var group = tab.AddGroup(T("Group:Tools")); + + ResetStuckEntities.AddUI(group); + RemoveTrafficLights.AddUI(group); +#if DEBUG + ResetSpeedLimits.AddUI(group); +#endif + } + + private static string T(string key) => Translation.Options.Get(key); + + private static void OnResetStuckEntitiesClicked() + => Singleton.instance.AddAction( + () => { UtilityManager.Instance.ResetStuckEntities(); }); + + private static void OnRemoveTrafficLightsClicked() { + ConfirmPanel.ShowModal( + T("Maintenance.Dialog.Title:Remove all traffic lights"), + T("Maintenance.Dialog.Text:Remove all traffic lights, Confirmation"), + (_, result) => { + if (result == 1) DoRemoveTrafficLights(); + }); + } + + private static void DoRemoveTrafficLights() + => Singleton.instance.AddAction( + () => TrafficLightManager.Instance.RemoveAllExistingTrafficLights()); + + private static void OnResetSpeedLimitsClicked() + => SpeedLimitManager.Instance.ResetSpeedLimits(); + } +} \ No newline at end of file diff --git a/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs b/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs index bfc0c495b..ffb652eea 100644 --- a/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs +++ b/TLM/TLM/State/OptionsTabs/OverlaysTab_OverlaysGroup.cs @@ -71,6 +71,12 @@ public static class OverlaysTab_OverlaysGroup { Label = "Overlay.Checkbox:Buildings", Validator = DebugOnlyValidator, }; + public static CheckboxOption ShowPathFindStats = + new(nameof(Options.showPathFindStats), Options.PersistTo.Savegame) { + Label = "Maintenance.Checkbox:Show path - find stats", + Validator = QueuedStatsOnlyValidator, + Handler = OnShowPathFindStatsChanged, + }; static OverlaysTab_OverlaysGroup() { try { @@ -113,6 +119,9 @@ internal static void AddUI(UIHelperBase tab) { VehicleOverlay.AddUI(group); CitizenOverlay.AddUI(group); BuildingOverlay.AddUI(group); +#endif +#if QUEUEDSTATS + ShowPathFindStats.AddUI(group); #endif } @@ -123,7 +132,19 @@ private static bool DebugOnlyValidator(bool desired, out bool result) { return true; } + private static bool QueuedStatsOnlyValidator(bool desired, out bool result) { +#if QUEUEDSTATS + result = desired; +#else + result = false; +#endif + return true; + } + private static void OnOverlayChanged(bool _) => OptionsManager.ReinitialiseSubTools(); + + private static void OnShowPathFindStatsChanged(bool _) + => OptionsManager.RebuildMenu(); } } \ No newline at end of file diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index bff206d73..a09d19394 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -148,12 +148,15 @@ + + + From 11a14ca9495fc9a1498a5ecb0f9bfae0e3ba0853 Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Sat, 19 Feb 2022 02:48:27 +0000 Subject: [PATCH 5/8] Add button stuff from #1424 --- TLM/TLM/State/ConfigData/Main.cs | 6 +++ TLM/TLM/State/GlobalConfig.cs | 2 +- TLM/TLM/TLM.csproj | 2 + TLM/TLM/UI/Helpers/ActionButton.cs | 65 +----------------------- TLM/TLM/UI/Helpers/OptionButtonBase.cs | 70 ++++++++++++++++++++++++++ TLM/TLM/UI/Helpers/UrlButton.cs | 52 +++++++++++++++++++ 6 files changed, 132 insertions(+), 65 deletions(-) create mode 100644 TLM/TLM/UI/Helpers/OptionButtonBase.cs create mode 100644 TLM/TLM/UI/Helpers/UrlButton.cs diff --git a/TLM/TLM/State/ConfigData/Main.cs b/TLM/TLM/State/ConfigData/Main.cs index 894c9e44f..682589f61 100644 --- a/TLM/TLM/State/ConfigData/Main.cs +++ b/TLM/TLM/State/ConfigData/Main.cs @@ -105,6 +105,12 @@ public SpeedUnit GetDisplaySpeedUnit() => DisplaySpeedLimitsMph /// public string RoadSignTheme = string.Empty; + /// + /// If true, links will open in + /// Steam Overlay if it is available. + /// + public bool OpenUrlsInSteamOverlay = false; + /// /// Storing version of What's New panel opened last time /// diff --git a/TLM/TLM/State/GlobalConfig.cs b/TLM/TLM/State/GlobalConfig.cs index 36526ac94..5d7f6f948 100644 --- a/TLM/TLM/State/GlobalConfig.cs +++ b/TLM/TLM/State/GlobalConfig.cs @@ -15,7 +15,7 @@ namespace TrafficManager.State { public class GlobalConfig : GenericObservable { public const string FILENAME = "TMPE_GlobalConfig.xml"; public const string BACKUP_FILENAME = FILENAME + ".bak"; - private static int LATEST_VERSION = 18; + private static int LATEST_VERSION = 19; public static GlobalConfig Instance { get => instance; diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index a09d19394..af55361ab 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -157,6 +157,8 @@ + + diff --git a/TLM/TLM/UI/Helpers/ActionButton.cs b/TLM/TLM/UI/Helpers/ActionButton.cs index bb0ec470f..f6750bdb4 100644 --- a/TLM/TLM/UI/Helpers/ActionButton.cs +++ b/TLM/TLM/UI/Helpers/ActionButton.cs @@ -1,73 +1,10 @@ namespace TrafficManager.UI.Helpers { - using ColossalFramework.UI; using ICities; - public class ActionButton { - private string _label; - private string _tooltip; - private bool _readOnly; - - private UIButton _ui; - - public event OnButtonClicked OnClicked; + public class ActionButton : OptionButtonBase { public OnButtonClicked Handler { set => OnClicked += value; } - - public bool HasUI => _ui != null; - - public string Label { - get => _label; - set { - _label = value; - UpdateLabel(); - } - } - - public string Tooltip { - get => _tooltip; - set { - _tooltip = value; - UpdateTooltip(); - } - } - - public bool ReadOnly { - get => _readOnly; - set { - _readOnly = value; - UpdateReadOnly(); - } - } - - public void AddUI(UIHelperBase container) { - _ui = container.AddButton(T(_label), OnClicked) as UIButton; - - UpdateTooltip(); - UpdateReadOnly(); - } - - private void UpdateLabel() { - if (!HasUI) return; - - _ui.text = T(_label); - } - - private void UpdateTooltip() { - if (!HasUI) return; - - _ui.tooltip = T(_tooltip); - } - - private void UpdateReadOnly() { - if (!HasUI) return; - - _ui.isInteractive = !_readOnly; - _ui.opacity = _readOnly ? 0.3f : 1f; - } - - private string T(string key) - => Translation.Options.Get(key); } } diff --git a/TLM/TLM/UI/Helpers/OptionButtonBase.cs b/TLM/TLM/UI/Helpers/OptionButtonBase.cs new file mode 100644 index 000000000..1b3c857d2 --- /dev/null +++ b/TLM/TLM/UI/Helpers/OptionButtonBase.cs @@ -0,0 +1,70 @@ +namespace TrafficManager.UI.Helpers { + using ColossalFramework.UI; + using ICities; + + public abstract class OptionButtonBase { + protected string _label; + protected string _tooltip; + protected bool _readOnly; + + protected UIButton _ui; + + protected event OnButtonClicked OnClicked; + + public bool HasUI => _ui != null; + + public string Label { + get => _label; + set { + _label = value; + UpdateLabel(); + } + } + + public string Tooltip { + get => _tooltip; + set { + _tooltip = value; + UpdateTooltip(); + } + } + + public bool ReadOnly { + get => _readOnly; + set { + _readOnly = value; + UpdateReadOnly(); + } + } + + public void AddUI(UIHelperBase container) { + _ui = container.AddButton(T(_label), OnClicked) as UIButton; + + UpdateTooltip(); + UpdateReadOnly(); + } + + protected virtual void UpdateLabel() { + if (!HasUI) return; + + _ui.text = T(_label); + } + + protected virtual void UpdateTooltip() { + if (!HasUI) return; + + _ui.tooltip = T(_tooltip); + } + + protected virtual void UpdateReadOnly() { + if (!HasUI) return; + + _ui.isInteractive = !_readOnly; + _ui.opacity = _readOnly ? 0.3f : 1f; + } + + protected virtual string T(string key) + => Translation.Options.Get(key); + + } +} diff --git a/TLM/TLM/UI/Helpers/UrlButton.cs b/TLM/TLM/UI/Helpers/UrlButton.cs new file mode 100644 index 000000000..c0b835d3f --- /dev/null +++ b/TLM/TLM/UI/Helpers/UrlButton.cs @@ -0,0 +1,52 @@ +namespace TrafficManager.UI.Helpers { + using ColossalFramework.PlatformServices; + using System.Diagnostics; + using TrafficManager.Lifecycle; + using TrafficManager.State; + + public class UrlButton : OptionButtonBase { + private string _url; + + public UrlButton() { + OnClicked += OpenURL; + } + + public static bool SteamOverlayAvailable + => PlatformService.platformType == PlatformType.Steam && + PlatformService.IsOverlayEnabled(); + + public string URL { + get => _url; + set { + _url = value; + UpdateTooltip(); + } + } + + protected override void UpdateTooltip() { + if (!HasUI) return; + + _ui.tooltip = string.IsNullOrEmpty(_tooltip) + ? _url + : $"{T(_tooltip)}:\n{_url}"; + } + + private void OpenURL() { + if (string.IsNullOrEmpty(_url)) return; + + if (TMPELifecycle.InGameOrEditor()) + SimulationManager.instance.SimulationPaused = true; + + bool useSteamOverlay = + SteamOverlayAvailable && + GlobalConfig.Instance.Main.OpenUrlsInSteamOverlay; + + if (useSteamOverlay) { + PlatformService.ActivateGameOverlayToWebPage(_url); + } else { + //Application.OpenURL(_url); + Process.Start(_url); + } + } + } +} From fd6b5480b43bd913d207890fd810f3646540f188 Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Sat, 19 Feb 2022 03:09:19 +0000 Subject: [PATCH 6/8] Update OptionButtonBase.cs --- TLM/TLM/UI/Helpers/OptionButtonBase.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TLM/TLM/UI/Helpers/OptionButtonBase.cs b/TLM/TLM/UI/Helpers/OptionButtonBase.cs index 1b3c857d2..7d5f407fe 100644 --- a/TLM/TLM/UI/Helpers/OptionButtonBase.cs +++ b/TLM/TLM/UI/Helpers/OptionButtonBase.cs @@ -53,7 +53,9 @@ protected virtual void UpdateLabel() { protected virtual void UpdateTooltip() { if (!HasUI) return; - _ui.tooltip = T(_tooltip); + _ui.tooltip = string.IsNullOrEmpty(_tooltip) + ? string.Empty + : T(_tooltip); } protected virtual void UpdateReadOnly() { From 1feedbfc291fc6c337189c743c2f0166792acd6b Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Mon, 28 Feb 2022 14:29:16 +0000 Subject: [PATCH 7/8] Fix broken reference --- TLM/TLM/Manager/Impl/OptionsManager.cs | 2 +- TLM/TLM/State/OptionsTabs/GeneralTab_LocalisationGroup.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/TLM/TLM/Manager/Impl/OptionsManager.cs b/TLM/TLM/Manager/Impl/OptionsManager.cs index 55257f431..91f37e41c 100644 --- a/TLM/TLM/Manager/Impl/OptionsManager.cs +++ b/TLM/TLM/Manager/Impl/OptionsManager.cs @@ -323,7 +323,7 @@ public byte[] SaveData(ref bool success) { /// internal static void RebuildMenu() { if (TMPELifecycle.Instance.Deserializing || ModUI.Instance == null) { - Log._Debug("OptionsManager.RebuildMenu() - Ignoring; Deserialising or ModUI is null"); + Log._Debug("OptionsManager.RebuildMenu() - Ignoring; Deserialising or ModUI.Instance is null"); return; } diff --git a/TLM/TLM/State/OptionsTabs/GeneralTab_LocalisationGroup.cs b/TLM/TLM/State/OptionsTabs/GeneralTab_LocalisationGroup.cs index bf33cd581..53b696f44 100644 --- a/TLM/TLM/State/OptionsTabs/GeneralTab_LocalisationGroup.cs +++ b/TLM/TLM/State/OptionsTabs/GeneralTab_LocalisationGroup.cs @@ -5,6 +5,7 @@ namespace TrafficManager.State { using System.Collections.Generic; using System.Linq; using TrafficManager.Lifecycle; + using TrafficManager.Manager.Impl; using TrafficManager.State.ConfigData; using TrafficManager.UI; using TrafficManager.UI.Helpers; @@ -100,7 +101,7 @@ private static void OnLanguageChanged(int newLanguageIndex) { // TODO: Move this to the owner class and implement IObserver Translation.SetCurrentLanguageToGameLanguage(); - Options.RebuildMenu(); + OptionsManager.RebuildMenu(); } else if (newLanguageIndex - 1 < Translation.AvailableLanguageCodes.Count) { // use tmpe language string newLang = Translation.AvailableLanguageCodes[newLanguageIndex - 1]; @@ -109,7 +110,7 @@ private static void OnLanguageChanged(int newLanguageIndex) { // TODO: Move this to the owner class and implement IObserver Translation.SetCurrentLanguageToTMPELanguage(); - Options.RebuildMenu(); + OptionsManager.RebuildMenu(); } else { Log.Warning($"GeneralTab.LocalisationGroup.onLanguageChanged({newLanguageIndex}): Invalid language index"); return; From 8c47ed335faabff5f831010f82511341d1b43bc7 Mon Sep 17 00:00:00 2001 From: aubergine10 Date: Mon, 28 Feb 2022 14:43:45 +0000 Subject: [PATCH 8/8] Remove unnecessary routing manager update The routing manager already does full recalc after deserialization so there's no need for options manager to queue that action --- TLM/TLM/Manager/Impl/OptionsManager.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/TLM/TLM/Manager/Impl/OptionsManager.cs b/TLM/TLM/Manager/Impl/OptionsManager.cs index 91f37e41c..5da1bafca 100644 --- a/TLM/TLM/Manager/Impl/OptionsManager.cs +++ b/TLM/TLM/Manager/Impl/OptionsManager.cs @@ -20,7 +20,6 @@ public class OptionsManager public static OptionsManager Instance = new OptionsManager(); // See: OnAfterLoadData() and related methods - private static bool _needUpdateRoutingManager = false; private static bool _needUpdateDedicatedTurningLanes = false; private static bool _needUpdateJunctionRestrictionsManager = false; @@ -58,11 +57,6 @@ public override void OnAfterLoadData() { base.OnAfterLoadData(); Log.Info("OptionsManger.OnAfterLoadData() checking for queued method calls"); - if (_needUpdateRoutingManager) { - _needUpdateRoutingManager = false; - UpdateRoutingManager(); - } - if (_needUpdateDedicatedTurningLanes) { _needUpdateDedicatedTurningLanes = false; UpdateDedicatedTurningLanes(); @@ -395,8 +389,7 @@ internal static void UpdateDedicatedTurningLanes() { /// internal static void UpdateRoutingManager() { if (TMPELifecycle.Instance.Deserializing) { - Log._Debug("OptionsManager.UpdateRoutingManager() - Waiting for deserialisation"); - _needUpdateRoutingManager = true; + Log._Debug("OptionsManager.UpdateRoutingManager() - Ignoring; Deserialising"); return; }