| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.EventSystems; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public class ChatHeadButton : TaskbarButton, IPointerEnterHandler, IPointerExitHandler |
| | 6 | | { |
| | 7 | | [SerializeField] internal ShowHideAnimator labelContainer; |
| | 8 | | [SerializeField] internal TMPro.TextMeshProUGUI label; |
| | 9 | | [SerializeField] internal RawImage portrait; |
| | 10 | | [SerializeField] internal UnreadNotificationBadge unreadNotificationBadge; |
| | 11 | | [SerializeField] internal Image onlineStatusIndicator; |
| 2 | 12 | | [SerializeField] internal Color onlineColor = Color.green; |
| 2 | 13 | | [SerializeField] internal Color offlineColor = Color.gray; |
| | 14 | |
|
| | 15 | | internal ulong lastTimestamp; |
| | 16 | | internal UserProfile profile; |
| | 17 | |
|
| | 18 | | public void Initialize(UserProfile profile) |
| | 19 | | { |
| 1 | 20 | | base.Initialize(); |
| 1 | 21 | | this.profile = profile; |
| 1 | 22 | | unreadNotificationBadge.Initialize(ChatController.i, profile.userId); |
| | 23 | |
|
| 1 | 24 | | if (profile.userName.Length > 10) |
| 1 | 25 | | label.text = profile.userName.Substring(0, 10) + "..."; |
| | 26 | | else |
| 0 | 27 | | label.text = profile.userName; |
| | 28 | |
|
| 1 | 29 | | profile.snapshotObserver.AddListener(Profile_OnFaceSnapshotReadyEvent); |
| 1 | 30 | | SetOnlineStatus(false); |
| 1 | 31 | | } |
| | 32 | |
|
| | 33 | | private void Profile_OnFaceSnapshotReadyEvent(Texture2D portraitTexture) |
| | 34 | | { |
| 0 | 35 | | this.portrait.texture = portraitTexture; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | private void OnDestroy() |
| | 39 | | { |
| 1 | 40 | | if (profile != null) |
| 1 | 41 | | profile.snapshotObserver.RemoveListener(Profile_OnFaceSnapshotReadyEvent); |
| 1 | 42 | | } |
| | 43 | |
|
| 0 | 44 | | public void OnPointerEnter(PointerEventData eventData) { labelContainer.Show(); } |
| | 45 | |
|
| 0 | 46 | | public void OnPointerExit(PointerEventData eventData) { labelContainer.Hide(); } |
| | 47 | |
|
| 2 | 48 | | public void SetOnlineStatus(bool isOnline) { onlineStatusIndicator.color = isOnline ? onlineColor : offlineColor; } |
| | 49 | | } |