YotogiCommandFactory.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 YotogiCommandFactory : 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 (YotogiCommandFactory.<>f__mg$cache0 == null)
  18. {
  19. YotogiCommandFactory.<>f__mg$cache0 = new Comparison<Transform>(YotogiCommandFactory.SortOriginal);
  20. }
  21. uigrid.onCustomSort = YotogiCommandFactory.<>f__mg$cache0;
  22. this.hidden_tree_transform_ = this.HiddenTree.transform;
  23. }
  24. public void UpdateCommand()
  25. {
  26. if (this.enabled_callback_func_ != null)
  27. {
  28. foreach (KeyValuePair<string, YotogiCommandFactory.Command> keyValuePair in this.command_dic_)
  29. {
  30. YotogiCommandFactory.Command value = keyValuePair.Value;
  31. for (int i = 0; i < value.children.Length; i++)
  32. {
  33. if (value.children[i].visible)
  34. {
  35. value.children[i].button.isEnabled = this.enabled_callback_func_(value.children[i].data);
  36. value.children[i].nameLabel.color = ((!value.children[i].button.isEnabled) ? Color.black : value.children[i].data.basic.color);
  37. }
  38. }
  39. }
  40. }
  41. if (this.change_color_callbacl_func_ != null)
  42. {
  43. foreach (KeyValuePair<string, YotogiCommandFactory.Command> keyValuePair2 in this.command_dic_)
  44. {
  45. YotogiCommandFactory.Command value2 = keyValuePair2.Value;
  46. for (int j = 0; j < value2.children.Length; j++)
  47. {
  48. if (value2.children[j].visible && value2.children[j].button.isEnabled)
  49. {
  50. Color color = value2.children[j].nameLabel.color;
  51. this.change_color_callbacl_func_(value2.children[j].data, ref color);
  52. if (color != value2.children[j].nameLabel.color)
  53. {
  54. value2.children[j].nameLabel.color = color;
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. public void SetCommandCreateCallBack(YotogiCommandFactory.CommandCreateCallBack func)
  62. {
  63. this.command_create_callback_func_ = func;
  64. }
  65. public void SetCommandCallback(YotogiCommandFactory.CommandCallback func)
  66. {
  67. this.callback_func_ = func;
  68. }
  69. public void SetCommandEnabledCallBack(YotogiCommandFactory.CommandEnabledCallBack func)
  70. {
  71. this.enabled_callback_func_ = func;
  72. }
  73. public void SetChangeCommandTextColorCallBack(YotogiCommandFactory.ChangeCommandTextColorCallBack func)
  74. {
  75. this.change_color_callbacl_func_ = func;
  76. }
  77. public void SetCommandExecConditionTextsCallback(YotogiCommandFactory.CommandExecConditionTextsCallback func)
  78. {
  79. this.exec_condition_call_back_ = func;
  80. }
  81. public void ReserveSkillCommand(Skill.Data.Command skill_command)
  82. {
  83. this.ClearSkillCommand();
  84. List<KeyValuePair<string, List<Skill.Data.Command.Data>>> list = new List<KeyValuePair<string, List<Skill.Data.Command.Data>>>();
  85. for (int i = 0; i < skill_command.data.Length; i++)
  86. {
  87. string group_name = skill_command.data[i].basic.group_name;
  88. bool flag = true;
  89. for (int j = 0; j < list.Count; j++)
  90. {
  91. if (list[j].Key == group_name)
  92. {
  93. list[j].Value.Add(skill_command.data[i]);
  94. flag = false;
  95. break;
  96. }
  97. }
  98. if (flag)
  99. {
  100. list.Add(new KeyValuePair<string, List<Skill.Data.Command.Data>>(group_name, new List<Skill.Data.Command.Data>()));
  101. list[list.Count - 1].Value.Add(skill_command.data[i]);
  102. }
  103. }
  104. for (int k = 0; k < list.Count; k++)
  105. {
  106. YotogiCommandFactory.Command command = new YotogiCommandFactory.Command();
  107. command.id = k * 100;
  108. command.visible = false;
  109. command.this_object = this.CreateTitle(list[k].Key, command.id);
  110. command.transform = command.this_object.transform;
  111. List<YotogiCommandFactory.Command.Children> list2 = new List<YotogiCommandFactory.Command.Children>();
  112. int num = command.id + 5;
  113. for (int l = 0; l < list[k].Value.Count; l++)
  114. {
  115. if (this.command_create_callback_func_ == null || this.command_create_callback_func_(list[k].Value[l]))
  116. {
  117. YotogiCommandFactory.Command.Children children = new YotogiCommandFactory.Command.Children();
  118. children.data = list[k].Value[l];
  119. children.id = num;
  120. children.visible = false;
  121. children.this_object = this.CreateCommand(children.data.basic.name, children.id, false);
  122. children.button = children.this_object.GetComponent<UIButton>();
  123. children.nameLabel = children.this_object.GetComponentInChildren<UILabel>();
  124. children.eventCollider = children.this_object.GetComponentInChildren<UIEventTrigger>().GetComponent<BoxCollider>();
  125. children.transform = children.this_object.transform;
  126. UIEventTrigger component = children.eventCollider.GetComponent<UIEventTrigger>();
  127. YotogiCommandFactory.Command.Children data = children;
  128. EventDelegate.Add(component.onHoverOver, delegate
  129. {
  130. this.OnHoverOver(data);
  131. });
  132. EventDelegate.Add(component.onHoverOut, delegate
  133. {
  134. this.OnHoverOut(data);
  135. });
  136. EventDelegate.Add(component.onDragStart, delegate
  137. {
  138. this.OnHoverOut(data);
  139. });
  140. list2.Add(children);
  141. num += 5;
  142. }
  143. }
  144. command.children = list2.ToArray();
  145. this.command_dic_.Add(list[k].Key, command);
  146. }
  147. }
  148. private void OnHoverOver(YotogiCommandFactory.Command.Children data)
  149. {
  150. if (this.exec_condition_call_back_ != null)
  151. {
  152. this.exec_condition_call_back_(data.this_object, data.data, true);
  153. }
  154. }
  155. private void OnHoverOut(YotogiCommandFactory.Command.Children data)
  156. {
  157. if (this.exec_condition_call_back_ != null)
  158. {
  159. this.exec_condition_call_back_(data.this_object, data.data, false);
  160. }
  161. }
  162. public void ClearSkillCommand()
  163. {
  164. this.ClearCommand();
  165. for (int i = 0; i < this.hidden_tree_transform_.childCount; i++)
  166. {
  167. UnityEngine.Object.Destroy(this.hidden_tree_transform_.GetChild(i).gameObject);
  168. }
  169. this.hidden_tree_transform_.DetachChildren();
  170. this.command_dic_.Clear();
  171. }
  172. public void AddCommand(Skill.Data.Command.Data command_data)
  173. {
  174. YotogiCommandFactory.Command command = this.command_dic_[command_data.basic.group_name];
  175. for (int i = 0; i < command.children.Length; i++)
  176. {
  177. if (command.children[i].data == command_data)
  178. {
  179. command.children[i].transform.SetParent(base.transform, false);
  180. command.children[i].visible = true;
  181. if (this.enabled_callback_func_ == null)
  182. {
  183. command.children[i].button.isEnabled = true;
  184. }
  185. else
  186. {
  187. command.children[i].button.isEnabled = this.enabled_callback_func_(command.children[i].data);
  188. }
  189. Color color = (!command.children[i].button.isEnabled) ? Color.black : command.children[i].data.basic.color;
  190. if (this.change_color_callbacl_func_ != null)
  191. {
  192. this.change_color_callbacl_func_(command.children[i].data, ref color);
  193. }
  194. command.children[i].nameLabel.color = color;
  195. command.children[i].eventCollider.enabled = !command.children[i].button.isEnabled;
  196. if (!command.visible)
  197. {
  198. command.transform.SetParent(base.transform, false);
  199. command.visible = true;
  200. }
  201. this.grid_update_ = true;
  202. return;
  203. }
  204. }
  205. }
  206. public void RemoveCommand(Skill.Data.Command.Data command_data)
  207. {
  208. YotogiCommandFactory.Command command = this.command_dic_[command_data.basic.group_name];
  209. for (int i = 0; i < command.children.Length; i++)
  210. {
  211. if (command.children[i].data == command_data)
  212. {
  213. command.children[i].transform.SetParent(this.hidden_tree_transform_, false);
  214. command.children[i].visible = false;
  215. bool flag = true;
  216. for (int j = 0; j < command.children.Length; j++)
  217. {
  218. if (command.children[j].visible)
  219. {
  220. flag = false;
  221. break;
  222. }
  223. }
  224. if (flag && command.visible)
  225. {
  226. command.transform.SetParent(this.hidden_tree_transform_, false);
  227. command.visible = false;
  228. }
  229. this.grid_update_ = true;
  230. return;
  231. }
  232. }
  233. }
  234. public GameObject GetCommandGameObject(Skill.Data.Command.Data command_data)
  235. {
  236. YotogiCommandFactory.Command command = this.command_dic_[command_data.basic.group_name];
  237. for (int i = 0; i < command.children.Length; i++)
  238. {
  239. if (command.children[i].data == command_data)
  240. {
  241. return command.children[i].this_object;
  242. }
  243. }
  244. return null;
  245. }
  246. public void ClearCommand()
  247. {
  248. foreach (KeyValuePair<string, YotogiCommandFactory.Command> keyValuePair in this.command_dic_)
  249. {
  250. YotogiCommandFactory.Command value = keyValuePair.Value;
  251. if (value.visible)
  252. {
  253. value.transform.SetParent(this.hidden_tree_transform_, false);
  254. value.visible = false;
  255. }
  256. for (int i = 0; i < value.children.Length; i++)
  257. {
  258. if (value.children[i].visible)
  259. {
  260. value.children[i].transform.SetParent(this.hidden_tree_transform_, false);
  261. value.children[i].visible = false;
  262. }
  263. }
  264. }
  265. this.grid_update_ = true;
  266. }
  267. public void LateUpdate()
  268. {
  269. if (this.grid_update_)
  270. {
  271. this.grid_.Reposition();
  272. this.grid_update_ = false;
  273. }
  274. }
  275. private GameObject CreateTitle(string name, int id)
  276. {
  277. if (name == null)
  278. {
  279. name = string.Empty;
  280. }
  281. GameObject gameObject = Utility.CreatePrefab(this.HiddenTree, "SceneYotogi/Yotogi/Prefab/CommandCategoryTitle", true);
  282. gameObject.GetComponent<UILabel>().text = name;
  283. gameObject.name = "-" + name;
  284. Vector3 localPosition = gameObject.transform.localPosition;
  285. localPosition.z = (float)id;
  286. gameObject.transform.localPosition = localPosition;
  287. return gameObject;
  288. }
  289. private GameObject CreateCommand(string name, int id, bool is_active)
  290. {
  291. if (name == null)
  292. {
  293. name = string.Empty;
  294. }
  295. GameObject gameObject = Utility.CreatePrefab(this.HiddenTree, "SceneYotogi/Yotogi/Prefab/Command", true);
  296. UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>().text = name;
  297. gameObject.name = "cm:" + name;
  298. Vector3 localPosition = gameObject.transform.localPosition;
  299. localPosition.z = (float)id;
  300. gameObject.transform.localPosition = localPosition;
  301. EventDelegate eventDelegate = new EventDelegate(this, "OnClick");
  302. EventDelegate.Parameter[] parameters = eventDelegate.parameters;
  303. parameters[0].obj = gameObject;
  304. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, eventDelegate);
  305. if (is_active)
  306. {
  307. UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>().color = Color.red;
  308. }
  309. return gameObject;
  310. }
  311. private void OnClick(GameObject obj)
  312. {
  313. if (this.callback_func_ == null)
  314. {
  315. return;
  316. }
  317. int num = (int)obj.transform.localPosition.z;
  318. foreach (KeyValuePair<string, YotogiCommandFactory.Command> keyValuePair in this.command_dic_)
  319. {
  320. YotogiCommandFactory.Command value = keyValuePair.Value;
  321. for (int i = 0; i < value.children.Length; i++)
  322. {
  323. if (value.children[i].id == num)
  324. {
  325. this.callback_func_(value.children[i].data);
  326. return;
  327. }
  328. }
  329. }
  330. }
  331. public GameObject HiddenTree;
  332. private UIGrid grid_;
  333. private Transform hidden_tree_transform_;
  334. private Dictionary<string, YotogiCommandFactory.Command> command_dic_ = new Dictionary<string, YotogiCommandFactory.Command>();
  335. private YotogiCommandFactory.CommandEnabledCallBack enabled_callback_func_;
  336. private YotogiCommandFactory.ChangeCommandTextColorCallBack change_color_callbacl_func_;
  337. private YotogiCommandFactory.CommandCreateCallBack command_create_callback_func_;
  338. private YotogiCommandFactory.CommandCallback callback_func_;
  339. private YotogiCommandFactory.CommandExecConditionTextsCallback exec_condition_call_back_;
  340. private bool grid_update_;
  341. [CompilerGenerated]
  342. private static Comparison<Transform> <>f__mg$cache0;
  343. public delegate bool CommandCreateCallBack(Skill.Data.Command.Data data);
  344. public delegate void CommandCallback(Skill.Data.Command.Data data);
  345. public delegate void CommandExecConditionTextsCallback(GameObject commandObj, Skill.Data.Command.Data data, bool visible);
  346. public delegate bool CommandEnabledCallBack(Skill.Data.Command.Data data);
  347. public delegate void ChangeCommandTextColorCallBack(Skill.Data.Command.Data data, ref Color color);
  348. private class CommandBase
  349. {
  350. public Transform transform;
  351. public GameObject this_object;
  352. public int id;
  353. public bool visible;
  354. }
  355. private class Command : YotogiCommandFactory.CommandBase
  356. {
  357. public YotogiCommandFactory.Command.Children[] children;
  358. public class Children : YotogiCommandFactory.CommandBase
  359. {
  360. public Skill.Data.Command.Data data;
  361. public UIButton button;
  362. public UILabel nameLabel;
  363. public BoxCollider eventCollider;
  364. }
  365. }
  366. }