| | 1 | | using DCL; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public class TaskbarMoreMenu : MonoBehaviour |
| | 7 | | { |
| | 8 | | [Header("Menu Animation")] |
| | 9 | | [SerializeField] internal ShowHideAnimator moreMenuAnimator; |
| 22 | 10 | | [SerializeField] internal float timeBetweenAnimations = 0.01f; |
| | 11 | |
|
| | 12 | | [Header("Collapse Button Config")] |
| | 13 | | [SerializeField] internal TaskbarMoreMenuButton collapseBarButton; |
| | 14 | | [SerializeField] internal GameObject collapseIcon; |
| | 15 | | [SerializeField] internal GameObject collapseText; |
| | 16 | | [SerializeField] internal GameObject expandIcon; |
| | 17 | | [SerializeField] internal GameObject expandText; |
| | 18 | |
|
| | 19 | | [Header("Other Buttons Config")] |
| | 20 | | [SerializeField] internal TaskbarMoreMenuButton hideUIButton; |
| | 21 | | [SerializeField] internal TaskbarMoreMenuButton controlsButton; |
| | 22 | | [SerializeField] internal InputAction_Trigger controlsToggleAction; |
| | 23 | | [SerializeField] internal TaskbarMoreMenuButton helpAndSupportButton; |
| | 24 | | [SerializeField] internal TaskbarMoreMenuButton tutorialButton; |
| | 25 | | [SerializeField] internal TaskbarMoreMenuButton dayModeButton; |
| | 26 | | [SerializeField] internal TaskbarMoreMenuButton nightModeButton; |
| | 27 | |
|
| | 28 | | private TaskbarHUDView view; |
| 22 | 29 | | protected internal List<TaskbarMoreMenuButton> sortedButtonsAnimations = new List<TaskbarMoreMenuButton>(); |
| | 30 | | internal Coroutine moreMenuAnimationsCoroutine; |
| | 31 | |
|
| | 32 | | public event System.Action<bool> OnMoreMenuOpened; |
| | 33 | | public event System.Action OnRestartTutorial; |
| | 34 | |
|
| | 35 | | public virtual void Initialize(TaskbarHUDView view) |
| | 36 | | { |
| 11 | 37 | | this.view = view; |
| | 38 | |
|
| 11 | 39 | | CommonScriptableObjects.tutorialActive.OnChange += TutorialActive_OnChange; |
| | 40 | |
|
| 11 | 41 | | collapseBarButton.gameObject.SetActive(true); |
| 11 | 42 | | hideUIButton.gameObject.SetActive(true); |
| 11 | 43 | | controlsButton.gameObject.SetActive(false); |
| 11 | 44 | | helpAndSupportButton.gameObject.SetActive(false); |
| 11 | 45 | | tutorialButton.gameObject.SetActive(true); |
| | 46 | |
|
| 11 | 47 | | SortButtonsAnimations(); |
| | 48 | |
|
| 11 | 49 | | RenderProfileManifest.i.OnChangeProfile += OnChangeProfile; |
| 11 | 50 | | OnChangeProfile(RenderProfileManifest.i.currentProfile); |
| | 51 | |
|
| 11 | 52 | | dayModeButton.mainButton.onClick.AddListener(() => |
| | 53 | | { |
| 0 | 54 | | RenderProfileManifest.i.currentProfile = RenderProfileManifest.i.defaultProfile; |
| 0 | 55 | | RenderProfileManifest.i.currentProfile.Apply(); |
| 0 | 56 | | view.moreButton.SetToggleState(false); |
| 0 | 57 | | }); |
| | 58 | |
|
| 11 | 59 | | nightModeButton.mainButton.onClick.AddListener(() => |
| | 60 | | { |
| 0 | 61 | | RenderProfileManifest.i.currentProfile = RenderProfileManifest.i.nightProfile; |
| 0 | 62 | | RenderProfileManifest.i.currentProfile.Apply(); |
| 0 | 63 | | view.moreButton.SetToggleState(false); |
| 0 | 64 | | }); |
| | 65 | |
|
| 15 | 66 | | collapseBarButton.mainButton.onClick.AddListener(() => { ToggleCollapseBar(); }); |
| | 67 | |
|
| 11 | 68 | | hideUIButton.mainButton.onClick.AddListener(() => { ToggleHideUI(); }); |
| | 69 | |
|
| 11 | 70 | | tutorialButton.mainButton.onClick.AddListener(() => { OnRestartTutorial?.Invoke(); }); |
| 11 | 71 | | } |
| | 72 | |
|
| | 73 | | protected void SortButtonsAnimations() |
| | 74 | | { |
| 11 | 75 | | sortedButtonsAnimations.Add(helpAndSupportButton); |
| 11 | 76 | | sortedButtonsAnimations.Add(controlsButton); |
| 11 | 77 | | sortedButtonsAnimations.Add(hideUIButton); |
| 11 | 78 | | sortedButtonsAnimations.Add(nightModeButton); |
| 11 | 79 | | sortedButtonsAnimations.Add(dayModeButton); |
| 11 | 80 | | sortedButtonsAnimations.Add(tutorialButton); |
| 11 | 81 | | sortedButtonsAnimations.Add(collapseBarButton); |
| 11 | 82 | | } |
| | 83 | |
|
| | 84 | | private void OnChangeProfile(RenderProfileWorld profile) |
| | 85 | | { |
| 11 | 86 | | if (profile == RenderProfileManifest.i.defaultProfile) |
| | 87 | | { |
| 11 | 88 | | dayModeButton.gameObject.SetActive(false); |
| 11 | 89 | | nightModeButton.gameObject.SetActive(true); |
| | 90 | |
|
| 11 | 91 | | if (moreMenuAnimator.isVisible) |
| 0 | 92 | | nightModeButton.PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Visible); |
| 0 | 93 | | } |
| | 94 | | else |
| | 95 | | { |
| 0 | 96 | | dayModeButton.gameObject.SetActive(true); |
| 0 | 97 | | nightModeButton.gameObject.SetActive(false); |
| | 98 | |
|
| 0 | 99 | | if (moreMenuAnimator.isVisible) |
| 0 | 100 | | dayModeButton.PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Visible); |
| | 101 | | } |
| 11 | 102 | | } |
| | 103 | |
|
| | 104 | | private void OnDestroy() |
| | 105 | | { |
| 11 | 106 | | CommonScriptableObjects.tutorialActive.OnChange -= TutorialActive_OnChange; |
| 11 | 107 | | RenderProfileManifest.i.OnChangeProfile -= OnChangeProfile; |
| 11 | 108 | | } |
| | 109 | |
|
| | 110 | | private void TutorialActive_OnChange(bool current, bool previous) |
| | 111 | | { |
| 0 | 112 | | collapseBarButton.gameObject.SetActive(!current); |
| 0 | 113 | | hideUIButton.gameObject.SetActive(!current); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | internal void ActivateControlsButton() |
| | 117 | | { |
| 2 | 118 | | controlsButton.gameObject.SetActive(true); |
| | 119 | |
|
| 2 | 120 | | controlsButton.mainButton.onClick.AddListener(() => |
| | 121 | | { |
| 0 | 122 | | controlsToggleAction.RaiseOnTriggered(); |
| 0 | 123 | | view.moreButton.SetToggleState(false); |
| 0 | 124 | | }); |
| 2 | 125 | | } |
| | 126 | |
|
| | 127 | | internal void ActivateHelpAndSupportButton() |
| | 128 | | { |
| 2 | 129 | | helpAndSupportButton.gameObject.SetActive(true); |
| | 130 | |
|
| 2 | 131 | | helpAndSupportButton.mainButton.onClick.AddListener(() => |
| | 132 | | { |
| 0 | 133 | | view.controller.helpAndSupportHud.SetVisibility(true); |
| 0 | 134 | | view.moreButton.SetToggleState(false); |
| 0 | 135 | | }); |
| 2 | 136 | | } |
| | 137 | |
|
| | 138 | | internal void ShowMoreMenu(bool visible, bool instant = false) |
| | 139 | | { |
| 11 | 140 | | CoroutineStarter.Stop(moreMenuAnimationsCoroutine); |
| 11 | 141 | | moreMenuAnimationsCoroutine = CoroutineStarter.Start(PlayMoreMenuAnimations(visible, instant)); |
| 11 | 142 | | OnMoreMenuOpened?.Invoke(visible); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | private IEnumerator PlayMoreMenuAnimations(bool visible, bool instant = false) |
| | 146 | | { |
| 11 | 147 | | if (visible) |
| | 148 | | { |
| 0 | 149 | | moreMenuAnimator.Show(instant); |
| | 150 | |
|
| 0 | 151 | | for (int i = 0; i < sortedButtonsAnimations.Count; i++) |
| | 152 | | { |
| 0 | 153 | | if (!sortedButtonsAnimations[i].gameObject.activeInHierarchy || |
| | 154 | | sortedButtonsAnimations[i].lastPlayedAnimation == TaskbarMoreMenuButton.AnimationStatus.In) |
| | 155 | | { |
| | 156 | | continue; |
| | 157 | | } |
| | 158 | |
|
| 0 | 159 | | sortedButtonsAnimations[i].PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.In); |
| 0 | 160 | | yield return new WaitForSeconds(timeBetweenAnimations); |
| | 161 | | } |
| 0 | 162 | | } |
| | 163 | | else |
| | 164 | | { |
| 22 | 165 | | for (int j = sortedButtonsAnimations.Count - 1; j >= 0; j--) |
| | 166 | | { |
| 11 | 167 | | if (!sortedButtonsAnimations[j].gameObject.activeInHierarchy || |
| | 168 | | sortedButtonsAnimations[j].lastPlayedAnimation == TaskbarMoreMenuButton.AnimationStatus.Out) |
| | 169 | | { |
| | 170 | | continue; |
| | 171 | | } |
| | 172 | |
|
| 11 | 173 | | sortedButtonsAnimations[j].PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Out); |
| 11 | 174 | | yield return new WaitForSeconds(timeBetweenAnimations); |
| | 175 | | } |
| | 176 | |
|
| 0 | 177 | | if (sortedButtonsAnimations.Count > 0) |
| 0 | 178 | | yield return new WaitForSeconds(sortedButtonsAnimations[0].GetAnimationLenght()); |
| | 179 | |
|
| 0 | 180 | | moreMenuAnimator.Hide(instant); |
| | 181 | | } |
| 0 | 182 | | } |
| | 183 | |
|
| 0 | 184 | | internal void ShowTutorialButton(bool visible) { tutorialButton.gameObject.SetActive(visible); } |
| | 185 | |
|
| | 186 | | private void ToggleCollapseBar() |
| | 187 | | { |
| 2 | 188 | | if (CommonScriptableObjects.tutorialActive) |
| 0 | 189 | | return; |
| | 190 | |
|
| 2 | 191 | | view.ShowBar(!view.isBarVisible); |
| | 192 | |
|
| 2 | 193 | | collapseIcon.SetActive(view.isBarVisible); |
| 2 | 194 | | collapseText.SetActive(view.isBarVisible); |
| 2 | 195 | | expandIcon.SetActive(!view.isBarVisible); |
| 2 | 196 | | expandText.SetActive(!view.isBarVisible); |
| | 197 | |
|
| 2 | 198 | | view.moreButton.SetToggleState(false); |
| 2 | 199 | | } |
| | 200 | |
|
| | 201 | | private void ToggleHideUI() |
| | 202 | | { |
| 0 | 203 | | if (CommonScriptableObjects.tutorialActive) |
| 0 | 204 | | return; |
| | 205 | |
|
| 0 | 206 | | CommonScriptableObjects.allUIHidden.Set(!CommonScriptableObjects.allUIHidden.Get()); |
| 0 | 207 | | view.moreButton.SetToggleState(false); |
| 0 | 208 | | } |
| | 209 | | } |