MainUIPanel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using Common.Utility.CombatEvent;
  4. using Core.Language;
  5. using Core.Utility;
  6. using Excel2Json;
  7. using Fort23.Core;
  8. using Fort23.UTool;
  9. using GameLogic.Bag;
  10. using GameLogic.Combat.CombatTool;
  11. using GameLogic.Combat.CombatType;
  12. using GameLogic.Hero;
  13. using UnityEngine;
  14. using Utility;
  15. namespace Fort23.Mono
  16. {
  17. [UIBinding(prefab = "MainUIPanel")]
  18. public partial class MainUIPanel : UIPanel
  19. {
  20. private CombatHeroEntity bossHeroEntity;
  21. private void Init()
  22. {
  23. InitRes();
  24. InitBattleHeroWidget();
  25. LevelUpdate(null);
  26. CheckEquipRedPoint(null);
  27. }
  28. protected override void AddEvent()
  29. {
  30. CombatEventManager.Instance.AddEventListener(CombatEventType.CombatExpAlter, CombatExpAlter);
  31. // EventManager.Instance.AddEventListener(CustomEventType.HeroPowerUp, OnHeroPowerUp);
  32. EventManager.Instance.AddEventListener(CustomEventType.ItemUpdate, OnItemUpdate);
  33. EventManager.Instance.AddEventListener(CustomEventType.ShowBossHp, ShowBossHp);
  34. EventManager.Instance.AddEventListener(CustomEventType.LevelUpdate, LevelUpdate);
  35. CombatEventManager.Instance.AddEventListener(CombatEventType.HeroHpUpdate, HeroHpUpdateEventData);
  36. EventManager.Instance.AddEventListener(CustomEventType.ShowBattleExp, ShowBattleExp);
  37. EventManager.Instance.AddEventListener(CustomEventType.StartBossBattle, StartBossBattle);
  38. EventManager.Instance.AddEventListener(CustomEventType.ShowDialogue, ShowDialogue);
  39. EventManager.Instance.AddEventListener(CustomEventType.AlterCombatHero, AlterCombatHero);
  40. EventManager.Instance.AddEventListener(CustomEventType.PlayerUseSkill, PlayerUseSkill);
  41. EventManager.Instance.AddEventListener(CustomEventType.OnCloseHeroPanel, OnHeroPanelClose);
  42. EventManager.Instance.AddEventListener(CustomEventType.Combat_EquipFall, CheckEquipRedPoint);
  43. EventManager.Instance.AddEventListener(CustomEventType.HeroEquip, CheckEquipRedPoint);
  44. EventManager.Instance.AddEventListener(CustomEventType.AlterCombatHero, OnCombatHeroChange);
  45. }
  46. protected override void DelEvent()
  47. {
  48. CombatEventManager.Instance.RemoveEventListener(CombatEventType.CombatExpAlter, CombatExpAlter);
  49. // EventManager.Instance.RemoveEventListener(CustomEventType.HeroPowerUp, OnHeroPowerUp);
  50. EventManager.Instance.RemoveEventListener(CustomEventType.ItemUpdate, OnItemUpdate);
  51. EventManager.Instance.RemoveEventListener(CustomEventType.ShowBossHp, ShowBossHp);
  52. EventManager.Instance.RemoveEventListener(CustomEventType.LevelUpdate, LevelUpdate);
  53. CombatEventManager.Instance.RemoveEventListener(CombatEventType.HeroHpUpdate, HeroHpUpdateEventData);
  54. EventManager.Instance.RemoveEventListener(CustomEventType.ShowBattleExp, ShowBattleExp);
  55. EventManager.Instance.RemoveEventListener(CustomEventType.ShowDialogue, ShowDialogue);
  56. EventManager.Instance.RemoveEventListener(CustomEventType.AlterCombatHero, AlterCombatHero);
  57. EventManager.Instance.RemoveEventListener(CustomEventType.OnCloseHeroPanel, OnHeroPanelClose);
  58. EventManager.Instance.RemoveEventListener(CustomEventType.Combat_EquipFall, CheckEquipRedPoint);
  59. EventManager.Instance.RemoveEventListener(CustomEventType.HeroEquip, CheckEquipRedPoint);
  60. EventManager.Instance.RemoveEventListener(CustomEventType.AlterCombatHero, OnCombatHeroChange);
  61. }
  62. /// <summary>
  63. /// 战斗英雄改变
  64. /// </summary>
  65. /// <param name="e"></param>
  66. private void OnCombatHeroChange(IEventData e)
  67. {
  68. if (PlayerManager.Instance.heroController.heroDicInLead.Count >= 4)
  69. {
  70. box.gameObject.SetActive(true);
  71. }
  72. else
  73. {
  74. box.gameObject.SetActive(false);
  75. }
  76. }
  77. /// <summary>
  78. /// 检查装备小红点
  79. /// </summary>
  80. /// <param name="e"></param>
  81. private void CheckEquipRedPoint(IEventData e)
  82. {
  83. // Combat_EquipFallEventData data = e as Combat_EquipFallEventData;
  84. bool betterEqs = PlayerManager.Instance.eqController.IsBetterEqs();
  85. if (betterEqs && PlayerManager.Instance.heroController.allHeroDic.Count > 1)
  86. {
  87. alterObj1.SetActive(true);
  88. }
  89. else
  90. {
  91. alterObj1.SetActive(false);
  92. }
  93. }
  94. private void OnHeroPanelClose(IEventData e)
  95. {
  96. int i = 0;
  97. bool b = false;
  98. foreach (WidgetHero widgetHero in widgetHeroes)
  99. {
  100. if (b)
  101. {
  102. break;
  103. }
  104. if (HeroUITools.IsLvUpShowGuild(widgetHero.heroInfo))
  105. {
  106. RectTransform rectTransform = hero_battle[i] as RectTransform;
  107. TxtGuildPanel.OpenTxtGuildPanel(LanguageManager.Instance.Text(154), new Vector2(rectTransform.position.x,
  108. rectTransform.position.y + 0.6f));
  109. b = true;
  110. }
  111. i++;
  112. }
  113. if (!b)
  114. {
  115. TxtGuildPanel.CloseTxtGuildPanel();
  116. }
  117. }
  118. private void PlayerUseSkill(IEventData iEventData)
  119. {
  120. Button_huiQiu_tween.Play("show", false);
  121. }
  122. private void StartBossBattle(IEventData iEventData)
  123. {
  124. UIManager.Instance.LoadAndOpenPanel<StartBossPanel>(null, UILayer.Middle);
  125. }
  126. private void ShowDialogue(IEventData iEventData)
  127. {
  128. ShowDialogueEventData dialogueData = iEventData as ShowDialogueEventData;
  129. string[] dialogueMessaga = dialogueData.dialogueMessaga;
  130. string[] icon = dialogueData.icon;
  131. System.Action finis = dialogueData.finish;
  132. ShowDialogueEventData.MessageShowType messageShowTyp = dialogueData.messageShowType;
  133. DialoguePanel.OpenDialoguePanel(dialogueMessaga, icon, messageShowTyp, finis);
  134. }
  135. private void ShowBattleExp(IEventData iEventData)
  136. {
  137. bossHp.SetActive(false);
  138. Slider_Exp_Process.SetActive(true);
  139. bossHeroEntity = null;
  140. }
  141. private void HeroHpUpdateEventData(IEventData iEventData)
  142. {
  143. HeroHpUpdateEventData heroHpUpdateEventData = iEventData as HeroHpUpdateEventData;
  144. if (heroHpUpdateEventData.combatHeroEntity == bossHeroEntity)
  145. {
  146. UpdateBossHp();
  147. }
  148. }
  149. public override void AddButtonEvent()
  150. {
  151. btnHeroBag.onClick.AddListener(OnClickHeroBag);
  152. Button_battleBoss.onClick.AddListener(OnClickButtonBattleBoss);
  153. box.onClick.AddListener(OnOpenBox);
  154. Button_huiQiu.onClick.AddListener(OnClickPlayerSkill);
  155. Icon_HeroExp_button.onClick.AddListener(OnClickIcon_HeroExp_button);
  156. Icon_Coin_button.onClick.AddListener(OnClickIcon_Coin_button);
  157. Icon_Diamon_button.onClick.AddListener(OnClickIcon_Diamon_button);
  158. }
  159. private void OnClickIcon_HeroExp_button()
  160. {
  161. // TipMessagePanel.OpenTipMessagePanel("英雄经验,可用于升级英雄等级<color=#ff0000>(每杀死一个小怪能获得经验,击杀boss能获得大量经验)</color>",
  162. // new Vector2(Icon_HeroExp_button.transform.position.x, Icon_HeroExp_button.transform.position.y - 0.5f));
  163. TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(104),
  164. new Vector2(Icon_HeroExp_button.transform.position.x, Icon_HeroExp_button.transform.position.y - 0.5f));
  165. }
  166. private void OnClickIcon_Coin_button()
  167. {
  168. // TipMessagePanel.OpenTipMessagePanel("金币,用于抽取英雄宝箱<color=#ff0000>(每杀死一个小怪有几率获得金币,击杀boss能获得大量金币)</color>",
  169. // new Vector2(Icon_Coin_button.transform.position.x, Icon_Coin_button.transform.position.y - 0.5f));
  170. TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(105),
  171. new Vector2(Icon_Coin_button.transform.position.x, Icon_Coin_button.transform.position.y - 0.5f));
  172. }
  173. private void OnClickIcon_Diamon_button()
  174. {
  175. TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(106),
  176. new Vector2(Icon_Diamon_button.transform.position.x, Icon_Diamon_button.transform.position.y - 0.5f));
  177. }
  178. private void OnOpenBox()
  179. {
  180. BoxPanel.OpenBoxPanel();
  181. }
  182. private async void OnClickButtonBattleBoss()
  183. {
  184. if (AccountFileInfo.Instance.playerData.isAllHeroDie)
  185. {
  186. LevelBattleCombatType levelBattleCombatType =
  187. CombatController.currActiveCombat.CombatTypeBasic as LevelBattleCombatType;
  188. levelBattleCombatType.StartBossCombat();
  189. Button_battleBoss.gameObject.SetActive(false);
  190. }
  191. }
  192. private async void OnClickPlayerSkill()
  193. {
  194. Debug.Log("显示描述");
  195. RectTransform huoQiu = Button_huiQiu.GetComponent<RectTransform>();
  196. // TipMessagePanel.OpenTipMessagePanel("点击屏幕空白处从天空中召唤一个陨石,对怪物造成1点伤害,并有<color=#ff0000>30%</color>概率获得1枚金币(boss怪<color=#ff0000>40%</color>掉落,金币数量<color=#ff0000>+2</color>)",
  197. // new Vector2(huoQiu.position.x, huoQiu.position.y + 0.5f));
  198. TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(107),
  199. new Vector2(huoQiu.position.x, huoQiu.position.y + 0.5f));
  200. }
  201. private async void OnClickHeroBag()
  202. {
  203. HeroBagPanel heroBagPanel = await UIManager.Instance.LoadAndOpenPanel<HeroBagPanel>(null, isFullUI: true);
  204. heroBagPanel.InitPanel();
  205. }
  206. private void AlterCombatHero(IEventData e)
  207. {
  208. InitHeroWidget();
  209. }
  210. private void OnItemUpdate(IEventData e)
  211. {
  212. ItemUpdateData data = e as ItemUpdateData;
  213. if (data.ItemInfo.itemID == GlobalParam.Item_Coin_ID)
  214. {
  215. txtCoin.text = BagController.Instance.GetItemInfo(GlobalParam.Item_Coin_ID).count.Value.ToStringEx();
  216. }
  217. else if (data.ItemInfo.itemID == GlobalParam.Item_Diamond_ID)
  218. {
  219. txtDiamond.text = BagController.Instance.GetItemInfo(GlobalParam.Item_Diamond_ID).count.Value
  220. .ToStringEx();
  221. }
  222. else if (data.ItemInfo.itemID == GlobalParam.Item_HeroExp_ID)
  223. {
  224. txtHeroExp.text = BagController.Instance.GetItemInfo(GlobalParam.Item_HeroExp_ID).count.Value
  225. .ToStringEx();
  226. }
  227. }
  228. private void LevelUpdate(IEventData eventData)
  229. {
  230. int levelBattle = AccountFileInfo.Instance.playerData.levelBattle;
  231. LevelBattleConfig levelBattleConfig = ConfigComponent.Instance.Get<LevelBattleConfig>(levelBattle);
  232. levelName.text = levelBattleConfig.levelName;
  233. }
  234. private void ShowBossHp(IEventData eventData)
  235. {
  236. ShowBossHpEventData showBossHpEventData = eventData as ShowBossHpEventData;
  237. bossHeroEntity = showBossHpEventData.boss;
  238. bossHp.SetActive(true);
  239. Slider_Exp_Process.SetActive(false);
  240. bossName.text = bossHeroEntity.CurrCombatHeroInfo.heroName;
  241. UpdateBossHp();
  242. OnHeroPanelClose(null);
  243. }
  244. protected void UpdateBossHp()
  245. {
  246. Slider_Hp_Boss.value = bossHeroEntity.CurrCombatHeroInfo.hp.Value * 1.0f /
  247. bossHeroEntity.MaxCombatHeroInfo.hp.Value;
  248. }
  249. private void CombatExpAlter(IEventData eventData)
  250. {
  251. ExpAlter();
  252. }
  253. private void ExpAlter()
  254. {
  255. if (CombatController.currActiveCombat == null || CombatController.currActiveCombat.CombatTypeBasic == null)
  256. {
  257. return;
  258. }
  259. LevelBattleCombatType levelBattleCombatType =
  260. CombatController.currActiveCombat.CombatTypeBasic as LevelBattleCombatType;
  261. float bl = (levelBattleCombatType.exp * 1.0f) / levelBattleCombatType.CurrMaxExp;
  262. exp.value = bl;
  263. TextExp.text = levelBattleCombatType.exp + "/" + levelBattleCombatType.CurrMaxExp;
  264. if (levelBattleCombatType.exp >= levelBattleCombatType.CurrMaxExp) // 到达目标值,开始打boss
  265. {
  266. if (!levelBattleCombatType.isBossCombat && AccountFileInfo.Instance.playerData.isAllHeroDie)
  267. {
  268. Button_battleBoss.gameObject.SetActive(true);
  269. }
  270. }
  271. else
  272. {
  273. Button_battleBoss.gameObject.SetActive(false);
  274. }
  275. }
  276. // private void OnHeroPowerUp(IEventData eventData)
  277. // {
  278. // HeroPowerUpEventData data = eventData as HeroPowerUpEventData;
  279. // HeroInfo heroInfo = (HeroInfo)PlayerManager.Instance.heroController.GetHeroInfo(data.heroModelID);
  280. //
  281. // foreach (WidgetHero widgetHero in widgetHeroes)
  282. // {
  283. // if (widgetHero.heroInfo.modelID == heroInfo.modelID)
  284. // {
  285. // widgetHero.UpdateWidgetUI(heroInfo);
  286. // break;
  287. // }
  288. // }
  289. // }
  290. public List<WidgetHero> widgetHeroes = new List<WidgetHero>();
  291. /// <summary>
  292. /// 把主界面的几个英雄UI归位
  293. /// </summary>
  294. /// <param name="wh"></param>
  295. public void RestWidgetHeroPos(WidgetHero wh)
  296. {
  297. Vector3 v;
  298. Vector3 origin;
  299. foreach (WidgetHero w in widgetHeroes)
  300. {
  301. if (wh != null && w.Equals(wh))
  302. {
  303. continue;
  304. }
  305. v = w.transform.parent.localPosition;
  306. if (v.y > 0)
  307. {
  308. origin = new Vector3(v.x, 0, v.z);
  309. w.transform.parent.localPosition = origin;
  310. w.SetMoreBtnActive(false);
  311. }
  312. }
  313. }
  314. private async void InitBattleHeroWidget()
  315. {
  316. Button_battleBoss.gameObject.SetActive(false);
  317. InitHeroWidget();
  318. // RectTransform rectTransform = hero_battle[0] as RectTransform;
  319. }
  320. private async void InitHeroWidget()
  321. {
  322. for (int j = 0; j < widgetHeroes.Count; j++)
  323. {
  324. UIManager.Instance.DormancyGComponent(widgetHeroes[j]);
  325. }
  326. widgetHeroes.Clear();
  327. int i = 0;
  328. foreach (KeyValuePair<int, HeroInfo> keyValuePair in PlayerManager.Instance.heroController.heroDicInLead)
  329. {
  330. RectTransform rectTransform = hero_battle[i] as RectTransform;
  331. WidgetHero itemHero = await UIManager.Instance.CreateGComponent<WidgetHero>(null,
  332. poolName: "WidgetHero", root: rectTransform);
  333. itemHero.InitHero(keyValuePair.Value);
  334. itemHero.own.gameObject.name= "hero_battle"+i;
  335. widgetHeroes.Add(itemHero);
  336. // if (HeroUITools.IsLvUpShowGuild(keyValuePair.Value))
  337. // {
  338. // TxtGuildPanel.OpenTxtGuildPanel("点这里提升英雄", new Vector2(rectTransform.position.x,
  339. // rectTransform.position.y + 0.6f));
  340. // }
  341. i++;
  342. }
  343. OnHeroPanelClose(null);
  344. }
  345. private void InitRes()
  346. {
  347. txtDiamond.text = BagController.Instance.GetItemInfo(GlobalParam.Item_Diamond_ID).count.Value.ToStringEx();
  348. txtCoin.text = BagController.Instance.GetItemInfo(GlobalParam.Item_Coin_ID).count.Value.ToStringEx();
  349. txtHeroExp.text = BagController.Instance.GetItemInfo(GlobalParam.Item_HeroExp_ID).count.Value.ToStringEx();
  350. OnCombatHeroChange(null);
  351. }
  352. }
  353. }