| | 1 | | using DCL.Social.Chat; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.EventSystems; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Social.Chat |
| | 9 | | { |
| | 10 | | public class PublicChatWindowComponentView : BaseComponentView, IPublicChatWindowView, IComponentModelConfig<PublicC |
| | 11 | | { |
| | 12 | | private const int MEMBERS_SECTION_WIDTH = 280; |
| | 13 | |
|
| | 14 | | [SerializeField] internal Button closeButton; |
| | 15 | | [SerializeField] internal Button backButton; |
| | 16 | | [SerializeField] internal TMP_Text nameLabel; |
| | 17 | | [SerializeField] internal ChatHUDView chatView; |
| | 18 | | [SerializeField] internal PublicChatModel model; |
| | 19 | | [SerializeField] internal ToggleComponentView muteToggle; |
| | 20 | | [SerializeField] internal RectTransform collapsableArea; |
| | 21 | | [SerializeField] internal ButtonComponentView expandMembersListButton; |
| | 22 | | [SerializeField] internal ButtonComponentView collapseMembersListButton; |
| | 23 | | [SerializeField] internal ChannelMembersComponentView membersList; |
| | 24 | | [SerializeField] internal ButtonComponentView goToCrowdButton; |
| | 25 | | [SerializeField] internal TMP_Text memberCountLabel; |
| | 26 | | [SerializeField] internal Button membersIconButton; |
| | 27 | |
|
| | 28 | | private Coroutine alphaRoutine; |
| | 29 | |
|
| | 30 | | public event Action OnClose; |
| | 31 | | public event Action OnBack; |
| | 32 | | public event Action<bool> OnFocused |
| | 33 | | { |
| 2 | 34 | | add => onFocused += value; |
| 0 | 35 | | remove => onFocused -= value; |
| | 36 | | } |
| | 37 | | public event Action OnClickOverWindow; |
| | 38 | | public event Action<bool> OnMuteChanged; |
| | 39 | | public event Action OnShowMembersList; |
| | 40 | | public event Action OnHideMembersList; |
| | 41 | | public event Action OnGoToCrowd; |
| | 42 | |
|
| 0 | 43 | | public bool IsActive => gameObject.activeInHierarchy; |
| 3 | 44 | | public IChatHUDComponentView ChatHUD => chatView; |
| 0 | 45 | | public RectTransform Transform => (RectTransform) transform; |
| 1 | 46 | | public IChannelMembersComponentView ChannelMembersHUD => membersList; |
| | 47 | |
|
| | 48 | | private bool isMembersSectionOpen; |
| | 49 | | private float collapsableAreaOriginalWidth; |
| | 50 | | private Color targetGraphicColor; |
| | 51 | |
|
| | 52 | | public override void Awake() |
| | 53 | | { |
| 11 | 54 | | base.Awake(); |
| | 55 | |
|
| 12 | 56 | | backButton.onClick.AddListener(() => OnBack?.Invoke()); |
| 12 | 57 | | closeButton.onClick.AddListener(() => OnClose?.Invoke()); |
| 11 | 58 | | muteToggle.OnSelectedChanged += (b, s, arg3) => OnMuteChanged?.Invoke(b); |
| 11 | 59 | | expandMembersListButton.onClick.AddListener(ToggleMembersSection); |
| 11 | 60 | | collapseMembersListButton.onClick.AddListener(ToggleMembersSection); |
| 11 | 61 | | collapsableAreaOriginalWidth = collapsableArea.sizeDelta.x; |
| 11 | 62 | | membersIconButton.onClick.AddListener(ToggleMembersSection); |
| 11 | 63 | | targetGraphicColor = membersIconButton.targetGraphic.color; |
| | 64 | |
|
| 11 | 65 | | if (goToCrowdButton != null) |
| 11 | 66 | | goToCrowdButton.onClick.AddListener(() => OnGoToCrowd?.Invoke()); |
| 11 | 67 | | } |
| | 68 | |
|
| | 69 | | public override void RefreshControl() |
| | 70 | | { |
| 3 | 71 | | nameLabel.text = $"~{model.name}"; |
| 3 | 72 | | memberCountLabel.text = model.memberCount.ToString(); |
| 3 | 73 | | muteToggle.SetIsOnWithoutNotify(model.muted); |
| 3 | 74 | | } |
| | 75 | |
|
| 2 | 76 | | public void Hide() => gameObject.SetActive(false); |
| | 77 | |
|
| | 78 | | public void Show() |
| | 79 | | { |
| 3 | 80 | | gameObject.SetActive(true); |
| | 81 | |
|
| 3 | 82 | | if (!isMembersSectionOpen) |
| 2 | 83 | | ToggleMembersSection(); |
| 3 | 84 | | } |
| | 85 | |
|
| | 86 | | public void Configure(PublicChatModel model) |
| | 87 | | { |
| 3 | 88 | | this.model = model; |
| 3 | 89 | | RefreshControl(); |
| 3 | 90 | | } |
| | 91 | |
|
| 1 | 92 | | public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke(); |
| | 93 | |
|
| | 94 | | public void UpdateMembersCount(int membersAmount) => |
| 1 | 95 | | memberCountLabel.text = membersAmount.ToString(); |
| | 96 | |
|
| | 97 | | private void ToggleMembersSection() |
| | 98 | | { |
| 2 | 99 | | isMembersSectionOpen = !isMembersSectionOpen; |
| | 100 | |
|
| 2 | 101 | | expandMembersListButton.gameObject.SetActive(!isMembersSectionOpen); |
| 2 | 102 | | collapseMembersListButton.gameObject.SetActive(isMembersSectionOpen); |
| | 103 | |
|
| 2 | 104 | | collapsableArea.SetSizeWithCurrentAnchors( |
| | 105 | | RectTransform.Axis.Horizontal, |
| | 106 | | isMembersSectionOpen ? collapsableAreaOriginalWidth + MEMBERS_SECTION_WIDTH : collapsableAreaOriginalWid |
| | 107 | |
|
| 2 | 108 | | if (isMembersSectionOpen) |
| | 109 | | { |
| 2 | 110 | | targetGraphicColor.a = 1f; |
| 2 | 111 | | membersIconButton.targetGraphic.color = targetGraphicColor; |
| 2 | 112 | | OnShowMembersList?.Invoke(); |
| | 113 | | } |
| | 114 | | else |
| | 115 | | { |
| 0 | 116 | | targetGraphicColor.a = 0f; |
| 0 | 117 | | membersIconButton.targetGraphic.color = targetGraphicColor; |
| 0 | 118 | | OnHideMembersList?.Invoke(); |
| | 119 | | } |
| 0 | 120 | | } |
| | 121 | | } |
| | 122 | | } |