| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.EventSystems; |
| | 6 | |
|
| | 7 | | public class TaskbarHUDController : IHUD |
| | 8 | | { |
| | 9 | | [Serializable] |
| | 10 | | public struct Configuration |
| | 11 | | { |
| | 12 | | public bool enableVoiceChat; |
| | 13 | | public bool enableQuestPanel; |
| | 14 | | } |
| | 15 | |
|
| | 16 | | public TaskbarHUDView view; |
| | 17 | | public WorldChatWindowController worldChatWindowHud; |
| | 18 | | public PrivateChatWindowController privateChatWindow; |
| | 19 | | public PublicChatChannelController publicChatChannel; |
| | 20 | | public FriendsHUDController friendsHud; |
| | 21 | | public VoiceChatWindowController voiceChatHud; |
| | 22 | |
|
| | 23 | | private IMouseCatcher mouseCatcher; |
| | 24 | | private InputAction_Trigger toggleFriendsTrigger; |
| | 25 | | private InputAction_Trigger closeWindowTrigger; |
| | 26 | | private InputAction_Trigger toggleWorldChatTrigger; |
| | 27 | | private Transform experiencesViewerTransform; |
| | 28 | | private IHUD chatToggleTargetWindow; |
| | 29 | | private IHUD chatInputTargetWindow; |
| | 30 | | private IHUD chatBackWindow; |
| | 31 | |
|
| | 32 | | public event Action OnAnyTaskbarButtonClicked; |
| | 33 | |
|
| 0 | 34 | | public RectTransform socialTooltipReference => view.socialTooltipReference; |
| | 35 | |
|
| 12 | 36 | | internal BaseVariable<bool> isEmotesWheelInitialized => DataStore.i.emotesCustomization.isWheelInitialized; |
| 11 | 37 | | internal BaseVariable<bool> isEmotesVisible => DataStore.i.HUDs.emotesVisible; |
| 0 | 38 | | internal BaseVariable<bool> emoteJustTriggeredFromShortcut => DataStore.i.HUDs.emoteJustTriggeredFromShortcut; |
| 12 | 39 | | internal BaseVariable<Transform> isExperiencesViewerInitialized => DataStore.i.experiencesViewer.isInitialized; |
| 15 | 40 | | internal BaseVariable<bool> isExperiencesViewerOpen => DataStore.i.experiencesViewer.isOpen; |
| 12 | 41 | | internal BaseVariable<int> numOfLoadedExperiences => DataStore.i.experiencesViewer.numOfLoadedExperiences; |
| | 42 | |
|
| 4 | 43 | | protected virtual TaskbarHUDView CreateView() { return TaskbarHUDView.Create(); } |
| | 44 | |
|
| | 45 | | public void Initialize(IMouseCatcher mouseCatcher) |
| | 46 | | { |
| 4 | 47 | | this.mouseCatcher = mouseCatcher; |
| | 48 | |
|
| 4 | 49 | | view = CreateView(); |
| | 50 | |
|
| 4 | 51 | | if (mouseCatcher != null) |
| | 52 | | { |
| 1 | 53 | | mouseCatcher.OnMouseLock -= MouseCatcher_OnMouseLock; |
| 1 | 54 | | mouseCatcher.OnMouseUnlock -= MouseCatcher_OnMouseUnlock; |
| 1 | 55 | | mouseCatcher.OnMouseLock += MouseCatcher_OnMouseLock; |
| 1 | 56 | | mouseCatcher.OnMouseUnlock += MouseCatcher_OnMouseUnlock; |
| | 57 | | } |
| | 58 | |
|
| 4 | 59 | | view.leftWindowContainerLayout.enabled = false; |
| | 60 | |
|
| 4 | 61 | | view.OnChatToggle += HandleChatToggle; |
| 4 | 62 | | view.OnFriendsToggle += HandleFriendsToggle; |
| 4 | 63 | | view.OnEmotesToggle += HandleEmotesToggle; |
| 4 | 64 | | view.OnExperiencesToggle += HandleExperiencesToggle; |
| 4 | 65 | | view.OnVoiceChatToggle += HandleVoiceChatToggle; |
| | 66 | |
|
| 4 | 67 | | toggleFriendsTrigger = Resources.Load<InputAction_Trigger>("ToggleFriends"); |
| 4 | 68 | | toggleFriendsTrigger.OnTriggered -= ToggleFriendsTrigger_OnTriggered; |
| 4 | 69 | | toggleFriendsTrigger.OnTriggered += ToggleFriendsTrigger_OnTriggered; |
| | 70 | |
|
| 4 | 71 | | closeWindowTrigger = Resources.Load<InputAction_Trigger>("CloseWindow"); |
| 4 | 72 | | closeWindowTrigger.OnTriggered -= CloseWindowTrigger_OnTriggered; |
| 4 | 73 | | closeWindowTrigger.OnTriggered += CloseWindowTrigger_OnTriggered; |
| | 74 | |
|
| 4 | 75 | | toggleWorldChatTrigger = Resources.Load<InputAction_Trigger>("ToggleWorldChat"); |
| 4 | 76 | | toggleWorldChatTrigger.OnTriggered -= ToggleWorldChatTrigger_OnTriggered; |
| 4 | 77 | | toggleWorldChatTrigger.OnTriggered += ToggleWorldChatTrigger_OnTriggered; |
| | 78 | |
|
| 4 | 79 | | isEmotesWheelInitialized.OnChange += InitializeEmotesSelector; |
| 4 | 80 | | InitializeEmotesSelector(isEmotesWheelInitialized.Get(), false); |
| 4 | 81 | | isEmotesVisible.OnChange += IsEmotesVisibleChanged; |
| | 82 | |
|
| 4 | 83 | | isExperiencesViewerOpen.OnChange += IsExperiencesViewerOpenChanged; |
| | 84 | |
|
| 4 | 85 | | view.leftWindowContainerAnimator.Show(); |
| | 86 | |
|
| 4 | 87 | | CommonScriptableObjects.isTaskbarHUDInitialized.Set(true); |
| 4 | 88 | | DataStore.i.builderInWorld.showTaskBar.OnChange += SetVisibility; |
| | 89 | |
|
| 4 | 90 | | isExperiencesViewerInitialized.OnChange += InitializeExperiencesViewer; |
| 4 | 91 | | InitializeExperiencesViewer(isExperiencesViewerInitialized.Get(), null); |
| | 92 | |
|
| 4 | 93 | | numOfLoadedExperiences.OnChange += NumOfLoadedExperiencesChanged; |
| 4 | 94 | | NumOfLoadedExperiencesChanged(numOfLoadedExperiences.Get(), 0); |
| 4 | 95 | | } |
| | 96 | |
|
| | 97 | | private void HandleFriendsToggle(bool show) |
| | 98 | | { |
| 3 | 99 | | if (show) |
| 2 | 100 | | OpenFriendsWindow(); |
| | 101 | | else |
| | 102 | | { |
| 1 | 103 | | friendsHud?.SetVisibility(false); |
| 1 | 104 | | OpenPublicChannelOnPreviewMode(); |
| | 105 | | } |
| | 106 | |
|
| 3 | 107 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | private void HandleEmotesToggle(bool show) |
| | 111 | | { |
| 0 | 112 | | if (show && emoteJustTriggeredFromShortcut.Get()) |
| | 113 | | { |
| 0 | 114 | | emoteJustTriggeredFromShortcut.Set(false); |
| 0 | 115 | | return; |
| | 116 | | } |
| | 117 | |
|
| 0 | 118 | | if (show) |
| | 119 | | { |
| 0 | 120 | | OpenPublicChannelOnPreviewMode(); |
| 0 | 121 | | ShowEmotes(); |
| 0 | 122 | | } |
| | 123 | | else |
| | 124 | | { |
| 0 | 125 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Emotes); |
| 0 | 126 | | isEmotesVisible.Set(false); |
| 0 | 127 | | OpenPublicChannelOnPreviewMode(); |
| | 128 | | } |
| 0 | 129 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | private void ShowEmotes() |
| | 133 | | { |
| 0 | 134 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 135 | | privateChatWindow.SetVisibility(false); |
| 0 | 136 | | friendsHud?.SetVisibility(false); |
| 0 | 137 | | isExperiencesViewerOpen.Set(false); |
| 0 | 138 | | voiceChatHud?.SetVisibility(false); |
| 0 | 139 | | isEmotesVisible.Set(true); |
| 0 | 140 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Emotes); |
| 0 | 141 | | } |
| | 142 | |
|
| | 143 | | private void HandleExperiencesToggle(bool show) |
| | 144 | | { |
| 0 | 145 | | if (show) |
| 0 | 146 | | ShowExperiences(); |
| | 147 | | else |
| | 148 | | { |
| 0 | 149 | | isExperiencesViewerOpen.Set(false); |
| 0 | 150 | | OpenPublicChannelOnPreviewMode(); |
| | 151 | | } |
| | 152 | |
|
| 0 | 153 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 154 | | } |
| | 155 | |
|
| | 156 | | private void HandleVoiceChatToggle(bool show) |
| | 157 | | { |
| 0 | 158 | | if (show) |
| 0 | 159 | | OpenVoiceChatWindow(); |
| | 160 | | else |
| 0 | 161 | | voiceChatHud?.SetVisibility(false); |
| 0 | 162 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 163 | | } |
| | 164 | |
|
| | 165 | | private void ShowExperiences() |
| | 166 | | { |
| 0 | 167 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 168 | | privateChatWindow.SetVisibility(false); |
| 0 | 169 | | publicChatChannel.SetVisibility(false); |
| 0 | 170 | | friendsHud?.SetVisibility(false); |
| 0 | 171 | | isEmotesVisible.Set(false); |
| 0 | 172 | | voiceChatHud?.SetVisibility(false); |
| 0 | 173 | | isExperiencesViewerOpen.Set(true); |
| 0 | 174 | | } |
| | 175 | |
|
| | 176 | | private void ToggleFriendsTrigger_OnTriggered(DCLAction_Trigger action) |
| | 177 | | { |
| 0 | 178 | | if (friendsHud == null) return; |
| | 179 | |
|
| 0 | 180 | | bool anyInputFieldIsSelected = EventSystem.current != null && |
| | 181 | | EventSystem.current.currentSelectedGameObject != null && |
| | 182 | | EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != n |
| | 183 | |
|
| 0 | 184 | | if (anyInputFieldIsSelected) return; |
| | 185 | |
|
| | 186 | |
|
| 0 | 187 | | mouseCatcher.UnlockCursor(); |
| | 188 | |
|
| 0 | 189 | | if (!friendsHud.View.IsActive()) |
| | 190 | | { |
| 0 | 191 | | view.leftWindowContainerAnimator.Show(); |
| 0 | 192 | | OpenFriendsWindow(); |
| 0 | 193 | | } |
| | 194 | | else |
| | 195 | | { |
| 0 | 196 | | CloseFriendsWindow(); |
| 0 | 197 | | OpenPublicChannelOnPreviewMode(); |
| | 198 | | } |
| 0 | 199 | | } |
| | 200 | |
|
| | 201 | | private void ToggleWorldChatTrigger_OnTriggered(DCLAction_Trigger action) |
| | 202 | | { |
| 0 | 203 | | bool anyInputFieldIsSelected = EventSystem.current != null && |
| | 204 | | EventSystem.current.currentSelectedGameObject != null && |
| | 205 | | EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != n |
| | 206 | |
|
| 0 | 207 | | if (anyInputFieldIsSelected) return; |
| | 208 | |
|
| 0 | 209 | | mouseCatcher.UnlockCursor(); |
| 0 | 210 | | chatBackWindow = worldChatWindowHud; |
| | 211 | |
|
| 0 | 212 | | if (!worldChatWindowHud.View.IsActive |
| | 213 | | && !privateChatWindow.View.IsActive |
| | 214 | | && !publicChatChannel.View.IsActive) |
| 0 | 215 | | OpenLastActiveChatWindow(chatInputTargetWindow); |
| 0 | 216 | | } |
| | 217 | |
|
| | 218 | | private void CloseWindowTrigger_OnTriggered(DCLAction_Trigger action) |
| | 219 | | { |
| 0 | 220 | | if (mouseCatcher.isLocked) return; |
| 0 | 221 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 222 | | privateChatWindow.SetVisibility(false); |
| 0 | 223 | | friendsHud?.SetVisibility(false); |
| 0 | 224 | | isEmotesVisible.Set(false); |
| 0 | 225 | | isExperiencesViewerOpen.Set(false); |
| 0 | 226 | | voiceChatHud?.SetVisibility(false); |
| 0 | 227 | | OpenPublicChannelOnPreviewMode(); |
| 0 | 228 | | } |
| | 229 | |
|
| | 230 | | private void HandleChatToggle(bool show) |
| | 231 | | { |
| 1 | 232 | | if (show) |
| | 233 | | { |
| 1 | 234 | | chatBackWindow = publicChatChannel; |
| 1 | 235 | | var openedWindow = OpenLastActiveChatWindow(chatToggleTargetWindow); |
| 1 | 236 | | if (openedWindow == publicChatChannel) |
| 1 | 237 | | publicChatChannel.DeactivatePreview(); |
| 0 | 238 | | else if (openedWindow == privateChatWindow) |
| 0 | 239 | | privateChatWindow.DeactivatePreview(); |
| 0 | 240 | | } |
| | 241 | | else |
| | 242 | | { |
| 0 | 243 | | if (chatToggleTargetWindow == publicChatChannel) |
| 0 | 244 | | publicChatChannel.ActivatePreview(); |
| 0 | 245 | | else if (chatToggleTargetWindow == privateChatWindow) |
| 0 | 246 | | privateChatWindow.ActivatePreview(); |
| | 247 | | else |
| | 248 | | { |
| 0 | 249 | | CloseAnyChatWindow(); |
| 0 | 250 | | OpenPublicChannelOnPreviewMode(); |
| | 251 | | } |
| | 252 | | } |
| | 253 | |
|
| 1 | 254 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 255 | | } |
| | 256 | |
|
| | 257 | | private void MouseCatcher_OnMouseUnlock() |
| | 258 | | { |
| | 259 | | // TODO: temporary deactivated current window fadein/fadeout until we get the full chat notifications feature im |
| | 260 | | // view.leftWindowContainerAnimator.Show(); |
| | 261 | | // view.RestoreLastToggle(); |
| 0 | 262 | | } |
| | 263 | |
|
| | 264 | | private void MouseCatcher_OnMouseLock() |
| | 265 | | { |
| | 266 | | // TODO: temporary deactivated current window fadein/fadeout until we get the full chat notifications feature im |
| | 267 | | // view.leftWindowContainerAnimator.Hide(); |
| | 268 | | // view.ToggleAllOff(); |
| 0 | 269 | | CloseFriendsWindow(); |
| 0 | 270 | | CloseChatList(); |
| 0 | 271 | | CloseVoiceChatWindow(); |
| 0 | 272 | | isExperiencesViewerOpen.Set(false); |
| | 273 | |
|
| 0 | 274 | | if (!privateChatWindow.View.IsActive |
| | 275 | | && !publicChatChannel.View.IsActive) |
| 0 | 276 | | OpenPublicChannelOnPreviewMode(); |
| 0 | 277 | | } |
| | 278 | |
|
| | 279 | | public void AddWorldChatWindow(WorldChatWindowController controller) |
| | 280 | | { |
| 2 | 281 | | if (controller?.View == null) |
| | 282 | | { |
| 0 | 283 | | Debug.LogWarning("AddChatWindow >>> World Chat Window doesn't exist yet!"); |
| 0 | 284 | | return; |
| | 285 | | } |
| | 286 | |
|
| 2 | 287 | | if (controller.View.Transform.parent == view.leftWindowContainer) return; |
| | 288 | |
|
| 2 | 289 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 2 | 290 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 291 | |
|
| 2 | 292 | | worldChatWindowHud = controller; |
| | 293 | |
|
| 2 | 294 | | view.ShowChatButton(); |
| 2 | 295 | | worldChatWindowHud.View.OnClose += OpenPublicChannelOnPreviewMode; |
| 2 | 296 | | } |
| | 297 | |
|
| | 298 | | private void OpenPublicChannelOnPreviewMode() |
| | 299 | | { |
| 1 | 300 | | chatToggleTargetWindow = publicChatChannel; |
| 1 | 301 | | publicChatChannel.SetVisibility(true, false); |
| 1 | 302 | | publicChatChannel.ActivatePreviewModeInstantly(); |
| 1 | 303 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| 1 | 304 | | } |
| | 305 | |
|
| | 306 | | private void OpenFriendsWindow() |
| | 307 | | { |
| 2 | 308 | | worldChatWindowHud.SetVisibility(false); |
| 2 | 309 | | privateChatWindow.SetVisibility(false); |
| 2 | 310 | | publicChatChannel.SetVisibility(false); |
| 2 | 311 | | isExperiencesViewerOpen.Set(false); |
| 2 | 312 | | isEmotesVisible.Set(false); |
| 2 | 313 | | voiceChatHud?.SetVisibility(false); |
| 2 | 314 | | friendsHud?.SetVisibility(true); |
| 2 | 315 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Friends); |
| 2 | 316 | | chatBackWindow = friendsHud; |
| 2 | 317 | | } |
| | 318 | |
|
| | 319 | | private void CloseFriendsWindow() |
| | 320 | | { |
| 0 | 321 | | friendsHud?.SetVisibility(false); |
| 0 | 322 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Friends); |
| 0 | 323 | | } |
| | 324 | |
|
| | 325 | | public void OpenPrivateChat(string userId) |
| | 326 | | { |
| 0 | 327 | | privateChatWindow.Setup(userId); |
| 0 | 328 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 329 | | publicChatChannel.SetVisibility(false); |
| 0 | 330 | | friendsHud?.SetVisibility(false); |
| 0 | 331 | | isExperiencesViewerOpen.Set(false); |
| 0 | 332 | | isEmotesVisible.Set(false); |
| 0 | 333 | | voiceChatHud?.SetVisibility(false); |
| 0 | 334 | | privateChatWindow.SetVisibility(true); |
| 0 | 335 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 336 | | chatToggleTargetWindow = privateChatWindow; |
| 0 | 337 | | chatInputTargetWindow = privateChatWindow; |
| 0 | 338 | | } |
| | 339 | |
|
| | 340 | | private IHUD OpenLastActiveChatWindow(IHUD lastActiveWindow) |
| | 341 | | { |
| 1 | 342 | | worldChatWindowHud.SetVisibility(false); |
| 1 | 343 | | privateChatWindow.SetVisibility(false); |
| 1 | 344 | | publicChatChannel.SetVisibility(false); |
| 1 | 345 | | friendsHud?.SetVisibility(false); |
| 1 | 346 | | isEmotesVisible.Set(false); |
| 1 | 347 | | isExperiencesViewerOpen.Set(false); |
| 1 | 348 | | voiceChatHud?.SetVisibility(false); |
| | 349 | |
|
| | 350 | | IHUD visibleWindow; |
| | 351 | |
|
| 1 | 352 | | if (lastActiveWindow == publicChatChannel) |
| | 353 | | { |
| 1 | 354 | | publicChatChannel.SetVisibility(true, true); |
| 1 | 355 | | visibleWindow = lastActiveWindow; |
| 1 | 356 | | } |
| 0 | 357 | | else if (lastActiveWindow != null) |
| | 358 | | { |
| 0 | 359 | | lastActiveWindow.SetVisibility(true); |
| 0 | 360 | | visibleWindow = lastActiveWindow; |
| 0 | 361 | | } |
| | 362 | | else |
| | 363 | | { |
| 0 | 364 | | publicChatChannel.SetVisibility(true, true); |
| 0 | 365 | | visibleWindow = publicChatChannel; |
| | 366 | | } |
| | 367 | |
|
| 1 | 368 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| | 369 | |
|
| 1 | 370 | | return visibleWindow; |
| | 371 | | } |
| | 372 | |
|
| | 373 | | private void CloseAnyChatWindow() |
| | 374 | | { |
| 0 | 375 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 376 | | privateChatWindow.SetVisibility(false); |
| 0 | 377 | | publicChatChannel.SetVisibility(false); |
| 0 | 378 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 379 | | } |
| | 380 | |
|
| | 381 | | public void OpenPublicChatChannel(string channelId, bool focusInputField) |
| | 382 | | { |
| 0 | 383 | | publicChatChannel?.Setup(channelId); |
| 0 | 384 | | worldChatWindowHud?.SetVisibility(false); |
| 0 | 385 | | privateChatWindow?.SetVisibility(false); |
| 0 | 386 | | friendsHud?.SetVisibility(false); |
| 0 | 387 | | isExperiencesViewerOpen?.Set(false); |
| 0 | 388 | | isEmotesVisible?.Set(false); |
| 0 | 389 | | voiceChatHud?.SetVisibility(false); |
| 0 | 390 | | publicChatChannel?.SetVisibility(true, focusInputField); |
| 0 | 391 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 392 | | chatToggleTargetWindow = publicChatChannel; |
| 0 | 393 | | chatInputTargetWindow = publicChatChannel; |
| 0 | 394 | | } |
| | 395 | |
|
| | 396 | | private void OpenChatList() |
| | 397 | | { |
| 0 | 398 | | privateChatWindow.SetVisibility(false); |
| 0 | 399 | | publicChatChannel.SetVisibility(false); |
| 0 | 400 | | friendsHud?.SetVisibility(false); |
| 0 | 401 | | isExperiencesViewerOpen.Set(false); |
| 0 | 402 | | isEmotesVisible.Set(false); |
| 0 | 403 | | voiceChatHud?.SetVisibility(false); |
| 0 | 404 | | worldChatWindowHud.SetVisibility(true); |
| 0 | 405 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 406 | | chatToggleTargetWindow = worldChatWindowHud; |
| 0 | 407 | | } |
| | 408 | |
|
| | 409 | | private void CloseChatList() |
| | 410 | | { |
| 0 | 411 | | if (!worldChatWindowHud.View.IsActive) return; |
| 0 | 412 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 413 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 414 | | } |
| | 415 | |
|
| | 416 | | private void OpenVoiceChatWindow() |
| | 417 | | { |
| 0 | 418 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 419 | | privateChatWindow.SetVisibility(false); |
| 0 | 420 | | publicChatChannel.SetVisibility(false); |
| 0 | 421 | | isExperiencesViewerOpen.Set(false); |
| 0 | 422 | | isEmotesVisible.Set(false); |
| 0 | 423 | | friendsHud?.SetVisibility(false); |
| 0 | 424 | | voiceChatHud?.SetVisibility(true); |
| 0 | 425 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.VoiceChat); |
| 0 | 426 | | } |
| | 427 | |
|
| | 428 | | private void CloseVoiceChatWindow() |
| | 429 | | { |
| 0 | 430 | | voiceChatHud?.SetVisibility(false); |
| 0 | 431 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.VoiceChat); |
| 0 | 432 | | } |
| | 433 | |
|
| | 434 | | public void AddPrivateChatWindow(PrivateChatWindowController controller) |
| | 435 | | { |
| 1 | 436 | | if (controller?.View == null) |
| | 437 | | { |
| 0 | 438 | | Debug.LogWarning("AddPrivateChatWindow >>> Private Chat Window doesn't exist yet!"); |
| 0 | 439 | | return; |
| | 440 | | } |
| | 441 | |
|
| 1 | 442 | | if (controller.View.Transform.parent == view.leftWindowContainer) |
| 0 | 443 | | return; |
| | 444 | |
|
| 1 | 445 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 1 | 446 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 447 | |
|
| 1 | 448 | | privateChatWindow = controller; |
| | 449 | |
|
| 1 | 450 | | controller.OnClosed += OpenPublicChannelOnPreviewMode; |
| 1 | 451 | | controller.OnPreviewModeChanged += HandlePrivateChannelPreviewMode; |
| 1 | 452 | | } |
| | 453 | |
|
| | 454 | | public void AddPublicChatChannel(PublicChatChannelController controller) |
| | 455 | | { |
| 1 | 456 | | if (controller?.View == null) |
| | 457 | | { |
| 0 | 458 | | Debug.LogWarning("AddPublicChatChannel >>> Public Chat Window doesn't exist yet!"); |
| 0 | 459 | | return; |
| | 460 | | } |
| | 461 | |
|
| 1 | 462 | | if (controller.View.Transform.parent == view.leftWindowContainer) return; |
| | 463 | |
|
| 1 | 464 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 1 | 465 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 466 | |
|
| 1 | 467 | | publicChatChannel = controller; |
| | 468 | |
|
| 1 | 469 | | controller.OnClosed += OpenPublicChannelOnPreviewMode; |
| 1 | 470 | | controller.OnPreviewModeChanged += HandlePublicChannelPreviewModeChanged; |
| 1 | 471 | | } |
| | 472 | |
|
| | 473 | | private void HandlePublicChannelPreviewModeChanged(bool isPreviewMode) |
| | 474 | | { |
| 2 | 475 | | if (!publicChatChannel.View.IsActive) return; |
| 2 | 476 | | if (isPreviewMode) |
| 1 | 477 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| | 478 | | else |
| 1 | 479 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 1 | 480 | | } |
| | 481 | |
|
| | 482 | | private void HandlePrivateChannelPreviewMode(bool isPreviewMode) |
| | 483 | | { |
| 0 | 484 | | if (!privateChatWindow.View.IsActive) return; |
| 0 | 485 | | if (isPreviewMode) |
| 0 | 486 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| | 487 | | else |
| 0 | 488 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 489 | | } |
| | 490 | |
|
| | 491 | | public void AddFriendsWindow(FriendsHUDController controller) |
| | 492 | | { |
| 3 | 493 | | if (controller?.View == null) |
| | 494 | | { |
| 0 | 495 | | Debug.LogWarning("AddFriendsWindow >>> Friends window doesn't exist yet!"); |
| 0 | 496 | | return; |
| | 497 | | } |
| | 498 | |
|
| 3 | 499 | | if (controller.View.Transform.parent == view.leftWindowContainer) |
| 0 | 500 | | return; |
| | 501 | |
|
| 3 | 502 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 3 | 503 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 504 | |
|
| 3 | 505 | | friendsHud = controller; |
| 3 | 506 | | view.ShowFriendsButton(); |
| 3 | 507 | | friendsHud.View.OnClose += () => |
| | 508 | | { |
| 0 | 509 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Friends); |
| 0 | 510 | | OpenPublicChannelOnPreviewMode(); |
| 0 | 511 | | }; |
| 3 | 512 | | } |
| | 513 | |
|
| | 514 | | public void AddVoiceChatWindow(VoiceChatWindowController controller) |
| | 515 | | { |
| 1 | 516 | | if (controller?.VoiceChatWindowView == null) |
| | 517 | | { |
| 1 | 518 | | Debug.LogWarning("AddVoiceChatWindow >>> Voice Chat window doesn't exist yet!"); |
| 1 | 519 | | return; |
| | 520 | | } |
| | 521 | |
|
| 0 | 522 | | if (controller.VoiceChatWindowView.Transform.parent == view.leftWindowContainer) |
| 0 | 523 | | return; |
| | 524 | |
|
| 0 | 525 | | controller.VoiceChatWindowView.Transform.SetParent(view.leftWindowContainer, false); |
| | 526 | |
|
| 0 | 527 | | voiceChatHud = controller; |
| 0 | 528 | | view.ShowVoiceChatButton(); |
| 0 | 529 | | voiceChatHud.VoiceChatWindowView.OnClose += () => view.ToggleOff(TaskbarHUDView.TaskbarButtonType.VoiceChat); |
| | 530 | |
|
| 0 | 531 | | if (controller?.VoiceChatBarView != null) |
| | 532 | | { |
| 0 | 533 | | controller.VoiceChatBarView.Transform.SetParent(view.altSectionContainer, false); |
| 0 | 534 | | controller.VoiceChatBarView.Transform.SetAsFirstSibling(); |
| | 535 | | } |
| 0 | 536 | | } |
| | 537 | |
|
| | 538 | | private void InitializeEmotesSelector(bool current, bool previous) |
| | 539 | | { |
| 8 | 540 | | if (!current) return; |
| 0 | 541 | | view.ShowEmotesButton(); |
| 0 | 542 | | } |
| | 543 | |
|
| 0 | 544 | | private void IsEmotesVisibleChanged(bool current, bool previous) => HandleEmotesToggle(current); |
| | 545 | |
|
| | 546 | | private void InitializeExperiencesViewer(Transform currentViewTransform, Transform previousViewTransform) |
| | 547 | | { |
| 4 | 548 | | if (currentViewTransform == null) |
| 4 | 549 | | return; |
| | 550 | |
|
| 0 | 551 | | experiencesViewerTransform = currentViewTransform; |
| 0 | 552 | | experiencesViewerTransform.SetParent(view.leftWindowContainer, false); |
| 0 | 553 | | experiencesViewerTransform.SetAsLastSibling(); |
| | 554 | |
|
| 0 | 555 | | view.ShowExperiencesButton(); |
| 0 | 556 | | } |
| | 557 | |
|
| | 558 | | private void IsExperiencesViewerOpenChanged(bool current, bool previous) |
| | 559 | | { |
| 0 | 560 | | if (current) |
| 0 | 561 | | return; |
| | 562 | |
|
| 0 | 563 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Experiences); |
| 0 | 564 | | OpenPublicChannelOnPreviewMode(); |
| 0 | 565 | | } |
| | 566 | |
|
| | 567 | | private void NumOfLoadedExperiencesChanged(int current, int previous) |
| | 568 | | { |
| 4 | 569 | | view.SetExperiencesVisibility(current > 0); |
| | 570 | |
|
| 4 | 571 | | if (current == 0) |
| 4 | 572 | | isExperiencesViewerOpen.Set(false); |
| 4 | 573 | | } |
| | 574 | |
|
| | 575 | | public void DisableFriendsWindow() |
| | 576 | | { |
| 0 | 577 | | view.friendsButton.transform.parent.gameObject.SetActive(false); |
| 0 | 578 | | } |
| | 579 | |
|
| | 580 | | public void Dispose() |
| | 581 | | { |
| 4 | 582 | | if (view != null) |
| | 583 | | { |
| 4 | 584 | | view.OnChatToggle -= HandleChatToggle; |
| 4 | 585 | | view.OnFriendsToggle -= HandleFriendsToggle; |
| 4 | 586 | | view.OnEmotesToggle -= HandleEmotesToggle; |
| 4 | 587 | | view.OnExperiencesToggle -= HandleExperiencesToggle; |
| 4 | 588 | | view.OnVoiceChatToggle -= HandleVoiceChatToggle; |
| | 589 | |
|
| 4 | 590 | | view.Destroy(); |
| | 591 | | } |
| | 592 | |
|
| 4 | 593 | | if (mouseCatcher != null) |
| | 594 | | { |
| 1 | 595 | | mouseCatcher.OnMouseLock -= MouseCatcher_OnMouseLock; |
| 1 | 596 | | mouseCatcher.OnMouseUnlock -= MouseCatcher_OnMouseUnlock; |
| | 597 | | } |
| | 598 | |
|
| 4 | 599 | | if (toggleFriendsTrigger != null) |
| 4 | 600 | | toggleFriendsTrigger.OnTriggered -= ToggleFriendsTrigger_OnTriggered; |
| | 601 | |
|
| 4 | 602 | | if (closeWindowTrigger != null) |
| 4 | 603 | | closeWindowTrigger.OnTriggered -= CloseWindowTrigger_OnTriggered; |
| | 604 | |
|
| 4 | 605 | | if (toggleWorldChatTrigger != null) |
| 4 | 606 | | toggleWorldChatTrigger.OnTriggered -= ToggleWorldChatTrigger_OnTriggered; |
| | 607 | |
|
| 4 | 608 | | DataStore.i.builderInWorld.showTaskBar.OnChange -= SetVisibility; |
| 4 | 609 | | isEmotesWheelInitialized.OnChange -= InitializeEmotesSelector; |
| 4 | 610 | | isEmotesVisible.OnChange -= IsEmotesVisibleChanged; |
| 4 | 611 | | isExperiencesViewerOpen.OnChange -= IsExperiencesViewerOpenChanged; |
| 4 | 612 | | isExperiencesViewerInitialized.OnChange -= InitializeExperiencesViewer; |
| 4 | 613 | | numOfLoadedExperiences.OnChange -= NumOfLoadedExperiencesChanged; |
| 4 | 614 | | } |
| | 615 | |
|
| 0 | 616 | | private void SetVisibility(bool visible, bool previus) { SetVisibility(visible); } |
| | 617 | |
|
| 2 | 618 | | public void SetVisibility(bool visible) { view.SetVisibility(visible); } |
| | 619 | |
|
| | 620 | | public void GoBackFromChat() |
| | 621 | | { |
| 0 | 622 | | if (chatBackWindow == friendsHud) |
| 0 | 623 | | OpenFriendsWindow(); |
| | 624 | | else |
| 0 | 625 | | OpenChatList(); |
| 0 | 626 | | } |
| | 627 | | } |