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