MainUIPanel.cs 13 KB

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