From 8b1fc7063b387542803c6bc214ccf8acb32870bd Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 19 May 2024 16:46:27 +0800 Subject: * rename --- Thronefall_1_0/Decompile/ThronefallUIElement.cs | 166 ++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 Thronefall_1_0/Decompile/ThronefallUIElement.cs (limited to 'Thronefall_1_0/Decompile/ThronefallUIElement.cs') diff --git a/Thronefall_1_0/Decompile/ThronefallUIElement.cs b/Thronefall_1_0/Decompile/ThronefallUIElement.cs new file mode 100644 index 0000000..e2c9d64 --- /dev/null +++ b/Thronefall_1_0/Decompile/ThronefallUIElement.cs @@ -0,0 +1,166 @@ +using UnityEngine; +using UnityEngine.Events; + +public abstract class ThronefallUIElement : MonoBehaviour +{ + public enum NavigationDirection + { + Right, + Left, + Up, + Down + } + + public enum SelectionState + { + Default, + Focussed, + Selected, + FocussedAndSelected + } + + protected SelectionState currentState; + + protected SelectionState previousState; + + public bool ignoreMouse; + + public bool autoSelectOnFocus; + + public bool cannotBeSelected; + + public ThronefallUIElement leftNav; + + public ThronefallUIElement rightNav; + + public ThronefallUIElement topNav; + + public ThronefallUIElement botNav; + + public UnityEvent onSelectionStateChange = new UnityEvent(); + + public UnityEvent onApply = new UnityEvent(); + + public UnityEvent onEmptyNavigate = new UnityEvent(); + + public SelectionState CurrentState => currentState; + + public SelectionState PreviousState => previousState; + + public virtual bool dragable => false; + + public void Apply() + { + if (!SceneTransitionManager.instance.SceneTransitionIsRunning) + { + onApply.Invoke(); + OnApply(); + } + } + + public void Select() + { + SetState(SelectionState.Selected); + } + + public void Focus() + { + SetState(SelectionState.Focussed); + } + + public void FocusAndSelect() + { + SetState(SelectionState.FocussedAndSelected); + } + + public void Clear() + { + SetState(SelectionState.Default); + } + + public void HardStateSet(SelectionState selectionState) + { + currentState = selectionState; + previousState = selectionState; + OnHardStateSet(selectionState); + } + + protected abstract void OnApply(); + + protected abstract void OnClear(); + + protected abstract void OnSelect(); + + protected abstract void OnFocus(); + + protected abstract void OnFocusAndSelect(); + + protected abstract void OnHardStateSet(SelectionState selectionState); + + private void SetState(SelectionState state) + { + if (state != currentState) + { + previousState = currentState; + currentState = state; + switch (currentState) + { + case SelectionState.Default: + OnClear(); + break; + case SelectionState.Focussed: + OnFocus(); + break; + case SelectionState.Selected: + OnSelect(); + break; + case SelectionState.FocussedAndSelected: + OnFocusAndSelect(); + break; + } + onSelectionStateChange.Invoke(); + } + } + + public ThronefallUIElement TryNavigate(NavigationDirection direction) + { + if (SceneTransitionManager.instance.SceneTransitionIsRunning) + { + return this; + } + ThronefallUIElement thronefallUIElement = null; + switch (direction) + { + case NavigationDirection.Down: + thronefallUIElement = botNav; + break; + case NavigationDirection.Up: + thronefallUIElement = topNav; + break; + case NavigationDirection.Left: + thronefallUIElement = leftNav; + break; + case NavigationDirection.Right: + thronefallUIElement = rightNav; + break; + } + if ((bool)thronefallUIElement && !thronefallUIElement.gameObject.activeInHierarchy) + { + return thronefallUIElement.TryNavigate(direction); + } + onEmptyNavigate.Invoke(direction); + return thronefallUIElement; + } + + public virtual void OnDrag(Vector2 mousePosition) + { + } + + public virtual void OnDragEnd() + { + } + + public virtual void OnDragStart() + { + } +} -- cgit v1.1-26-g67d0