SelectFaBaoPanel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using System.Collections.Generic;
  2. using Core.Language;
  3. using Fort23.Core;
  4. using GameLogic.Hero;
  5. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  6. using Utility;
  7. namespace Fort23.Mono
  8. {
  9. [UIBinding(prefab = "SelectFaBaoPanel")]
  10. public partial class SelectFaBaoPanel : UIPanel
  11. {
  12. private void Init()
  13. {
  14. }
  15. protected override void AddEvent()
  16. {
  17. }
  18. protected override void DelEvent()
  19. {
  20. }
  21. public override void AddButtonEvent()
  22. {
  23. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  24. Btn_Change.onClick.AddListener(() =>
  25. {
  26. PlayerManager.Instance.FaBaoControl.ChangeUseFaBao(selectIndex, selectedFaBaoInfo);
  27. currentFaBaoInfo = selectedFaBaoInfo;
  28. selectedFaBaoInfo = null;
  29. CustomInit(selectIndex);
  30. });
  31. Btn_UpGrade.onClick.AddListener(() =>
  32. {
  33. if (selectedFaBaoInfo != null)
  34. {
  35. selectedFaBaoInfo.UpGrade();
  36. UpadaFabaoBag();
  37. UpdateUI(selectedFaBaoInfo);
  38. UpdataGradeUI(true);
  39. }
  40. });
  41. Btn_PeiYang.onClick.AddListener(() =>
  42. {
  43. BtnUpGradeRoot.SetActive(true);
  44. BtnChangeRoot.SetActive(false);
  45. UpdataGradeUI(true);
  46. });
  47. Btn_Cancel.onClick.AddListener(() =>
  48. {
  49. BtnUpGradeRoot.SetActive(false);
  50. BtnChangeRoot.SetActive(true);
  51. UpdataGradeUI(false);
  52. });
  53. }
  54. List<FaBaoAttributeWidget> faBaoAttributeWidgets = new List<FaBaoAttributeWidget>();
  55. List<FaBaoWidget> faBaoWidgets = new List<FaBaoWidget>();
  56. FaBaoWidget currentFaBaoWidget = null;
  57. FaBaoInfo currentFaBaoInfo;
  58. FaBaoInfo selectedFaBaoInfo;
  59. int selectIndex;
  60. public async override CTask<bool> AsyncInit(object[] uiData)
  61. {
  62. // await UpadaFabaoBag();
  63. return await base.AsyncInit(uiData);
  64. }
  65. private void UpdataGradeUI(bool isStartUpGrade)
  66. {
  67. if (isStartUpGrade)
  68. {
  69. AccountFileInfo.FaBaoData faBaoData = new AccountFileInfo.FaBaoData();
  70. faBaoData.id = selectedFaBaoInfo.FaBaoData.id;
  71. faBaoData.level = selectedFaBaoInfo.FaBaoData.level + 1;
  72. FaBaoInfo nextFabaoInfo = new FaBaoInfo(faBaoData);
  73. foreach (var faBaoAttributeWidget in faBaoAttributeWidgets)
  74. {
  75. faBaoAttributeWidget.StartUpGrad(nextFabaoInfo);
  76. }
  77. Text_NextLv.text = "+1";
  78. Text_NextPower.text = "+" + (nextFabaoInfo.qiangDu - selectedFaBaoInfo.qiangDu);
  79. Text_NextLv.gameObject.SetActive(true);
  80. Text_NextPower.gameObject.SetActive(true);
  81. }
  82. else
  83. {
  84. foreach (var faBaoAttributeWidget in faBaoAttributeWidgets)
  85. {
  86. faBaoAttributeWidget.EndUpGrade();
  87. }
  88. Text_NextLv.gameObject.SetActive(false);
  89. Text_NextPower.gameObject.SetActive(false);
  90. }
  91. }
  92. private async CTask UpadaFabaoBag()
  93. {
  94. foreach (var faBaoAttributeWidget in faBaoWidgets)
  95. {
  96. UIManager.Instance.DormancyGComponent(faBaoAttributeWidget);
  97. }
  98. faBaoWidgets.Clear();
  99. if (PlayerManager.Instance.FaBaoControl.myAllFaBao.Count > 0)
  100. {
  101. for (var i = 0; i < PlayerManager.Instance.FaBaoControl.myAllFaBao.Count; i++)
  102. {
  103. if (PlayerManager.Instance.FaBaoControl.myAllFaBao[i] == currentFaBaoInfo)
  104. {
  105. continue;
  106. }
  107. FaBaoWidget faBaoWidget = await UIManager.Instance.CreateGComponent<FaBaoWidget>(null, Content);
  108. faBaoWidget.CustomInit(PlayerManager.Instance.FaBaoControl.myAllFaBao[i]);
  109. faBaoWidget.onClick = OnClick;
  110. faBaoWidgets.Add(faBaoWidget);
  111. }
  112. NoFaBagRoot.gameObject.SetActive(false);
  113. }
  114. else
  115. {
  116. NoFaBagRoot.gameObject.SetActive(true);
  117. }
  118. }
  119. private void OnClick(ItemWidgetBasic obj)
  120. {
  121. FaBaoWidget faBao = obj as FaBaoWidget;
  122. selectedFaBaoInfo = faBao.faoInfo;
  123. Btn_Change.gameObject.SetActive(true);
  124. UpdateFaBaoUI(selectedFaBaoInfo);
  125. FaBaoInfoRoot.SetActive(true);
  126. Text_NoFabaoTips.gameObject.gameObject.SetActive(false);
  127. }
  128. public async void CustomInit(int selectIndex)
  129. {
  130. this.selectIndex = selectIndex;
  131. BtnUpGradeRoot.SetActive(false);
  132. BtnChangeRoot.SetActive(true);
  133. currentFaBaoInfo = PlayerManager.Instance.FaBaoControl.FightFaBao[selectIndex];
  134. selectedFaBaoInfo = currentFaBaoInfo;
  135. UpdateUI(selectedFaBaoInfo);
  136. UpadaFabaoBag();
  137. }
  138. private async void UpdateUI(FaBaoInfo faBaoInfo)
  139. {
  140. if (faBaoInfo != null)
  141. {
  142. if (currentFaBaoWidget == null)
  143. currentFaBaoWidget = await UIManager.Instance.CreateGComponent<FaBaoWidget>(null, CurrentFaBaoRoot);
  144. currentFaBaoWidget.onClick = OnClick;
  145. currentFaBaoWidget.CustomInit(faBaoInfo);
  146. UpdateFaBaoUI(faBaoInfo);
  147. FaBaoInfoRoot.SetActive(true);
  148. Text_NoFabaoTips.gameObject.gameObject.SetActive(false);
  149. equipTipsRoot.gameObject.SetActive(true);
  150. Btn_PeiYang.gameObject.SetActive(true);
  151. Btn_Change.gameObject.SetActive(true);
  152. }
  153. else
  154. {
  155. FaBaoInfoRoot.SetActive(false);
  156. Text_NoFabaoTips.gameObject.gameObject.SetActive(true);
  157. Btn_PeiYang.gameObject.SetActive(false);
  158. equipTipsRoot.gameObject.SetActive(false);
  159. Btn_Change.gameObject.SetActive(false);
  160. }
  161. }
  162. private async void UpdateFaBaoUI(FaBaoInfo faBaoInfo)
  163. {
  164. foreach (var faBaoAttributeWidget in faBaoAttributeWidgets)
  165. {
  166. UIManager.Instance.DormancyGComponent(faBaoAttributeWidget);
  167. }
  168. faBaoAttributeWidgets.Clear();
  169. Text_FaBaoName.text = LanguageManager.Instance.Text(faBaoInfo.FabaoConfig.name) + " Lv." +
  170. faBaoInfo.FabaoPowerupConfig.ID;
  171. Text_Power.text = $"强度:{faBaoInfo.qiangDu}";
  172. Text_Desc.text = UtilTools.GetString(LanguageManager.Instance.Text(faBaoInfo.SkillConfig.dec),
  173. faBaoInfo.effectValue);
  174. switch (faBaoInfo.FabaoConfig.magicAttribute)
  175. {
  176. case 1:
  177. Icon_Attribute.GetComponent<CustomStateController>().ChangeState(0);
  178. Text_Attribute.text = "金";
  179. break;
  180. case 2:
  181. Icon_Attribute.GetComponent<CustomStateController>().ChangeState(1);
  182. Text_Attribute.text = "木";
  183. break;
  184. case 4:
  185. Icon_Attribute.GetComponent<CustomStateController>().ChangeState(2);
  186. Text_Attribute.text = "水";
  187. break;
  188. case 8:
  189. Icon_Attribute.GetComponent<CustomStateController>().ChangeState(3);
  190. Text_Attribute.text = "火";
  191. break;
  192. case 16:
  193. Icon_Attribute.GetComponent<CustomStateController>().ChangeState(4);
  194. Text_Attribute.text = "土";
  195. break;
  196. }
  197. foreach (var keyValuePair in faBaoInfo.attriButedIC)
  198. {
  199. FaBaoAttributeWidget faBaoAttributeWidget =
  200. await UIManager.Instance.CreateGComponent<FaBaoAttributeWidget>(null, FaBaoAttributeWidgetRoot);
  201. faBaoAttributeWidget.CusomtInit(selectedFaBaoInfo, keyValuePair.Key);
  202. faBaoAttributeWidgets.Add(faBaoAttributeWidget);
  203. }
  204. }
  205. public async static CTask<SelectFaBaoPanel> OpenPanel(int selectIndex)
  206. {
  207. SelectFaBaoPanel selectFaBaoPanel = await UIManager.Instance.LoadAndOpenPanel<SelectFaBaoPanel>(null);
  208. selectFaBaoPanel.CustomInit(selectIndex);
  209. return selectFaBaoPanel;
  210. }
  211. public override void Close()
  212. {
  213. foreach (var faBaoAttributeWidget in faBaoAttributeWidgets)
  214. {
  215. UIManager.Instance.DormancyGComponent(faBaoAttributeWidget);
  216. }
  217. faBaoAttributeWidgets.Clear();
  218. foreach (var faBaoAttributeWidget in faBaoWidgets)
  219. {
  220. UIManager.Instance.DormancyGComponent(faBaoAttributeWidget);
  221. }
  222. faBaoWidgets.Clear();
  223. UIManager.Instance.DormancyGComponent(currentFaBaoWidget);
  224. currentFaBaoWidget = null;
  225. BtnUpGradeRoot.SetActive(false);
  226. BtnChangeRoot.SetActive(true);
  227. currentFaBaoInfo = null;
  228. selectedFaBaoInfo = null;
  229. base.Close();
  230. }
  231. }
  232. }