| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UIComponents.Scripts.Components; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.EventSystems; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Social.Chat |
| | 9 | | { |
| | 10 | | public class ChatMentionSuggestionEntryComponentView : BaseComponentView<ChatMentionSuggestionModel>, |
| | 11 | | ISelectHandler, IDeselectHandler, ISubmitHandler |
| | 12 | | { |
| | 13 | | [SerializeField] internal Button selectButton; |
| | 14 | | [SerializeField] internal TMP_Text userNameLabel; |
| | 15 | | [SerializeField] internal ImageComponentView faceImage; |
| | 16 | |
|
| | 17 | | private bool isSelected; |
| | 18 | |
|
| | 19 | | public event Action<ChatMentionSuggestionModel> OnSubmitted; |
| | 20 | |
|
| | 21 | | public bool IsSelected |
| | 22 | | { |
| | 23 | | get |
| | 24 | | { |
| 0 | 25 | | GameObject selectedGameObject = EventSystem.current.currentSelectedGameObject; |
| 0 | 26 | | return selectedGameObject == gameObject || selectedGameObject == selectButton.gameObject |
| | 27 | | || isSelected; |
| | 28 | | } |
| | 29 | | } |
| | 30 | |
|
| | 31 | | public override void Awake() |
| | 32 | | { |
| 6 | 33 | | base.Awake(); |
| | 34 | |
|
| 7 | 35 | | selectButton.onClick.AddListener(() => OnSubmitted?.Invoke(model)); |
| 6 | 36 | | } |
| | 37 | |
|
| | 38 | | public override void RefreshControl() |
| | 39 | | { |
| 4 | 40 | | userNameLabel.text = model.userName; |
| 4 | 41 | | faceImage.SetImage(model.imageUrl); |
| 4 | 42 | | } |
| | 43 | |
|
| | 44 | | public void OnSelect(BaseEventData eventData) |
| | 45 | | { |
| 2 | 46 | | selectButton.OnSelect(eventData); |
| 2 | 47 | | isSelected = true; |
| 2 | 48 | | } |
| | 49 | |
|
| | 50 | | public void OnDeselect(BaseEventData eventData) |
| | 51 | | { |
| 0 | 52 | | selectButton.OnDeselect(eventData); |
| 0 | 53 | | isSelected = false; |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | public void OnSubmit(BaseEventData eventData) => |
| 0 | 57 | | selectButton.OnSubmit(eventData); |
| | 58 | |
|
| | 59 | | public void Deselect() => |
| 0 | 60 | | OnDeselect(null); |
| | 61 | |
|
| | 62 | | public void Select() => |
| 2 | 63 | | OnSelect(null); |
| | 64 | | } |
| | 65 | | } |