| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UIComponents.Scripts.Components; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | public class SearchRecordComponentView : BaseComponentView<SearchRecordComponentModel>, ISearchRecordComponentView |
| | 9 | | { |
| | 10 | | [SerializeField] internal TMP_Text recordText; |
| | 11 | | [SerializeField] internal TMP_Text recordTextNoPlayerCount; |
| | 12 | | [SerializeField] internal GameObject historyIcon; |
| | 13 | | [SerializeField] private Button recordButton; |
| | 14 | | [SerializeField] internal GameObject playerCountParent; |
| | 15 | | [SerializeField] internal TMP_Text playerCount; |
| | 16 | |
|
| | 17 | | public event Action<string> OnSelectedHistoryRecord; |
| | 18 | | public event Action<Vector2Int> OnSelectedRegularRecord; |
| | 19 | |
|
| | 20 | | public override void Awake() |
| | 21 | | { |
| 9 | 22 | | base.Awake(); |
| | 23 | |
|
| 9 | 24 | | recordButton.onClick.RemoveAllListeners(); |
| 9 | 25 | | recordButton.onClick.AddListener(OnSelectedRecord); |
| 9 | 26 | | } |
| | 27 | |
|
| | 28 | | public void OnSelectedRecord() |
| | 29 | | { |
| 0 | 30 | | if (model.isHistory) |
| | 31 | | { |
| 0 | 32 | | OnSelectedHistoryRecord?.Invoke(model.recordText); |
| | 33 | | } |
| | 34 | | else |
| | 35 | | { |
| 0 | 36 | | OnSelectedRegularRecord?.Invoke(model.placeCoordinates); |
| | 37 | | } |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | public override void RefreshControl() |
| | 41 | | { |
| 5 | 42 | | if (model == null) |
| 0 | 43 | | return; |
| | 44 | |
|
| 5 | 45 | | SetRecordText(model.recordText); |
| 5 | 46 | | SetIcon(model.isHistory); |
| 5 | 47 | | SetPlayerCount(model.playerCount); |
| 5 | 48 | | SetCoordinates(model.placeCoordinates); |
| 5 | 49 | | } |
| | 50 | |
|
| | 51 | | public void SetRecordText(string text) |
| | 52 | | { |
| 6 | 53 | | model.recordText = text; |
| 6 | 54 | | recordText.text = text; |
| 6 | 55 | | recordTextNoPlayerCount.text = text; |
| 6 | 56 | | } |
| | 57 | |
|
| | 58 | | public void SetIcon(bool isHistory) |
| | 59 | | { |
| 6 | 60 | | model.isHistory = isHistory; |
| 6 | 61 | | historyIcon.SetActive(isHistory); |
| 6 | 62 | | } |
| | 63 | |
|
| | 64 | | public void SetPlayerCount(int count) |
| | 65 | | { |
| 7 | 66 | | playerCountParent.SetActive(count > 0); |
| 7 | 67 | | recordText.gameObject.SetActive(count > 0); |
| 7 | 68 | | recordTextNoPlayerCount.gameObject.SetActive(count == 0); |
| 7 | 69 | | playerCount.text = count.ToString(); |
| 7 | 70 | | } |
| | 71 | |
|
| | 72 | | public void SetCoordinates(Vector2Int coordinates) |
| | 73 | | { |
| 5 | 74 | | model.placeCoordinates = coordinates; |
| 5 | 75 | | } |
| | 76 | | } |