| | 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 | |
|
| 4 | 31 | | public override void Start() { friendNameShowHideAnimator.gameObject.SetActive(false); } |
| | 32 | |
|
| | 33 | | public void Configure(BaseComponentModel newModel) |
| | 34 | | { |
| 9 | 35 | | model = (FriendHeadForPlaceCardComponentModel)newModel; |
| 9 | 36 | | RefreshControl(); |
| 9 | 37 | | } |
| | 38 | |
|
| | 39 | | public override void RefreshControl() |
| | 40 | | { |
| 9 | 41 | | if (model == null) |
| 0 | 42 | | return; |
| | 43 | |
|
| 9 | 44 | | SetBackgroundColor(model.backgroundColor); |
| 9 | 45 | | SetUserProfile(model.userProfile); |
| 9 | 46 | | } |
| | 47 | |
|
| | 48 | | public override void OnFocus() |
| | 49 | | { |
| 1 | 50 | | base.OnFocus(); |
| | 51 | |
|
| 1 | 52 | | if (!model.userProfile) |
| 0 | 53 | | return; |
| | 54 | |
|
| 1 | 55 | | if (!friendNameShowHideAnimator.gameObject.activeSelf) |
| 1 | 56 | | friendNameShowHideAnimator.gameObject.SetActive(true); |
| | 57 | |
|
| 1 | 58 | | friendNameShowHideAnimator.Show(); |
| 1 | 59 | | } |
| | 60 | |
|
| | 61 | | public override void OnLoseFocus() |
| | 62 | | { |
| 15 | 63 | | base.OnLoseFocus(); |
| | 64 | |
|
| 15 | 65 | | friendNameShowHideAnimator.Hide(); |
| 15 | 66 | | } |
| | 67 | |
|
| | 68 | | public override void Dispose() |
| | 69 | | { |
| 20 | 70 | | base.Dispose(); |
| | 71 | |
|
| 20 | 72 | | if (model.userProfile != null) |
| 14 | 73 | | model.userProfile.snapshotObserver.RemoveListener(OnFaceSnapshotLoaded); |
| | 74 | |
|
| 20 | 75 | | if (friendPortrait != null) |
| 18 | 76 | | friendPortrait.Dispose(); |
| 20 | 77 | | } |
| | 78 | |
|
| | 79 | | public void SetBackgroundColor(Color newColor) |
| | 80 | | { |
| 10 | 81 | | model.backgroundColor = newColor; |
| | 82 | |
|
| 10 | 83 | | if (friendBackground != null) |
| 10 | 84 | | friendBackground.color = newColor; |
| 10 | 85 | | } |
| | 86 | |
|
| | 87 | | public void SetUserProfile(UserProfile profile) |
| | 88 | | { |
| 11 | 89 | | model.userProfile = profile; |
| | 90 | |
|
| 11 | 91 | | if (model.userProfile != null) |
| | 92 | | { |
| 10 | 93 | | friendName.text = model.userProfile.userName; |
| 10 | 94 | | model.userProfile.snapshotObserver.RemoveListener(OnFaceSnapshotLoaded); |
| 10 | 95 | | model.userProfile.snapshotObserver.AddListener(OnFaceSnapshotLoaded); |
| 10 | 96 | | } |
| | 97 | | else |
| | 98 | | { |
| 1 | 99 | | friendName.text = ""; |
| | 100 | | } |
| 1 | 101 | | } |
| | 102 | |
|
| | 103 | | internal void OnFaceSnapshotLoaded(Texture2D texture) |
| | 104 | | { |
| 1 | 105 | | if (friendPortrait == null) |
| 0 | 106 | | return; |
| | 107 | |
|
| 1 | 108 | | friendPortrait.SetImage(texture); |
| 1 | 109 | | } |
| | 110 | | } |