YotogiOldSkillContainerViewer.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using wf;
  5. using Yotogis;
  6. public class YotogiOldSkillContainerViewer
  7. {
  8. public YotogiOldSkillContainerViewer(GameObject root_obj, MonoBehaviour parent)
  9. {
  10. this.root_obj_ = root_obj;
  11. this.parent_obj_ = UTY.GetChildObject(this.root_obj_, "SkillContainerViewer", false);
  12. GameObject childObject = UTY.GetChildObject(this.parent_obj_, "HpGroup", false);
  13. this.setting_hp_gauge_transform_ = UTY.GetChildObject(childObject, "Gauge", false).GetComponent<Transform>();
  14. GameObject childObject2 = UTY.GetChildObject(childObject, "Values", false);
  15. this.setting_max_hp_ = UTY.GetChildObject(childObject2, "MaxHp", false).GetComponent<UILabel>();
  16. this.setting_cur_hp_ = UTY.GetChildObject(childObject2, "CurrentHp", false).GetComponent<UILabel>();
  17. GameObject childObject3 = UTY.GetChildObject(this.parent_obj_, "SkillParent", false);
  18. this.skill_parent_grid_ = childObject3.GetComponent<UIGrid>();
  19. this.select_object_array_ = new YotogiOldSkillContainerViewer.YotogiSkillSelectSlot[7];
  20. for (int i = 0; i < this.select_object_array_.Length; i++)
  21. {
  22. this.select_object_array_[i] = new YotogiOldSkillContainerViewer.YotogiSkillSelectSlot(UTY.GetChildObject(childObject3, "SkillIconUnit" + i, false), new YotogiOldSkillIconDrag.OnDragChangeCallback(this.OnDragChangeCallback));
  23. YotogiOldSkillIcon component = this.select_object_array_[i].skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
  24. component.SetOnClickEvent(new YotogiOldSkillIcon.OnClickEvent(this.OnRightClickIcon));
  25. }
  26. EventDelegate.Add(UTY.GetChildObject(this.parent_obj_, "DeselectAll", false).GetComponent<UIButton>().onClick, new EventDelegate(parent, "OnClickAllReset"));
  27. }
  28. public void Init(Maid maid)
  29. {
  30. this.maid_ = maid;
  31. for (int i = 0; i < this.select_object_array_.Length; i++)
  32. {
  33. this.select_object_array_[i].SetMaid(this.maid_);
  34. this.select_object_array_[i].SetSkillData(null);
  35. }
  36. }
  37. public void SetOnSkillChangeEvent(Action<YotogiOldSkillContainerViewer> call_back)
  38. {
  39. this.on_change_call_back_ = call_back;
  40. }
  41. public void SetMaxHp(int max_hp)
  42. {
  43. this.setting_max_hp_.text = max_hp.ToString();
  44. int num = int.Parse(this.setting_cur_hp_.text);
  45. if (max_hp < num)
  46. {
  47. this.SetCurrentHp(max_hp);
  48. }
  49. }
  50. public void SetCurrentHp(int cur_hp)
  51. {
  52. int num = int.Parse(this.setting_max_hp_.text);
  53. if (num < cur_hp)
  54. {
  55. cur_hp = num;
  56. }
  57. if (cur_hp <= 0)
  58. {
  59. this.setting_cur_hp_.color = Color.red;
  60. }
  61. else
  62. {
  63. this.setting_cur_hp_.color = Color.white;
  64. }
  65. this.setting_cur_hp_.text = cur_hp.ToString();
  66. if (cur_hp < 0)
  67. {
  68. cur_hp = 0;
  69. }
  70. Hashtable args = TweenHash.EaseOutSine(TweenHash.Type.Scale, new Vector3((float)cur_hp / (float)num, 1f, 1f), 0.4f);
  71. iTween.ScaleTo(this.setting_hp_gauge_transform_.gameObject, args);
  72. }
  73. public bool AddSkill(Skill.Old.Data data)
  74. {
  75. for (int i = 0; i < this.select_object_array_.Length; i++)
  76. {
  77. if (this.select_object_array_[i].skill_data == null)
  78. {
  79. this.select_object_array_[i].SetSkillData(data);
  80. if (this.on_change_call_back_ != null)
  81. {
  82. this.on_change_call_back_(this);
  83. }
  84. return true;
  85. }
  86. }
  87. return false;
  88. }
  89. public void ResetAllSkill()
  90. {
  91. for (int i = 0; i < this.select_object_array_.Length; i++)
  92. {
  93. this.select_object_array_[i].SetSkillData(null);
  94. }
  95. if (this.on_change_call_back_ != null)
  96. {
  97. this.on_change_call_back_(this);
  98. }
  99. }
  100. public Skill.Old.Data[] GetSettingSkillArray()
  101. {
  102. int num = 0;
  103. for (int i = 0; i < this.select_object_array_.Length; i++)
  104. {
  105. if (this.select_object_array_[i].skill_data != null)
  106. {
  107. num++;
  108. }
  109. }
  110. Skill.Old.Data[] array = new Skill.Old.Data[num];
  111. int num2 = 0;
  112. for (int j = 0; j < this.select_object_array_.Length; j++)
  113. {
  114. if (this.select_object_array_[j].skill_data != null)
  115. {
  116. array[num2] = this.select_object_array_[j].skill_data;
  117. num2++;
  118. }
  119. }
  120. return array;
  121. }
  122. private void OnRightClickIcon(GameObject my, YotogiOldSkillIcon click_obj)
  123. {
  124. if (UICamera.currentKey != KeyCode.Mouse1)
  125. {
  126. return;
  127. }
  128. YotogiOldSkillContainerViewer.YotogiSkillSelectSlot yotogiSkillSelectSlot = null;
  129. for (int i = 0; i < this.select_object_array_.Length; i++)
  130. {
  131. if (this.select_object_array_[i].skill_icon_obj == my)
  132. {
  133. yotogiSkillSelectSlot = this.select_object_array_[i];
  134. break;
  135. }
  136. }
  137. NDebug.AssertNull(yotogiSkillSelectSlot != null);
  138. yotogiSkillSelectSlot.SetSkillData(null);
  139. for (int j = 0; j < this.select_object_array_.Length; j++)
  140. {
  141. if (this.select_object_array_[j].skill_data == null && j + 1 < this.select_object_array_.Length && this.select_object_array_[j + 1].skill_data != null)
  142. {
  143. this.select_object_array_[j].Swap(this.select_object_array_[j + 1]);
  144. this.select_object_array_[j].skill_icon_obj.GetComponent<YotogiOldSkillIconDrag>().MoveReset();
  145. this.select_object_array_[j + 1].skill_icon_obj.transform.localPosition = Vector3.zero;
  146. }
  147. }
  148. if (this.on_change_call_back_ != null)
  149. {
  150. this.on_change_call_back_(this);
  151. }
  152. }
  153. private void OnDragChangeCallback(GameObject my_obj, GameObject change_obj)
  154. {
  155. YotogiOldSkillContainerViewer.YotogiSkillSelectSlot yotogiSkillSelectSlot = null;
  156. YotogiOldSkillContainerViewer.YotogiSkillSelectSlot yotogiSkillSelectSlot2 = null;
  157. for (int i = 0; i < this.select_object_array_.Length; i++)
  158. {
  159. if (this.select_object_array_[i].skill_icon_obj == my_obj)
  160. {
  161. yotogiSkillSelectSlot = this.select_object_array_[i];
  162. }
  163. else if (this.select_object_array_[i].skill_icon_obj == change_obj)
  164. {
  165. yotogiSkillSelectSlot2 = this.select_object_array_[i];
  166. }
  167. if (yotogiSkillSelectSlot != null && yotogiSkillSelectSlot2 != null)
  168. {
  169. break;
  170. }
  171. }
  172. yotogiSkillSelectSlot.Swap(yotogiSkillSelectSlot2);
  173. }
  174. private Maid maid_;
  175. private GameObject root_obj_;
  176. private GameObject parent_obj_;
  177. private UIGrid skill_parent_grid_;
  178. private Transform setting_hp_gauge_transform_;
  179. private UILabel setting_cur_hp_;
  180. private UILabel setting_max_hp_;
  181. private YotogiOldSkillContainerViewer.YotogiSkillSelectSlot[] select_object_array_;
  182. private Action<YotogiOldSkillContainerViewer> on_change_call_back_;
  183. private class YotogiSkillSelectSlot
  184. {
  185. public YotogiSkillSelectSlot(GameObject skill_icon_parent, YotogiOldSkillIconDrag.OnDragChangeCallback event_call_back)
  186. {
  187. this.skill_icon_obj = UTY.GetChildObject(skill_icon_parent, "SkillIconDrag", false);
  188. this.skill_icon_collider_ = this.skill_icon_obj.GetComponent<BoxCollider>();
  189. this.icon_btn_obj_ = this.skill_icon_obj.GetComponent<UIButton>();
  190. this.skill_icon_scripts_ = this.skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
  191. this.btn_event_trigger_ = this.skill_icon_obj.gameObject.GetComponent<UIEventTrigger>();
  192. EventDelegate.Add(this.btn_event_trigger_.onHoverOver, delegate()
  193. {
  194. this.VisibleSkillName(true);
  195. });
  196. EventDelegate.Add(this.btn_event_trigger_.onHoverOut, delegate()
  197. {
  198. this.VisibleSkillName(false);
  199. });
  200. EventDelegate.Add(this.btn_event_trigger_.onDragStart, delegate()
  201. {
  202. this.VisibleSkillName(false);
  203. });
  204. this.skill_name_bg_ = UTY.GetChildObject(skill_icon_parent, "SkillName", false).GetComponent<UISprite>();
  205. this.skill_name_label_ = UTY.GetChildObject(this.skill_name_bg_.gameObject, "Val", false).GetComponent<UILabel>();
  206. GameObject childObject = UTY.GetChildObject(skill_icon_parent, "StarGroup", false);
  207. this.star_obj = new GameObject[3];
  208. for (int i = 0; i < this.star_obj.Length; i++)
  209. {
  210. this.star_obj[i] = UTY.GetChildObject(childObject, "Star" + i, false);
  211. }
  212. if (event_call_back != null)
  213. {
  214. this.skill_icon_obj.GetComponent<YotogiOldSkillIconDrag>().SetOnOnDragChangeCallback(event_call_back);
  215. }
  216. }
  217. public void VisibleSkillName(bool val)
  218. {
  219. if (!this.skill_icon_collider_.enabled || this.skill_data_ == null)
  220. {
  221. val = false;
  222. }
  223. float alpha = 0f;
  224. if (val)
  225. {
  226. alpha = 1f;
  227. }
  228. this.skill_name_bg_.alpha = alpha;
  229. this.skill_name_label_.alpha = alpha;
  230. }
  231. public void Swap(YotogiOldSkillContainerViewer.YotogiSkillSelectSlot target)
  232. {
  233. GameObject gameObject = this.skill_icon_obj;
  234. this.skill_icon_obj = target.skill_icon_obj;
  235. target.skill_icon_obj = gameObject;
  236. this.skill_icon_collider_ = this.skill_icon_obj.GetComponent<BoxCollider>();
  237. this.icon_btn_obj_ = this.skill_icon_obj.GetComponent<UIButton>();
  238. this.skill_icon_scripts_ = this.skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
  239. this.btn_event_trigger_ = this.skill_icon_obj.gameObject.GetComponent<UIEventTrigger>();
  240. this.btn_event_trigger_.onHoverOver.Clear();
  241. this.btn_event_trigger_.onHoverOut.Clear();
  242. this.btn_event_trigger_.onDragStart.Clear();
  243. EventDelegate.Add(this.btn_event_trigger_.onHoverOver, delegate()
  244. {
  245. this.VisibleSkillName(true);
  246. });
  247. EventDelegate.Add(this.btn_event_trigger_.onHoverOut, delegate()
  248. {
  249. this.VisibleSkillName(false);
  250. });
  251. EventDelegate.Add(this.btn_event_trigger_.onDragStart, delegate()
  252. {
  253. this.VisibleSkillName(false);
  254. });
  255. target.skill_icon_collider_ = target.skill_icon_obj.GetComponent<BoxCollider>();
  256. target.icon_btn_obj_ = target.skill_icon_obj.GetComponent<UIButton>();
  257. target.skill_icon_scripts_ = target.skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
  258. target.btn_event_trigger_ = target.skill_icon_obj.gameObject.GetComponent<UIEventTrigger>();
  259. target.btn_event_trigger_.onHoverOver.Clear();
  260. target.btn_event_trigger_.onHoverOut.Clear();
  261. target.btn_event_trigger_.onDragStart.Clear();
  262. EventDelegate.Add(target.btn_event_trigger_.onHoverOver, delegate()
  263. {
  264. target.VisibleSkillName(true);
  265. });
  266. EventDelegate.Add(target.btn_event_trigger_.onHoverOut, delegate()
  267. {
  268. target.VisibleSkillName(false);
  269. });
  270. EventDelegate.Add(target.btn_event_trigger_.onDragStart, delegate()
  271. {
  272. target.VisibleSkillName(false);
  273. });
  274. Skill.Old.Data skill_data = this.skill_data;
  275. this.skill_data_ = target.skill_data;
  276. target.skill_data_ = skill_data;
  277. this.SetSkillData(this.skill_data);
  278. target.SetSkillData(target.skill_data);
  279. Transform parent = this.skill_icon_obj.transform.parent;
  280. this.skill_icon_obj.transform.parent = target.skill_icon_obj.transform.parent;
  281. target.skill_icon_obj.transform.parent = parent;
  282. }
  283. public void SetSkillData(Skill.Old.Data skill_data)
  284. {
  285. this.skill_data_ = skill_data;
  286. if (this.skill_data_ == null)
  287. {
  288. this.icon_btn_obj_.SetState(UIButtonColor.State.Normal, true);
  289. this.skill_icon_collider_.enabled = false;
  290. }
  291. else
  292. {
  293. this.skill_icon_collider_.enabled = true;
  294. }
  295. this.skill_icon_scripts_.SetSkillData(this.skill_data_);
  296. this.UpdateData();
  297. }
  298. public void UpdateData()
  299. {
  300. int num = 0;
  301. if (this.skill_data != null && this.maid_ != null)
  302. {
  303. num = this.maid_.status.yotogiSkill.Get(this.skill_data.id).level;
  304. }
  305. num = ((this.star_obj.Length >= num) ? num : this.star_obj.Length);
  306. for (int i = 0; i < this.star_obj.Length; i++)
  307. {
  308. this.star_obj[i].SetActive(i <= num - 1);
  309. }
  310. if (this.skill_data_ == null)
  311. {
  312. this.skill_name_label_.text = string.Empty;
  313. this.VisibleSkillName(false);
  314. }
  315. else
  316. {
  317. this.skill_name_label_.text = this.skill_data_.name;
  318. this.skill_name_label_.width = 0;
  319. this.skill_name_label_.MakePixelPerfect();
  320. this.skill_name_bg_.width = this.skill_name_label_.width + 20;
  321. }
  322. }
  323. public void SetMaid(Maid maid)
  324. {
  325. this.maid_ = maid;
  326. }
  327. public Skill.Old.Data skill_data
  328. {
  329. get
  330. {
  331. return this.skill_data_;
  332. }
  333. }
  334. public UIEventTrigger btn_event_trigger
  335. {
  336. get
  337. {
  338. return this.btn_event_trigger_;
  339. }
  340. }
  341. private Maid maid_;
  342. public GameObject skill_icon_obj;
  343. public GameObject[] star_obj;
  344. private UIEventTrigger btn_event_trigger_;
  345. private UISprite skill_name_bg_;
  346. private UILabel skill_name_label_;
  347. private UIButton icon_btn_obj_;
  348. private YotogiOldSkillIcon skill_icon_scripts_;
  349. private BoxCollider skill_icon_collider_;
  350. private Skill.Old.Data skill_data_;
  351. }
  352. }