B08_TaskListItem.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class B08_TaskListItem : MonoBehaviour
  6. {
  7. public Text typeText;
  8. public Text titleText;
  9. public Text stateText;
  10. public Text dateText;
  11. public Text ctrlText;
  12. public GameObject more;
  13. public Button moreButton;
  14. public bool moreMessage = false;
  15. public RectTransform rect;
  16. public GameObject pointItemPrefab;
  17. public List<B08_TaskPointItem> PointItems = new List<B08_TaskPointItem>();
  18. public Transform itemContent;
  19. public B08_TaskInfoData InfoData;
  20. public GCYWLayer gcywLayer;
  21. public static B08_TaskListItem currentTaskListItem;
  22. public void Init()
  23. {
  24. rect = this.GetComponent<RectTransform>();
  25. typeText = this.transform.Find("typeText").GetComponent<Text>();
  26. titleText = this.transform.Find("titleText").GetComponent<Text>();
  27. stateText = this.transform.Find("stateText").GetComponent<Text>();
  28. dateText = this.transform.Find("dateText").GetComponent<Text>();
  29. ctrlText = this.transform.Find("ctrlText").GetComponent<Text>();
  30. more = this.transform.Find("more").gameObject;
  31. more.SetActive(false);
  32. moreButton = ctrlText.GetComponent<Button>();
  33. moreButton.onClick.AddListener(() => { ChangeMoreMessage(!moreMessage); });
  34. moreMessage = false;
  35. ctrlText.text = "<color=#00EFFF>详情</color>";
  36. rect.sizeDelta = new Vector2(360, 38);
  37. more.SetActive(false);
  38. }
  39. public void ChangeMoreMessage(bool moreMes = false)
  40. {
  41. moreMessage = moreMes;
  42. if (moreMessage)
  43. {
  44. if (currentTaskListItem != null && currentTaskListItem != this)
  45. {
  46. if (currentTaskListItem.moreMessage)
  47. {
  48. currentTaskListItem.ChangeMoreMessage(false);
  49. }
  50. }
  51. ctrlText.text = "<color=#00FF3F>收起</color>";
  52. rect.sizeDelta = new Vector2(360, 354);
  53. more.SetActive(true);
  54. gcywLayer.SetTaskImgPanelData(InfoData.Locations, InfoData.createTime);
  55. currentTaskListItem = this;
  56. }
  57. else
  58. {
  59. ctrlText.text = "<color=#00EFFF>详情</color>";
  60. rect.sizeDelta = new Vector2(360, 38);
  61. more.SetActive(false);
  62. }
  63. }
  64. public void SetData(GCYWLayer baseLayer, B08_TaskInfoData data)
  65. {
  66. gcywLayer = baseLayer;
  67. InfoData = data;
  68. string typeStr = "";
  69. switch (data.type)
  70. {
  71. case "0":
  72. typeStr = "电气";
  73. break;
  74. case "1":
  75. typeStr = "闸站";
  76. break;
  77. case "2":
  78. typeStr = "堤防";
  79. break;
  80. case "3":
  81. typeStr = "交叉建筑";
  82. break;
  83. case "4":
  84. typeStr = "定期专项";
  85. break;
  86. }
  87. typeText.text = typeStr;
  88. titleText.text = data.title;
  89. stateText.text = data.status;
  90. dateText.text = data.createTime;
  91. for (int i = 0; i < PointItems.Count; i++)
  92. {
  93. Destroy(PointItems[i].gameObject);
  94. }
  95. PointItems.Clear();
  96. if (data.taskItems == null) return;
  97. for (int i = 0; i < data.taskItems.Length; i++)
  98. {
  99. B08_TaskPointItem tempItem = Instantiate(pointItemPrefab, itemContent).GetComponent<B08_TaskPointItem>();
  100. tempItem.SetData(baseLayer, data.taskItems[i], i, data.createTime);
  101. var button = tempItem.GetComponent<ExtendedButton_PointItem>();
  102. button.index = i;
  103. button.onPointerEnter += baseLayer.SetTaskPointIconHeightLight;
  104. PointItems.Add(tempItem);
  105. }
  106. }
  107. }