WindowPartsPopUpList.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WindowPartsPopUpList : MonoBehaviour
  5. {
  6. public virtual void Awake()
  7. {
  8. EventDelegate.Add(this.PopupList.onChange, delegate
  9. {
  10. if (this.onChangePopUpListValue == null || this.onChangePopUpListValue.Count <= 0)
  11. {
  12. return;
  13. }
  14. bool flag = false;
  15. KeyValuePair<string, UnityEngine.Object> obj = new KeyValuePair<string, UnityEngine.Object>(string.Empty, null);
  16. for (int j = 0; j < this.popup_value_list_.Count; j++)
  17. {
  18. if (this.popup_value_list_[j].Key == this.PopupList.value)
  19. {
  20. obj = this.popup_value_list_[j];
  21. flag = true;
  22. break;
  23. }
  24. }
  25. if (flag)
  26. {
  27. for (int k = 0; k < this.onChangePopUpListValue.Count; k++)
  28. {
  29. this.onChangePopUpListValue[k](obj);
  30. }
  31. }
  32. });
  33. this.init_popup_list_value_ = new List<string>(this.PopupList.items);
  34. this.popup_value_list_ = new List<KeyValuePair<string, UnityEngine.Object>>();
  35. for (int i = 0; i < this.init_popup_list_value_.Count; i++)
  36. {
  37. this.popup_value_list_.Add(new KeyValuePair<string, UnityEngine.Object>(this.init_popup_list_value_[i], null));
  38. }
  39. }
  40. public virtual bool SetPopupValue(string name)
  41. {
  42. this.PopupList.Close();
  43. for (int i = 0; i < this.popup_value_list_.Count; i++)
  44. {
  45. if (this.popup_value_list_[i].Key == name)
  46. {
  47. this.PopupList.value = name;
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. public KeyValuePair<string, UnityEngine.Object> popup_select_value
  54. {
  55. get
  56. {
  57. for (int i = 0; i < this.popup_value_list_.Count; i++)
  58. {
  59. if (this.popup_value_list_[i].Key == this.PopupList.value)
  60. {
  61. return this.popup_value_list_[i];
  62. }
  63. }
  64. if (0 < this.popup_value_list_.Count)
  65. {
  66. return this.popup_value_list_[0];
  67. }
  68. return new KeyValuePair<string, UnityEngine.Object>(string.Empty, null);
  69. }
  70. }
  71. public List<KeyValuePair<string, UnityEngine.Object>> popup_value_list
  72. {
  73. get
  74. {
  75. if (this.popup_value_list_ != null)
  76. {
  77. return new List<KeyValuePair<string, UnityEngine.Object>>(this.popup_value_list_);
  78. }
  79. return null;
  80. }
  81. set
  82. {
  83. this.popup_value_list_ = null;
  84. if (value != null)
  85. {
  86. this.popup_value_list_ = new List<KeyValuePair<string, UnityEngine.Object>>(value);
  87. }
  88. else
  89. {
  90. this.popup_value_list_ = new List<KeyValuePair<string, UnityEngine.Object>>();
  91. for (int i = 0; i < this.init_popup_list_value_.Count; i++)
  92. {
  93. this.popup_value_list_.Add(new KeyValuePair<string, UnityEngine.Object>(this.init_popup_list_value_[i], null));
  94. }
  95. }
  96. List<string> list = new List<string>();
  97. for (int j = 0; j < this.popup_value_list_.Count; j++)
  98. {
  99. list.Add(this.popup_value_list_[j].Key);
  100. }
  101. this.PopupList.items = list;
  102. }
  103. }
  104. public UIPopupList PopupList;
  105. public List<Action<KeyValuePair<string, UnityEngine.Object>>> onChangePopUpListValue = new List<Action<KeyValuePair<string, UnityEngine.Object>>>();
  106. private List<KeyValuePair<string, UnityEngine.Object>> popup_value_list_;
  107. private List<string> init_popup_list_value_;
  108. }