YotogiCommandFactory.cs 12 KB

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