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

Main menu and tool code refactoring #656

Merged
merged 23 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a102f82
WIP: Refactoring LinearToolButton into a more generic skinnable button
kvakvs Feb 4, 2020
615bf7b
Renamed BaseUI and menu button classes and moved some generic files i…
kvakvs Feb 6, 2020
da42d76
Get properties in UButton are now abstract functions
kvakvs Feb 9, 2020
2c18c05
Replaced graphics loading for UIMainButton with new Atlas code
kvakvs Feb 17, 2020
8232b00
Skinnable BaseUButton and generalized with MainMenuButton
kvakvs Feb 17, 2020
6a0424c
ButtonSkin allows overriding background
kvakvs Feb 17, 2020
a972721
Main menu is scaled to screen size fraction
kvakvs Feb 18, 2020
692796d
Toggle Traffic Light button is used for testing
kvakvs Feb 18, 2020
7d93f2f
Graphics for TimedTL, ManualTL, ToggleTL tools
kvakvs Feb 18, 2020
011ef14
Added green buttons, Lane Arrows and Lane Connector
kvakvs Feb 18, 2020
1e7777d
Reverted textures; Smarter toggle button behaviour; Minor refactorings
kvakvs Feb 18, 2020
038ced1
Rebase fixes: Renamed BaseUI/UIBase to ModUI
kvakvs Feb 18, 2020
cfbbf53
Fix width of the main menu panel
kvakvs Feb 19, 2020
1dab933
LoadingExtension.ModUi is now a singleton ModUI accessible via ModUI.…
kvakvs Feb 19, 2020
14e498c
Merge remote-tracking branch 'tmpe/master' into 523-facelift-mainmenu
kvakvs Feb 19, 2020
7195857
Submodules reset to master state
kvakvs Feb 19, 2020
f8c0931
Fixed main button to always 50px. Added min scale for main panel butt…
kvakvs Feb 19, 2020
a0ad205
Added missing spacings; Minor renaming
kvakvs Feb 20, 2020
5b089c7
UI scale slider affects mainmenu panel now
kvakvs Feb 20, 2020
5cbd1e5
Toned down button textures; added v11 to 11 in main button; Review no…
kvakvs Feb 21, 2020
05fabdd
Get a View for debug menu
kvakvs Feb 21, 2020
65cd4fe
MenuLayout class responsible for menu row breaking and sizing
kvakvs Feb 21, 2020
36b1f71
MaxCols counting fixed; Rows counting fixed
kvakvs Feb 21, 2020
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
2 changes: 1 addition & 1 deletion TLM/CSUtil.CameraControl
2 changes: 1 addition & 1 deletion TLM/OptionsFramework
2 changes: 1 addition & 1 deletion TLM/TLM/Custom/AI/CustomRoadBaseAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void CustomClickNodeButton(ushort nodeId, ref NetNode data, int index) {
data.m_flags |= NetNode.Flags.CustomTrafficLights;*/

// NON-STOCK CODE START
ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)UIBase
ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)ModUI
.GetTrafficManagerTool(true)
.GetSubTool(ToolMode.SwitchTrafficLight);
toggleTool.ToggleTrafficLight(nodeId, ref data, false);
Expand Down
15 changes: 7 additions & 8 deletions TLM/TLM/LoadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public class ManualHarmonyPatch {
/// </summary>
public static Translation TranslationDatabase = new Translation();

public static UIBase BaseUI { get; private set; }

public static UITransportDemand TransportDemandUI { get; private set; }

public static List<ICustomManager> RegisteredManagers { get; private set; }
Expand Down Expand Up @@ -368,10 +366,10 @@ void Destroy<T>() where T : MonoBehaviour {
}

Log.Info("Removing Controls from UI.");
if (BaseUI != null) {
BaseUI.Close(); // Hide the UI ASAP
Object.Destroy(BaseUI);
BaseUI = null;
if (ModUI.Instance != null) {
ModUI.Instance.Close(); // Hide the UI ASAP
Object.Destroy(ModUI.Instance);
ModUI.SetSingletonInstance(null);
Log._Debug("removed UIBase instance.");
}

Expand Down Expand Up @@ -544,9 +542,10 @@ public override void OnLevelLoaded(LoadMode mode) {
}

Log.Info("Adding Controls to UI.");
if (BaseUI == null) {
if (ModUI.Instance == null) {
Log._Debug("Adding UIBase instance.");
BaseUI = ToolsModifierControl.toolController.gameObject.AddComponent<UIBase>();
ModUI.SetSingletonInstance(
ToolsModifierControl.toolController.gameObject.AddComponent<ModUI>());
}

// Init transport demand UI
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/RedirectionFramework
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed TLM/TLM/Resources/MainMenu/MenuButton.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions TLM/TLM/State/ConfigData/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace TrafficManager.State.ConfigData {
using System;
using System.Collections.Generic;
using System.Linq;
using TrafficManager.UI.MainMenu;
Expand Down Expand Up @@ -29,16 +30,16 @@ public class Main {
/// </summary>
public bool EnableTutorial = true;

/// <summary>
/// Determines if the main menu shall be displayed in a tiny format
/// </summary>
/// <summary>Determines if the main menu shall be displayed in a tiny format.</summary>
[Obsolete("Main Menu now scales based on screen size")]
public bool TinyMainMenu = true;

/// <summary>
/// User interface transparency
/// </summary>
/// <summary>User interface transparency</summary>
public byte GuiTransparency = 30;

/// <summary>User interface scale for TM:PE.</summary>
public float GuiScale = 100f;

/// <summary>
/// Overlay transparency
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/State/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ private set {
//private object ObserverLock = new object();

/// <summary>
/// Holds a list of observers which are being notified as soon as the configuration is updated
/// Initializes static members of the <see cref="GlobalConfig"/> class.
/// Holds a list of observers which are being notified as soon as the configuration is updated.
/// </summary>
//private List<IObserver<GlobalConfig>> observers = new List<IObserver<GlobalConfig>>();

static GlobalConfig() {
Reload();
}
Expand Down
6 changes: 3 additions & 3 deletions TLM/TLM/State/Keybinds/KeybindSettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ private void CreateUI_Global() {
AddKeybindRowUI(Translation.Options.Get("Keybind:Toggle Main Menu"),
ToggleMainMenu);
ToggleMainMenu.OnKeyChanged(() => {
if (LoadingExtension.BaseUI != null &&
LoadingExtension.BaseUI.MainMenuButton != null) {
LoadingExtension.BaseUI.MainMenuButton.UpdateTooltip();
if (ModUI.Instance != null &&
ModUI.Instance.MainMenuButton != null) {
ModUI.Instance.MainMenuButton.UpdateButtonImageAndTooltip();
}
});

Expand Down
21 changes: 13 additions & 8 deletions TLM/TLM/State/Keybinds/KeybindUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,23 @@ public void CreateKeybindButton(UIPanel parent, KeybindSetting setting, SavedInp
btn.eventKeyDown += OnBindingKeyDown;
btn.eventMouseDown += OnBindingMouseDown;
btn.objectUserData
= new KeybindSetting.Editable {Target = setting, TargetKey = editKey};
= new KeybindSetting.Editable { Target = setting, TargetKey = editKey };

AddXButton(parent, editKey, btn);
AddXButton(parent, editKey, btn, setting);
}

/// <summary>
/// Add X button to the right of another button
/// </summary>
/// <param name="parent">The panel to host the new button</param>
/// <param name="editKey">The key to be cleared on click</param>
/// <param name="alignTo">Align X button to the right of this</param>
private static void AddXButton(UIPanel parent, SavedInputKey editKey, UIButton alignTo) {
var btnX = parent.AddUIComponent<UIButton>();
/// <param name="parent">The panel to host the new button.</param>
/// <param name="editKey">The key to be cleared on click.</param>
/// <param name="alignTo">Align X button to the right of this.</param>
/// <param name="setting">KeybindSetting to notify that key was cleared.</param>
private static void AddXButton(UIPanel parent,
SavedInputKey editKey,
UIButton alignTo,
KeybindSetting setting) {
UIButton btnX = parent.AddUIComponent<UIButton>();
btnX.autoSize = false;
btnX.size = new Vector2(ROW_HEIGHT, ROW_HEIGHT);
btnX.normalBgSprite = "buttonclose";
Expand All @@ -161,6 +165,7 @@ private static void AddXButton(UIPanel parent, SavedInputKey editKey, UIButton a
btnX.eventClicked += (component, eventParam) => {
editKey.value = SavedInputKey.Empty;
alignTo.text = Keybind.ToLocalizedString(editKey);
setting.NotifyKeyChanged();
};
}

Expand Down Expand Up @@ -214,7 +219,7 @@ private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter evParam) {
var message = Translation.Options.Get("Keybinds.Dialog.Text:Keybind conflict")
+ "\n\n" + maybeConflict;
Log.Info($"Keybind conflict: {message}");
UIView.library
UIView.library
.ShowModal<ExceptionPanel>("ExceptionPanel")
.SetMessage("Key Conflict", message, false);
} else {
Expand Down
8 changes: 4 additions & 4 deletions TLM/TLM/State/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public static bool
/// a new language. Takes a second, very slow.
/// </summary>
internal static void RebuildMenu() {
if (LoadingExtension.BaseUI != null) {
if (ModUI.Instance != null) {
Log._Debug("Rebuilding the TM:PE menu...");
LoadingExtension.BaseUI.RebuildMenu();
ModUI.Instance.RebuildMenu();

// TM:PE main button also needs to be uidated
if (LoadingExtension.BaseUI.MainMenuButton != null) {
LoadingExtension.BaseUI.MainMenuButton.UpdateTooltip();
if (ModUI.Instance.MainMenuButton != null) {
ModUI.Instance.MainMenuButton.UpdateButtonImageAndTooltip();
}

LoadingExtension.TranslationDatabase.ReloadTutorialTranslations();
Expand Down
52 changes: 35 additions & 17 deletions TLM/TLM/State/OptionsTabs/OptionsGeneralTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public static class OptionsGeneralTab {
[UsedImplicitly]
private static UICheckBox _lockMenuToggle;

[UsedImplicitly]
private static UICheckBox _tinyMenuToggle;

private static UISlider _guiTransparencySlider;
private static UISlider _guiScaleSlider;
private static UISlider _overlayTransparencySlider;

[UsedImplicitly]
Expand All @@ -44,7 +42,6 @@ private static string T(string key) {
}

internal static void MakeSettings_General(ExtUITabstrip tabStrip) {

UIHelper panelHelper = tabStrip.AddTabPage(T("Tab:General"));

UIHelperBase generalGroup = panelHelper.AddGroup(
Expand Down Expand Up @@ -82,10 +79,16 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
T("General.Checkbox:Lock main menu window position"),
GlobalConfig.Instance.Main.MainMenuPosLocked,
OnLockMenuChanged) as UICheckBox;
_tinyMenuToggle = generalGroup.AddCheckbox(
T("General.Checkbox:Compact main menu"),
GlobalConfig.Instance.Main.TinyMainMenu,
OnCompactMainMenuChanged) as UICheckBox;

_guiScaleSlider = generalGroup.AddSlider(
T("General.Slider:GUI scale") + ":",
65,
200,
5,
GlobalConfig.Instance.Main.GuiScale,
OnGuiScaleChanged) as UISlider;
_guiScaleSlider.parent.Find<UILabel>("Label").width = 500;

_guiTransparencySlider = generalGroup.AddSlider(
T("General.Slider:Window transparency") + ":",
0,
Expand All @@ -94,6 +97,7 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
GlobalConfig.Instance.Main.GuiTransparency,
OnGuiTransparencyChanged) as UISlider;
_guiTransparencySlider.parent.Find<UILabel>("Label").width = 500;

_overlayTransparencySlider = generalGroup.AddSlider(
T("General.Slider:Overlay transparency") + ":",
0,
Expand Down Expand Up @@ -176,7 +180,7 @@ private static void OnLanguageChanged(int newLanguageIndex) {
private static void OnLockButtonChanged(bool newValue) {
Log._Debug($"Button lock changed to {newValue}");
if (Options.IsGameLoaded(false)) {
LoadingExtension.BaseUI.MainMenuButton.SetPosLock(newValue);
ModUI.Instance.MainMenuButton.SetPosLock(newValue);
}

GlobalConfig.Instance.Main.MainMenuButtonPosLocked = newValue;
Expand All @@ -186,20 +190,13 @@ private static void OnLockButtonChanged(bool newValue) {
private static void OnLockMenuChanged(bool newValue) {
Log._Debug($"Menu lock changed to {newValue}");
if (Options.IsGameLoaded(false)) {
LoadingExtension.BaseUI.MainMenu.SetPosLock(newValue);
ModUI.Instance.MainMenu.SetPosLock(newValue);
}

GlobalConfig.Instance.Main.MainMenuPosLocked = newValue;
GlobalConfig.WriteConfig();
}

private static void OnCompactMainMenuChanged(bool newValue) {
Log._Debug($"Compact main menu changed to {newValue}");
GlobalConfig.Instance.Main.TinyMainMenu = newValue;
GlobalConfig.Instance.NotifyObservers(GlobalConfig.Instance);
GlobalConfig.WriteConfig();
}

private static void OnEnableTutorialsChanged(bool newValue) {
Log._Debug($"Enable tutorial messages changed to {newValue}");
GlobalConfig.Instance.Main.EnableTutorial = newValue;
Expand Down Expand Up @@ -238,6 +235,17 @@ private static void OnGuiTransparencyChanged(float newVal) {
Log._Debug($"GuiTransparency changed to {GlobalConfig.Instance.Main.GuiTransparency}");
}

private static void OnGuiScaleChanged(float newVal) {
SetGuiScale(newVal);
_guiScaleSlider.tooltip
= string.Format(
T("General.Tooltip.Format:GUI scale: {0}%"),
GlobalConfig.Instance.Main.GuiScale);

GlobalConfig.WriteConfig();
Log._Debug($"GuiScale changed to {GlobalConfig.Instance.Main.GuiScale}");
}

private static void OnOverlayTransparencyChanged(float newVal) {
if (!Options.IsGameLoaded()) {
return;
Expand Down Expand Up @@ -314,6 +322,16 @@ public static void SetGuiTransparency(byte val) {
}
}

public static void SetGuiScale(float val) {
bool changed = (int)val != (int)GlobalConfig.Instance.Main.GuiScale;
GlobalConfig.Instance.Main.GuiScale = val;

if (changed && _guiScaleSlider != null) {
_guiScaleSlider.value = val;
ModUI.Instance.NotifyGuiScaleChanged();
}
}

public static void SetOverlayTransparency(byte val) {
bool changed = val != GlobalConfig.Instance.Main.OverlayTransparency;
GlobalConfig.Instance.Main.OverlayTransparency = val;
Expand Down
Loading