MainHeroPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Animancer;
  4. using Animancer.TransitionLibraries;
  5. using Core.Language;
  6. using Excel2Json;
  7. using Fort23.Core;
  8. using Fort23.UTool;
  9. using GameLogic.Hero;
  10. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  11. using UnityEngine;
  12. using UnityEngine.UI.Extensions;
  13. using Utility;
  14. namespace Fort23.Mono
  15. {
  16. [UIBinding(prefab = "MainHeroPanel")]
  17. public partial class MainHeroPanel : UIPanel
  18. {
  19. List<BtnFaBaoWidget> btnFaBaoWidgets = new List<BtnFaBaoWidget>();
  20. private GameObjectPool modelObj;
  21. private void Init()
  22. {
  23. isAddStack = true;
  24. IsShowAppBar = true;
  25. }
  26. protected override void AddEvent()
  27. {
  28. }
  29. protected override void DelEvent()
  30. {
  31. }
  32. public override CTask GetFocus()
  33. {
  34. TitlePanel.OpenPanel(new List<int>() { 1001, 1002 });
  35. AppBarPanel.OpenPanel(this);
  36. return base.GetFocus();
  37. }
  38. public override CTask LoseFocus()
  39. {
  40. // TitlePanel.ClosePanel();
  41. // AppBarPanel.ClosePanel();
  42. return base.LoseFocus();
  43. }
  44. private HeroInfo heroInfo;
  45. private List<HeroAttributeWidget> HeroAttributeWidgets = new List<HeroAttributeWidget>();
  46. public override void AddButtonEvent()
  47. {
  48. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  49. Btn_Sentiment.onClick.AddListener(() => { SentimentPanel.OpenPanel(); });
  50. reorderableList.OnElementRemoved.AddListener(GetReorderableDataBegin);
  51. reorderableList.OnElementDropped.AddListener(GetReorderableData);
  52. }
  53. public int FromIndex;
  54. public int ToIndex;
  55. private async void GetReorderableDataBegin(ReorderableList.ReorderableListEventStruct arg0)
  56. {
  57. FromIndex = arg0.FromIndex;
  58. }
  59. private async void GetReorderableData(ReorderableList.ReorderableListEventStruct arg0)
  60. {
  61. ToIndex = arg0.ToIndex;
  62. //一样直接不交换
  63. if (ToIndex == FromIndex)
  64. {
  65. return;
  66. }
  67. if (ToIndex > PlayerManager.Instance.myHero.powerUpConfig.MaxFabaoNum - 1)
  68. {
  69. return;
  70. }
  71. FaBaoInfo faBaoInfo = PlayerManager.Instance.FaBaoControl.FightFaBao[FromIndex];
  72. List<FaBaoInfo> faBaoInfos = PlayerManager.Instance.FaBaoControl.FightFaBao.ToList();
  73. faBaoInfos.RemoveAt(FromIndex);
  74. faBaoInfos.Insert(ToIndex,faBaoInfo);
  75. for (var i = 0; i < faBaoInfos.Count; i++)
  76. {
  77. PlayerManager.Instance.FaBaoControl.ChangeUseFaBao(i, faBaoInfos[i]);
  78. }
  79. BtnFaBaoWidget btnFaBaoWidget = btnFaBaoWidgets[FromIndex];
  80. btnFaBaoWidgets.RemoveAt(FromIndex);
  81. btnFaBaoWidgets.Insert(ToIndex,btnFaBaoWidget);
  82. for (var i = 0; i < btnFaBaoWidgets.Count; i++)
  83. {
  84. btnFaBaoWidgets[i].CustomInit(i);
  85. }
  86. }
  87. public async override CTask<bool> AsyncInit(object[] uiData)
  88. {
  89. await CustomInit();
  90. base.AsyncInit(uiData);
  91. return true;
  92. }
  93. public async CTask CustomInit()
  94. {
  95. foreach (var btnFaBaoWidget in btnFaBaoWidgets)
  96. {
  97. UIManager.Instance.DormancyGComponent(btnFaBaoWidget);
  98. }
  99. btnFaBaoWidgets.Clear();
  100. for (int i = 0; i < 4; i++)
  101. {
  102. BtnFaBaoWidget btnFaBaoWidget =
  103. await UIManager.Instance.CreateGComponent<BtnFaBaoWidget>(null, FaBaoRoot);
  104. btnFaBaoWidget.CustomInit(i);
  105. btnFaBaoWidget.OnClick = OnClick;
  106. btnFaBaoWidgets.Add(btnFaBaoWidget);
  107. }
  108. heroInfo = PlayerManager.Instance.myHero;
  109. HeroAttributeWidget heroAttributeWidget =
  110. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  111. Content, isInstance: true);
  112. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  113. heroAttributeWidget.CustomInit1(10712, new HeroAttributeData("生命", "",
  114. PlayerManager.Instance.myHero.hp.Value.ToStringEx()));
  115. HeroAttributeWidgets.Add(heroAttributeWidget);
  116. heroAttributeWidget =
  117. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  118. Content, isInstance: true);
  119. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  120. heroAttributeWidget.CustomInit1(10713, new HeroAttributeData("攻击", "",
  121. PlayerManager.Instance.myHero.attack.Value.ToStringEx()));
  122. HeroAttributeWidgets.Add(heroAttributeWidget);
  123. heroAttributeWidget =
  124. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  125. Content, isInstance: true);
  126. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  127. heroAttributeWidget.CustomInit1(10714, new HeroAttributeData("防御", "",
  128. PlayerManager.Instance.myHero.defense.Value.ToStringEx()));
  129. HeroAttributeWidgets.Add(heroAttributeWidget);
  130. // heroAttributeWidget =
  131. // await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  132. // Content, isInstance: true);
  133. // heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  134. // heroAttributeWidget.CustomInit1(10715, new HeroAttributeData("攻击速度", "",
  135. // PlayerManager.Instance.myHero.attSpeed.Value.ToString()));
  136. // HeroAttributeWidgets.Add(heroAttributeWidget);
  137. heroAttributeWidget =
  138. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  139. Content, isInstance: true);
  140. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  141. heroAttributeWidget.CustomInit1(10716, new HeroAttributeData("金灵根", "",
  142. PlayerManager.Instance.myHero.Metal.ToString()));
  143. HeroAttributeWidgets.Add(heroAttributeWidget);
  144. heroAttributeWidget =
  145. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  146. Content, isInstance: true);
  147. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  148. heroAttributeWidget.CustomInit1(10717, new HeroAttributeData("木灵根", "",
  149. PlayerManager.Instance.myHero.Wood.ToString()));
  150. HeroAttributeWidgets.Add(heroAttributeWidget);
  151. heroAttributeWidget =
  152. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  153. Content, isInstance: true);
  154. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  155. heroAttributeWidget.CustomInit1(10718, new HeroAttributeData("水灵根", "",
  156. PlayerManager.Instance.myHero.Water.ToString()));
  157. HeroAttributeWidgets.Add(heroAttributeWidget);
  158. heroAttributeWidget =
  159. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  160. Content, isInstance: true);
  161. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  162. heroAttributeWidget.CustomInit1(10719, new HeroAttributeData("火灵根", "",
  163. PlayerManager.Instance.myHero.Fire.ToString()));
  164. HeroAttributeWidgets.Add(heroAttributeWidget);
  165. heroAttributeWidget =
  166. await UIManager.Instance.CreateGComponentForObject<HeroAttributeWidget>(HeroAttributeWidgetGam, null,
  167. Content, isInstance: true);
  168. heroAttributeWidget.OnClick = heroAttributeWidgetOnClick;
  169. heroAttributeWidget.CustomInit1(10720, new HeroAttributeData("土灵根", "",
  170. PlayerManager.Instance.myHero.Earth.ToString()));
  171. HeroAttributeWidgets.Add(heroAttributeWidget);
  172. }
  173. private void heroAttributeWidgetOnClick(ItemWidgetBasic obj)
  174. {
  175. HeroAttributeWidget heroAttributeWidget = obj as HeroAttributeWidget;
  176. TipMessagePanel.OpenTipMessagePanel(heroAttributeWidget.lanID);
  177. }
  178. private async void OnClick(ItemWidgetBasic obj)
  179. {
  180. BtnFaBaoWidget btnFaBaoWidget = obj as BtnFaBaoWidget;
  181. if (btnFaBaoWidget.index > PlayerManager.Instance.myHero.powerUpConfig.MaxFabaoNum - 1)
  182. {
  183. HeroPowerUpConfig[] heroPowerUpConfigs = ConfigComponent.Instance.GetAll<HeroPowerUpConfig>();
  184. foreach (var heroPowerUpConfig in heroPowerUpConfigs)
  185. {
  186. if (heroPowerUpConfig.MaxFabaoNum > btnFaBaoWidget.index)
  187. {
  188. TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(10331,
  189. LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[0]) +
  190. LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[1]) +
  191. LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[2])));
  192. return;
  193. }
  194. }
  195. TipMessagePanel.OpenTipMessagePanel("当前位置未解锁");
  196. return;
  197. }
  198. int redDotID = 9;
  199. AccountFileInfo.RedDot redDot = RedDotManager.Instance.GetRedDot(redDotID);
  200. if (redDot == null)
  201. {
  202. redDot = new AccountFileInfo.RedDot();
  203. redDot.id = redDotID;
  204. }
  205. if (!redDot.Params.Contains(btnFaBaoWidget.index.ToString()))
  206. {
  207. redDot.Params.Add(btnFaBaoWidget.index.ToString());
  208. RedDotManager.Instance.AddRedDot(redDot);
  209. RedDotManager.Instance.ChangeStateRedDot(redDotID, 0);
  210. }
  211. SelectFaBaoPanel selectFaBaoPanel = await SelectFaBaoPanel.OpenPanel(btnFaBaoWidget.index);
  212. await selectFaBaoPanel.UIClosed();
  213. foreach (var b in btnFaBaoWidgets)
  214. {
  215. b.CustomInit(b.index);
  216. }
  217. }
  218. public async static CTask<MainHeroPanel> OpenPanel()
  219. {
  220. MainHeroPanel mainHeroPanel =
  221. await UIManager.Instance.LoadAndOpenPanel<MainHeroPanel>(null, isFullUI: true);
  222. return mainHeroPanel;
  223. }
  224. public async override CTask Close()
  225. {
  226. UIManager.Instance.DormancyGComponent(modelObj);
  227. modelObj = null;
  228. foreach (var btnFaBaoWidget in btnFaBaoWidgets)
  229. {
  230. UIManager.Instance.DormancyGComponent(btnFaBaoWidget);
  231. }
  232. btnFaBaoWidgets.Clear();
  233. foreach (var heroAttributeWidget in HeroAttributeWidgets)
  234. {
  235. UIManager.Instance.DormancyGComponent(heroAttributeWidget);
  236. }
  237. HeroAttributeWidgets.Clear();
  238. await base.Close();
  239. }
  240. }
  241. }