| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class VoiceChatPlayerComponentView : BaseComponentView, IVoiceChatPlayerComponentView, IComponentModelConfig<Voic |
| | 7 | | { |
| | 8 | | [Header("Prefab References")] |
| | 9 | | [SerializeField] internal ImageComponentView avatarPreview; |
| | 10 | | [SerializeField] internal Sprite defaultUserSprite; |
| | 11 | | [SerializeField] internal TextMeshProUGUI userName; |
| | 12 | | [SerializeField] internal GameObject buttonsContainer; |
| | 13 | | [SerializeField] internal ButtonComponentView muteButton; |
| | 14 | | [SerializeField] internal Image muteButtonImage; |
| | 15 | | [SerializeField] internal ButtonComponentView unmuteButton; |
| | 16 | | [SerializeField] internal GameObject blockedGO; |
| | 17 | | [SerializeField] internal GameObject friendLabel; |
| | 18 | | [SerializeField] internal GameObject backgroundHover; |
| | 19 | | [SerializeField] internal Color talkingColor; |
| | 20 | | [SerializeField] internal Color nonTalkingColor; |
| | 21 | | [SerializeField] internal ButtonComponentView menuButton; |
| | 22 | | [SerializeField] internal RectTransform menuPositionReference; |
| | 23 | |
|
| | 24 | | [Header("Configuration")] |
| | 25 | | [SerializeField] internal VoiceChatPlayerComponentModel model; |
| | 26 | |
|
| | 27 | | public event Action<string, bool> OnMuteUser; |
| | 28 | | public event Action<string> OnContextMenuOpen; |
| | 29 | |
|
| | 30 | | public override void Awake() |
| | 31 | | { |
| 106 | 32 | | base.Awake(); |
| | 33 | |
|
| 106 | 34 | | muteButton.onClick.AddListener(() => |
| | 35 | | { |
| 0 | 36 | | SetAsMuted(true); |
| 0 | 37 | | OnMuteUser?.Invoke(model.userId, true); |
| 0 | 38 | | }); |
| | 39 | |
|
| 106 | 40 | | unmuteButton.onClick.AddListener(() => |
| | 41 | | { |
| 0 | 42 | | SetAsMuted(false); |
| 0 | 43 | | OnMuteUser?.Invoke(model.userId, false); |
| 0 | 44 | | }); |
| | 45 | |
|
| 106 | 46 | | menuButton.onClick.AddListener(() => OnContextMenuOpen?.Invoke(model.userId)); |
| 106 | 47 | | } |
| | 48 | |
|
| | 49 | | public void Configure(VoiceChatPlayerComponentModel newModel) |
| | 50 | | { |
| 2 | 51 | | model = newModel; |
| 2 | 52 | | RefreshControl(); |
| 2 | 53 | | } |
| | 54 | |
|
| | 55 | | public override void RefreshControl() |
| | 56 | | { |
| 2 | 57 | | if (model == null) |
| 0 | 58 | | return; |
| | 59 | |
|
| 2 | 60 | | SetUserImage(model.userImageUrl); |
| 2 | 61 | | SetUserName(model.userName); |
| 2 | 62 | | SetAsMuted(model.isMuted); |
| 2 | 63 | | SetAsTalking(model.isTalking); |
| 2 | 64 | | SetAsBlocked(model.isBlocked); |
| 2 | 65 | | SetAsFriend(model.isFriend); |
| 2 | 66 | | SetAsJoined(model.isJoined); |
| 2 | 67 | | SetBackgroundHover(model.isBackgroundHover); |
| 2 | 68 | | } |
| | 69 | |
|
| 0 | 70 | | public void SetUserId(string userId) { model.userId = userId; } |
| | 71 | |
|
| | 72 | | public void SetUserImage(string url) |
| | 73 | | { |
| 3 | 74 | | model.userImageUrl = url; |
| | 75 | |
|
| 3 | 76 | | if (avatarPreview == null) |
| 0 | 77 | | return; |
| | 78 | |
|
| 3 | 79 | | if (!string.IsNullOrEmpty(url)) |
| 1 | 80 | | avatarPreview.SetImage(url); |
| | 81 | | else |
| 2 | 82 | | avatarPreview.SetImage(defaultUserSprite); |
| 2 | 83 | | } |
| | 84 | |
|
| | 85 | | public void SetUserName(string userName) |
| | 86 | | { |
| 3 | 87 | | model.userName = userName; |
| | 88 | |
|
| 3 | 89 | | if (userName == null) |
| 0 | 90 | | return; |
| | 91 | |
|
| 3 | 92 | | this.userName.text = userName; |
| 3 | 93 | | } |
| | 94 | |
|
| | 95 | | public void SetAsMuted(bool isMuted) |
| | 96 | | { |
| 6 | 97 | | model.isMuted = isMuted; |
| | 98 | |
|
| 6 | 99 | | if (muteButton != null) |
| 6 | 100 | | muteButton.gameObject.SetActive(!isMuted); |
| | 101 | |
|
| 6 | 102 | | if (unmuteButton != null) |
| 6 | 103 | | unmuteButton.gameObject.SetActive(isMuted); |
| 6 | 104 | | } |
| | 105 | |
|
| | 106 | | public void SetAsTalking(bool isTalking) |
| | 107 | | { |
| 10 | 108 | | model.isTalking = isTalking; |
| | 109 | |
|
| 10 | 110 | | if (muteButtonImage == null) |
| 0 | 111 | | return; |
| | 112 | |
|
| 10 | 113 | | muteButtonImage.color = isTalking ? talkingColor : nonTalkingColor; |
| 10 | 114 | | } |
| | 115 | |
|
| | 116 | | public void SetAsBlocked(bool isBlocked) |
| | 117 | | { |
| 10 | 118 | | model.isBlocked = isBlocked; |
| | 119 | |
|
| 10 | 120 | | if (blockedGO == null) |
| 0 | 121 | | return; |
| | 122 | |
|
| 10 | 123 | | blockedGO.SetActive(isBlocked); |
| 10 | 124 | | } |
| | 125 | |
|
| | 126 | | public void SetAsFriend(bool isFriend) |
| | 127 | | { |
| 10 | 128 | | model.isFriend = isFriend; |
| | 129 | |
|
| 10 | 130 | | if (friendLabel == null) |
| 0 | 131 | | return; |
| | 132 | |
|
| 10 | 133 | | friendLabel.SetActive(isFriend); |
| 10 | 134 | | } |
| | 135 | |
|
| | 136 | | public void SetAsJoined(bool isJoined) |
| | 137 | | { |
| 19 | 138 | | model.isJoined = isJoined; |
| | 139 | |
|
| 19 | 140 | | if (buttonsContainer == null) |
| 0 | 141 | | return; |
| | 142 | |
|
| 19 | 143 | | buttonsContainer.SetActive(isJoined); |
| 19 | 144 | | } |
| | 145 | |
|
| | 146 | | public void SetBackgroundHover(bool isHover) |
| | 147 | | { |
| 113 | 148 | | model.isBackgroundHover = isHover; |
| | 149 | |
|
| 113 | 150 | | if (backgroundHover != null) |
| 113 | 151 | | backgroundHover.SetActive(isHover); |
| | 152 | |
|
| 113 | 153 | | if (menuButton != null) |
| 113 | 154 | | menuButton.gameObject.SetActive(isHover); |
| 113 | 155 | | } |
| | 156 | |
|
| 8 | 157 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 158 | |
|
| | 159 | | public void DockAndOpenUserContextMenu(UserContextMenu contextMenuPanel) |
| | 160 | | { |
| 1 | 161 | | var panelTransform = (RectTransform)contextMenuPanel.transform; |
| 1 | 162 | | panelTransform.pivot = menuPositionReference.pivot; |
| 1 | 163 | | panelTransform.position = menuPositionReference.position; |
| 1 | 164 | | contextMenuPanel.Show(model.userId); |
| 1 | 165 | | } |
| | 166 | |
|
| | 167 | | public override void OnFocus() |
| | 168 | | { |
| 1 | 169 | | base.OnFocus(); |
| | 170 | |
|
| 1 | 171 | | SetBackgroundHover(true); |
| 1 | 172 | | } |
| | 173 | |
|
| | 174 | | public override void OnLoseFocus() |
| | 175 | | { |
| 108 | 176 | | base.OnLoseFocus(); |
| | 177 | |
|
| 108 | 178 | | SetBackgroundHover(false); |
| 108 | 179 | | } |
| | 180 | |
|
| | 181 | | public override void Dispose() |
| | 182 | | { |
| 126 | 183 | | base.Dispose(); |
| | 184 | |
|
| 126 | 185 | | muteButton.onClick.RemoveAllListeners(); |
| 126 | 186 | | unmuteButton.onClick.RemoveAllListeners(); |
| 126 | 187 | | menuButton.onClick.RemoveAllListeners(); |
| 126 | 188 | | } |
| | 189 | |
|
| | 190 | | internal static VoiceChatPlayerComponentView Create() |
| | 191 | | { |
| 84 | 192 | | VoiceChatPlayerComponentView voiceChatPlayerComponentView = Instantiate(Resources.Load<GameObject>("SocialBarV1/ |
| 84 | 193 | | voiceChatPlayerComponentView.name = "_VoiceChatPlayer"; |
| | 194 | |
|
| 84 | 195 | | return voiceChatPlayerComponentView; |
| | 196 | | } |
| | 197 | | } |