Skip to content

Commit

Permalink
Merge pull request #1432 from CitiesSkylinesMods/refactor-remainder-g…
Browse files Browse the repository at this point in the history
…eneral-tab

Refactor remainder of  `General` tab
  • Loading branch information
originalfoo authored Feb 28, 2022
2 parents e647943 + 3a5f455 commit e00e9c8
Show file tree
Hide file tree
Showing 20 changed files with 416 additions and 464 deletions.
9 changes: 8 additions & 1 deletion TLM/TLM/Lifecycle/TMPELifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace TrafficManager.Lifecycle {
using UnityEngine.SceneManagement;
using UnityEngine;
using JetBrains.Annotations;
using UI.WhatsNew;
using TrafficManager.UI.WhatsNew;
using System.Diagnostics.CodeAnalysis;
using TrafficManager.UI.Helpers;
using TrafficManager.API.Traffic.Enums;
Expand Down Expand Up @@ -62,6 +62,13 @@ public static bool InGameOrEditor() =>
SceneManager.GetActiveScene().name != "MainMenu" &&
SceneManager.GetActiveScene().name != "Startup";

/// <summary>
/// Determines if modifications to segments may be published in the current state.
/// </summary>
/// <returns>Returns <c>true</c> if changes may be published, otherwise <c>false</c>.</returns>
public bool MayPublishSegmentChanges()
=> InGameOrEditor() && !Instance.Deserializing;

public static AppMode? AppMode => SimulationManager.instance.m_ManagersWrapper.loading?.currentMode;

public static SimulationManager.UpdateMode UpdateMode => SimulationManager.instance.m_metaData.m_updateMode;
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace TrafficManager.Manager.Impl {
using static CSUtil.Commons.TernaryBoolUtil;
using TrafficManager.Util;
using TrafficManager.Util.Extensions;
using TrafficManager.Lifecycle;

public class JunctionRestrictionsManager
: AbstractGeometryObservingManager,
Expand Down Expand Up @@ -1018,7 +1019,7 @@ private void OnSegmentChange(ushort segmentId,

if (requireRecalc) {
RoutingManager.Instance.RequestRecalculation(segmentId);
if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segmentId);
}
}
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Manager/Impl/LaneArrowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TrafficManager.Manager.Impl {
using UnityEngine;
using static TrafficManager.Util.Shortcuts;
using TrafficManager.Util.Extensions;
using TrafficManager.Lifecycle;

public class LaneArrowManager
: AbstractGeometryObservingManager,
Expand Down Expand Up @@ -200,7 +201,7 @@ private static void RecalculateFlags(uint laneId) {
private void OnLaneChange(uint laneId) {
ushort segment = laneId.ToLane().m_segment;
RoutingManager.Instance.RequestRecalculation(segment);
if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segment);
}
}
Expand Down
9 changes: 5 additions & 4 deletions TLM/TLM/Manager/Impl/LaneConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace TrafficManager.Manager.Impl {
using static TrafficManager.Util.Shortcuts;
using TrafficManager.Util;
using TrafficManager.Util.Extensions;
using TrafficManager.Lifecycle;

public class LaneConnectionManager
: AbstractGeometryObservingManager,
Expand Down Expand Up @@ -247,7 +248,7 @@ internal bool RemoveLaneConnection(uint laneId1, uint laneId2, bool startNode1)
ref NetNode commonNode = ref commonNodeId.ToNode();
RoutingManager.Instance.RequestNodeRecalculation(ref commonNode);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance;
extSegmentManager.PublishSegmentChanges(segmentId1);
extSegmentManager.PublishSegmentChanges(segmentId2);
Expand Down Expand Up @@ -310,7 +311,7 @@ internal void RemoveLaneConnectionsFromSegment(ushort segmentId,
if (recalcAndPublish) {
RoutingManager.Instance.RequestRecalculation(segmentId);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segmentId);
}
}
Expand Down Expand Up @@ -364,7 +365,7 @@ internal void RemoveLaneConnections(uint laneId,
ushort segment = laneId.ToLane().m_segment;
RoutingManager.Instance.RequestRecalculation(segment);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segment);
}
}
Expand Down Expand Up @@ -426,7 +427,7 @@ internal bool AddLaneConnection(uint sourceLaneId,
RoutingManager.Instance.RequestRecalculation(sourceSegmentId, false);
RoutingManager.Instance.RequestRecalculation(targetSegmentId, false);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance;
extSegmentManager.PublishSegmentChanges(sourceSegmentId);
extSegmentManager.PublishSegmentChanges(targetSegmentId);
Expand Down
15 changes: 7 additions & 8 deletions TLM/TLM/Manager/Impl/OptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public bool TryGetOptionByName<TVal>(string optionName, out TVal value) {
return true;
}

[Obsolete("Use TMPELifecycle method of same name instead")]
public bool MayPublishSegmentChanges()
=> TMPELifecycle.Instance.MayPublishSegmentChanges();

/// <summary>
/// Converts SimulationAccuracy to SimulationAccuracy
/// </summary>
Expand All @@ -64,11 +68,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) {
Expand Down Expand Up @@ -104,7 +103,7 @@ public bool LoadData(byte[] data) {

Log.Info($"OptionsManager.LoadData: {data.Length} bytes");

GeneralTab.SetSimulationAccuracy(ConvertToSimulationAccuracy(LoadByte(data, idx: 0)));
GeneralTab_SimulationGroup.SetSimulationAccuracy(ConvertToSimulationAccuracy(LoadByte(data, idx: 0)));
// skip Options.setLaneChangingRandomization(options[1]);
GameplayTab_VehicleBehaviourGroup.SetRecklessDrivers(LoadByte(data, idx: 2));
PoliciesTab.SetRelaxedBusses(LoadBool(data, idx: 3));
Expand Down Expand Up @@ -133,7 +132,7 @@ public bool LoadData(byte[] data) {
PoliciesTab.SetPreferOuterLane(LoadBool(data, idx: 26));
ToCheckbox(data, idx: 27, GameplayTab_VehicleBehaviourGroup.IndividualDrivingStyle, false);
PoliciesTab.SetEvacBussesMayIgnoreRules(LoadBool(data, idx: 28));
GeneralTab.SetInstantEffects(LoadBool(data, idx: 29));
// skip ToCheckbox(data, idx: 29, GeneralTab_SimulationGroup.InstantEffects, true);
MaintenanceTab.SetParkingRestrictionsEnabled(LoadBool(data, idx: 30));
OverlaysTab.SetParkingRestrictionsOverlay(LoadBool(data, idx: 31));
PoliciesTab.SetBanRegularTrafficOnBusLanes(LoadBool(data, idx: 32));
Expand Down Expand Up @@ -231,7 +230,7 @@ public byte[] SaveData(ref bool success) {
save[26] = (byte)(Options.preferOuterLane ? 1 : 0);
save[27] = GameplayTab_VehicleBehaviourGroup.IndividualDrivingStyle.Save();
save[28] = (byte)(Options.evacBussesMayIgnoreRules ? 1 : 0);
save[29] = (byte)(Options.instantEffects ? 1 : 0);
save[29] = 0; // (byte)(Options.instantEffects ? 1 : 0);
save[30] = (byte)(Options.parkingRestrictionsEnabled ? 1 : 0);
save[31] = (byte)(Options.parkingRestrictionsOverlay ? 1 : 0);
save[32] = (byte)(Options.banRegularTrafficOnBusLanes ? 1 : 0);
Expand Down
7 changes: 4 additions & 3 deletions TLM/TLM/Manager/Impl/VehicleRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TrafficManager.Manager.Impl {
using TrafficManager.Traffic;
using TrafficManager.Util;
using TrafficManager.Util.Extensions;
using TrafficManager.Lifecycle;

public class VehicleRestrictionsManager
: AbstractGeometryObservingManager,
Expand Down Expand Up @@ -447,7 +448,7 @@ internal bool SetAllowedVehicleTypes(ushort segmentId,

NotifyStartEndNode(segmentId);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segmentId);
}

Expand Down Expand Up @@ -494,7 +495,7 @@ public void AddAllowedType(ushort segmentId,
Flags.SetLaneAllowedVehicleTypes(segmentId, laneIndex, laneId, allowedTypes);
NotifyStartEndNode(segmentId);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segmentId);
}
}
Expand Down Expand Up @@ -539,7 +540,7 @@ public void RemoveAllowedType(ushort segmentId,
Flags.SetLaneAllowedVehicleTypes(segmentId, laneIndex, laneId, allowedTypes);
NotifyStartEndNode(segmentId);

if (OptionsManager.Instance.MayPublishSegmentChanges()) {
if (TMPELifecycle.Instance.MayPublishSegmentChanges()) {
ExtSegmentManager.Instance.PublishSegmentChanges(segmentId);
}
}
Expand Down
20 changes: 12 additions & 8 deletions TLM/TLM/State/ConfigData/Main.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace TrafficManager.State.ConfigData {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Xml.Serialization;
using JetBrains.Annotations;
using TrafficManager.UI.MainMenu;
using TrafficManager.UI.SubTools.SpeedLimits;

[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Reviewed.")]
public class Main {
/// <summary>Whether floating keybinds panel is visible.</summary>
public bool KeybindsPanelVisible = true;
Expand Down Expand Up @@ -45,30 +47,32 @@ public class Main {
public bool EnableTutorial = true;

/// <summary>Determines if the main menu shall be displayed in a tiny format.</summary>
[Obsolete("Do not use. TM:PE now has UI scale slider")]
[Obsolete("Use GuiScale instead")]
public bool TinyMainMenu = true;

/// <summary>User interface transparency, unit: percents, range: 0..100.</summary>
[Obsolete("Value is not used anymore, use GuiOpacity instead")]
/// <summary>User interface transparency, unit: percents, range: 0..90.</summary>
[Obsolete("Use GuiOpacity instead")]
public byte GuiTransparency = 75;

/// <summary>User interface opacity, unit: percents, range: 0..100.</summary>
/// <summary>User interface opacity, unit: percents, range: 10..100.</summary>
public byte GuiOpacity = 75;

/// <summary>User interface scale for TM:PE. Unit: percents, range: 30..200f.</summary>
public float GuiScale = 100f;

/// <summary>
/// if checked, size remains constant but pixel count changes when resolution changes. Quality drops with lower resolutions.
/// if unchecked checked, size changes constant but pixel count remains the same. Maintains same image quality for all resolution.
/// if unchecked, size changes constant but pixel count remains the same. Maintains same image quality for all resolution.
/// </summary>
public bool GuiScaleToResolution = true;

/// <summary>
/// Overlay transparency
/// </summary>
/// <summary>Overlay transparency, unit: percents, range: 0..90</summary>
[Obsolete("Use OverlayOpacity instead")]
public byte OverlayTransparency = 40;

/// <summary>Overlay icons opacity, unit: percent, range: 10..100.</summary>
public byte OverlayOpacity = 60;

/// <summary>
/// Extended mod compatibility check
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions TLM/TLM/State/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace TrafficManager.State {
public class GlobalConfig : GenericObservable<GlobalConfig> {
public const string FILENAME = "TMPE_GlobalConfig.xml";
public const string BACKUP_FILENAME = FILENAME + ".bak";
private static int LATEST_VERSION = 19;
private static int LATEST_VERSION = 20;

public static GlobalConfig Instance {
get => instance;
Expand Down Expand Up @@ -101,10 +101,12 @@ private static GlobalConfig WriteDefaultConfig(GlobalConfig oldConfig,
conf.Main.MainMenuPosLocked = oldConfig.Main.MainMenuPosLocked;

conf.Main.GuiOpacity = oldConfig.Main.GuiOpacity;
conf.Main.OverlayTransparency = oldConfig.Main.OverlayTransparency;
conf.Main.OverlayOpacity = oldConfig.Main.OverlayOpacity;

conf.Main.EnableTutorial = oldConfig.Main.EnableTutorial;
conf.Main.DisplayedTutorialMessages = oldConfig.Main.DisplayedTutorialMessages;

conf.Main.OpenUrlsInSteamOverlay = oldConfig.Main.OpenUrlsInSteamOverlay;
}

modifiedTime = WriteConfig(conf);
Expand Down
7 changes: 0 additions & 7 deletions TLM/TLM/State/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public enum PersistTo {
/// </remarks>
public static bool Available = false;

public static bool instantEffects = true;
public static bool individualDrivingStyle = true;
public static int recklessDrivers = 3;

Expand Down Expand Up @@ -114,12 +113,6 @@ public enum PersistTo {
public static bool turnOnRedEnabled = true;
public static bool laneConnectorEnabled = true;

[UsedImplicitly]
public static bool scanForKnownIncompatibleModsEnabled = true;

[UsedImplicitly]
public static bool ignoreDisabledModsEnabled;

public static VehicleRestrictionsAggression vehicleRestrictionsAggression =
VehicleRestrictionsAggression.Medium;

Expand Down
Loading

0 comments on commit e00e9c8

Please sign in to comment.