| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | public class PubllishLandListAdapter : MonoBehaviour |
| | 9 | | { |
| | 10 | | public enum AdapterState |
| | 11 | | { |
| | 12 | | ENABLE = 0, |
| | 13 | | DISABLE = 1 |
| | 14 | | } |
| | 15 | |
|
| | 16 | | public event Action<LandWithAccess> OnLandSelected; |
| | 17 | |
|
| | 18 | | [SerializeField] internal TextMeshProUGUI landNameTxt; |
| | 19 | |
|
| | 20 | | [SerializeField] internal Button selectButton; |
| | 21 | |
|
| | 22 | | internal LandWithAccess land; |
| | 23 | | internal AdapterState currentState; |
| | 24 | |
|
| 0 | 25 | | public AdapterState GetState() => currentState; |
| 0 | 26 | | public LandWithAccess GetLand() => land; |
| | 27 | |
|
| 0 | 28 | | private void Awake() { selectButton.onClick.AddListener(ItemSelected); } |
| | 29 | |
|
| 0 | 30 | | private void OnDestroy() { selectButton.onClick.RemoveAllListeners(); } |
| | 31 | |
|
| | 32 | | public void SetContent(LandWithAccess land, AdapterState state) |
| | 33 | | { |
| 0 | 34 | | this.land = land; |
| | 35 | |
|
| 0 | 36 | | string text = land.name; |
| 0 | 37 | | string coordsText = BIWUtils.Vector2INTToString(land.baseCoords); |
| 0 | 38 | | if(!text.Contains(coordsText)) |
| 0 | 39 | | text += " <color=#716B7C>"+coordsText+"</color>"; |
| | 40 | |
|
| 0 | 41 | | landNameTxt.text = text; |
| | 42 | |
|
| 0 | 43 | | SetState(state); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | public void SetState(AdapterState state) |
| | 47 | | { |
| 0 | 48 | | currentState = state; |
| 0 | 49 | | } |
| | 50 | |
|
| 0 | 51 | | public void ItemSelected() { OnLandSelected?.Invoke(land); } |
| | 52 | | } |