internal void RemoveChatHead(ChatHeadButton chatHead, bool saveStatusInStorage = true) { if (chatHead == null) { return; } var animator = chatHead.GetComponent <ShowHideAnimator>(); if (animator != null) { animator.OnWillFinishHide -= Animator_OnWillFinishHide; animator.OnWillFinishHide += Animator_OnWillFinishHide; animator.Hide(); } else { Destroy(chatHead.gameObject); } chatHeads.Remove(chatHead); if (saveStatusInStorage) { LatestOpenChatsList.Model chatHeadToRemove = CommonScriptableObjects.latestOpenChats.GetList().FirstOrDefault(c => c.userId == chatHead.profile.userId); CommonScriptableObjects.latestOpenChats.Remove(chatHeadToRemove); SaveLatestOpenChats(); } }
private void FriendsController_OnUpdateUserStatus(string userId, FriendsController.UserStatus userStatus) { ChatHeadButton updatedChatHead = chatHeads.FirstOrDefault(ch => ch.profile.userId == userId); if (updatedChatHead != null) { updatedChatHead.SetOnlineStatus(userStatus.presence == PresenceStatus.ONLINE); } }
public void AddPrivateChatWindow(PrivateChatWindowHUDController controller) { if (controller == null || controller.view == null) { Debug.LogWarning("AddPrivateChatWindow >>> Private Chat Window doesn't exist yet!"); return; } if (controller.view.transform.parent == view.windowContainer) { return; } controller.view.transform.SetParent(view.windowContainer, false); privateChatWindowHud = controller; privateChatWindowHud.view.OnMinimize += () => { ChatHeadButton btn = view.GetButtonList().FirstOrDefault( (x) => x is ChatHeadButton && (x as ChatHeadButton).profile.userId == privateChatWindowHud.conversationUserId) as ChatHeadButton; if (btn != null) { btn.SetToggleState(false, false); } if (!AnyWindowsDifferentThanChatIsOpen()) { worldChatWindowHud.MarkWorldChatMessagesAsRead(); } }; privateChatWindowHud.view.OnClose += () => { ChatHeadButton btn = view.GetButtonList().FirstOrDefault( (x) => x is ChatHeadButton && (x as ChatHeadButton).profile.userId == privateChatWindowHud.conversationUserId) as ChatHeadButton; if (btn != null) { btn.SetToggleState(false, false); view.chatHeadsGroup.RemoveChatHead(btn); } if (!AnyWindowsDifferentThanChatIsOpen()) { worldChatWindowHud.MarkWorldChatMessagesAsRead(); } }; }
private void ChatHeadsGroup_OnHeadOpen(TaskbarButton taskbarBtn) { ChatHeadButton head = taskbarBtn as ChatHeadButton; if (taskbarBtn == null) { return; } OpenPrivateChatWindow(head.profile.userId); }
internal ChatHeadButton AddChatHead(string userId, ulong timestamp, bool saveStatusInStorage = true) { var existingHead = chatHeads.FirstOrDefault(x => x.profile.userId == userId); if (existingHead != null) { existingHead.lastTimestamp = timestamp; SortChatHeads(); if (saveStatusInStorage) { LatestOpenChatsList.Model existingHeadInStorage = CommonScriptableObjects.latestOpenChats.GetList().FirstOrDefault(c => c.userId == userId); if (existingHeadInStorage != null) { existingHeadInStorage.lastTimestamp = timestamp; SaveLatestOpenChats(); } } return(existingHead); } GameObject prefab = Resources.Load(CHAT_HEAD_PATH) as GameObject; GameObject instance = Instantiate(prefab, container); ChatHeadButton chatHead = instance.GetComponent <ChatHeadButton>(); chatHead.Initialize(UserProfileController.userProfilesCatalog.Get(userId)); chatHead.lastTimestamp = timestamp; chatHead.OnToggleOn += OnToggleOn; chatHead.OnToggleOff += OnToggleOff; if (friendsController != null && friendsController.GetFriends().TryGetValue(userId, out FriendsController.UserStatus friendStatus)) { chatHead.SetOnlineStatus(friendStatus.presence == PresenceStatus.ONLINE); } var animator = chatHead.GetComponent <ShowHideAnimator>(); if (animator != null) { animator.Show(); } chatHeads.Add(chatHead); SortChatHeads(); if (saveStatusInStorage) { CommonScriptableObjects.latestOpenChats.Add(new LatestOpenChatsList.Model { userId = userId, lastTimestamp = timestamp }); SaveLatestOpenChats(); } if (chatHeads.Count > MAX_GROUP_SIZE) { var lastChatHead = chatHeads[chatHeads.Count - 1]; RemoveChatHead(lastChatHead, saveStatusInStorage); } return(chatHead); }
public void ToggleWindowsProperly() { privateChatController = new PrivateChatWindowHUDController(); privateChatController.Initialize(chatController); controller.AddPrivateChatWindow(privateChatController); const string badPositionMsg = "Anchored position should be zero or it won't be correctly placed inside the taskbar"; const string badPivotMsg = "Pivot should be zero or it won't be correctly placed inside the taskbar"; RectTransform rt = privateChatController.view.transform as RectTransform; Assert.AreEqual(Vector2.zero, rt.anchoredPosition, badPositionMsg); Assert.AreEqual(Vector2.zero, rt.pivot, badPivotMsg); worldChatWindowController = new WorldChatWindowHUDController(); worldChatWindowController.Initialize(chatController, null); controller.AddWorldChatWindow(worldChatWindowController); rt = worldChatWindowController.view.transform as RectTransform; Assert.AreEqual(Vector2.zero, rt.anchoredPosition, badPositionMsg); Assert.AreEqual(Vector2.zero, rt.pivot, badPivotMsg); friendsHudController = new FriendsHUDController(); friendsHudController.Initialize(friendsController, UserProfile.GetOwnUserProfile()); controller.AddFriendsWindow(friendsHudController); rt = friendsHudController.view.transform as RectTransform; Assert.AreEqual(Vector2.zero, rt.anchoredPosition, badPositionMsg); Assert.AreEqual(Vector2.zero, rt.pivot, badPivotMsg); TestHelpers_Friends.FakeAddFriend(friendsController, friendsHudController.view, "test-1"); TestHelpers_Chat.FakePrivateChatMessageFrom(chatController, "test-1", "test message!"); var buttonList = view.GetButtonList(); Assert.AreEqual(8, buttonList.Count, "Chat head is missing when receiving a private message?"); Assert.IsFalse(view.chatButton.toggledOn); Assert.IsTrue(buttonList[2] is ChatHeadButton); ChatHeadButton headButton = buttonList[2] as ChatHeadButton; Assert.IsFalse(headButton.toggledOn); //NOTE(Brian): Toggle chat head on and test it works as intended headButton.toggleButton.onClick.Invoke(); Assert.IsTrue(headButton.lineOnIndicator.isVisible); Assert.IsFalse(view.friendsButton.lineOnIndicator.isVisible); Assert.IsFalse(view.chatButton.lineOnIndicator.isVisible); Assert.IsTrue(controller.privateChatWindowHud.view.gameObject.activeInHierarchy); //NOTE(Brian): Toggle friends window on and test all other windows are untoggled view.friendsButton.toggleButton.onClick.Invoke(); Assert.IsFalse(controller.privateChatWindowHud.view.gameObject.activeInHierarchy); Assert.IsFalse(headButton.lineOnIndicator.isVisible); Assert.IsTrue(view.friendsButton.lineOnIndicator.isVisible); Assert.IsFalse(view.chatButton.lineOnIndicator.isVisible); //NOTE(Brian): Toggle friends window off and test all other windows are untoggled view.friendsButton.toggleButton.onClick.Invoke(); Assert.IsFalse(controller.privateChatWindowHud.view.gameObject.activeInHierarchy); Assert.IsFalse(headButton.lineOnIndicator.isVisible); Assert.IsFalse(view.friendsButton.lineOnIndicator.isVisible); //NOTE(Brian): Toggle friends on, and then chat button on. Then check if world chat window is showing up. view.friendsButton.toggleButton.onClick.Invoke(); view.chatButton.toggleButton.onClick.Invoke(); Assert.IsTrue(controller.worldChatWindowHud.view.gameObject.activeInHierarchy); Assert.IsFalse(controller.friendsHud.view.gameObject.activeInHierarchy); Assert.IsFalse(view.friendsButton.lineOnIndicator.isVisible); }