YotogiCommandFactory.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. if (this.exec_condition_call_back_ != null)
  152. {
  153. this.exec_condition_call_back_(data.this_object, data.data, true);
  154. }
  155. }
  156. private void OnHoverOut(YotogiCommandFactory.Command.Children data)
  157. {
  158. if (this.exec_condition_call_back_ != null)
  159. {
  160. this.exec_condition_call_back_(data.this_object, data.data, false);
  161. }
  162. }
  163. public void ClearSkillCommand()
  164. {
  165. this.ClearCommand();
  166. for (int i = 0; i < this.hidden_tree_transform_.childCount; i++)
  167. {
  168. UnityEngine.Object.Destroy(this.hidden_tree_transform_.GetChild(i).gameObject);
  169. }
  170. this.hidden_tree_transform_.DetachChildren();
  171. this.command_dic_.Clear();
  172. }
  173. public void AddCommand(Skill.Data.Command.Data command_data)
  174. {
  175. YotogiCommandFactory.Command command = this.command_dic_[this.GetGroupName(command_data.basic)];
  176. for (int i = 0; i < command.children.Length; i++)
  177. {
  178. if (command.children[i].data == command_data)
  179. {
  180. command.children[i].transform.SetParent(base.transform, false);
  181. command.children[i].visible = true;
  182. if (this.enabled_callback_func_ == null)
  183. {
  184. command.children[i].button.isEnabled = true;
  185. }
  186. else
  187. {
  188. command.children[i].button.isEnabled = this.enabled_callback_func_(command.children[i].data);
  189. }
  190. Color color = (!command.children[i].button.isEnabled) ? Color.black : command.children[i].data.basic.color;
  191. if (this.change_color_callbacl_func_ != null)
  192. {
  193. this.change_color_callbacl_func_(command.children[i].data, ref color);
  194. }
  195. command.children[i].nameLabel.color = color;
  196. command.children[i].eventCollider.enabled = !command.children[i].button.isEnabled;
  197. if (!command.visible)
  198. {
  199. command.transform.SetParent(base.transform, false);
  200. command.visible = true;
  201. }
  202. this.grid_update_ = true;
  203. return;
  204. }
  205. }
  206. }
  207. public void RemoveCommand(Skill.Data.Command.Data command_data)
  208. {
  209. YotogiCommandFactory.Command command = this.command_dic_[this.GetGroupName(command_data.basic)];
  210. for (int i = 0; i < command.children.Length; i++)
  211. {
  212. if (command.children[i].data == command_data)
  213. {
  214. command.children[i].transform.SetParent(this.hidden_tree_transform_, false);
  215. command.children[i].visible = false;
  216. bool flag = true;
  217. for (int j = 0; j < command.children.Length; j++)
  218. {
  219. if (command.children[j].visible)
  220. {
  221. flag = false;
  222. break;
  223. }
  224. }
  225. if (flag && command.visible)
  226. {
  227. command.transform.SetParent(this.hidden_tree_transform_, false);
  228. command.visible = false;
  229. }
  230. this.grid_update_ = true;
  231. return;
  232. }
  233. }
  234. }
  235. public GameObject GetCommandGameObject(Skill.Data.Command.Data command_data)
  236. {
  237. YotogiCommandFactory.Command command = this.command_dic_[this.GetGroupName(command_data.basic)];
  238. for (int i = 0; i < command.children.Length; i++)
  239. {
  240. if (command.children[i].data == command_data)
  241. {
  242. return command.children[i].this_object;
  243. }
  244. }
  245. return null;
  246. }
  247. public void ClearCommand()
  248. {
  249. foreach (KeyValuePair<string, YotogiCommandFactory.Command> keyValuePair in this.command_dic_)
  250. {
  251. YotogiCommandFactory.Command value = keyValuePair.Value;
  252. if (value.visible)
  253. {
  254. value.transform.SetParent(this.hidden_tree_transform_, false);
  255. value.visible = false;
  256. }
  257. for (int i = 0; i < value.children.Length; i++)
  258. {
  259. if (value.children[i].visible)
  260. {
  261. value.children[i].transform.SetParent(this.hidden_tree_transform_, false);
  262. value.children[i].visible = false;
  263. }
  264. }
  265. }
  266. this.grid_update_ = true;
  267. }
  268. public void LateUpdate()
  269. {
  270. if (this.grid_update_)
  271. {
  272. this.grid_.Reposition();
  273. this.grid_update_ = false;
  274. }
  275. }
  276. private GameObject CreateTitle(string name, int id)
  277. {
  278. if (name == null)
  279. {
  280. name = string.Empty;
  281. }
  282. GameObject gameObject = Utility.CreatePrefab(this.HiddenTree, "SceneYotogi/Yotogi/Prefab/CommandCategoryTitle", true);
  283. UILabel component = gameObject.GetComponent<UILabel>();
  284. component.text = name;
  285. if (GameUty.supportMultiLanguage)
  286. {
  287. component.text = string.Empty;
  288. Localize component2 = component.GetComponent<Localize>();
  289. component2.SetTerm(name);
  290. if (string.IsNullOrEmpty(component.text))
  291. {
  292. component.text = Utility.GetTermLastWord(name);
  293. }
  294. }
  295. gameObject.name = "-" + name;
  296. Vector3 localPosition = gameObject.transform.localPosition;
  297. localPosition.z = (float)id;
  298. gameObject.transform.localPosition = localPosition;
  299. return gameObject;
  300. }
  301. private GameObject CreateCommand(string name, int id, bool is_active)
  302. {
  303. if (name == null)
  304. {
  305. name = string.Empty;
  306. }
  307. GameObject gameObject = Utility.CreatePrefab(this.HiddenTree, "SceneYotogi/Yotogi/Prefab/Command", true);
  308. UILabel component = UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>();
  309. component.text = name;
  310. if (GameUty.supportMultiLanguage)
  311. {
  312. component.text = string.Empty;
  313. Localize component2 = component.GetComponent<Localize>();
  314. component2.SetTerm(name);
  315. if (string.IsNullOrEmpty(component.text))
  316. {
  317. component.text = Utility.GetTermLastWord(name);
  318. }
  319. }
  320. gameObject.name = "cm:" + name;
  321. Vector3 localPosition = gameObject.transform.localPosition;
  322. localPosition.z = (float)id;
  323. gameObject.transform.localPosition = localPosition;
  324. EventDelegate eventDelegate = new EventDelegate(this, "OnClick");
  325. EventDelegate.Parameter[] parameters = eventDelegate.parameters;
  326. parameters[0].obj = gameObject;
  327. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, eventDelegate);
  328. if (is_active)
  329. {
  330. UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>().color = Color.red;
  331. }
  332. return gameObject;
  333. }
  334. private void OnClick(GameObject obj)
  335. {
  336. if (this.callback_func_ == null)
  337. {
  338. return;
  339. }
  340. int num = (int)obj.transform.localPosition.z;
  341. foreach (KeyValuePair<string, YotogiCommandFactory.Command> keyValuePair in this.command_dic_)
  342. {
  343. YotogiCommandFactory.Command value = keyValuePair.Value;
  344. for (int i = 0; i < value.children.Length; i++)
  345. {
  346. if (value.children[i].id == num)
  347. {
  348. this.callback_func_(value.children[i].data);
  349. return;
  350. }
  351. }
  352. }
  353. }
  354. private string GetGroupName(Skill.Data.Command.Data.Basic commandDataBasic)
  355. {
  356. return (!GameUty.supportMultiLanguage) ? commandDataBasic.group_name : commandDataBasic.termGroupName;
  357. }
  358. private string GetCommandName(Skill.Data.Command.Data.Basic commandDataBasic)
  359. {
  360. return (!GameUty.supportMultiLanguage) ? commandDataBasic.name : commandDataBasic.termName;
  361. }
  362. public GameObject HiddenTree;
  363. private UIGrid grid_;
  364. private Transform hidden_tree_transform_;
  365. private Dictionary<string, YotogiCommandFactory.Command> command_dic_ = new Dictionary<string, YotogiCommandFactory.Command>();
  366. private YotogiCommandFactory.CommandEnabledCallBack enabled_callback_func_;
  367. private YotogiCommandFactory.ChangeCommandTextColorCallBack change_color_callbacl_func_;
  368. private YotogiCommandFactory.CommandCreateCallBack command_create_callback_func_;
  369. private YotogiCommandFactory.CommandCallback callback_func_;
  370. private YotogiCommandFactory.CommandExecConditionTextsCallback exec_condition_call_back_;
  371. private bool grid_update_;
  372. [CompilerGenerated]
  373. private static Comparison<Transform> <>f__mg$cache0;
  374. public delegate bool CommandCreateCallBack(Skill.Data.Command.Data data);
  375. public delegate void CommandCallback(Skill.Data.Command.Data data);
  376. public delegate void CommandExecConditionTextsCallback(GameObject commandObj, Skill.Data.Command.Data data, bool visible);
  377. public delegate bool CommandEnabledCallBack(Skill.Data.Command.Data data);
  378. public delegate void ChangeCommandTextColorCallBack(Skill.Data.Command.Data data, ref Color color);
  379. private class CommandBase
  380. {
  381. public Transform transform;
  382. public GameObject this_object;
  383. public int id;
  384. public bool visible;
  385. }
  386. private class Command : YotogiCommandFactory.CommandBase
  387. {
  388. public YotogiCommandFactory.Command.Children[] children;
  389. public class Children : YotogiCommandFactory.CommandBase
  390. {
  391. public Skill.Data.Command.Data data;
  392. public UIButton button;
  393. public UILabel nameLabel;
  394. public BoxCollider eventCollider;
  395. }
  396. }
  397. }