| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace DCL.Social.Chat |
| | 8 | | { |
| | 9 | | public class ChatChannelComponentView : BaseComponentView, IChatChannelWindowView, IComponentModelConfig<PublicChatM |
| | 10 | | IPointerDownHandler |
| | 11 | | { |
| | 12 | | private const int MEMBERS_SECTION_WIDTH = 280; |
| | 13 | |
|
| | 14 | | [SerializeField] internal Button closeButton; |
| | 15 | | [SerializeField] internal Button backButton; |
| | 16 | | [SerializeField] internal Button optionsButton; |
| | 17 | | [SerializeField] internal TMP_Text nameLabel; |
| | 18 | | [SerializeField] internal ChatHUDView chatView; |
| | 19 | | [SerializeField] internal PublicChatModel model; |
| | 20 | | [SerializeField] internal GameObject messagesLoading; |
| | 21 | | [SerializeField] internal ScrollRect scroll; |
| | 22 | | [SerializeField] internal GameObject oldMessagesLoadingContainer; |
| | 23 | | [SerializeField] internal ChannelContextualMenu contextualMenu; |
| | 24 | | [SerializeField] internal TMP_Text memberCountLabel; |
| | 25 | | [SerializeField] internal RectTransform collapsableArea; |
| | 26 | | [SerializeField] internal Button membersIconButton; |
| | 27 | | [SerializeField] internal ButtonComponentView expandMembersListButton; |
| | 28 | | [SerializeField] internal ButtonComponentView collapseMembersListButton; |
| | 29 | | [SerializeField] internal ChannelMembersComponentView membersList; |
| | 30 | | [SerializeField] internal ToggleComponentView muteToggle; |
| | 31 | |
|
| | 32 | | private Coroutine alphaRoutine; |
| | 33 | | private bool isMembersSectionOpen; |
| | 34 | | private float collapsableAreaOriginalWidth; |
| | 35 | |
|
| | 36 | | public event Action OnClose; |
| | 37 | | public event Action<bool> OnFocused; |
| | 38 | | public event Action OnBack; |
| | 39 | | public event Action OnRequireMoreMessages; |
| | 40 | | public event Action OnLeaveChannel; |
| | 41 | | public event Action OnShowMembersList; |
| | 42 | | public event Action OnHideMembersList; |
| | 43 | | public event Action<bool> OnMuteChanged; |
| | 44 | | public event Action<string> OnCopyNameRequested; |
| | 45 | |
|
| 0 | 46 | | public bool IsActive => gameObject.activeInHierarchy; |
| 3 | 47 | | public IChatHUDComponentView ChatHUD => chatView; |
| 1 | 48 | | public IChannelMembersComponentView ChannelMembersHUD => membersList; |
| 0 | 49 | | public RectTransform Transform => (RectTransform) transform; |
| 0 | 50 | | public bool IsFocused => isFocused; |
| | 51 | | private Color targetGraphicColor; |
| | 52 | |
|
| | 53 | | public override void Awake() |
| | 54 | | { |
| 2 | 55 | | base.Awake(); |
| 2 | 56 | | backButton.onClick.AddListener(() => OnBack?.Invoke()); |
| 2 | 57 | | closeButton.onClick.AddListener(() => OnClose?.Invoke()); |
| 3 | 58 | | contextualMenu.OnLeave += () => OnLeaveChannel?.Invoke(); |
| 2 | 59 | | contextualMenu.OnNameCopied += s => OnCopyNameRequested?.Invoke(s); |
| 2 | 60 | | optionsButton.onClick.AddListener(ShowOptionsMenu); |
| | 61 | | // TODO: It was decided to temporally remove the loading of the channel's history. We'll re-enable it later. |
| | 62 | | //scroll.onValueChanged.AddListener(scrollPos => |
| | 63 | | //{ |
| | 64 | | // if (scrollPos.y > 0.995f) |
| | 65 | | // OnRequireMoreMessages?.Invoke(); |
| | 66 | | //}); |
| | 67 | |
|
| 2 | 68 | | collapsableAreaOriginalWidth = collapsableArea.sizeDelta.x; |
| 2 | 69 | | membersIconButton.onClick.AddListener(ToggleMembersSection); |
| 2 | 70 | | expandMembersListButton.onClick.AddListener(ToggleMembersSection); |
| 2 | 71 | | collapseMembersListButton.onClick.AddListener(ToggleMembersSection); |
| 2 | 72 | | muteToggle.OnSelectedChanged += (b, s, arg3) => OnMuteChanged?.Invoke(b); |
| 2 | 73 | | targetGraphicColor = membersIconButton.targetGraphic.color; |
| 2 | 74 | | } |
| | 75 | |
|
| | 76 | | public override void RefreshControl() |
| | 77 | | { |
| 1 | 78 | | nameLabel.text = $"#{model.name}"; |
| 1 | 79 | | memberCountLabel.text = model.memberCount.ToString(); |
| 1 | 80 | | muteToggle.SetIsOnWithoutNotify(model.muted); |
| 1 | 81 | | } |
| | 82 | |
|
| 1 | 83 | | public void Hide() => gameObject.SetActive(false); |
| | 84 | |
|
| | 85 | | public void Show() |
| | 86 | | { |
| 2 | 87 | | gameObject.SetActive(true); |
| | 88 | |
|
| 2 | 89 | | if (!isMembersSectionOpen) |
| 1 | 90 | | ToggleMembersSection(); |
| 2 | 91 | | } |
| | 92 | |
|
| | 93 | | public void Setup(PublicChatModel model) |
| | 94 | | { |
| 1 | 95 | | this.model = model; |
| 1 | 96 | | RefreshControl(); |
| 1 | 97 | | } |
| | 98 | |
|
| | 99 | | public void SetLoadingMessagesActive(bool isActive) |
| | 100 | | { |
| 2 | 101 | | if (messagesLoading == null) return; |
| 2 | 102 | | messagesLoading.SetActive(isActive); |
| 2 | 103 | | } |
| | 104 | |
|
| | 105 | | public void SetOldMessagesLoadingActive(bool isActive) |
| | 106 | | { |
| 2 | 107 | | if (oldMessagesLoadingContainer == null) return; |
| 2 | 108 | | oldMessagesLoadingContainer.SetActive(isActive); |
| 2 | 109 | | oldMessagesLoadingContainer.transform.SetAsFirstSibling(); |
| 2 | 110 | | } |
| | 111 | |
|
| 0 | 112 | | public void Configure(PublicChatModel newModel) => Setup(newModel); |
| | 113 | |
|
| 0 | 114 | | public void OnPointerDown(PointerEventData eventData) => OnFocused?.Invoke(true); |
| | 115 | |
|
| | 116 | | public override void OnPointerExit(PointerEventData eventData) |
| | 117 | | { |
| 0 | 118 | | base.OnPointerExit(eventData); |
| 0 | 119 | | OnFocused?.Invoke(false); |
| 0 | 120 | | } |
| | 121 | |
|
| | 122 | | private void ShowOptionsMenu() |
| | 123 | | { |
| 1 | 124 | | contextualMenu.SetHeaderTitle($"#{model.name}"); |
| 1 | 125 | | contextualMenu.Show(); |
| 1 | 126 | | } |
| | 127 | |
|
| | 128 | | private void ToggleMembersSection() |
| | 129 | | { |
| 1 | 130 | | isMembersSectionOpen = !isMembersSectionOpen; |
| | 131 | |
|
| 1 | 132 | | expandMembersListButton.gameObject.SetActive(!isMembersSectionOpen); |
| 1 | 133 | | collapseMembersListButton.gameObject.SetActive(isMembersSectionOpen); |
| | 134 | |
|
| 1 | 135 | | contextualMenu.gameObject.transform.SetParent(collapsableArea); |
| | 136 | |
|
| 1 | 137 | | collapsableArea.SetSizeWithCurrentAnchors( |
| | 138 | | RectTransform.Axis.Horizontal, |
| | 139 | | isMembersSectionOpen ? collapsableAreaOriginalWidth + MEMBERS_SECTION_WIDTH : collapsableAreaOriginalWid |
| | 140 | |
|
| 1 | 141 | | contextualMenu.gameObject.transform.SetParent(this.transform); |
| | 142 | |
|
| 1 | 143 | | if (isMembersSectionOpen) |
| | 144 | | { |
| 1 | 145 | | targetGraphicColor.a = 1f; |
| 1 | 146 | | membersIconButton.targetGraphic.color = targetGraphicColor; |
| 1 | 147 | | OnShowMembersList?.Invoke(); |
| | 148 | | } |
| | 149 | | else |
| | 150 | | { |
| 0 | 151 | | targetGraphicColor.a = 0f; |
| 0 | 152 | | membersIconButton.targetGraphic.color = targetGraphicColor; |
| 0 | 153 | | OnHideMembersList?.Invoke(); |
| | 154 | | } |
| 0 | 155 | | } |
| | 156 | | } |
| | 157 | | } |