| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public class PublishLandListView : ListView<LandWithAccess> |
| | 8 | | { |
| | 9 | | public event Action<LandWithAccess> OnLandSelected; |
| | 10 | | public event Action<LandWithAccess> OnWrongLandSelected; |
| | 11 | |
|
| | 12 | | [SerializeField] internal PubllishLandListAdapter adapter; |
| | 13 | |
|
| 0 | 14 | | private List<PubllishLandListAdapter> adapterList = new List<PubllishLandListAdapter>(); |
| | 15 | | private int projectRows; |
| | 16 | | private int projectCols; |
| | 17 | |
|
| | 18 | | private bool selectedSet = false; |
| | 19 | | private RectTransform rectTransform; |
| | 20 | |
|
| | 21 | | public void Awake() |
| | 22 | | { |
| 0 | 23 | | rectTransform = GetComponent<RectTransform>(); |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public void SetActive(bool isActive) |
| | 27 | | { |
| 0 | 28 | | gameObject.SetActive(isActive); |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | public void SetContent(int cols, int rows, List<LandWithAccess>lands) |
| | 32 | | { |
| 0 | 33 | | contentPanelTransform.gameObject.SetActive( lands.Count > 0); |
| 0 | 34 | | projectCols = cols; |
| 0 | 35 | | projectRows = rows; |
| 0 | 36 | | selectedSet = false; |
| | 37 | |
|
| 0 | 38 | | SetContent(lands); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void AddAdapters() |
| | 42 | | { |
| 0 | 43 | | base.AddAdapters(); |
| | 44 | |
|
| 0 | 45 | | foreach (LandWithAccess landWithAccess in contentList) |
| | 46 | | { |
| 0 | 47 | | CreateAdapter(landWithAccess); |
| | 48 | | } |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | public override void RemoveAdapters() |
| | 52 | | { |
| 0 | 53 | | base.RemoveAdapters(); |
| 0 | 54 | | adapterList.Clear(); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | public void HideEmptyContent() |
| | 58 | | { |
| 0 | 59 | | emptyContentMark.SetActive(false); |
| 0 | 60 | | } |
| | 61 | |
|
| | 62 | | internal void SelectedLand(LandWithAccess land) |
| | 63 | | { |
| 0 | 64 | | foreach (PubllishLandListAdapter adapter in adapterList) |
| | 65 | | { |
| 0 | 66 | | if (adapter.GetLand() != land) |
| | 67 | | continue; |
| | 68 | |
|
| 0 | 69 | | if (adapter.GetState() == PubllishLandListAdapter.AdapterState.ENABLE) |
| | 70 | | { |
| 0 | 71 | | OnLandSelected?.Invoke(land); |
| 0 | 72 | | } |
| | 73 | | else |
| | 74 | | { |
| 0 | 75 | | OnWrongLandSelected?.Invoke(land); |
| | 76 | | } |
| | 77 | | } |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | internal void CreateAdapter(LandWithAccess land) |
| | 81 | | { |
| 0 | 82 | | Vector2Int rowsAndColum = BIWUtils.GetRowsAndColumsFromLand(land); |
| 0 | 83 | | PubllishLandListAdapter instanciatedAdapter = Instantiate(adapter, contentPanelTransform).GetComponent<PubllishL |
| 0 | 84 | | var status = rowsAndColum.x >= projectCols && rowsAndColum.y >= projectRows && BIWUtils.HasSquareSize(land) ? Pu |
| | 85 | |
|
| 0 | 86 | | instanciatedAdapter.SetContent(land, status); |
| 0 | 87 | | instanciatedAdapter.OnLandSelected += SelectedLand; |
| 0 | 88 | | adapterList.Add(instanciatedAdapter); |
| 0 | 89 | | } |
| | 90 | |
|
| 0 | 91 | | private void Update() { HideIfClickedOutside(); } |
| | 92 | |
|
| | 93 | | private void HideIfClickedOutside() |
| | 94 | | { |
| 0 | 95 | | if (Input.GetMouseButtonDown(0) && |
| | 96 | | !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition)) |
| | 97 | | { |
| 0 | 98 | | SetActive(false); |
| | 99 | | } |
| 0 | 100 | | } |
| | 101 | | } |