diff --git a/TLM/TLM/State/ConfigData/Main.cs b/TLM/TLM/State/ConfigData/Main.cs
index 894c9e44f..7339f024d 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 = true;
+
///
/// 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/State/OptionsTabs/GeneralTab.cs b/TLM/TLM/State/OptionsTabs/GeneralTab.cs
index 82940895c..d0043923e 100644
--- a/TLM/TLM/State/OptionsTabs/GeneralTab.cs
+++ b/TLM/TLM/State/OptionsTabs/GeneralTab.cs
@@ -1,5 +1,4 @@
namespace TrafficManager.State {
- using System;
using System.Collections.Generic;
using System.Linq;
using TrafficManager.API.Traffic.Enums;
@@ -9,7 +8,6 @@ namespace TrafficManager.State {
using JetBrains.Annotations;
using TrafficManager.U;
using TrafficManager.UI.Helpers;
- using TrafficManager.UI.SubTools.SpeedLimits;
using TrafficManager.UI;
using UnityEngine;
using TrafficManager.Lifecycle;
@@ -18,6 +16,19 @@ namespace TrafficManager.State {
using UI.WhatsNew;
public static class GeneralTab {
+ public static ActionButton WhatsNewButton = new() {
+ Label = "What's New?",
+ Handler = WhatsNew.OpenModal,
+ };
+
+ public static CheckboxOption OpenUrlsInSteamOverlay =
+ new (nameof(GlobalConfig.Instance.Main.OpenUrlsInSteamOverlay), Options.PersistTo.Global) {
+ Label = "Checkbox:Use Steam Overlay to show TM:PE website links",
+ Tooltip = "Checkbox.Tooltip:When disabled, website links will open in your default web browser",
+ Handler = OnOpenUrlsInSteamOverlayChanged,
+ Value = GlobalConfig.Instance.Main.OpenUrlsInSteamOverlay,
+ };
+
private static UICheckBox _instantEffectsToggle;
[UsedImplicitly]
@@ -60,7 +71,7 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
#endif
tab.AddSpace(5);
- tab.AddButton("What's New?", WhatsNew.OpenModal);
+ WhatsNewButton.AddUI(tab);
tab.AddSpace(5);
group = tab.AddGroup(T("General.Group:Localisation"));
@@ -141,6 +152,8 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
GlobalConfig.Instance.Main.EnableTutorial,
OnEnableTutorialsChanged) as UICheckBox;
+ OpenUrlsInSteamOverlay.AddUI(group);
+
group = tab.AddGroup(T("General.Group:Simulation"));
string[] simPrecisionOptions = new[] {
@@ -428,6 +441,14 @@ private static void OnRoadSignsThemeChanged(int newThemeIndex) {
GlobalConfig.WriteConfig();
}
+ private static void OnOpenUrlsInSteamOverlayChanged(bool val) {
+ var current = GlobalConfig.Instance.Main.OpenUrlsInSteamOverlay;
+ if (current == val) return;
+
+ GlobalConfig.Instance.Main.OpenUrlsInSteamOverlay = val;
+ GlobalConfig.WriteConfig();
+ }
+
private static void OnSimulationAccuracyChanged(int newAccuracy) {
if (!Options.IsGameLoaded()) {
return;
diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj
index f413e0cab..06edb7de3 100644
--- a/TLM/TLM/TLM.csproj
+++ b/TLM/TLM/TLM.csproj
@@ -151,6 +151,9 @@
+
+
+
diff --git a/TLM/TLM/UI/Helpers/ActionButton.cs b/TLM/TLM/UI/Helpers/ActionButton.cs
new file mode 100644
index 000000000..40ada4ba6
--- /dev/null
+++ b/TLM/TLM/UI/Helpers/ActionButton.cs
@@ -0,0 +1,13 @@
+namespace TrafficManager.UI.Helpers {
+ using ICities;
+
+ public class ActionButton : OptionButtonBase {
+
+ public OnButtonClicked Handler {
+ set {
+ OnClicked -= value;
+ OnClicked += value;
+ }
+ }
+ }
+}
diff --git a/TLM/TLM/UI/Helpers/OptionButtonBase.cs b/TLM/TLM/UI/Helpers/OptionButtonBase.cs
new file mode 100644
index 000000000..4c90e22e4
--- /dev/null
+++ b/TLM/TLM/UI/Helpers/OptionButtonBase.cs
@@ -0,0 +1,72 @@
+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;
+
+ public event OnButtonClicked OnClicked;
+
+ public bool HasUI => _ui != null;
+
+ public string Label {
+ get => _label ?? string.Empty;
+ 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 = string.IsNullOrEmpty(_tooltip)
+ ? string.Empty
+ : 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..b253d92dc
--- /dev/null
+++ b/TLM/TLM/UI/Helpers/UrlButton.cs
@@ -0,0 +1,53 @@
+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;
+ 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);
+ }
+ }
+ }
+}