PopupAndTabList.cs 10 KB

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