HeroBagPanel.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }
  20. protected override void DelEvent()
  21. {
  22. EventManager.Instance.RemoveEventListener(CustomEventType.MainLvUp, OnMainLvUp);
  23. EventManager.Instance.RemoveEventListener(CustomEventType.HeroEquip, CheckAlterRed);
  24. }
  25. public override void AddButtonEvent()
  26. {
  27. btnBack.onClick.AddListener(OnclickClose);
  28. btnEquip.onClick.AddListener(OnclickEquipment);
  29. }
  30. private async void OnclickEquipment()
  31. {
  32. ProfessionEquipmentPanel professionEquipmentPanel = await UIManager.
  33. Instance.LoadAndOpenPanel<ProfessionEquipmentPanel>(null, isFullUI: true);
  34. professionEquipmentPanel.InitPanel();
  35. }
  36. private void OnMainLvUp(IEventData e)
  37. {
  38. // SimpleEventData data = e as SimpleEventData;
  39. UpdateMainLv();
  40. }
  41. private void OnclickClose()
  42. {
  43. UIManager.Instance.HideUIUIPanel(this);
  44. }
  45. private void UpdateMainLv()
  46. {
  47. txtMainLv.text = LanguageManager.Instance.Text(64, PlayerManager.Instance.heroController.mainLevel);
  48. }
  49. private void CheckAlterRed(IEventData e = null)
  50. {
  51. if (PlayerManager.Instance.eqController.IsBetterEqs(false))
  52. {
  53. AlerRed.SetActive(true);
  54. }
  55. else
  56. {
  57. AlerRed.SetActive(false);
  58. }
  59. }
  60. public void InitPanel()
  61. {
  62. InitMainHeroWidget();
  63. UpdateMainLv();
  64. CheckAlterRed();
  65. }
  66. public List<WidgetHero> widgetHeroes = new List<WidgetHero>();
  67. private async void InitMainHeroWidget()
  68. {
  69. widgetHeroes.Clear();
  70. int i = 0;
  71. foreach (KeyValuePair<int,HeroInfo> keyValuePair in PlayerManager.Instance.heroController.heroDicInLead)
  72. {
  73. RectTransform rectTransform = mainHeroes[i] as RectTransform;
  74. WidgetHero itemHero = await UIManager.Instance.CreateGComponent<WidgetHero>(null,
  75. poolName: "WidgetHero", root: rectTransform);
  76. itemHero.InitHeroForBag(keyValuePair.Value);
  77. widgetHeroes.Add(itemHero);
  78. i++;
  79. }
  80. }
  81. }
  82. }