PopupAndTabList.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using wf;
  6. public class PopupAndTabList : 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.TabPanel.gameObject.transform.childCount == 0, "eorro");
  19. for (int i = 0; i < element; i++)
  20. {
  21. GameObject gameObject = Utility.CreatePrefab(this.TabPanel.gameObject, "ScenePhotoMode/WindowListItem", true);
  22. gameObject.name = i.ToString();
  23. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  24. EventDelegate.Add(gameObject.GetComponent<UIWFTabButton>().onSelect, new EventDelegate.Callback(this.OnSelectItem));
  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. this.TabPanel.UpdateChildren();
  36. for (int j = 0; j < this.TabPanel.transform.childCount; j++)
  37. {
  38. this.TabPanel.transform.GetChild(j).gameObject.SetActive(false);
  39. }
  40. }
  41. public void ResaveButton<T>(Dictionary<string, T> popup_and_button_name_list, int magnification) where T : ICollection
  42. {
  43. NDebug.Assert(this.TabPanel.gameObject.transform.childCount == 0, "eorro");
  44. int num = 0;
  45. foreach (KeyValuePair<string, T> keyValuePair in popup_and_button_name_list)
  46. {
  47. int num2 = num;
  48. T value = keyValuePair.Value;
  49. if (num2 < value.Count)
  50. {
  51. T value2 = keyValuePair.Value;
  52. num = value2.Count;
  53. }
  54. }
  55. num *= magnification;
  56. for (int i = 0; i < num; i++)
  57. {
  58. GameObject gameObject = Utility.CreatePrefab(this.TabPanel.gameObject, "ScenePhotoMode/WindowListItem", true);
  59. gameObject.name = i.ToString();
  60. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  61. EventDelegate.Add(gameObject.GetComponent<UIWFTabButton>().onSelect, new EventDelegate.Callback(this.OnSelectItem));
  62. }
  63. Transform transform = base.transform;
  64. BasePhotoWindow component;
  65. do
  66. {
  67. component = transform.GetComponent<BasePhotoWindow>();
  68. transform = transform.parent;
  69. }
  70. while (component == null);
  71. component.UpdateChildren();
  72. this.TabPanel.UpdateChildren();
  73. for (int j = 0; j < this.TabPanel.transform.childCount; j++)
  74. {
  75. this.TabPanel.transform.GetChild(j).gameObject.SetActive(false);
  76. }
  77. }
  78. public void SetData(Dictionary<string, List<KeyValuePair<string, object>>> popup_and_button_name_list, bool create_margin = false)
  79. {
  80. if (popup_and_button_name_list != null && this.TabPanel.gameObject.transform.childCount == 0)
  81. {
  82. this.ResaveButton<List<KeyValuePair<string, object>>>(popup_and_button_name_list, create_margin ? 3 : 1);
  83. }
  84. this.popup_and_button_name_list_ = new Dictionary<string, List<PopupAndTabList.ElementData>>();
  85. if (popup_and_button_name_list == null)
  86. {
  87. this.ResetSelect();
  88. this.cur_select_btn_name_ = string.Empty;
  89. return;
  90. }
  91. foreach (KeyValuePair<string, List<KeyValuePair<string, object>>> keyValuePair in popup_and_button_name_list)
  92. {
  93. List<PopupAndTabList.ElementData> list = new List<PopupAndTabList.ElementData>();
  94. for (int i = 0; i < keyValuePair.Value.Count; i++)
  95. {
  96. list.Add(new PopupAndTabList.ElementData
  97. {
  98. draw_title = keyValuePair.Value[i].Key,
  99. guid = Guid.NewGuid(),
  100. value = keyValuePair.Value[i].Value
  101. });
  102. }
  103. this.popup_and_button_name_list_.Add(keyValuePair.Key, list);
  104. }
  105. }
  106. public void AddData(string popup_category_name, KeyValuePair<string, object> value_data)
  107. {
  108. List<PopupAndTabList.ElementData> list = this.popup_and_button_name_list_[popup_category_name];
  109. list.Add(new PopupAndTabList.ElementData
  110. {
  111. draw_title = value_data.Key,
  112. guid = Guid.NewGuid(),
  113. value = value_data.Value
  114. });
  115. }
  116. public void ResetSelect()
  117. {
  118. if (this.TabPanel.GetSelectButtonObject() != null)
  119. {
  120. this.TabPanel.GetSelectButtonObject().SetSelect(false);
  121. }
  122. this.TabPanel.ResetSelect();
  123. }
  124. protected void OnChangePopUpList(KeyValuePair<string, UnityEngine.Object> popup_val)
  125. {
  126. if (this.TabPanel.GetSelectButtonObject() != null)
  127. {
  128. this.cur_select_btn_name_ = this.TabPanel.GetSelectButtonObject().name;
  129. }
  130. this.TabPanel.ResetSelect();
  131. UIGrid component = this.TabPanel.GetComponent<UIGrid>();
  132. for (int i = 0; i < this.TabPanel.transform.childCount; i++)
  133. {
  134. this.TabPanel.transform.GetChild(i).GetComponent<UIWFTabButton>().SetSelect(false);
  135. this.TabPanel.transform.GetChild(i).gameObject.name = string.Empty;
  136. this.TabPanel.transform.GetChild(i).gameObject.SetActive(false);
  137. }
  138. if (this.popup_and_button_name_list_ == null || !this.popup_and_button_name_list_.ContainsKey(popup_val.Key))
  139. {
  140. component.Reposition();
  141. this.ScrollView.ResetPosition();
  142. this.cur_select_btn_name_ = string.Empty;
  143. for (int j = 0; j < this.onChangePopUpListValue.Count; j++)
  144. {
  145. this.onChangePopUpListValue[j](popup_val);
  146. }
  147. return;
  148. }
  149. UIWFTabButton uiwftabButton = null;
  150. List<PopupAndTabList.ElementData> list = this.popup_and_button_name_list_[popup_val.Key];
  151. for (int k = 0; k < list.Count; k++)
  152. {
  153. GameObject gameObject = this.TabPanel.transform.GetChild(k).gameObject;
  154. gameObject.SetActive(true);
  155. gameObject.name = list[k].guid.ToString();
  156. gameObject.GetComponentInChildren<UILabel>().text = list[k].draw_title;
  157. if (gameObject.name == this.cur_select_btn_name_)
  158. {
  159. uiwftabButton = gameObject.GetComponent<UIWFTabButton>();
  160. }
  161. }
  162. component.Reposition();
  163. this.ScrollView.ResetPosition();
  164. if (uiwftabButton != null)
  165. {
  166. this.is_select_func_call_ = false;
  167. this.TabPanel.Select(uiwftabButton);
  168. this.is_select_func_call_ = true;
  169. }
  170. for (int l = 0; l < this.onChangePopUpListValue.Count; l++)
  171. {
  172. this.onChangePopUpListValue[l](popup_val);
  173. }
  174. }
  175. private void OnSelectItem()
  176. {
  177. if (!UIWFSelectButton.current.isSelected)
  178. {
  179. return;
  180. }
  181. this.cur_select_btn_name_ = UIWFSelectButton.current.gameObject.name;
  182. if (this.is_select_func_call_)
  183. {
  184. foreach (KeyValuePair<string, List<PopupAndTabList.ElementData>> keyValuePair in this.popup_and_button_name_list_)
  185. {
  186. for (int i = 0; i < keyValuePair.Value.Count; i++)
  187. {
  188. if (this.cur_select_btn_name_ == keyValuePair.Value[i].guid.ToString())
  189. {
  190. for (int j = 0; j < this.onSelect.Count; j++)
  191. {
  192. this.onSelect[j](keyValuePair.Value[i].value);
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. public virtual bool SetPopupValue(string name)
  200. {
  201. return this.PopUpList.SetPopupValue(name);
  202. }
  203. public virtual string GetCategoryNameFromSelectButton(object value_object)
  204. {
  205. if (value_object == null)
  206. {
  207. return string.Empty;
  208. }
  209. foreach (KeyValuePair<string, List<PopupAndTabList.ElementData>> keyValuePair in this.popup_and_button_name_list_)
  210. {
  211. for (int i = 0; i < keyValuePair.Value.Count; i++)
  212. {
  213. if (keyValuePair.Value[i].value == value_object)
  214. {
  215. return keyValuePair.Key;
  216. }
  217. }
  218. }
  219. return string.Empty;
  220. }
  221. public virtual bool SetSelectButton(object value_object, bool fire_event)
  222. {
  223. if (value_object == null)
  224. {
  225. return false;
  226. }
  227. PopupAndTabList.ElementData elementData = null;
  228. string categoryNameFromSelectButton = this.GetCategoryNameFromSelectButton(value_object);
  229. if (!string.IsNullOrEmpty(categoryNameFromSelectButton))
  230. {
  231. int num = 0;
  232. while (num < this.popup_and_button_name_list_[categoryNameFromSelectButton].Count && elementData == null)
  233. {
  234. if (this.popup_and_button_name_list_[categoryNameFromSelectButton][num].value == value_object)
  235. {
  236. elementData = this.popup_and_button_name_list_[categoryNameFromSelectButton][num];
  237. }
  238. num++;
  239. }
  240. }
  241. if (elementData == null)
  242. {
  243. return false;
  244. }
  245. string key = this.PopUpList.popup_select_value.Key;
  246. if (key != categoryNameFromSelectButton)
  247. {
  248. this.SetPopupValue(categoryNameFromSelectButton);
  249. }
  250. bool result = false;
  251. Transform transform = this.TabPanel.transform;
  252. for (int i = 0; i < transform.childCount; i++)
  253. {
  254. if (transform.GetChild(i).gameObject.name == elementData.guid.ToString())
  255. {
  256. this.is_select_func_call_ = fire_event;
  257. this.TabPanel.Select(transform.GetChild(i).GetComponent<UIWFTabButton>());
  258. this.is_select_func_call_ = true;
  259. result = true;
  260. break;
  261. }
  262. }
  263. if (key != categoryNameFromSelectButton)
  264. {
  265. this.SetPopupValue(key);
  266. }
  267. return result;
  268. }
  269. public List<KeyValuePair<string, UnityEngine.Object>> popup_value_list
  270. {
  271. get
  272. {
  273. return this.PopUpList.popup_value_list;
  274. }
  275. set
  276. {
  277. this.PopUpList.popup_value_list = value;
  278. }
  279. }
  280. public WindowPartsPopUpList PopUpList;
  281. public UIWFTabPanel TabPanel;
  282. public UIScrollView ScrollView;
  283. public List<Action<KeyValuePair<string, UnityEngine.Object>>> onChangePopUpListValue = new List<Action<KeyValuePair<string, UnityEngine.Object>>>();
  284. public List<Action<object>> onSelect = new List<Action<object>>();
  285. private Dictionary<string, List<PopupAndTabList.ElementData>> popup_and_button_name_list_;
  286. private string cur_select_btn_name_;
  287. private bool is_select_func_call_;
  288. private class ElementData
  289. {
  290. public Guid guid;
  291. public string draw_title;
  292. public object value;
  293. }
  294. }