| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public class TaskbarHUDView : MonoBehaviour |
| | 6 | | { |
| | 7 | | const string VIEW_PATH = "Taskbar"; |
| | 8 | |
|
| | 9 | | [Header("Taskbar Animation")] |
| | 10 | | [SerializeField] internal ShowHideAnimator taskbarAnimator; |
| | 11 | |
|
| | 12 | | [Header("Left Side Config")] |
| | 13 | | [SerializeField] internal RectTransform leftWindowContainer; |
| | 14 | |
|
| | 15 | | [SerializeField] internal ShowHideAnimator leftWindowContainerAnimator; |
| | 16 | | [SerializeField] internal LayoutGroup leftWindowContainerLayout; |
| | 17 | | [SerializeField] internal GameObject voiceChatButtonPlaceholder; |
| | 18 | | [SerializeField] internal VoiceChatButton voiceChatButton; |
| | 19 | | [SerializeField] internal TaskbarButton chatButton; |
| | 20 | | [SerializeField] internal TaskbarButton friendsButton; |
| | 21 | | [SerializeField] internal ChatHeadGroupView chatHeadsGroup; |
| | 22 | |
|
| | 23 | | [SerializeField] internal GameObject experiencesContainer; |
| | 24 | | [SerializeField] internal TaskbarButton experiencesButton; |
| | 25 | |
|
| | 26 | | [SerializeField] internal RectTransform socialTooltipReference; |
| | 27 | |
|
| | 28 | | [Header("Old TaskbarCompatibility (temporal)")] |
| | 29 | | [SerializeField] internal RectTransform taskbarPanelTransf; |
| | 30 | |
|
| | 31 | | [SerializeField] internal Image taskbarPanelImage; |
| | 32 | |
|
| | 33 | | internal TaskbarHUDController controller; |
| 5 | 34 | | internal bool isBarVisible = true; |
| | 35 | |
|
| | 36 | | public event System.Action OnChatToggleOn; |
| | 37 | | public event System.Action OnChatToggleOff; |
| | 38 | | public event System.Action OnFriendsToggleOn; |
| | 39 | | public event System.Action OnFriendsToggleOff; |
| | 40 | | public event System.Action OnExperiencesToggleOn; |
| | 41 | | public event System.Action OnExperiencesToggleOff; |
| | 42 | |
|
| | 43 | | internal List<TaskbarButton> GetButtonList() |
| | 44 | | { |
| 14 | 45 | | var taskbarButtonList = new List<TaskbarButton>(); |
| 14 | 46 | | taskbarButtonList.Add(chatButton); |
| 14 | 47 | | taskbarButtonList.Add(friendsButton); |
| 14 | 48 | | taskbarButtonList.AddRange(chatHeadsGroup.chatHeads); |
| 14 | 49 | | taskbarButtonList.Add(experiencesButton); |
| | 50 | |
|
| 14 | 51 | | return taskbarButtonList; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | internal static TaskbarHUDView Create(TaskbarHUDController controller, IChatController chatController, |
| | 55 | | IFriendsController friendsController) |
| | 56 | | { |
| 4 | 57 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<TaskbarHUDView>(); |
| 4 | 58 | | view.Initialize(controller, chatController, friendsController); |
| 4 | 59 | | return view; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public void Initialize(TaskbarHUDController controller, IChatController chatController, |
| | 63 | | IFriendsController friendsController) |
| | 64 | | { |
| 4 | 65 | | this.controller = controller; |
| | 66 | |
|
| 4 | 67 | | ShowBar(true, true); |
| 4 | 68 | | chatButton.transform.parent.gameObject.SetActive(false); |
| 4 | 69 | | friendsButton.transform.parent.gameObject.SetActive(false); |
| 4 | 70 | | experiencesButton.transform.parent.gameObject.SetActive(false); |
| 4 | 71 | | voiceChatButtonPlaceholder.SetActive(false); |
| 4 | 72 | | voiceChatButton.gameObject.SetActive(false); |
| | 73 | |
|
| 4 | 74 | | chatHeadsGroup.Initialize(chatController, friendsController); |
| 4 | 75 | | chatButton.Initialize(); |
| 4 | 76 | | friendsButton.Initialize(); |
| 4 | 77 | | experiencesButton.Initialize(); |
| | 78 | |
|
| 4 | 79 | | chatHeadsGroup.OnHeadToggleOn += OnWindowToggleOn; |
| 4 | 80 | | chatHeadsGroup.OnHeadToggleOff += OnWindowToggleOff; |
| | 81 | |
|
| 4 | 82 | | chatButton.OnToggleOn += OnWindowToggleOn; |
| 4 | 83 | | chatButton.OnToggleOff += OnWindowToggleOff; |
| | 84 | |
|
| 4 | 85 | | friendsButton.OnToggleOn += OnWindowToggleOn; |
| 4 | 86 | | friendsButton.OnToggleOff += OnWindowToggleOff; |
| | 87 | |
|
| 4 | 88 | | experiencesButton.OnToggleOn += OnWindowToggleOn; |
| 4 | 89 | | experiencesButton.OnToggleOff += OnWindowToggleOff; |
| 4 | 90 | | } |
| | 91 | |
|
| | 92 | | private void OnWindowToggleOff(TaskbarButton obj) |
| | 93 | | { |
| 5 | 94 | | if (obj == friendsButton) |
| 2 | 95 | | OnFriendsToggleOff?.Invoke(); |
| 3 | 96 | | else if (obj == chatButton) |
| 2 | 97 | | OnChatToggleOff?.Invoke(); |
| 1 | 98 | | else if (obj == experiencesButton) |
| 0 | 99 | | OnExperiencesToggleOff?.Invoke(); |
| | 100 | |
|
| 5 | 101 | | if (AllButtonsToggledOff()) |
| | 102 | | { |
| 5 | 103 | | chatButton.SetToggleState(false, useCallback: false); |
| 5 | 104 | | controller.worldChatWindowHud.SetVisibility(true); |
| | 105 | | } |
| 5 | 106 | | } |
| | 107 | |
|
| | 108 | | public bool AllButtonsToggledOff() |
| | 109 | | { |
| 7 | 110 | | var btns = GetButtonList(); |
| | 111 | |
|
| 7 | 112 | | bool allToggledOff = true; |
| | 113 | |
|
| 62 | 114 | | foreach (var btn in btns) |
| | 115 | | { |
| 24 | 116 | | if (btn.toggledOn) |
| 0 | 117 | | allToggledOff = false; |
| | 118 | | } |
| | 119 | |
|
| 7 | 120 | | return allToggledOff; |
| | 121 | | } |
| | 122 | |
|
| | 123 | | private void OnWindowToggleOn(TaskbarButton obj) |
| | 124 | | { |
| 6 | 125 | | if (obj == friendsButton) |
| 2 | 126 | | OnFriendsToggleOn?.Invoke(); |
| 4 | 127 | | else if (obj == chatButton) |
| 3 | 128 | | OnChatToggleOn?.Invoke(); |
| 1 | 129 | | else if (obj == experiencesButton) |
| 0 | 130 | | OnExperiencesToggleOn?.Invoke(); |
| | 131 | |
|
| 6 | 132 | | SelectButton(obj); |
| 6 | 133 | | } |
| | 134 | |
|
| | 135 | | public void SelectButton(TaskbarButton obj) |
| | 136 | | { |
| 6 | 137 | | var taskbarButtonList = GetButtonList(); |
| | 138 | |
|
| 56 | 139 | | foreach (var btn in taskbarButtonList) |
| | 140 | | { |
| 22 | 141 | | if (btn != obj) |
| 16 | 142 | | btn.SetToggleState(false, useCallback: true); |
| | 143 | | } |
| 6 | 144 | | } |
| | 145 | |
|
| 4 | 146 | | internal void OnAddChatWindow() { chatButton.transform.parent.gameObject.SetActive(true); } |
| | 147 | |
|
| 6 | 148 | | internal void OnAddFriendsWindow() { friendsButton.transform.parent.gameObject.SetActive(true); } |
| | 149 | |
|
| 0 | 150 | | internal void OnAddExperiencesWindow() { experiencesButton.transform.parent.gameObject.SetActive(true); } |
| | 151 | |
|
| | 152 | | internal void OnAddVoiceChat() |
| | 153 | | { |
| 0 | 154 | | voiceChatButtonPlaceholder.SetActive(true); |
| 0 | 155 | | voiceChatButton.gameObject.SetActive(true); |
| 0 | 156 | | } |
| | 157 | |
|
| | 158 | | internal void ShowBar(bool visible, bool instant = false) |
| | 159 | | { |
| 4 | 160 | | if (visible) |
| 4 | 161 | | taskbarAnimator.Show(instant); |
| | 162 | | else |
| 0 | 163 | | taskbarAnimator.Hide(instant); |
| | 164 | |
|
| 4 | 165 | | isBarVisible = visible; |
| 4 | 166 | | } |
| | 167 | |
|
| 2 | 168 | | public void SetVisibility(bool visible) { gameObject.SetActive(visible); } |
| | 169 | |
|
| 8 | 170 | | public void SetExperiencesVisbility(bool visible) { experiencesContainer.SetActive(visible); } |
| | 171 | |
|
| | 172 | | private void OnDestroy() |
| | 173 | | { |
| 4 | 174 | | if (chatHeadsGroup != null) |
| | 175 | | { |
| 4 | 176 | | chatHeadsGroup.OnHeadToggleOn -= OnWindowToggleOn; |
| 4 | 177 | | chatHeadsGroup.OnHeadToggleOff -= OnWindowToggleOff; |
| | 178 | | } |
| | 179 | |
|
| 4 | 180 | | if (chatButton != null) |
| | 181 | | { |
| 4 | 182 | | chatButton.OnToggleOn -= OnWindowToggleOn; |
| 4 | 183 | | chatButton.OnToggleOff -= OnWindowToggleOff; |
| | 184 | | } |
| | 185 | |
|
| 4 | 186 | | if (friendsButton != null) |
| | 187 | | { |
| 4 | 188 | | friendsButton.OnToggleOn -= OnWindowToggleOn; |
| 4 | 189 | | friendsButton.OnToggleOff -= OnWindowToggleOff; |
| | 190 | | } |
| | 191 | |
|
| 4 | 192 | | if (experiencesButton != null) |
| | 193 | | { |
| 4 | 194 | | experiencesButton.OnToggleOn -= OnWindowToggleOn; |
| 4 | 195 | | experiencesButton.OnToggleOff -= OnWindowToggleOff; |
| | 196 | | } |
| 4 | 197 | | } |
| | 198 | | } |