HeroBagPanel.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using Common.Utility.CombatEvent;
  3. using Core.Language;
  4. using Fort23.Core;
  5. using GameLogic.Hero;
  6. using UnityEngine;
  7. namespace Fort23.Mono
  8. {
  9. [UIBinding(prefab = "HeroBagPanel" )]
  10. public partial class HeroBagPanel : UIPanel
  11. {
  12. private void Init()
  13. {
  14. }
  15. protected override void AddEvent()
  16. {
  17. EventManager.Instance.AddEventListener(CustomEventType.MainLvUp, OnMainLvUp);
  18. EventManager.Instance.AddEventListener(CustomEventType.HeroEquip, CheckAlterRed);
  19. EventManager.Instance.AddEventListener(CustomEventType.Combat_EquipFall, CheckAlterRed);
  20. }
  21. protected override void DelEvent()
  22. {
  23. EventManager.Instance.RemoveEventListener(CustomEventType.MainLvUp, OnMainLvUp);
  24. EventManager.Instance.RemoveEventListener(CustomEventType.HeroEquip, CheckAlterRed);
  25. EventManager.Instance.RemoveEventListener(CustomEventType.Combat_EquipFall, CheckAlterRed);
  26. }
  27. public override void AddButtonEvent()
  28. {
  29. btnBack.onClick.AddListener(OnclickClose);
  30. btnEquip.onClick.AddListener(OnclickEquipment);
  31. }
  32. private async void OnclickEquipment()
  33. {
  34. ProfessionEquipmentPanel professionEquipmentPanel = await UIManager.
  35. Instance.LoadAndOpenPanel<ProfessionEquipmentPanel>(null, isFullUI: true);
  36. professionEquipmentPanel.InitPanel();
  37. }
  38. private void OnMainLvUp(IEventData e)
  39. {
  40. // SimpleEventData data = e as SimpleEventData;
  41. UpdateMainLv();
  42. }
  43. private void OnclickClose()
  44. {
  45. UIManager.Instance.HideUIUIPanel(this);
  46. }
  47. private void UpdateMainLv()
  48. {
  49. txtMainLv.text = LanguageManager.Instance.Text(64, PlayerManager.Instance.heroController.mainLevel);
  50. }
  51. private void CheckAlterRed(IEventData e = null)
  52. {
  53. if (PlayerManager.Instance.eqController.atLeastOneBetterEq)
  54. {
  55. AlerRed.SetActive(true);
  56. }
  57. else
  58. {
  59. AlerRed.SetActive(false);
  60. }
  61. }
  62. public void InitPanel()
  63. {
  64. InitMainHeroWidget();
  65. UpdateMainLv();
  66. CheckAlterRed();
  67. }
  68. public List<WidgetHero> widgetHeroes = new List<WidgetHero>();
  69. private async void InitMainHeroWidget()
  70. {
  71. widgetHeroes.Clear();
  72. int i = 0;
  73. foreach (KeyValuePair<int,HeroInfo> keyValuePair in PlayerManager.Instance.heroController.heroDicInLead)
  74. {
  75. RectTransform rectTransform = mainHeroes[i] as RectTransform;
  76. WidgetHero itemHero = await UIManager.Instance.CreateGComponent<WidgetHero>(null,
  77. poolName: "WidgetHero", root: rectTransform);
  78. itemHero.InitHeroForBag(keyValuePair.Value);
  79. widgetHeroes.Add(itemHero);
  80. i++;
  81. }
  82. }
  83. }
  84. }