PopupAndButtonList.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using wf;
  6. public class PopupAndButtonList : MonoBehaviour
  7. {
  8. public virtual void Awake()
  9. {
  10. this.is_select_func_call_ = true;
  11. this.PopUpList.onChangePopUpListValue.Add(new Action<KeyValuePair<string, UnityEngine.Object>>(this.OnChangePopUpList));
  12. }
  13. public virtual void Start()
  14. {
  15. }
  16. public void ResaveButton(int element)
  17. {
  18. NDebug.Assert(this.Grid.gameObject.transform.childCount == 0, "eorro");
  19. for (int i = 0; i < element; i++)
  20. {
  21. GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItemNormalButton", true);
  22. gameObject.name = i.ToString();
  23. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  24. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickButton));
  25. }
  26. Transform transform = base.transform;
  27. BasePhotoWindow component;
  28. do
  29. {
  30. component = transform.GetComponent<BasePhotoWindow>();
  31. transform = transform.parent;
  32. }
  33. while (component == null);
  34. component.UpdateChildren();
  35. for (int j = 0; j < this.Grid.transform.childCount; j++)
  36. {
  37. this.Grid.transform.GetChild(j).gameObject.SetActive(false);
  38. }
  39. }
  40. public void ResaveButton<T>(Dictionary<string, T> popup_and_button_name_list, int magnification) where T : ICollection
  41. {
  42. int num = 0;
  43. foreach (KeyValuePair<string, T> keyValuePair in popup_and_button_name_list)
  44. {
  45. int num2 = num;
  46. T value = keyValuePair.Value;
  47. if (num2 < value.Count)
  48. {
  49. T value2 = keyValuePair.Value;
  50. num = value2.Count;
  51. }
  52. }
  53. num *= magnification;
  54. for (int i = 0; i < num; i++)
  55. {
  56. GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItem", true);
  57. gameObject.name = i.ToString();
  58. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  59. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickButton));
  60. }
  61. Transform transform = base.transform;
  62. BasePhotoWindow component;
  63. do
  64. {
  65. component = transform.GetComponent<BasePhotoWindow>();
  66. transform = transform.parent;
  67. }
  68. while (component == null);
  69. component.UpdateChildren();
  70. for (int j = 0; j < this.Grid.transform.childCount; j++)
  71. {
  72. this.Grid.transform.GetChild(j).gameObject.SetActive(false);
  73. }
  74. }
  75. public void SetData(Dictionary<string, List<KeyValuePair<string, object>>> popup_and_button_name_list, bool create_margin = false)
  76. {
  77. if (popup_and_button_name_list != null && this.Grid.gameObject.transform.childCount == 0)
  78. {
  79. this.ResaveButton<List<KeyValuePair<string, object>>>(popup_and_button_name_list, create_margin ? 3 : 1);
  80. }
  81. this.popup_and_button_name_list_ = new Dictionary<string, List<PopupAndButtonList.ElementData>>();
  82. if (popup_and_button_name_list == null)
  83. {
  84. return;
  85. }
  86. foreach (KeyValuePair<string, List<KeyValuePair<string, object>>> keyValuePair in popup_and_button_name_list)
  87. {
  88. List<PopupAndButtonList.ElementData> list = new List<PopupAndButtonList.ElementData>();
  89. for (int i = 0; i < keyValuePair.Value.Count; i++)
  90. {
  91. list.Add(new PopupAndButtonList.ElementData
  92. {
  93. draw_title = keyValuePair.Value[i].Key,
  94. guid = Guid.NewGuid(),
  95. value = keyValuePair.Value[i].Value
  96. });
  97. }
  98. this.popup_and_button_name_list_.Add(keyValuePair.Key, list);
  99. }
  100. }
  101. public void AddData(string popup_category_name, KeyValuePair<string, object> value_data)
  102. {
  103. List<PopupAndButtonList.ElementData> list = this.popup_and_button_name_list_[popup_category_name];
  104. list.Add(new PopupAndButtonList.ElementData
  105. {
  106. draw_title = value_data.Key,
  107. guid = Guid.NewGuid(),
  108. value = value_data.Value
  109. });
  110. }
  111. protected void OnChangePopUpList(KeyValuePair<string, UnityEngine.Object> popup_val)
  112. {
  113. for (int i = 0; i < this.Grid.transform.childCount; i++)
  114. {
  115. this.Grid.transform.GetChild(i).gameObject.name = string.Empty;
  116. this.Grid.transform.GetChild(i).gameObject.SetActive(false);
  117. }
  118. if (this.popup_and_button_name_list_ == null || !this.popup_and_button_name_list_.ContainsKey(popup_val.Key))
  119. {
  120. Utility.ResetNGUI(this.Grid);
  121. Utility.ResetNGUI(this.ScrollView);
  122. for (int j = 0; j < this.onChangePopUpListValue.Count; j++)
  123. {
  124. this.onChangePopUpListValue[j](popup_val);
  125. }
  126. return;
  127. }
  128. List<PopupAndButtonList.ElementData> list = this.popup_and_button_name_list_[popup_val.Key];
  129. for (int k = 0; k < list.Count; k++)
  130. {
  131. GameObject gameObject = this.Grid.transform.GetChild(k).gameObject;
  132. gameObject.SetActive(true);
  133. gameObject.name = list[k].guid.ToString();
  134. gameObject.GetComponentInChildren<UILabel>().text = list[k].draw_title;
  135. }
  136. Utility.ResetNGUI(this.Grid);
  137. Utility.ResetNGUI(this.ScrollView);
  138. for (int l = 0; l < this.onChangePopUpListValue.Count; l++)
  139. {
  140. this.onChangePopUpListValue[l](popup_val);
  141. }
  142. }
  143. private void OnClickButton()
  144. {
  145. string name = UIButton.current.gameObject.name;
  146. foreach (KeyValuePair<string, List<PopupAndButtonList.ElementData>> keyValuePair in this.popup_and_button_name_list_)
  147. {
  148. for (int i = 0; i < keyValuePair.Value.Count; i++)
  149. {
  150. if (name == keyValuePair.Value[i].guid.ToString())
  151. {
  152. for (int j = 0; j < this.onClickEventList.Count; j++)
  153. {
  154. this.onClickEventList[j](keyValuePair.Value[i].value);
  155. }
  156. }
  157. }
  158. }
  159. }
  160. public virtual bool SetPopupValue(string name)
  161. {
  162. return this.PopUpList.SetPopupValue(name);
  163. }
  164. public virtual string GetCategoryNameFromSelectButton(object value_object)
  165. {
  166. if (value_object == null)
  167. {
  168. return string.Empty;
  169. }
  170. foreach (KeyValuePair<string, List<PopupAndButtonList.ElementData>> keyValuePair in this.popup_and_button_name_list_)
  171. {
  172. for (int i = 0; i < keyValuePair.Value.Count; i++)
  173. {
  174. if (keyValuePair.Value[i].value == value_object)
  175. {
  176. return keyValuePair.Key;
  177. }
  178. }
  179. }
  180. return string.Empty;
  181. }
  182. public List<KeyValuePair<string, UnityEngine.Object>> popup_value_list
  183. {
  184. get
  185. {
  186. return this.PopUpList.popup_value_list;
  187. }
  188. set
  189. {
  190. this.PopUpList.popup_value_list = value;
  191. }
  192. }
  193. public WindowPartsPopUpList PopUpList;
  194. public UIGrid Grid;
  195. public UIScrollView ScrollView;
  196. public List<Action<KeyValuePair<string, UnityEngine.Object>>> onChangePopUpListValue = new List<Action<KeyValuePair<string, UnityEngine.Object>>>();
  197. public List<Action<object>> onClickEventList = new List<Action<object>>();
  198. private Dictionary<string, List<PopupAndButtonList.ElementData>> popup_and_button_name_list_;
  199. private bool is_select_func_call_;
  200. private class ElementData
  201. {
  202. public Guid guid;
  203. public string draw_title;
  204. public object value;
  205. }
  206. }