YotogiOldCommandFactory.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. using wf;
  6. using Yotogis;
  7. public class YotogiOldCommandFactory : MonoBehaviour
  8. {
  9. public static int SortOriginal(Transform a, Transform b)
  10. {
  11. return a.localPosition.z.CompareTo(b.localPosition.z);
  12. }
  13. private void Awake()
  14. {
  15. this.grid_ = base.gameObject.GetComponent<UIGrid>();
  16. UIGrid uigrid = this.grid_;
  17. if (YotogiOldCommandFactory.<>f__mg$cache0 == null)
  18. {
  19. YotogiOldCommandFactory.<>f__mg$cache0 = new Comparison<Transform>(YotogiOldCommandFactory.SortOriginal);
  20. }
  21. uigrid.onCustomSort = YotogiOldCommandFactory.<>f__mg$cache0;
  22. this.hidden_tree_transform_ = this.HiddenTree.transform;
  23. }
  24. public void UpdateCommandEnabled()
  25. {
  26. if (this.enabled_callback_func_ == null)
  27. {
  28. return;
  29. }
  30. foreach (KeyValuePair<string, YotogiOldCommandFactory.Command> keyValuePair in this.command_dic_)
  31. {
  32. YotogiOldCommandFactory.Command value = keyValuePair.Value;
  33. for (int i = 0; i < value.children.Length; i++)
  34. {
  35. if (value.children[i].visible)
  36. {
  37. value.children[i].this_object.GetComponent<UIButton>().isEnabled = this.enabled_callback_func_(value.children[i].data);
  38. }
  39. }
  40. }
  41. }
  42. public void SetCommandCallback(YotogiOldCommandFactory.CommandCallback func)
  43. {
  44. this.callback_func_ = func;
  45. }
  46. public void SetCommandEnabledCallBack(YotogiOldCommandFactory.CommandEnabledCallBack func)
  47. {
  48. this.enabled_callback_func_ = func;
  49. }
  50. public void ReserveSkillCommand(Skill.Old.Data.Command skill_command)
  51. {
  52. this.ClearSkillCommand();
  53. List<KeyValuePair<string, List<Skill.Old.Data.Command.Data>>> list = new List<KeyValuePair<string, List<Skill.Old.Data.Command.Data>>>();
  54. for (int i = 0; i < skill_command.data.Length; i++)
  55. {
  56. string group_name = skill_command.data[i].basic.group_name;
  57. bool flag = true;
  58. for (int j = 0; j < list.Count; j++)
  59. {
  60. if (list[j].Key == group_name)
  61. {
  62. list[j].Value.Add(skill_command.data[i]);
  63. flag = false;
  64. break;
  65. }
  66. }
  67. if (flag)
  68. {
  69. list.Add(new KeyValuePair<string, List<Skill.Old.Data.Command.Data>>(group_name, new List<Skill.Old.Data.Command.Data>()));
  70. list[list.Count - 1].Value.Add(skill_command.data[i]);
  71. }
  72. }
  73. for (int k = 0; k < list.Count; k++)
  74. {
  75. YotogiOldCommandFactory.Command command = new YotogiOldCommandFactory.Command();
  76. command.id = k * 100;
  77. command.visible = false;
  78. command.this_object = this.CreateTitle(list[k].Key, command.id);
  79. command.transform = command.this_object.transform;
  80. command.children = new YotogiOldCommandFactory.Command.Children[list[k].Value.Count];
  81. int num = command.id + 5;
  82. for (int l = 0; l < list[k].Value.Count; l++)
  83. {
  84. YotogiOldCommandFactory.Command.Children children = new YotogiOldCommandFactory.Command.Children();
  85. children.data = list[k].Value[l];
  86. children.id = num;
  87. children.visible = false;
  88. children.this_object = this.CreateCommand(children.data.basic.name, children.id, children.data.basic.active_command);
  89. children.transform = children.this_object.transform;
  90. command.children[l] = children;
  91. num += 5;
  92. }
  93. this.command_dic_.Add(list[k].Key, command);
  94. }
  95. }
  96. public void ClearSkillCommand()
  97. {
  98. this.ClearCommand();
  99. for (int i = 0; i < this.hidden_tree_transform_.childCount; i++)
  100. {
  101. UnityEngine.Object.Destroy(this.hidden_tree_transform_.GetChild(i).gameObject);
  102. }
  103. this.hidden_tree_transform_.DetachChildren();
  104. this.command_dic_.Clear();
  105. }
  106. public void AddCommand(Skill.Old.Data.Command.Data command_data)
  107. {
  108. YotogiOldCommandFactory.Command command = this.command_dic_[command_data.basic.group_name];
  109. for (int i = 0; i < command.children.Length; i++)
  110. {
  111. if (command.children[i].data == command_data)
  112. {
  113. command.children[i].transform.SetParent(base.transform, false);
  114. command.children[i].visible = true;
  115. if (this.enabled_callback_func_ == null)
  116. {
  117. command.children[i].this_object.GetComponent<UIButton>().isEnabled = true;
  118. }
  119. else
  120. {
  121. command.children[i].this_object.GetComponent<UIButton>().isEnabled = this.enabled_callback_func_(command.children[i].data);
  122. }
  123. if (!command.visible)
  124. {
  125. command.transform.SetParent(base.transform, false);
  126. command.visible = true;
  127. }
  128. this.grid_update_ = true;
  129. return;
  130. }
  131. }
  132. }
  133. public void RemoveCommand(Skill.Old.Data.Command.Data command_data)
  134. {
  135. YotogiOldCommandFactory.Command command = this.command_dic_[command_data.basic.group_name];
  136. for (int i = 0; i < command.children.Length; i++)
  137. {
  138. if (command.children[i].data == command_data)
  139. {
  140. command.children[i].transform.SetParent(this.hidden_tree_transform_, false);
  141. command.children[i].visible = false;
  142. bool flag = true;
  143. for (int j = 0; j < command.children.Length; j++)
  144. {
  145. if (command.children[j].visible)
  146. {
  147. flag = false;
  148. break;
  149. }
  150. }
  151. if (flag && command.visible)
  152. {
  153. command.transform.SetParent(this.hidden_tree_transform_, false);
  154. command.visible = false;
  155. }
  156. this.grid_update_ = true;
  157. return;
  158. }
  159. }
  160. }
  161. public GameObject GetCommandGameObject(Skill.Old.Data.Command.Data command_data)
  162. {
  163. YotogiOldCommandFactory.Command command = this.command_dic_[command_data.basic.group_name];
  164. for (int i = 0; i < command.children.Length; i++)
  165. {
  166. if (command.children[i].data == command_data)
  167. {
  168. return command.children[i].this_object;
  169. }
  170. }
  171. return null;
  172. }
  173. public void ClearCommand()
  174. {
  175. foreach (KeyValuePair<string, YotogiOldCommandFactory.Command> keyValuePair in this.command_dic_)
  176. {
  177. YotogiOldCommandFactory.Command value = keyValuePair.Value;
  178. if (value.visible)
  179. {
  180. value.transform.SetParent(this.hidden_tree_transform_, false);
  181. value.visible = false;
  182. }
  183. for (int i = 0; i < value.children.Length; i++)
  184. {
  185. if (value.children[i].visible)
  186. {
  187. value.children[i].transform.SetParent(this.hidden_tree_transform_, false);
  188. value.children[i].visible = false;
  189. }
  190. }
  191. }
  192. this.grid_update_ = true;
  193. }
  194. public void LateUpdate()
  195. {
  196. if (this.grid_update_)
  197. {
  198. this.grid_.Reposition();
  199. this.grid_update_ = false;
  200. }
  201. }
  202. private GameObject CreateTitle(string name, int id)
  203. {
  204. if (name == null)
  205. {
  206. name = string.Empty;
  207. }
  208. GameObject gameObject = Utility.CreatePrefab(this.HiddenTree, "SceneYotogi/Yotogi/Prefab/CommandCategoryTitle", true);
  209. gameObject.GetComponent<UILabel>().text = name;
  210. gameObject.name = "-" + name;
  211. Vector3 localPosition = gameObject.transform.localPosition;
  212. localPosition.z = (float)id;
  213. gameObject.transform.localPosition = localPosition;
  214. return gameObject;
  215. }
  216. private GameObject CreateCommand(string name, int id, bool is_active)
  217. {
  218. if (name == null)
  219. {
  220. name = string.Empty;
  221. }
  222. GameObject gameObject = Utility.CreatePrefab(this.HiddenTree, "SceneYotogi/Yotogi/Prefab/Command", true);
  223. UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>().text = name;
  224. gameObject.name = "cm:" + name;
  225. Vector3 localPosition = gameObject.transform.localPosition;
  226. localPosition.z = (float)id;
  227. gameObject.transform.localPosition = localPosition;
  228. EventDelegate eventDelegate = new EventDelegate(this, "OnClick");
  229. EventDelegate.Parameter[] parameters = eventDelegate.parameters;
  230. parameters[0].obj = gameObject;
  231. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, eventDelegate);
  232. if (is_active)
  233. {
  234. UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>().color = Color.red;
  235. }
  236. return gameObject;
  237. }
  238. private void OnClick(GameObject obj)
  239. {
  240. if (this.callback_func_ == null)
  241. {
  242. return;
  243. }
  244. int num = (int)obj.transform.localPosition.z;
  245. foreach (KeyValuePair<string, YotogiOldCommandFactory.Command> keyValuePair in this.command_dic_)
  246. {
  247. YotogiOldCommandFactory.Command value = keyValuePair.Value;
  248. for (int i = 0; i < value.children.Length; i++)
  249. {
  250. if (value.children[i].id == num)
  251. {
  252. this.callback_func_(value.children[i].data);
  253. return;
  254. }
  255. }
  256. }
  257. }
  258. public GameObject HiddenTree;
  259. private UIGrid grid_;
  260. private Transform hidden_tree_transform_;
  261. private Dictionary<string, YotogiOldCommandFactory.Command> command_dic_ = new Dictionary<string, YotogiOldCommandFactory.Command>();
  262. private YotogiOldCommandFactory.CommandEnabledCallBack enabled_callback_func_;
  263. private YotogiOldCommandFactory.CommandCallback callback_func_;
  264. private bool grid_update_;
  265. [CompilerGenerated]
  266. private static Comparison<Transform> <>f__mg$cache0;
  267. public delegate void CommandCallback(Skill.Old.Data.Command.Data data);
  268. public delegate bool CommandEnabledCallBack(Skill.Old.Data.Command.Data data);
  269. private class CommandBase
  270. {
  271. public Transform transform;
  272. public GameObject this_object;
  273. public int id;
  274. public bool visible;
  275. }
  276. private class Command : YotogiOldCommandFactory.CommandBase
  277. {
  278. public YotogiOldCommandFactory.Command.Children[] children;
  279. public class Children : YotogiOldCommandFactory.CommandBase
  280. {
  281. public Skill.Old.Data.Command.Data data;
  282. }
  283. }
  284. }