PopupAndButtonList.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 PopupAndButtonList : 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.Grid.gameObject.transform.childCount == 0, "eorro");
  20. for (int i = 0; i < element; i++)
  21. {
  22. GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItemNormalButton", true);
  23. gameObject.name = i.ToString();
  24. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  25. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickButton));
  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. for (int j = 0; j < this.Grid.transform.childCount; j++)
  37. {
  38. this.Grid.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. int num = 0;
  44. foreach (KeyValuePair<string, T> keyValuePair in popup_and_button_name_list)
  45. {
  46. int num2 = num;
  47. T value = keyValuePair.Value;
  48. if (num2 < value.Count)
  49. {
  50. T value2 = keyValuePair.Value;
  51. num = value2.Count;
  52. }
  53. }
  54. num *= magnification;
  55. for (int i = 0; i < num; i++)
  56. {
  57. GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItem", true);
  58. gameObject.name = i.ToString();
  59. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  60. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickButton));
  61. }
  62. Transform transform = base.transform;
  63. BasePhotoWindow component;
  64. do
  65. {
  66. component = transform.GetComponent<BasePhotoWindow>();
  67. transform = transform.parent;
  68. }
  69. while (component == null);
  70. component.UpdateChildren();
  71. for (int j = 0; j < this.Grid.transform.childCount; j++)
  72. {
  73. this.Grid.transform.GetChild(j).gameObject.SetActive(false);
  74. }
  75. }
  76. public void SetData(Dictionary<string, List<KeyValuePair<string, object>>> popup_and_button_name_list, Dictionary<string, List<string>> buttonTermList, bool create_margin = false)
  77. {
  78. if (popup_and_button_name_list != null && this.Grid.gameObject.transform.childCount == 0)
  79. {
  80. this.ResaveButton<List<KeyValuePair<string, object>>>(popup_and_button_name_list, create_margin ? 3 : 1);
  81. }
  82. this.popup_and_button_name_list_ = new Dictionary<string, List<PopupAndButtonList.ElementData>>();
  83. if (popup_and_button_name_list == null)
  84. {
  85. return;
  86. }
  87. foreach (KeyValuePair<string, List<KeyValuePair<string, object>>> keyValuePair in popup_and_button_name_list)
  88. {
  89. List<string> list = null;
  90. if (buttonTermList != null && buttonTermList.ContainsKey(keyValuePair.Key))
  91. {
  92. list = buttonTermList[keyValuePair.Key];
  93. }
  94. List<PopupAndButtonList.ElementData> list2 = new List<PopupAndButtonList.ElementData>();
  95. for (int i = 0; i < keyValuePair.Value.Count; i++)
  96. {
  97. list2.Add(new PopupAndButtonList.ElementData
  98. {
  99. draw_title = keyValuePair.Value[i].Key,
  100. term = ((list == null) ? string.Empty : list[i]),
  101. guid = Guid.NewGuid(),
  102. value = keyValuePair.Value[i].Value
  103. });
  104. }
  105. this.popup_and_button_name_list_.Add(keyValuePair.Key, list2);
  106. }
  107. }
  108. public void AddData(string popup_category_name, KeyValuePair<string, object> value_data)
  109. {
  110. List<PopupAndButtonList.ElementData> list = this.popup_and_button_name_list_[popup_category_name];
  111. list.Add(new PopupAndButtonList.ElementData
  112. {
  113. draw_title = value_data.Key,
  114. guid = Guid.NewGuid(),
  115. value = value_data.Value
  116. });
  117. }
  118. protected void OnChangePopUpList(KeyValuePair<string, UnityEngine.Object> popup_val)
  119. {
  120. for (int i = 0; i < this.Grid.transform.childCount; i++)
  121. {
  122. this.Grid.transform.GetChild(i).gameObject.name = string.Empty;
  123. this.Grid.transform.GetChild(i).gameObject.SetActive(false);
  124. }
  125. if (this.popup_and_button_name_list_ == null || !this.popup_and_button_name_list_.ContainsKey(popup_val.Key))
  126. {
  127. Utility.ResetNGUI(this.Grid);
  128. Utility.ResetNGUI(this.ScrollView);
  129. for (int j = 0; j < this.onChangePopUpListValue.Count; j++)
  130. {
  131. this.onChangePopUpListValue[j](popup_val);
  132. }
  133. return;
  134. }
  135. List<PopupAndButtonList.ElementData> list = this.popup_and_button_name_list_[popup_val.Key];
  136. for (int k = 0; k < list.Count; k++)
  137. {
  138. GameObject gameObject = this.Grid.transform.GetChild(k).gameObject;
  139. gameObject.SetActive(true);
  140. gameObject.name = list[k].guid.ToString();
  141. gameObject.GetComponentInChildren<UILabel>().text = list[k].draw_title;
  142. if (Product.supportMultiLanguage)
  143. {
  144. Localize componentInChildren = gameObject.GetComponentInChildren<Localize>();
  145. if (componentInChildren != null)
  146. {
  147. componentInChildren.enabled = !string.IsNullOrEmpty(list[k].term);
  148. if (componentInChildren.enabled)
  149. {
  150. componentInChildren.SetTerm(list[k].term);
  151. }
  152. }
  153. }
  154. }
  155. Utility.ResetNGUI(this.Grid);
  156. Utility.ResetNGUI(this.ScrollView);
  157. for (int l = 0; l < this.onChangePopUpListValue.Count; l++)
  158. {
  159. this.onChangePopUpListValue[l](popup_val);
  160. }
  161. }
  162. private void OnClickButton()
  163. {
  164. string name = UIButton.current.gameObject.name;
  165. foreach (KeyValuePair<string, List<PopupAndButtonList.ElementData>> keyValuePair in this.popup_and_button_name_list_)
  166. {
  167. for (int i = 0; i < keyValuePair.Value.Count; i++)
  168. {
  169. if (name == keyValuePair.Value[i].guid.ToString())
  170. {
  171. for (int j = 0; j < this.onClickEventList.Count; j++)
  172. {
  173. this.onClickEventList[j](keyValuePair.Value[i].value);
  174. }
  175. }
  176. }
  177. }
  178. }
  179. public virtual bool SetPopupValue(string name)
  180. {
  181. return this.PopUpList.SetPopupValue(name);
  182. }
  183. public virtual string GetCategoryNameFromSelectButton(object value_object)
  184. {
  185. if (value_object == null)
  186. {
  187. return string.Empty;
  188. }
  189. foreach (KeyValuePair<string, List<PopupAndButtonList.ElementData>> keyValuePair in this.popup_and_button_name_list_)
  190. {
  191. for (int i = 0; i < keyValuePair.Value.Count; i++)
  192. {
  193. if (keyValuePair.Value[i].value == value_object)
  194. {
  195. return keyValuePair.Key;
  196. }
  197. }
  198. }
  199. return string.Empty;
  200. }
  201. public List<KeyValuePair<string, UnityEngine.Object>> popup_value_list
  202. {
  203. get
  204. {
  205. return this.PopUpList.popup_value_list;
  206. }
  207. set
  208. {
  209. this.PopUpList.popup_value_list = value;
  210. }
  211. }
  212. public WindowPartsPopUpList PopUpList;
  213. public UIGrid Grid;
  214. public UIScrollView ScrollView;
  215. public List<Action<KeyValuePair<string, UnityEngine.Object>>> onChangePopUpListValue = new List<Action<KeyValuePair<string, UnityEngine.Object>>>();
  216. public List<Action<object>> onClickEventList = new List<Action<object>>();
  217. private Dictionary<string, List<PopupAndButtonList.ElementData>> popup_and_button_name_list_;
  218. private bool is_select_func_call_;
  219. private class ElementData
  220. {
  221. public Guid guid;
  222. public string draw_title;
  223. public string term;
  224. public object value;
  225. }
  226. }