| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Chat; |
| | 4 | | using DCL.Social.Chat; |
| | 5 | | using DCL.Interface; |
| | 6 | | using DCL.Social.Friends; |
| | 7 | | using Analytics; |
| | 8 | | using DCL.Social.Chat; |
| | 9 | | using System; |
| | 10 | | using System.Threading; |
| | 11 | | using TMPro; |
| | 12 | | using UnityEngine; |
| | 13 | | using UnityEngine.EventSystems; |
| | 14 | |
|
| | 15 | | public class TaskbarHUDController : IHUD |
| | 16 | | { |
| | 17 | | private const string INTERCOM_URL = "https://decentraland.org/help/"; |
| | 18 | |
|
| | 19 | | private readonly IChatController chatController; |
| | 20 | | private readonly IFriendsController friendsController; |
| | 21 | |
|
| | 22 | | [Serializable] |
| | 23 | | public struct Configuration |
| | 24 | | { |
| | 25 | | public bool enableVoiceChat; |
| | 26 | | public bool enableQuestPanel; |
| | 27 | | } |
| | 28 | |
|
| | 29 | | public TaskbarHUDView view; |
| | 30 | | public WorldChatWindowController worldChatWindowHud; |
| | 31 | | public PrivateChatWindowController privateChatWindow; |
| | 32 | | public PublicChatWindowController publicChatWindow; |
| | 33 | | public ChatChannelHUDController channelChatWindow; |
| | 34 | | public FriendsHUDController friendsHud; |
| | 35 | | public VoiceChatWindowController voiceChatHud; |
| | 36 | |
|
| | 37 | | private IMouseCatcher mouseCatcher; |
| | 38 | | private ISupportAnalytics analytics; |
| | 39 | | private InputAction_Trigger toggleFriendsTrigger; |
| | 40 | | private InputAction_Trigger closeWindowTrigger; |
| | 41 | | private InputAction_Trigger toggleWorldChatTrigger; |
| | 42 | | private Transform experiencesViewerTransform; |
| | 43 | | private Transform notificationViewerTransform; |
| | 44 | | private Transform topNotificationViewerTransform; |
| | 45 | | private IHUD chatBackWindow; |
| | 46 | | private SearchChannelsWindowController searchChannelsHud; |
| | 47 | | private CreateChannelWindowController channelCreationWindow; |
| | 48 | | private LeaveChannelConfirmationWindowController channelLeaveWindow; |
| 4 | 49 | | private CancellationTokenSource openPrivateChatCancellationToken = new (); |
| | 50 | |
|
| 3 | 51 | | private bool isFriendsFeatureEnabled => DataStore.i.featureFlags.flags.Get().IsFeatureEnabled("friends_enabled"); |
| | 52 | |
|
| | 53 | | public event Action OnAnyTaskbarButtonClicked; |
| | 54 | |
|
| 0 | 55 | | public RectTransform socialTooltipReference => view.socialTooltipReference; |
| | 56 | |
|
| 12 | 57 | | internal BaseVariable<bool> isEmotesWheelInitialized => DataStore.i.emotesCustomization.isWheelInitialized; |
| 11 | 58 | | internal BaseVariable<bool> isEmotesVisible => DataStore.i.HUDs.emotesVisible; |
| 0 | 59 | | internal BaseVariable<bool> emoteJustTriggeredFromShortcut => DataStore.i.HUDs.emoteJustTriggeredFromShortcut; |
| 12 | 60 | | internal BaseVariable<Transform> isExperiencesViewerInitialized => DataStore.i.experiencesViewer.isInitialized; |
| 8 | 61 | | internal BaseVariable<Transform> notificationPanelTransform => DataStore.i.HUDs.notificationPanelTransform; |
| 8 | 62 | | internal BaseVariable<Transform> topNotificationPanelTransform => DataStore.i.HUDs.topNotificationPanelTransform; |
| 15 | 63 | | internal BaseVariable<bool> isExperiencesViewerOpen => DataStore.i.experiencesViewer.isOpen; |
| 12 | 64 | | internal BaseVariable<int> numOfLoadedExperiences => DataStore.i.experiencesViewer.numOfLoadedExperiences; |
| 5 | 65 | | internal BaseVariable<string> openChat => DataStore.i.HUDs.openChat; |
| 2 | 66 | | internal BaseVariable<bool> isPromoteChannelsToastVisible => DataStore.i.channels.isPromoteToastVisible; |
| | 67 | |
|
| 4 | 68 | | public TaskbarHUDController(IChatController chatController, IFriendsController friendsController, ISupportAnalytics |
| | 69 | | { |
| 4 | 70 | | this.chatController = chatController; |
| 4 | 71 | | this.friendsController = friendsController; |
| 4 | 72 | | this.analytics = analytics; |
| 4 | 73 | | } |
| | 74 | |
|
| | 75 | | protected virtual TaskbarHUDView CreateView() |
| | 76 | | { |
| 4 | 77 | | return TaskbarHUDView.Create(); |
| | 78 | | } |
| | 79 | |
|
| | 80 | | public void Initialize(IMouseCatcher mouseCatcher) |
| | 81 | | { |
| 4 | 82 | | this.mouseCatcher = mouseCatcher; |
| | 83 | |
|
| 4 | 84 | | view = CreateView(); |
| | 85 | |
|
| 4 | 86 | | if (mouseCatcher != null) |
| | 87 | | { |
| 0 | 88 | | mouseCatcher.OnMouseLock -= MouseCatcher_OnMouseLock; |
| 0 | 89 | | mouseCatcher.OnMouseUnlock -= MouseCatcher_OnMouseUnlock; |
| 0 | 90 | | mouseCatcher.OnMouseLock += MouseCatcher_OnMouseLock; |
| 0 | 91 | | mouseCatcher.OnMouseUnlock += MouseCatcher_OnMouseUnlock; |
| | 92 | | } |
| | 93 | |
|
| 4 | 94 | | view.leftWindowContainerLayout.enabled = false; |
| | 95 | |
|
| 4 | 96 | | view.OnChatToggle += HandleChatToggle; |
| 4 | 97 | | view.OnFriendsToggle += HandleFriendsToggle; |
| 4 | 98 | | view.OnEmotesToggle += HandleEmotesToggle; |
| 4 | 99 | | view.OnExperiencesToggle += HandleExperiencesToggle; |
| 4 | 100 | | view.OnVoiceChatToggle += HandleVoiceChatToggle; |
| 4 | 101 | | view.OnIntercomPressed += OpenIntercom; |
| | 102 | |
|
| 4 | 103 | | toggleFriendsTrigger = Resources.Load<InputAction_Trigger>("ToggleFriends"); |
| 4 | 104 | | toggleFriendsTrigger.OnTriggered -= ToggleFriendsTrigger_OnTriggered; |
| 4 | 105 | | toggleFriendsTrigger.OnTriggered += ToggleFriendsTrigger_OnTriggered; |
| | 106 | |
|
| 4 | 107 | | closeWindowTrigger = Resources.Load<InputAction_Trigger>("CloseWindow"); |
| 4 | 108 | | closeWindowTrigger.OnTriggered -= CloseWindowTrigger_OnTriggered; |
| 4 | 109 | | closeWindowTrigger.OnTriggered += CloseWindowTrigger_OnTriggered; |
| | 110 | |
|
| 4 | 111 | | toggleWorldChatTrigger = Resources.Load<InputAction_Trigger>("ToggleWorldChat"); |
| 4 | 112 | | toggleWorldChatTrigger.OnTriggered -= ToggleWorldChatTrigger_OnTriggered; |
| 4 | 113 | | toggleWorldChatTrigger.OnTriggered += ToggleWorldChatTrigger_OnTriggered; |
| | 114 | |
|
| 4 | 115 | | isEmotesWheelInitialized.OnChange += InitializeEmotesSelector; |
| 4 | 116 | | InitializeEmotesSelector(isEmotesWheelInitialized.Get(), false); |
| 4 | 117 | | isEmotesVisible.OnChange += IsEmotesVisibleChanged; |
| | 118 | |
|
| 4 | 119 | | isExperiencesViewerOpen.OnChange += IsExperiencesViewerOpenChanged; |
| | 120 | |
|
| 4 | 121 | | view.leftWindowContainerAnimator.Show(); |
| | 122 | |
|
| 4 | 123 | | CommonScriptableObjects.isTaskbarHUDInitialized.Set(true); |
| | 124 | |
|
| 4 | 125 | | isExperiencesViewerInitialized.OnChange += InitializeExperiencesViewer; |
| 4 | 126 | | InitializeExperiencesViewer(isExperiencesViewerInitialized.Get(), null); |
| | 127 | |
|
| 4 | 128 | | notificationPanelTransform.OnChange += InitializeNotificationPanel; |
| 4 | 129 | | InitializeNotificationPanel(notificationPanelTransform.Get(), null); |
| | 130 | |
|
| 4 | 131 | | topNotificationPanelTransform.OnChange += InitializeTopNotificationPanel; |
| 4 | 132 | | InitializeTopNotificationPanel(topNotificationPanelTransform.Get(), null); |
| | 133 | |
|
| 4 | 134 | | numOfLoadedExperiences.OnChange += NumOfLoadedExperiencesChanged; |
| 4 | 135 | | NumOfLoadedExperiencesChanged(numOfLoadedExperiences.Get(), 0); |
| | 136 | |
|
| 4 | 137 | | openChat.OnChange += OpenChat; |
| 4 | 138 | | } |
| | 139 | |
|
| | 140 | | private void OpenIntercom() |
| | 141 | | { |
| 0 | 142 | | analytics.SendOpenSupport(OpenSupportSource.Taskbar); |
| 0 | 143 | | WebInterface.OpenURL(INTERCOM_URL); |
| 0 | 144 | | } |
| | 145 | |
|
| | 146 | | private void HandleFriendsToggle(bool show) |
| | 147 | | { |
| 3 | 148 | | if (show) |
| 2 | 149 | | OpenFriendsWindow(); |
| | 150 | | else |
| | 151 | | { |
| 1 | 152 | | friendsHud?.SetVisibility(false); |
| 1 | 153 | | ToggleOffChatIcon(); |
| | 154 | | } |
| | 155 | |
|
| 3 | 156 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 157 | | } |
| | 158 | |
|
| | 159 | | private void HandleEmotesToggle(bool show) |
| | 160 | | { |
| 0 | 161 | | if (show && emoteJustTriggeredFromShortcut.Get()) |
| | 162 | | { |
| 0 | 163 | | emoteJustTriggeredFromShortcut.Set(false); |
| 0 | 164 | | return; |
| | 165 | | } |
| | 166 | |
|
| 0 | 167 | | if (show) |
| | 168 | | { |
| 0 | 169 | | ToggleOffChatIcon(); |
| 0 | 170 | | ShowEmotes(); |
| | 171 | | } |
| | 172 | | else |
| | 173 | | { |
| 0 | 174 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Emotes); |
| 0 | 175 | | isEmotesVisible.Set(false); |
| 0 | 176 | | ToggleOffChatIcon(); |
| | 177 | | } |
| | 178 | |
|
| 0 | 179 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 180 | | } |
| | 181 | |
|
| | 182 | | private void ShowEmotes() |
| | 183 | | { |
| 0 | 184 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 185 | | privateChatWindow.SetVisibility(false); |
| 0 | 186 | | channelChatWindow.SetVisibility(false); |
| 0 | 187 | | friendsHud?.SetVisibility(false); |
| 0 | 188 | | searchChannelsHud.SetVisibility(false); |
| 0 | 189 | | isExperiencesViewerOpen.Set(false); |
| 0 | 190 | | voiceChatHud?.SetVisibility(false); |
| 0 | 191 | | isEmotesVisible.Set(true); |
| 0 | 192 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Emotes); |
| 0 | 193 | | } |
| | 194 | |
|
| | 195 | | private void HandleExperiencesToggle(bool show) |
| | 196 | | { |
| 0 | 197 | | if (show) |
| 0 | 198 | | ShowExperiences(); |
| | 199 | | else |
| | 200 | | { |
| 0 | 201 | | isExperiencesViewerOpen.Set(false); |
| 0 | 202 | | ToggleOffChatIcon(); |
| | 203 | | } |
| | 204 | |
|
| 0 | 205 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 206 | | } |
| | 207 | |
|
| | 208 | | private void HandleVoiceChatToggle(bool show) |
| | 209 | | { |
| 0 | 210 | | if (show) |
| 0 | 211 | | OpenVoiceChatWindow(); |
| | 212 | | else |
| 0 | 213 | | voiceChatHud?.SetVisibility(false); |
| | 214 | |
|
| 0 | 215 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 216 | | } |
| | 217 | |
|
| | 218 | | private void ShowExperiences() |
| | 219 | | { |
| 0 | 220 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 221 | | privateChatWindow.SetVisibility(false); |
| 0 | 222 | | publicChatWindow.SetVisibility(false); |
| 0 | 223 | | channelChatWindow.SetVisibility(false); |
| 0 | 224 | | searchChannelsHud.SetVisibility(false); |
| 0 | 225 | | friendsHud?.SetVisibility(false); |
| 0 | 226 | | isEmotesVisible.Set(false); |
| 0 | 227 | | voiceChatHud?.SetVisibility(false); |
| 0 | 228 | | isExperiencesViewerOpen.Set(true); |
| 0 | 229 | | isPromoteChannelsToastVisible.Set(false); |
| 0 | 230 | | } |
| | 231 | |
|
| | 232 | | private void ToggleFriendsTrigger_OnTriggered(DCLAction_Trigger action) |
| | 233 | | { |
| 0 | 234 | | if (friendsHud == null) return; |
| 0 | 235 | | if (!isFriendsFeatureEnabled) return; |
| | 236 | |
|
| 0 | 237 | | bool anyInputFieldIsSelected = EventSystem.current != null && |
| | 238 | | EventSystem.current.currentSelectedGameObject != null && |
| | 239 | | EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != |
| | 240 | | null; |
| | 241 | |
|
| 0 | 242 | | if (anyInputFieldIsSelected) return; |
| | 243 | |
|
| 0 | 244 | | mouseCatcher.UnlockCursor(); |
| | 245 | |
|
| 0 | 246 | | if (!friendsHud.View.IsActive()) |
| | 247 | | { |
| 0 | 248 | | view.leftWindowContainerAnimator.Show(); |
| 0 | 249 | | OpenFriendsWindow(); |
| | 250 | | } |
| | 251 | | else |
| | 252 | | { |
| 0 | 253 | | CloseFriendsWindow(); |
| 0 | 254 | | ToggleOffChatIcon(); |
| | 255 | | } |
| 0 | 256 | | } |
| | 257 | |
|
| | 258 | | private void ToggleWorldChatTrigger_OnTriggered(DCLAction_Trigger action) |
| | 259 | | { |
| 0 | 260 | | bool anyInputFieldIsSelected = EventSystem.current != null && |
| | 261 | | EventSystem.current.currentSelectedGameObject != null && |
| | 262 | | EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != |
| | 263 | | null; |
| | 264 | |
|
| 0 | 265 | | if (anyInputFieldIsSelected) return; |
| | 266 | |
|
| 0 | 267 | | mouseCatcher.UnlockCursor(); |
| 0 | 268 | | chatBackWindow = worldChatWindowHud; |
| | 269 | |
|
| 0 | 270 | | if (!worldChatWindowHud.View.IsActive |
| | 271 | | && !privateChatWindow.View.IsActive |
| | 272 | | && !publicChatWindow.View.IsActive) |
| 0 | 273 | | OpenLastActiveChatWindow(); |
| 0 | 274 | | } |
| | 275 | |
|
| | 276 | | private void CloseWindowTrigger_OnTriggered(DCLAction_Trigger action) |
| | 277 | | { |
| 0 | 278 | | if (mouseCatcher.IsLocked) return; |
| | 279 | |
|
| 0 | 280 | | if (publicChatWindow.View.IsActive || |
| | 281 | | channelChatWindow.View.IsActive || |
| | 282 | | privateChatWindow.View.IsActive) |
| | 283 | | { |
| 0 | 284 | | if (!DataStore.i.mentions.isMentionSuggestionVisible.Get()) |
| | 285 | | { |
| 0 | 286 | | publicChatWindow.SetVisibility(false); |
| 0 | 287 | | privateChatWindow.SetVisibility(false); |
| 0 | 288 | | channelChatWindow.SetVisibility(false); |
| 0 | 289 | | OpenChatList(); |
| | 290 | | } |
| | 291 | | } |
| | 292 | | else |
| | 293 | | { |
| 0 | 294 | | publicChatWindow.SetVisibility(false); |
| 0 | 295 | | privateChatWindow.SetVisibility(false); |
| 0 | 296 | | channelChatWindow.SetVisibility(false); |
| 0 | 297 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 298 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| | 299 | | } |
| | 300 | |
|
| 0 | 301 | | CloseFriendsWindow(); |
| 0 | 302 | | CloseVoiceChatWindow(); |
| 0 | 303 | | isEmotesVisible.Set(false); |
| 0 | 304 | | isExperiencesViewerOpen.Set(false); |
| 0 | 305 | | } |
| | 306 | |
|
| | 307 | | private void HandleChatToggle(bool show) |
| | 308 | | { |
| 1 | 309 | | if (show) |
| | 310 | | { |
| 1 | 311 | | chatBackWindow = worldChatWindowHud; |
| 1 | 312 | | OpenChatList(); |
| | 313 | | } |
| 0 | 314 | | else { CloseAnyChatWindow(); } |
| | 315 | |
|
| 1 | 316 | | OnAnyTaskbarButtonClicked?.Invoke(); |
| 0 | 317 | | } |
| | 318 | |
|
| 0 | 319 | | private void MouseCatcher_OnMouseUnlock() { } |
| | 320 | |
|
| | 321 | | private void MouseCatcher_OnMouseLock() |
| | 322 | | { |
| 0 | 323 | | CloseFriendsWindow(); |
| 0 | 324 | | CloseChatList(); |
| 0 | 325 | | CloseVoiceChatWindow(); |
| 0 | 326 | | isExperiencesViewerOpen.Set(false); |
| | 327 | |
|
| 0 | 328 | | if (!privateChatWindow.View.IsActive |
| | 329 | | && !publicChatWindow.View.IsActive |
| | 330 | | && !channelChatWindow.View.IsActive) |
| 0 | 331 | | ToggleOffChatIcon(); |
| 0 | 332 | | } |
| | 333 | |
|
| | 334 | | public void AddWorldChatWindow(WorldChatWindowController controller) |
| | 335 | | { |
| 2 | 336 | | if (controller?.View == null) |
| | 337 | | { |
| 0 | 338 | | Debug.LogWarning("AddChatWindow >>> World Chat Window doesn't exist yet!"); |
| 0 | 339 | | return; |
| | 340 | | } |
| | 341 | |
|
| 2 | 342 | | if (controller.View.Transform.parent == view.leftWindowContainer) return; |
| | 343 | |
|
| 2 | 344 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 2 | 345 | | notificationViewerTransform?.SetAsLastSibling(); |
| 2 | 346 | | topNotificationViewerTransform?.SetAsFirstSibling(); |
| 2 | 347 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 348 | |
|
| 2 | 349 | | worldChatWindowHud = controller; |
| | 350 | |
|
| 2 | 351 | | view.ShowChatButton(); |
| 2 | 352 | | worldChatWindowHud.OnCloseView += ToggleOffChatIcon; |
| 2 | 353 | | worldChatWindowHud.OnOpenChannelCreation += OpenChannelCreation; |
| 2 | 354 | | worldChatWindowHud.OnOpenChannelLeave += OpenChannelLeaveConfirmation; |
| 2 | 355 | | } |
| | 356 | |
|
| | 357 | | private void ToggleOffChatIcon() => |
| 4 | 358 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| | 359 | |
|
| | 360 | | private void OpenFriendsWindow() |
| | 361 | | { |
| 2 | 362 | | worldChatWindowHud.SetVisibility(false); |
| 2 | 363 | | privateChatWindow.SetVisibility(false); |
| 2 | 364 | | publicChatWindow.SetVisibility(false); |
| 2 | 365 | | channelChatWindow?.SetVisibility(false); |
| 2 | 366 | | searchChannelsHud.SetVisibility(false); |
| 2 | 367 | | isExperiencesViewerOpen.Set(false); |
| 2 | 368 | | isEmotesVisible.Set(false); |
| 2 | 369 | | voiceChatHud?.SetVisibility(false); |
| 2 | 370 | | friendsHud?.SetVisibility(true); |
| 2 | 371 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Friends); |
| 2 | 372 | | chatBackWindow = friendsHud; |
| 2 | 373 | | isPromoteChannelsToastVisible.Set(false); |
| 2 | 374 | | } |
| | 375 | |
|
| | 376 | |
|
| | 377 | | private void CloseFriendsWindow() |
| | 378 | | { |
| 0 | 379 | | if(friendsHud is { IsVisible: true }) |
| | 380 | | { |
| 0 | 381 | | friendsHud?.SetVisibility(false); |
| 0 | 382 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Friends); |
| | 383 | | } |
| 0 | 384 | | } |
| | 385 | |
|
| | 386 | | public void OpenPrivateChat(string userId) |
| | 387 | | { |
| 0 | 388 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 389 | | publicChatWindow.SetVisibility(false); |
| 0 | 390 | | channelChatWindow.SetVisibility(false); |
| 0 | 391 | | searchChannelsHud.SetVisibility(false); |
| 0 | 392 | | friendsHud?.SetVisibility(false); |
| 0 | 393 | | isExperiencesViewerOpen.Set(false); |
| 0 | 394 | | isEmotesVisible.Set(false); |
| 0 | 395 | | voiceChatHud?.SetVisibility(false); |
| 0 | 396 | | openChat.Set(userId, false); |
| 0 | 397 | | privateChatWindow.Setup(userId); |
| 0 | 398 | | privateChatWindow.SetVisibility(true); |
| 0 | 399 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 400 | | } |
| | 401 | |
|
| | 402 | | private void OpenLastActiveChatWindow() |
| | 403 | | { |
| 0 | 404 | | string lastOpenedChat = openChat.Get(); |
| | 405 | |
|
| 0 | 406 | | string newChat = string.IsNullOrEmpty(lastOpenedChat) |
| | 407 | | ? ChatUtils.NEARBY_CHANNEL_ID |
| | 408 | | : lastOpenedChat; |
| | 409 | |
|
| 0 | 410 | | if (newChat == ChatUtils.CONVERSATION_LIST_ID) |
| 0 | 411 | | newChat = ChatUtils.NEARBY_CHANNEL_ID; |
| | 412 | |
|
| 0 | 413 | | openChat.Set(newChat, true); |
| 0 | 414 | | } |
| | 415 | |
|
| | 416 | | private void CloseAnyChatWindow() |
| | 417 | | { |
| 0 | 418 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 419 | | privateChatWindow.SetVisibility(false); |
| 0 | 420 | | publicChatWindow.SetVisibility(false); |
| 0 | 421 | | channelChatWindow.SetVisibility(false); |
| 0 | 422 | | searchChannelsHud.SetVisibility(false); |
| 0 | 423 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 424 | | } |
| | 425 | |
|
| | 426 | | public void OpenChannelChat(string channelId) |
| | 427 | | { |
| 0 | 428 | | openChat.Set(channelId, false); |
| 0 | 429 | | channelChatWindow?.Setup(channelId); |
| 0 | 430 | | channelChatWindow?.SetVisibility(true); |
| 0 | 431 | | publicChatWindow?.SetVisibility(false); |
| 0 | 432 | | worldChatWindowHud?.SetVisibility(false); |
| 0 | 433 | | privateChatWindow?.SetVisibility(false); |
| 0 | 434 | | searchChannelsHud.SetVisibility(false); |
| 0 | 435 | | friendsHud?.SetVisibility(false); |
| 0 | 436 | | isExperiencesViewerOpen?.Set(false); |
| 0 | 437 | | isEmotesVisible?.Set(false); |
| 0 | 438 | | voiceChatHud?.SetVisibility(false); |
| | 439 | |
|
| 0 | 440 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 441 | | } |
| | 442 | |
|
| | 443 | | public void OpenPublicChat(string channelId, bool focusInputField) |
| | 444 | | { |
| 0 | 445 | | openChat.Set(channelId, false); |
| 0 | 446 | | publicChatWindow?.Setup(channelId); |
| 0 | 447 | | publicChatWindow?.SetVisibility(true, focusInputField); |
| 0 | 448 | | channelChatWindow?.SetVisibility(false); |
| 0 | 449 | | worldChatWindowHud?.SetVisibility(false); |
| 0 | 450 | | privateChatWindow?.SetVisibility(false); |
| 0 | 451 | | searchChannelsHud?.SetVisibility(false); |
| 0 | 452 | | friendsHud?.SetVisibility(false); |
| 0 | 453 | | isExperiencesViewerOpen?.Set(false); |
| 0 | 454 | | isEmotesVisible?.Set(false); |
| 0 | 455 | | voiceChatHud?.SetVisibility(false); |
| | 456 | |
|
| 0 | 457 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 458 | | } |
| | 459 | |
|
| | 460 | | private void OpenChatList() |
| | 461 | | { |
| 1 | 462 | | privateChatWindow.SetVisibility(false); |
| 1 | 463 | | publicChatWindow.SetVisibility(false); |
| 1 | 464 | | channelChatWindow.SetVisibility(false); |
| 1 | 465 | | searchChannelsHud.SetVisibility(false); |
| 1 | 466 | | friendsHud?.SetVisibility(false); |
| 1 | 467 | | isExperiencesViewerOpen.Set(false); |
| 1 | 468 | | isEmotesVisible.Set(false); |
| 1 | 469 | | voiceChatHud?.SetVisibility(false); |
| 1 | 470 | | openChat.Set(ChatUtils.CONVERSATION_LIST_ID, false); |
| 1 | 471 | | worldChatWindowHud.SetVisibility(true); |
| 1 | 472 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 1 | 473 | | } |
| | 474 | |
|
| | 475 | | private void CloseChatList() |
| | 476 | | { |
| 0 | 477 | | if (!worldChatWindowHud.View.IsActive) return; |
| 0 | 478 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 479 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 480 | | } |
| | 481 | |
|
| | 482 | | private void OpenVoiceChatWindow() |
| | 483 | | { |
| 0 | 484 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 485 | | privateChatWindow.SetVisibility(false); |
| 0 | 486 | | publicChatWindow.SetVisibility(false); |
| 0 | 487 | | channelChatWindow.SetVisibility(false); |
| 0 | 488 | | searchChannelsHud.SetVisibility(false); |
| 0 | 489 | | isExperiencesViewerOpen.Set(false); |
| 0 | 490 | | isEmotesVisible.Set(false); |
| 0 | 491 | | friendsHud?.SetVisibility(false); |
| 0 | 492 | | voiceChatHud?.SetVisibility(true); |
| 0 | 493 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.VoiceChat); |
| 0 | 494 | | isPromoteChannelsToastVisible.Set(false); |
| 0 | 495 | | } |
| | 496 | |
|
| | 497 | | private void CloseVoiceChatWindow() |
| | 498 | | { |
| 0 | 499 | | if(voiceChatHud?.IsVisible ?? false) |
| | 500 | | { |
| 0 | 501 | | voiceChatHud?.SetVisibility(false); |
| 0 | 502 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.VoiceChat); |
| | 503 | | } |
| 0 | 504 | | } |
| | 505 | |
|
| | 506 | | public void AddPrivateChatWindow(PrivateChatWindowController controller) |
| | 507 | | { |
| 1 | 508 | | if (controller?.View == null) |
| | 509 | | { |
| 0 | 510 | | Debug.LogWarning("AddPrivateChatWindow >>> Private Chat Window doesn't exist yet!"); |
| 0 | 511 | | return; |
| | 512 | | } |
| | 513 | |
|
| 1 | 514 | | if (controller.View.Transform.parent == view.leftWindowContainer) |
| 0 | 515 | | return; |
| | 516 | |
|
| 1 | 517 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 1 | 518 | | notificationViewerTransform?.SetAsLastSibling(); |
| 1 | 519 | | topNotificationViewerTransform?.SetAsFirstSibling(); |
| 1 | 520 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 521 | |
|
| 1 | 522 | | privateChatWindow = controller; |
| | 523 | |
|
| 1 | 524 | | controller.OnClosed += ToggleOffChatIcon; |
| 1 | 525 | | } |
| | 526 | |
|
| | 527 | | public void AddPublicChatChannel(PublicChatWindowController controller) |
| | 528 | | { |
| 1 | 529 | | if (controller?.View == null) |
| | 530 | | { |
| 0 | 531 | | Debug.LogWarning("AddPublicChatChannel >>> Public Chat Window doesn't exist yet!"); |
| 0 | 532 | | return; |
| | 533 | | } |
| | 534 | |
|
| 1 | 535 | | if (controller.View.Transform.parent == view.leftWindowContainer) return; |
| | 536 | |
|
| 1 | 537 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 1 | 538 | | notificationViewerTransform?.SetAsLastSibling(); |
| 1 | 539 | | topNotificationViewerTransform?.SetAsFirstSibling(); |
| 1 | 540 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 541 | |
|
| 1 | 542 | | publicChatWindow = controller; |
| | 543 | |
|
| 1 | 544 | | controller.OnClosed += ToggleOffChatIcon; |
| 1 | 545 | | } |
| | 546 | |
|
| | 547 | | public void AddFriendsWindow(FriendsHUDController controller) |
| | 548 | | { |
| 3 | 549 | | if (controller?.View == null) |
| | 550 | | { |
| 0 | 551 | | Debug.LogWarning("AddFriendsWindow >>> Friends window doesn't exist yet!"); |
| 0 | 552 | | return; |
| | 553 | | } |
| | 554 | |
|
| 3 | 555 | | if (controller.View.Transform.parent == view.leftWindowContainer) |
| 0 | 556 | | return; |
| | 557 | |
|
| 3 | 558 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 3 | 559 | | notificationViewerTransform?.SetAsLastSibling(); |
| 3 | 560 | | topNotificationViewerTransform?.SetAsFirstSibling(); |
| 3 | 561 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 562 | |
|
| 3 | 563 | | friendsHud = controller; |
| | 564 | |
|
| 3 | 565 | | if (isFriendsFeatureEnabled) |
| 0 | 566 | | view.ShowFriendsButton(); |
| | 567 | | else |
| 3 | 568 | | view.HideFriendsButton(); |
| | 569 | |
|
| 3 | 570 | | friendsHud.OnViewClosed += () => |
| | 571 | | { |
| 0 | 572 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Friends); |
| 0 | 573 | | ToggleOffChatIcon(); |
| 0 | 574 | | }; |
| 3 | 575 | | } |
| | 576 | |
|
| | 577 | | public void AddVoiceChatWindow(VoiceChatWindowController controller) |
| | 578 | | { |
| 1 | 579 | | if (controller?.VoiceChatWindowView == null) |
| | 580 | | { |
| 1 | 581 | | Debug.LogWarning("AddVoiceChatWindow >>> Voice Chat window doesn't exist yet!"); |
| 1 | 582 | | return; |
| | 583 | | } |
| | 584 | |
|
| 0 | 585 | | if (controller.VoiceChatWindowView.Transform.parent == view.leftWindowContainer) |
| 0 | 586 | | return; |
| | 587 | |
|
| 0 | 588 | | controller.VoiceChatWindowView.Transform.SetParent(view.leftWindowContainer, false); |
| | 589 | |
|
| 0 | 590 | | voiceChatHud = controller; |
| 0 | 591 | | view.ShowVoiceChatButton(); |
| 0 | 592 | | voiceChatHud.OnCloseView += () => view.ToggleOff(TaskbarHUDView.TaskbarButtonType.VoiceChat); |
| | 593 | |
|
| 0 | 594 | | if (controller?.VoiceChatBarView != null) |
| | 595 | | { |
| 0 | 596 | | controller.VoiceChatBarView.Transform.SetParent(view.altSectionContainer, false); |
| 0 | 597 | | controller.VoiceChatBarView.Transform.SetAsFirstSibling(); |
| | 598 | | } |
| 0 | 599 | | } |
| | 600 | |
|
| | 601 | | private void InitializeEmotesSelector(bool current, bool previous) |
| | 602 | | { |
| 8 | 603 | | if (!current) return; |
| 0 | 604 | | view.ShowEmotesButton(); |
| 0 | 605 | | } |
| | 606 | |
|
| | 607 | | private void IsEmotesVisibleChanged(bool current, bool previous) => |
| 0 | 608 | | HandleEmotesToggle(current); |
| | 609 | |
|
| | 610 | | private void InitializeExperiencesViewer(Transform currentViewTransform, Transform previousViewTransform) |
| | 611 | | { |
| 4 | 612 | | if (currentViewTransform == null) |
| 4 | 613 | | return; |
| | 614 | |
|
| 0 | 615 | | experiencesViewerTransform = currentViewTransform; |
| 0 | 616 | | experiencesViewerTransform.SetParent(view.leftWindowContainer, false); |
| 0 | 617 | | experiencesViewerTransform.SetAsLastSibling(); |
| | 618 | |
|
| 0 | 619 | | view.ShowExperiencesButton(); |
| 0 | 620 | | } |
| | 621 | |
|
| | 622 | | private void InitializeNotificationPanel(Transform currentPanelTransform, Transform previousPanelTransform) |
| | 623 | | { |
| 4 | 624 | | if (currentPanelTransform == null) |
| 4 | 625 | | return; |
| | 626 | |
|
| 0 | 627 | | notificationViewerTransform = currentPanelTransform; |
| 0 | 628 | | notificationViewerTransform.SetParent(view.leftWindowContainer, false); |
| 0 | 629 | | notificationViewerTransform.SetAsLastSibling(); |
| 0 | 630 | | experiencesViewerTransform.SetAsLastSibling(); |
| 0 | 631 | | } |
| | 632 | |
|
| | 633 | | private void InitializeTopNotificationPanel(Transform currentPanelTransform, Transform previousPanelTransform) |
| | 634 | | { |
| 4 | 635 | | if (currentPanelTransform == null) |
| 4 | 636 | | return; |
| | 637 | |
|
| 0 | 638 | | topNotificationViewerTransform = currentPanelTransform; |
| 0 | 639 | | topNotificationViewerTransform.SetParent(view.leftWindowContainer, false); |
| 0 | 640 | | topNotificationViewerTransform.SetAsFirstSibling(); |
| 0 | 641 | | } |
| | 642 | |
|
| | 643 | | private void OpenChat(string chatId, string previous) |
| | 644 | | { |
| 0 | 645 | | if (chatId == ChatUtils.NEARBY_CHANNEL_ID) |
| 0 | 646 | | OpenPublicChat(ChatUtils.NEARBY_CHANNEL_ID, true); |
| 0 | 647 | | else if (chatController.GetAllocatedChannel(chatId) != null) |
| | 648 | | { |
| 0 | 649 | | if (chatController.GetAllocatedChannel(chatId).Joined) |
| 0 | 650 | | OpenChannelChat(chatId); |
| | 651 | | else |
| 0 | 652 | | return; |
| | 653 | | } |
| 0 | 654 | | else if (chatId == ChatUtils.CONVERSATION_LIST_ID) |
| 0 | 655 | | OpenChatList(); |
| | 656 | | else |
| | 657 | | { |
| | 658 | | async UniTaskVoid OpenPrivateChatAsync(string chatId, CancellationToken cancellationToken = default) |
| | 659 | | { |
| 0 | 660 | | var friendshipStatus = await friendsController.GetFriendshipStatus(chatId, cancellationToken); |
| | 661 | |
|
| 0 | 662 | | if (friendshipStatus == FriendshipStatus.FRIEND) |
| 0 | 663 | | OpenPrivateChat(chatId); |
| 0 | 664 | | } |
| | 665 | |
|
| 0 | 666 | | openPrivateChatCancellationToken.Cancel(); |
| 0 | 667 | | openPrivateChatCancellationToken.Dispose(); |
| 0 | 668 | | openPrivateChatCancellationToken = new CancellationTokenSource(); |
| 0 | 669 | | OpenPrivateChatAsync(chatId, openPrivateChatCancellationToken.Token).Forget(); |
| | 670 | | } |
| 0 | 671 | | } |
| | 672 | |
|
| | 673 | | private void IsExperiencesViewerOpenChanged(bool current, bool previous) |
| | 674 | | { |
| 0 | 675 | | if (current) |
| 0 | 676 | | return; |
| | 677 | |
|
| 0 | 678 | | view.ToggleOff(TaskbarHUDView.TaskbarButtonType.Experiences); |
| 0 | 679 | | ToggleOffChatIcon(); |
| 0 | 680 | | } |
| | 681 | |
|
| | 682 | | private void NumOfLoadedExperiencesChanged(int current, int previous) |
| | 683 | | { |
| 4 | 684 | | view.SetExperiencesVisibility(current > 0); |
| | 685 | |
|
| 4 | 686 | | if (current == 0) |
| 4 | 687 | | isExperiencesViewerOpen.Set(false); |
| 4 | 688 | | } |
| | 689 | |
|
| | 690 | | public void DisableFriendsWindow() |
| | 691 | | { |
| 0 | 692 | | view.friendsButton.transform.parent.gameObject.SetActive(false); |
| 0 | 693 | | } |
| | 694 | |
|
| | 695 | | public void Dispose() |
| | 696 | | { |
| 4 | 697 | | if (view != null) |
| | 698 | | { |
| 4 | 699 | | view.OnChatToggle -= HandleChatToggle; |
| 4 | 700 | | view.OnFriendsToggle -= HandleFriendsToggle; |
| 4 | 701 | | view.OnEmotesToggle -= HandleEmotesToggle; |
| 4 | 702 | | view.OnExperiencesToggle -= HandleExperiencesToggle; |
| 4 | 703 | | view.OnVoiceChatToggle -= HandleVoiceChatToggle; |
| | 704 | |
|
| 4 | 705 | | view.Destroy(); |
| | 706 | | } |
| | 707 | |
|
| 4 | 708 | | if (mouseCatcher != null) |
| | 709 | | { |
| 0 | 710 | | mouseCatcher.OnMouseLock -= MouseCatcher_OnMouseLock; |
| 0 | 711 | | mouseCatcher.OnMouseUnlock -= MouseCatcher_OnMouseUnlock; |
| | 712 | | } |
| | 713 | |
|
| 4 | 714 | | if (toggleFriendsTrigger != null) |
| 4 | 715 | | toggleFriendsTrigger.OnTriggered -= ToggleFriendsTrigger_OnTriggered; |
| | 716 | |
|
| 4 | 717 | | if (closeWindowTrigger != null) |
| 4 | 718 | | closeWindowTrigger.OnTriggered -= CloseWindowTrigger_OnTriggered; |
| | 719 | |
|
| 4 | 720 | | if (toggleWorldChatTrigger != null) |
| 4 | 721 | | toggleWorldChatTrigger.OnTriggered -= ToggleWorldChatTrigger_OnTriggered; |
| | 722 | |
|
| 4 | 723 | | isEmotesWheelInitialized.OnChange -= InitializeEmotesSelector; |
| 4 | 724 | | isEmotesVisible.OnChange -= IsEmotesVisibleChanged; |
| 4 | 725 | | isExperiencesViewerOpen.OnChange -= IsExperiencesViewerOpenChanged; |
| 4 | 726 | | isExperiencesViewerInitialized.OnChange -= InitializeExperiencesViewer; |
| 4 | 727 | | numOfLoadedExperiences.OnChange -= NumOfLoadedExperiencesChanged; |
| | 728 | |
|
| 4 | 729 | | openPrivateChatCancellationToken.Cancel(); |
| 4 | 730 | | openPrivateChatCancellationToken.Dispose(); |
| 4 | 731 | | } |
| | 732 | |
|
| | 733 | | public void SetVisibility(bool visible) |
| | 734 | | { |
| 1 | 735 | | view.SetVisibility(visible); |
| 1 | 736 | | } |
| | 737 | |
|
| | 738 | | public void GoBackFromChat() |
| | 739 | | { |
| 0 | 740 | | if (chatBackWindow == friendsHud) |
| 0 | 741 | | OpenFriendsWindow(); |
| | 742 | | else |
| 0 | 743 | | OpenChatList(); |
| 0 | 744 | | } |
| | 745 | |
|
| | 746 | | public void AddChatChannel(ChatChannelHUDController controller) |
| | 747 | | { |
| 1 | 748 | | if (controller?.View == null) |
| | 749 | | { |
| 0 | 750 | | Debug.LogWarning("AddChatChannel >>> Chat Window doesn't exist yet!"); |
| 0 | 751 | | return; |
| | 752 | | } |
| | 753 | |
|
| 1 | 754 | | if (controller.View.Transform.parent == view.leftWindowContainer) return; |
| | 755 | |
|
| 1 | 756 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 1 | 757 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 758 | |
|
| 1 | 759 | | channelChatWindow = controller; |
| | 760 | |
|
| 1 | 761 | | controller.OnClosed += ToggleOffChatIcon; |
| 1 | 762 | | controller.OnOpenChannelLeave += OpenChannelLeaveConfirmation; |
| 1 | 763 | | } |
| | 764 | |
|
| | 765 | | public void AddChannelSearch(SearchChannelsWindowController controller) |
| | 766 | | { |
| 1 | 767 | | if (controller.View.Transform.parent == view.leftWindowContainer) return; |
| | 768 | |
|
| 1 | 769 | | controller.View.Transform.SetParent(view.leftWindowContainer, false); |
| 1 | 770 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 771 | |
|
| 1 | 772 | | searchChannelsHud = controller; |
| | 773 | |
|
| 1 | 774 | | controller.OnClosed += () => |
| | 775 | | { |
| 0 | 776 | | controller.SetVisibility(false); |
| 0 | 777 | | ToggleOffChatIcon(); |
| 0 | 778 | | }; |
| | 779 | |
|
| 1 | 780 | | controller.OnBack += GoBackFromChat; |
| 1 | 781 | | controller.OnOpenChannelCreation += OpenChannelCreation; |
| 1 | 782 | | controller.OnOpenChannelLeave += OpenChannelLeaveConfirmation; |
| 1 | 783 | | } |
| | 784 | |
|
| | 785 | | public void AddChannelCreation(CreateChannelWindowController controller) |
| | 786 | | { |
| 0 | 787 | | if (controller.View.Transform.parent == view.fullScreenWindowContainer) return; |
| | 788 | |
|
| 0 | 789 | | controller.View.Transform.SetParent(view.fullScreenWindowContainer, false); |
| 0 | 790 | | experiencesViewerTransform?.SetAsLastSibling(); |
| | 791 | |
|
| 0 | 792 | | channelCreationWindow = controller; |
| | 793 | |
|
| 0 | 794 | | controller.OnNavigateToChannelWindow += channelId => |
| | 795 | | { |
| 0 | 796 | | OpenChannelChat(channelId); |
| 0 | 797 | | channelCreationWindow.SetVisibility(false); |
| 0 | 798 | | }; |
| 0 | 799 | | } |
| | 800 | |
|
| | 801 | | private void OpenChannelCreation() |
| | 802 | | { |
| 0 | 803 | | channelCreationWindow.SetVisibility(true); |
| 0 | 804 | | } |
| | 805 | |
|
| | 806 | | public void AddChannelLeaveConfirmation(LeaveChannelConfirmationWindowController controller) |
| | 807 | | { |
| 0 | 808 | | if (controller.View.Transform.parent == view.fullScreenWindowContainer) return; |
| | 809 | |
|
| 0 | 810 | | controller.View.Transform.SetParent(view.fullScreenWindowContainer, false); |
| 0 | 811 | | channelLeaveWindow = controller; |
| 0 | 812 | | } |
| | 813 | |
|
| | 814 | | private void OpenChannelLeaveConfirmation(string channelId) |
| | 815 | | { |
| 0 | 816 | | channelLeaveWindow.SetChannelToLeave(channelId); |
| 0 | 817 | | channelLeaveWindow.SetVisibility(true); |
| 0 | 818 | | } |
| | 819 | |
|
| | 820 | | public void OpenChannelSearch() |
| | 821 | | { |
| 0 | 822 | | privateChatWindow.SetVisibility(false); |
| 0 | 823 | | publicChatWindow.SetVisibility(false); |
| 0 | 824 | | channelChatWindow.SetVisibility(false); |
| 0 | 825 | | searchChannelsHud.SetVisibility(true); |
| 0 | 826 | | friendsHud?.SetVisibility(false); |
| 0 | 827 | | isExperiencesViewerOpen.Set(false); |
| 0 | 828 | | isEmotesVisible.Set(false); |
| 0 | 829 | | voiceChatHud?.SetVisibility(false); |
| 0 | 830 | | worldChatWindowHud.SetVisibility(false); |
| 0 | 831 | | view.ToggleOn(TaskbarHUDView.TaskbarButtonType.Chat); |
| 0 | 832 | | } |
| | 833 | | } |