From ab5a33742a1ca37a4d71e38de06cc84092101d5c Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Thu, 14 Sep 2023 19:24:38 +0200 Subject: [PATCH 01/12] Mono ui input manager --- NEG/UI/UnityUi/MonoUiInputManger.cs | 23 +++++++++++++++---- NEG/UI/UnityUi/Window/MonoWindow.cs | 1 + .../WindowSlot/SingleWindowSlotWithHistory.cs | 10 ++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index 22cd060..4f87f94 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using NEG.UI.UnityUi.Window; +using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.InputSystem; using UnityEngine.InputSystem.UI; @@ -31,9 +32,9 @@ namespace NEG.UI.UnityUi //var keyboardAction = new InputAction(binding: "//*"); //keyboardAction.performed += (context) => CurrentInputSource = EInputSource.Keyboard; //keyboardAction.Enable(); - var gamepadAction = new InputAction(binding: "//*"); - gamepadAction.performed += (context) => OnSelectionChangeStarted(); - gamepadAction.Enable(); + //var gamepadAction = new InputAction(binding: "//*"); + //gamepadAction.performed += (context) => OnSelectionChangeStarted(); + //gamepadAction.Enable(); var mouseAction = new InputAction(binding: "//*"); mouseAction.performed += (context) => @@ -56,6 +57,20 @@ namespace NEG.UI.UnityUi { CurrentSelectionSource = SelectionSource.Direction; Cursor.visible = false; + if (EventSystem.current.currentSelectedGameObject == null) + { + EventSystem.current.SetSelectedGameObject(((MonoWindow)MonoUiManager.Instance.CurrentMainWindow).DefaultSelectedItem); + return; + } + var data = new PointerEventData(EventSystem.current); + var currentSelected = EventSystem.current.currentSelectedGameObject; + for (var current = EventSystem.current.currentSelectedGameObject.transform; + current != null; + current = current.parent) + { + ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); + } + EventSystem.current.SetSelectedGameObject(currentSelected); } private void SetPointerInput() diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index ddbc35a..db8b882 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -24,6 +24,7 @@ namespace NEG.UI.UnityUi.Window public bool IsMainWindow { get; private set; } private IWindowSlot DefaultWindowSlot => windowSlots[0]; + public GameObject DefaultSelectedItem => defaultSelectedItem; [SerializeField] private List windowSlots; diff --git a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs index a718257..10d010e 100644 --- a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs +++ b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs @@ -1,7 +1,10 @@ -using NEG.UI.UnityUi.WindowSlot; +using NEG.UI; +using NEG.UI.UnityUi.Window; +using NEG.UI.UnityUi.WindowSlot; using NEG.UI.Window; using System.Collections.Generic; using System.Linq; +using UnityEngine.EventSystems; namespace NegUtils.NEG.UI.UnityUi.WindowSlot { @@ -41,8 +44,11 @@ namespace NegUtils.NEG.UI.UnityUi.WindowSlot window.SetClosedState(); windowsHistory.Remove(window); if (window != currentWindow || windowsHistory.Count == 0) return; - windowsHistory[^1].SeVisibleState(); currentWindow = windowsHistory[^1]; + currentWindow.SeVisibleState(); + if(UiManager.Instance.CurrentMainWindow == window) + UiManager.Instance.SetMainWindow(currentWindow); + EventSystem.current.SetSelectedGameObject(((MonoWindow)currentWindow).DefaultSelectedItem); } public override void CloseAllWindows() { -- 2.47.2 From 8835f620e9d9c766e0e86e8a3e4efeb240d7ecb4 Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Fri, 15 Sep 2023 14:01:24 +0200 Subject: [PATCH 02/12] null check --- NEG/UI/UnityUi/MonoUiInputManger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index 4f87f94..de79046 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -57,7 +57,7 @@ namespace NEG.UI.UnityUi { CurrentSelectionSource = SelectionSource.Direction; Cursor.visible = false; - if (EventSystem.current.currentSelectedGameObject == null) + if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject == null) { EventSystem.current.SetSelectedGameObject(((MonoWindow)MonoUiManager.Instance.CurrentMainWindow).DefaultSelectedItem); return; -- 2.47.2 From 6b01de0095dff5f85ddb87d8127de68996394c5e Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Fri, 15 Sep 2023 14:03:55 +0200 Subject: [PATCH 03/12] fix --- NEG/UI/UnityUi/MonoUiInputManger.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index de79046..51ac5c6 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -55,9 +55,13 @@ namespace NEG.UI.UnityUi private void SetDirectionInput() { + if (EventSystem.current == null) + { + return; + } CurrentSelectionSource = SelectionSource.Direction; Cursor.visible = false; - if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject == null) + if (EventSystem.current.currentSelectedGameObject == null) { EventSystem.current.SetSelectedGameObject(((MonoWindow)MonoUiManager.Instance.CurrentMainWindow).DefaultSelectedItem); return; -- 2.47.2 From 1abfcc00420aef6888c08c314486b3276b38843e Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Fri, 15 Sep 2023 16:53:41 +0200 Subject: [PATCH 04/12] null check --- NEG/UI/UiManager.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEG/UI/UiManager.cs b/NEG/UI/UiManager.cs index c25e4b3..70b7478 100644 --- a/NEG/UI/UiManager.cs +++ b/NEG/UI/UiManager.cs @@ -183,6 +183,8 @@ namespace NEG.UI while (popupsToShow.TryDequeue(out var d, out int p)) { + if(d == null) + continue; if(!d.IsValid) continue; if(d == currentShownPopup.data) -- 2.47.2 From ebfeb14515c70c768c03c0743a93a2fcb5194123 Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Tue, 19 Sep 2023 12:42:51 +0200 Subject: [PATCH 05/12] Add new auto window open --- NEG/UI/UiManager.cs | 3 ++- .../UnityUi/Area/AutoOpenWindowWhenNoOther.cs | 17 +++++++++++++++++ .../Area/AutoOpenWindowWhenNoOther.cs.meta | 3 +++ NEG/UI/UnityUi/Window/MonoWindow.cs | 6 ++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs create mode 100644 NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs.meta diff --git a/NEG/UI/UiManager.cs b/NEG/UI/UiManager.cs index 70b7478..59c2bb0 100644 --- a/NEG/UI/UiManager.cs +++ b/NEG/UI/UiManager.cs @@ -152,7 +152,8 @@ namespace NEG.UI { if(CurrentMainWindow != window) return; - + + CurrentMainWindow = null; //TODO: select new main window } diff --git a/NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs b/NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs new file mode 100644 index 0000000..c9ba380 --- /dev/null +++ b/NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs @@ -0,0 +1,17 @@ +using NEG.UI.UnityUi.Window; +using NEG.UI.Window; +using UnityEngine; + +namespace NEG.UI.Area +{ + public class AutoOpenWindowWhenNoOther : MonoBehaviour + { + [SerializeField] private MonoWindow window; + + private void Start() + { + if(UiManager.Instance.CurrentMainWindow == null) + window.Open(); + } + } +} \ No newline at end of file diff --git a/NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs.meta b/NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs.meta new file mode 100644 index 0000000..14ed8c2 --- /dev/null +++ b/NEG/UI/UnityUi/Area/AutoOpenWindowWhenNoOther.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 473c065573984067a824ebf3b605c3ab +timeCreated: 1695048071 \ No newline at end of file diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index db8b882..b6b8986 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -55,6 +55,12 @@ namespace NEG.UI.UnityUi.Window private void Awake() => ((IWindow)this).SetHiddenState(); + private void OnDestroy() + { + if(gameObject.activeSelf) + UiManager.Instance.OnWindowClosed(this); + } + private void OnValidate() { #if !NEG_UI_DISABLE_WARNING_DEFAULT_SELECTION -- 2.47.2 From 610179c21d472be8cb2a9063e343042deee7b686 Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Tue, 19 Sep 2023 21:41:39 +0200 Subject: [PATCH 06/12] Add linux builds --- Editor/BuildingUtils.cs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs index b2acc8d..7cc5407 100644 --- a/Editor/BuildingUtils.cs +++ b/Editor/BuildingUtils.cs @@ -56,13 +56,13 @@ public static class BuildingUtils UploadSteam(); } - [MenuItem("Tools/Build/All Release")] public static void BuildRelease() { if(!CanBuild()) return; BuildWindowsRelease(); + BuildLinuxRelease(); } [MenuItem("Tools/Build/All Development")] @@ -88,6 +88,15 @@ public static class BuildingUtils return; BuildWindows(true); } + + [MenuItem("Tools/Build/Platform/Linux/x64-Release")] + public static void BuildLinuxRelease() + { + if(!CanBuild()) + return; + BuildLinux(true); + } + [MenuItem("Tools/Build/Platform/Android/GooglePlay")] public static void BuildGooglePlay() @@ -109,7 +118,7 @@ public static class BuildingUtils BuildPipeline.BuildPlayer(buildPlayerOptions); } - private static void BuildWindows(bool release) + private static void BuildWindows(bool release, string[] additionalDefines = default) { var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] }; for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) @@ -117,12 +126,31 @@ public static class BuildingUtils buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path; } + buildPlayerOptions.extraScriptingDefines = additionalDefines; + buildPlayerOptions.target = BuildTarget.StandaloneWindows64; buildPlayerOptions.options = release ? BuildOptions.None : BuildOptions.Development; buildPlayerOptions.locationPathName = Application.dataPath + $"/../../{Application.productName}-Steam/ContentBuilder/content/windows/{Application.productName}.exe"; BuildPipeline.BuildPlayer(buildPlayerOptions); } + + private static void BuildLinux(bool release, string[] additionalDefines = default) + { + var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] }; + for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) + { + buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path; + } + + buildPlayerOptions.extraScriptingDefines = additionalDefines; + + buildPlayerOptions.target = BuildTarget.StandaloneLinux64; + buildPlayerOptions.options = release ? BuildOptions.None : BuildOptions.Development; + buildPlayerOptions.locationPathName = Application.dataPath + + $"/../../{Application.productName}-Steam/ContentBuilder/content/linux/{Application.productName}.x86_64"; + BuildPipeline.BuildPlayer(buildPlayerOptions); + } private static void IncreaseBuildNumber() { @@ -137,7 +165,7 @@ public static class BuildingUtils private static void UploadSteam() { - string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && run_build.bat"; + string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat"; var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}") { -- 2.47.2 From 0148de0db74dc7b6098c20ce5e568b7be9848175 Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Mon, 2 Oct 2023 21:52:09 +0200 Subject: [PATCH 07/12] Moa nullchecks --- NEG/UI/UnityUi/MonoUiInputManger.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index 51ac5c6..f6b55ac 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -55,25 +55,29 @@ namespace NEG.UI.UnityUi private void SetDirectionInput() { - if (EventSystem.current == null) + if (EventSystem.current == null || MonoUiManager.Instance == null || CurrentSelectionSource == SelectionSource.Direction) { return; } CurrentSelectionSource = SelectionSource.Direction; Cursor.visible = false; - if (EventSystem.current.currentSelectedGameObject == null) + if (EventSystem.current.currentSelectedGameObject == null && MonoUiManager.Instance.CurrentMainWindow != null) { EventSystem.current.SetSelectedGameObject(((MonoWindow)MonoUiManager.Instance.CurrentMainWindow).DefaultSelectedItem); return; } var data = new PointerEventData(EventSystem.current); var currentSelected = EventSystem.current.currentSelectedGameObject; - for (var current = EventSystem.current.currentSelectedGameObject.transform; - current != null; - current = current.parent) + if (currentSelected != null) { - ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); + for (var current = EventSystem.current.currentSelectedGameObject.transform; + current != null; + current = current.parent) + { + ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); + } } + EventSystem.current.SetSelectedGameObject(currentSelected); } -- 2.47.2 From 164fd2f79419eef52f0a86315a5cbe16bd08db80 Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Tue, 3 Oct 2023 15:55:02 +0200 Subject: [PATCH 08/12] ui update --- Editor/BuildingUtils.cs | 27 ++++++++++++++++++- NEG/UI/UiManager.cs | 12 ++++++--- NEG/UI/UnityUi/MonoUiInputManger.cs | 6 +++-- NEG/UI/UnityUi/Window/MonoWindow.cs | 1 + NEG/UI/UnityUi/Window/MonoWindow.cs.meta | 12 +++++++-- NEG/UI/UnityUi/WindowSlot/SingleWindowSlot.cs | 8 +++++- .../WindowSlot/SingleWindowSlotWithHistory.cs | 2 +- 7 files changed, 58 insertions(+), 10 deletions(-) diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs index 7cc5407..a95774f 100644 --- a/Editor/BuildingUtils.cs +++ b/Editor/BuildingUtils.cs @@ -55,6 +55,18 @@ public static class BuildingUtils BuildDevelopment(); UploadSteam(); } + + + [MenuItem("Tools/Build/Steam/Demo")] + public static void SteamDemo() + { + if(!CanBuild()) + return; + + IncreaseBuildNumber(); + BuildDemo(); + UploadSteam(true); + } [MenuItem("Tools/Build/All Release")] public static void BuildRelease() @@ -72,6 +84,15 @@ public static class BuildingUtils return; BuildWindowsDevelopment(); } + + [MenuItem("Tools/Build/All Demo")] + public static void BuildDemo() + { + if(!CanBuild()) + return; + BuildWindows(true, new[] {"DEMO"}); + BuildLinux(true, new[] {"DEMO"}); + } [MenuItem("Tools/Build/Platform/Windows/x64-Development")] public static void BuildWindowsDevelopment() @@ -163,9 +184,13 @@ public static class BuildingUtils PlayerSettings.bundleVersion = string.Join(".", versionParts); } - private static void UploadSteam() + private static void UploadSteam(bool demo = false) { string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat"; + if (demo) + { + command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_demo.bat"; + } var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}") { diff --git a/NEG/UI/UiManager.cs b/NEG/UI/UiManager.cs index 59c2bb0..1be26f6 100644 --- a/NEG/UI/UiManager.cs +++ b/NEG/UI/UiManager.cs @@ -6,6 +6,7 @@ using NEG.Utils; using NegUtils.NEG.UI; using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; namespace NEG.UI @@ -34,7 +35,7 @@ namespace NEG.UI /// /// Current window that is considered main (focused, lastly opened). Can be null. /// - public IWindow CurrentMainWindow { get; protected set; } + public IWindow CurrentMainWindow => mainWindows.LastOrDefault(); public PopupData CurrentPopup => currentShownPopup.data; @@ -47,6 +48,8 @@ namespace NEG.UI //TODO: localize private string localizedYes = "Yes", localizedNo = "No", localizedOk = "Ok"; + private List mainWindows; + protected UiManager(IArea startArea) { if (Instance != null) @@ -58,6 +61,7 @@ namespace NEG.UI Instance = this; CurrentArea = startArea; + mainWindows = new List(); } /// @@ -146,14 +150,16 @@ namespace NEG.UI public virtual void Dispose() => Instance = null; - public void SetMainWindow(IWindow window) => CurrentMainWindow = window; + public void SetMainWindow(IWindow window) => mainWindows.Add(window); + + public void MainWindowClosed(IWindow window) => mainWindows.Remove(window); public void OnWindowClosed(IWindow window) { if(CurrentMainWindow != window) return; - CurrentMainWindow = null; + MainWindowClosed(window); //TODO: select new main window } diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index f6b55ac..202a724 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -48,14 +48,14 @@ namespace NEG.UI.UnityUi private void OnSelectionChangeStarted() { - if(CurrentSelectionSource == SelectionSource.Direction) + if(CurrentSelectionSource == SelectionSource.Direction && EventSystem.current.currentSelectedGameObject != null) return; SetDirectionInput(); } private void SetDirectionInput() { - if (EventSystem.current == null || MonoUiManager.Instance == null || CurrentSelectionSource == SelectionSource.Direction) + if (EventSystem.current == null || MonoUiManager.Instance == null ) { return; } @@ -95,6 +95,8 @@ namespace NEG.UI.UnityUi if (EventSystem.current.currentInputModule == null) return; + EventSystem.current.SetSelectedGameObject(null); + var module = (InputSystemUIInputModule)EventSystem.current.currentInputModule; var result = module.GetLastRaycastResult(0); if(result.gameObject == null) diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index b6b8986..e1f0dfc 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -12,6 +12,7 @@ using UnityEngine.Serialization; namespace NEG.UI.UnityUi.Window { + [DefaultExecutionOrder(10)] public class MonoWindow : MonoBehaviour, IWindow { public event Action OnOpened; diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs.meta b/NEG/UI/UnityUi/Window/MonoWindow.cs.meta index 4f6091a..d50bd3d 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs.meta +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 85d136d6850728d4b96c26fa286ffe3c -timeCreated: 1670709296 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 10 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlot.cs b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlot.cs index 04c49b9..9fff830 100644 --- a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlot.cs +++ b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlot.cs @@ -24,7 +24,13 @@ namespace NEG.UI.WindowSlot window.SetOpenedState(this, data); } - public override void DetachWindow(IWindow window) => CurrentWindow = null; + public override void DetachWindow(IWindow window) + { + if(UiManager.Instance.CurrentMainWindow == window) + UiManager.Instance.MainWindowClosed(window); + CurrentWindow = null; + } + public override void CloseAllWindows() => CurrentWindow = null; } } \ No newline at end of file diff --git a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs index 10d010e..fc3390c 100644 --- a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs +++ b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs @@ -47,7 +47,7 @@ namespace NegUtils.NEG.UI.UnityUi.WindowSlot currentWindow = windowsHistory[^1]; currentWindow.SeVisibleState(); if(UiManager.Instance.CurrentMainWindow == window) - UiManager.Instance.SetMainWindow(currentWindow); + UiManager.Instance.MainWindowClosed(window); EventSystem.current.SetSelectedGameObject(((MonoWindow)currentWindow).DefaultSelectedItem); } public override void CloseAllWindows() -- 2.47.2 From 566430650f08d43bc372388d4f375dae858462ae Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Tue, 10 Oct 2023 20:25:34 +0200 Subject: [PATCH 09/12] moa fixes --- CoroutineUtils.cs | 1 + NEG/UI/UiManager.cs | 12 +++--------- NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs | 2 +- NEG/UI/UnityUi/Area/MonoArea.cs.meta | 12 ++++++++++-- NEG/UI/UnityUi/MonoUiInputManger.cs | 2 ++ NEG/UI/UnityUi/Window/MonoWindow.cs | 8 +++++++- NEG/UI/UnityUi/Window/MonoWindow.cs.meta | 2 +- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CoroutineUtils.cs b/CoroutineUtils.cs index a8f88ce..a91c31c 100644 --- a/CoroutineUtils.cs +++ b/CoroutineUtils.cs @@ -27,6 +27,7 @@ namespace NEG.Utils action?.Invoke(); } + public static void ActionAfterEndOfFrame(this MonoBehaviour mono, Action action) => mono.StartCoroutine(ActionAtNextFrame(action)); public static IEnumerator ActionAfterEndOfFrame(Action action) { yield return WaitForEndOfFrame; diff --git a/NEG/UI/UiManager.cs b/NEG/UI/UiManager.cs index 1be26f6..68d7efe 100644 --- a/NEG/UI/UiManager.cs +++ b/NEG/UI/UiManager.cs @@ -150,19 +150,13 @@ namespace NEG.UI public virtual void Dispose() => Instance = null; - public void SetMainWindow(IWindow window) => mainWindows.Add(window); + public void SetMainWindow(IWindow window) => mainWindows.Add(window); public void MainWindowClosed(IWindow window) => mainWindows.Remove(window); - public void OnWindowClosed(IWindow window) - { - if(CurrentMainWindow != window) - return; - - MainWindowClosed(window); - //TODO: select new main window - } + public void OnWindowClosed(IWindow window) => MainWindowClosed(window); + //TODO: select new main window protected void PopupClosed(PopupData data) { if (currentShownPopup.data != data) diff --git a/NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs b/NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs index 1334558..b7211c5 100644 --- a/NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs +++ b/NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs @@ -12,7 +12,7 @@ namespace NEG.UI.Area protected override void OnBackUsed(IControllable.BackUsed backUsed) { base.OnBackUsed(backUsed); - UiManager.Instance.CurrentMainWindow.Close(); + UiManager.Instance.CurrentMainWindow?.Close(); backUsed.Used = true; } } diff --git a/NEG/UI/UnityUi/Area/MonoArea.cs.meta b/NEG/UI/UnityUi/Area/MonoArea.cs.meta index 958b733..883d00d 100644 --- a/NEG/UI/UnityUi/Area/MonoArea.cs.meta +++ b/NEG/UI/UnityUi/Area/MonoArea.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 39eb59ca1ef60934abb3f0c64169be65 -timeCreated: 1670707479 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 10 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index 202a724..dfff504 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -22,6 +22,8 @@ namespace NEG.UI.UnityUi { var defaultActions = new DefaultInputActions(); InputActionReference.Create(defaultActions.UI.Navigate).action.performed += (ctx) => OnSelectionChangeStarted(); + InputActionReference.Create(defaultActions.UI.Cancel).action.performed += + (_) => UiManager.Instance.UseBack(); defaultActions.Enable(); if (Gamepad.current != null) diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index e1f0dfc..6536f7c 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -23,6 +23,8 @@ namespace NEG.UI.UnityUi.Window public IWindowSlot Parent { get; private set; } public bool IsMainWindow { get; private set; } + + public bool IsOpened { get; protected set; } private IWindowSlot DefaultWindowSlot => windowSlots[0]; public GameObject DefaultSelectedItem => defaultSelectedItem; @@ -34,6 +36,7 @@ namespace NEG.UI.UnityUi.Window public void SetOpenedState(IWindowSlot parentSlot, object data) { gameObject.SetActive(true); + IsOpened = true; Parent = parentSlot; EventSystem.current.SetSelectedGameObject(defaultSelectedItem); if (parentSlot.OpenWindowAsMain) @@ -44,6 +47,7 @@ namespace NEG.UI.UnityUi.Window public void SetClosedState() { gameObject.SetActive(false); + IsOpened = false; Parent = null; ((ISlotsHolder)this).CloseAllWindows(); UiManager.Instance.OnWindowClosed(this); @@ -58,8 +62,10 @@ namespace NEG.UI.UnityUi.Window private void OnDestroy() { - if(gameObject.activeSelf) + if (IsOpened) + { UiManager.Instance.OnWindowClosed(this); + } } private void OnValidate() diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs.meta b/NEG/UI/UnityUi/Window/MonoWindow.cs.meta index d50bd3d..2e55018 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs.meta +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 10 + executionOrder: 11 icon: {instanceID: 0} userData: assetBundleName: -- 2.47.2 From d9fc097783d6e7560c338bd990f1fe9191b69a80 Mon Sep 17 00:00:00 2001 From: BitterSmile Date: Tue, 21 Nov 2023 16:34:45 +0100 Subject: [PATCH 10/12] login screen done --- NEG/UI/UnityUi/Area/MonoArea.cs | 2 +- NEG/UI/UnityUi/MonoController.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NEG/UI/UnityUi/Area/MonoArea.cs b/NEG/UI/UnityUi/Area/MonoArea.cs index 2829582..535489a 100644 --- a/NEG/UI/UnityUi/Area/MonoArea.cs +++ b/NEG/UI/UnityUi/Area/MonoArea.cs @@ -36,7 +36,7 @@ namespace NEG.UI.Area public void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data); - private void Awake() + protected virtual void Awake() { if (setAsDefaultArea) UiManager.Instance.CurrentArea = this; diff --git a/NEG/UI/UnityUi/MonoController.cs b/NEG/UI/UnityUi/MonoController.cs index 7c4afdb..e6c9a7b 100644 --- a/NEG/UI/UnityUi/MonoController.cs +++ b/NEG/UI/UnityUi/MonoController.cs @@ -1,4 +1,5 @@ using KBCore.Refs; +using NEG.UI.UnityUi.Window; using NegUtils.NEG.UI; using System; using UnityEngine; @@ -11,6 +12,8 @@ namespace NEG.UI.UnityUi [SerializeField, Self] protected InterfaceRef controllable; + protected MonoWindow ControllableAsWindow => (MonoWindow)controllable.Value; + protected virtual void Awake() { controllable.Value.OnOpened += OnOpened; -- 2.47.2 From 8d5b903b1afaf614fb0c2e01fb339a7b90d84e74 Mon Sep 17 00:00:00 2001 From: BitterSmile Date: Sat, 16 Dec 2023 22:22:25 +0100 Subject: [PATCH 11/12] working on city --- NEG/UI/UiManager.cs | 2 +- NEG/UI/UnityUi/MonoUiInputManger.cs | 4 +--- NEG/UI/UnityUi/MonoUiManager.cs | 13 +++++++++++++ NEG/UI/UnityUi/Window/NoReactionOnBack.cs | 13 +++++++++++++ NEG/UI/UnityUi/Window/NoReactionOnBack.cs.meta | 3 +++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 NEG/UI/UnityUi/Window/NoReactionOnBack.cs create mode 100644 NEG/UI/UnityUi/Window/NoReactionOnBack.cs.meta diff --git a/NEG/UI/UiManager.cs b/NEG/UI/UiManager.cs index 68d7efe..f55b0da 100644 --- a/NEG/UI/UiManager.cs +++ b/NEG/UI/UiManager.cs @@ -170,7 +170,7 @@ namespace NEG.UI protected void SetDefaultPopup(IDefaultPopup popup) => currentDefaultPopup = popup; - private void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null) + protected virtual void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null) { if (forceShow) { diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index dfff504..4aac796 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -12,12 +12,10 @@ namespace NEG.UI.UnityUi Direction } - public class UiInputModule { } + public class UiInputModule { public SelectionSource CurrentSelectionSource { get; protected set; }} public class DefaultInputModule : UiInputModule { - public SelectionSource CurrentSelectionSource { get; private set; } - public DefaultInputModule() { var defaultActions = new DefaultInputActions(); diff --git a/NEG/UI/UnityUi/MonoUiManager.cs b/NEG/UI/UnityUi/MonoUiManager.cs index e5ced8c..7db2fb4 100644 --- a/NEG/UI/UnityUi/MonoUiManager.cs +++ b/NEG/UI/UnityUi/MonoUiManager.cs @@ -3,11 +3,13 @@ using NEG.UI.Popup; using NEG.UI.UnityUi.Buttons.Reaction; using NEG.UI.UnityUi.Buttons.Settings; using NEG.UI.UnityUi.Popup; +using NEG.UI.UnityUi.Window; using NEG.Utils; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Assertions; +using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using Object = UnityEngine.Object; @@ -68,6 +70,17 @@ namespace NEG.UI.UnityUi Instance = null; } + protected override void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null) + { + base.UpdatePopupsState(forceShow, priority, data); + if(inputModule.CurrentSelectionSource != SelectionSource.Direction) + return; + if (CurrentPopup == null && (EventSystem.current.currentSelectedGameObject != null || !EventSystem.current.currentSelectedGameObject.activeInHierarchy)) + { + EventSystem.current.SetSelectedGameObject(((MonoWindow)CurrentMainWindow).DefaultSelectedItem); + } + } + private void SpawnDefaultPopup() { var canvas = Object.Instantiate(canvasPrefab); diff --git a/NEG/UI/UnityUi/Window/NoReactionOnBack.cs b/NEG/UI/UnityUi/Window/NoReactionOnBack.cs new file mode 100644 index 0000000..7ba12ee --- /dev/null +++ b/NEG/UI/UnityUi/Window/NoReactionOnBack.cs @@ -0,0 +1,13 @@ +using NegUtils.NEG.UI; + +namespace NEG.UI.UnityUi.Window +{ + public class NoReactionOnBack : MonoController + { + protected override void OnBackUsed(IControllable.BackUsed backUsed) + { + base.OnBackUsed(backUsed); + backUsed.Used = true; + } + } +} \ No newline at end of file diff --git a/NEG/UI/UnityUi/Window/NoReactionOnBack.cs.meta b/NEG/UI/UnityUi/Window/NoReactionOnBack.cs.meta new file mode 100644 index 0000000..8be0e77 --- /dev/null +++ b/NEG/UI/UnityUi/Window/NoReactionOnBack.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c4a5380c95244c76ac79f820d16ea11c +timeCreated: 1702565120 \ No newline at end of file -- 2.47.2 From 1818d99caf07435b11c3672a51535b117976cf1f Mon Sep 17 00:00:00 2001 From: BitterSmile Date: Tue, 6 Feb 2024 18:07:28 +0100 Subject: [PATCH 12/12] null fix --- NEG/UI/UnityUi/MonoUiManager.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NEG/UI/UnityUi/MonoUiManager.cs b/NEG/UI/UnityUi/MonoUiManager.cs index 7db2fb4..dbafda8 100644 --- a/NEG/UI/UnityUi/MonoUiManager.cs +++ b/NEG/UI/UnityUi/MonoUiManager.cs @@ -75,8 +75,11 @@ namespace NEG.UI.UnityUi base.UpdatePopupsState(forceShow, priority, data); if(inputModule.CurrentSelectionSource != SelectionSource.Direction) return; - if (CurrentPopup == null && (EventSystem.current.currentSelectedGameObject != null || !EventSystem.current.currentSelectedGameObject.activeInHierarchy)) + + if (CurrentPopup == null && (EventSystem.current.currentSelectedGameObject == null || !EventSystem.current.currentSelectedGameObject.activeInHierarchy)) { + if(((MonoWindow)CurrentMainWindow).DefaultSelectedItem == null) + return; EventSystem.current.SetSelectedGameObject(((MonoWindow)CurrentMainWindow).DefaultSelectedItem); } } -- 2.47.2