| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public interface IFriendHeadForPlaceCardComponentView |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Set the background color for the friend. |
| | 9 | | /// </summary> |
| | 10 | | /// <param name="newText">New color.</param> |
| | 11 | | void SetBackgroundColor(Color newColor); |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Set the user profile information. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="profile">User profile.</param> |
| | 17 | | void SetUserProfile(UserProfile profile); |
| | 18 | | } |
| | 19 | |
|
| | 20 | | public class FriendHeadForPlaceCardComponentView : BaseComponentView, IFriendHeadForPlaceCardComponentView, IComponentMo |
| | 21 | | { |
| | 22 | | [Header("Prefab References")] |
| | 23 | | [SerializeField] internal ImageComponentView friendPortrait; |
| | 24 | | [SerializeField] internal Image friendBackground; |
| | 25 | | [SerializeField] internal TextMeshProUGUI friendName; |
| | 26 | | [SerializeField] internal ShowHideAnimator friendNameShowHideAnimator; |
| | 27 | |
|
| | 28 | | [Header("Configuration")] |
| | 29 | | [SerializeField] internal FriendHeadForPlaceCardComponentModel model; |
| | 30 | |
|
| | 31 | | public void Start() |
| | 32 | | { |
| 2 | 33 | | friendNameShowHideAnimator.gameObject.SetActive(false); |
| 2 | 34 | | } |
| | 35 | |
|
| | 36 | | public void Configure(FriendHeadForPlaceCardComponentModel newModel) |
| | 37 | | { |
| 9 | 38 | | model = newModel; |
| 9 | 39 | | RefreshControl(); |
| 9 | 40 | | } |
| | 41 | |
|
| | 42 | | public override void RefreshControl() |
| | 43 | | { |
| 9 | 44 | | if (model == null) |
| 0 | 45 | | return; |
| | 46 | |
|
| 9 | 47 | | SetBackgroundColor(model.backgroundColor); |
| 9 | 48 | | SetUserProfile(model.userProfile); |
| 9 | 49 | | } |
| | 50 | |
|
| | 51 | | public override void OnFocus() |
| | 52 | | { |
| 1 | 53 | | base.OnFocus(); |
| | 54 | |
|
| 1 | 55 | | if (!model.userProfile) |
| 0 | 56 | | return; |
| | 57 | |
|
| 1 | 58 | | if (!friendNameShowHideAnimator.gameObject.activeSelf) |
| 1 | 59 | | friendNameShowHideAnimator.gameObject.SetActive(true); |
| | 60 | |
|
| 1 | 61 | | friendNameShowHideAnimator.Show(); |
| 1 | 62 | | } |
| | 63 | |
|
| | 64 | | public override void OnLoseFocus() |
| | 65 | | { |
| 15 | 66 | | base.OnLoseFocus(); |
| | 67 | |
|
| 15 | 68 | | friendNameShowHideAnimator.Hide(); |
| 15 | 69 | | } |
| | 70 | |
|
| | 71 | | public override void Dispose() |
| | 72 | | { |
| 20 | 73 | | base.Dispose(); |
| | 74 | |
|
| 20 | 75 | | if (model.userProfile != null) |
| 14 | 76 | | model.userProfile.snapshotObserver.RemoveListener(OnFaceSnapshotLoaded); |
| | 77 | |
|
| 20 | 78 | | if (friendPortrait != null) |
| 18 | 79 | | friendPortrait.Dispose(); |
| 20 | 80 | | } |
| | 81 | |
|
| | 82 | | public void SetBackgroundColor(Color newColor) |
| | 83 | | { |
| 10 | 84 | | model.backgroundColor = newColor; |
| | 85 | |
|
| 10 | 86 | | if (friendBackground != null) |
| 10 | 87 | | friendBackground.color = newColor; |
| 10 | 88 | | } |
| | 89 | |
|
| | 90 | | public void SetUserProfile(UserProfile profile) |
| | 91 | | { |
| 11 | 92 | | model.userProfile = profile; |
| | 93 | |
|
| 11 | 94 | | if (model.userProfile != null) |
| | 95 | | { |
| 10 | 96 | | friendName.text = model.userProfile.userName; |
| 10 | 97 | | model.userProfile.snapshotObserver.RemoveListener(OnFaceSnapshotLoaded); |
| 10 | 98 | | model.userProfile.snapshotObserver.AddListener(OnFaceSnapshotLoaded); |
| | 99 | | } |
| | 100 | | else |
| | 101 | | { |
| 1 | 102 | | friendName.text = ""; |
| | 103 | | } |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | internal void OnFaceSnapshotLoaded(Texture2D texture) |
| | 107 | | { |
| 1 | 108 | | if (friendPortrait == null) |
| 0 | 109 | | return; |
| | 110 | |
|
| 1 | 111 | | friendPortrait.SetImage(texture); |
| 1 | 112 | | } |
| | 113 | | } |