MainUIPanel.cs 16 KB

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