-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01dffb6
commit 11a14ca
Showing
6 changed files
with
132 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |