Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor features, overlays, and junction option groups #1422

Merged
merged 15 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TLM/TLM/Lifecycle/TMPELifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ public bool MayPublishSegmentChanges()

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;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Manager/Impl/LaneArrowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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);
}
Expand Down
213 changes: 168 additions & 45 deletions TLM/TLM/Manager/Impl/OptionsManager.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion TLM/TLM/Patch/_RoadBaseAI/UpdateLanesPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UpdateLanesPatch {
/// </summary>
[UsedImplicitly]
static void Postfix(ushort segmentID) {
if (PoliciesTab.DedicatedTurningLanes) {
if (Options.DedicatedTurningLanes) {
BuiltIn(segmentID);
}

Expand Down
71 changes: 18 additions & 53 deletions TLM/TLM/State/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UICheckBox> debugSwitchFields = new List<UICheckBox>();
private static List<UITextField> debugValueFields = new List<UITextField>();
Expand All @@ -39,7 +38,7 @@ public enum PersistTo {
/// </summary>
/// <remarks>
/// Is set <c>true</c> after options are loaded via <see cref="Manager.Impl.OptionsManager"/>.
/// Is set <c>false</c> while options are being saved, and also when level unloads.
/// Is set <c>false</c> while options are being loaded, and also when level unloads.
/// </remarks>
public static bool Available = false;

Expand All @@ -60,24 +59,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;
Expand All @@ -90,28 +79,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;

public static VehicleRestrictionsAggression vehicleRestrictionsAggression =
VehicleRestrictionsAggression.Medium;
Expand All @@ -136,31 +123,9 @@ public enum PersistTo {

public static bool showDefaultSpeedSubIcon;

/// <summary>
/// Invoked on options change to refresh the main menu and possibly update the labels for
/// a new language. Takes a second, very slow.
/// </summary>
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);
Expand Down
5 changes: 5 additions & 0 deletions TLM/TLM/State/OptionsTabs/GeneralTab.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace TrafficManager.State {
using UnityEngine;
using TrafficManager.Lifecycle;
using TrafficManager.Manager.Impl;
using TrafficManager.State.ConfigData;
using TrafficManager.UI;
using TrafficManager.UI.Textures;
using TrafficManager.UI.Helpers;
using TrafficManager.UI.WhatsNew;

Expand Down
5 changes: 3 additions & 2 deletions TLM/TLM/State/OptionsTabs/GeneralTab_LocalisationGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +101,7 @@ private static void OnLanguageChanged(int newLanguageIndex) {

// TODO: Move this to the owner class and implement IObserver<ModUI.EventPublishers.LanguageChangeNotification>
Translation.SetCurrentLanguageToGameLanguage();
Options.RebuildMenu();
OptionsManager.RebuildMenu();
} else if (newLanguageIndex - 1 < Translation.AvailableLanguageCodes.Count) {
// use tmpe language
string newLang = Translation.AvailableLanguageCodes[newLanguageIndex - 1];
Expand All @@ -109,7 +110,7 @@ private static void OnLanguageChanged(int newLanguageIndex) {

// TODO: Move this to the owner class and implement IObserver<ModUI.EventPublishers.LanguageChangeNotification>
Translation.SetCurrentLanguageToTMPELanguage();
Options.RebuildMenu();
OptionsManager.RebuildMenu();
} else {
Log.Warning($"GeneralTab.LocalisationGroup.onLanguageChanged({newLanguageIndex}): Invalid language index");
return;
Expand Down
Loading