DragonEggEquipmentUICtrl.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FL.Data;
  7. using FL.Data.Items;
  8. using System.Collections.Generic;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class DragonEggEquipmentUICtrl : UIController<DragonEggEquipmentUIVM>
  18. {
  19. private List<CommonItemBaseView> _equipItemList;
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
  24. Init();
  25. ShowEquipUI();
  26. }
  27. protected override void OnDisable()
  28. {
  29. RemoveUIListenres();
  30. EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
  31. if (_equipItemList != null)
  32. {
  33. _equipItemList.Clear();
  34. _equipItemList = null;
  35. }
  36. }
  37. #region UI事件
  38. private void AddUIListenres()
  39. {
  40. }
  41. private void RemoveUIListenres()
  42. {
  43. }
  44. #endregion
  45. private void Init()
  46. {
  47. if (_equipItemList == null)
  48. {
  49. _equipItemList = new List<CommonItemBaseView>()
  50. {
  51. VM.Weapon,VM.Helmet,VM.Clothes,VM.Hand,VM.Pants,VM.Boots
  52. };
  53. }
  54. }
  55. /// <summary>
  56. /// 显示装备UI
  57. /// </summary>
  58. private void ShowEquipUI()
  59. {
  60. UiParam _uiParam = new UiParam();
  61. _uiParam.bShowBtn = true;
  62. _uiParam.bShowLevel = true;
  63. int index = 1;
  64. _equipItemList.ForEach((item) =>
  65. {
  66. EquipItem equipData = ItemData.Instance.GetEquipData((EEquipType)index);
  67. if (equipData != null)
  68. {
  69. item.Ctrl.ShowUI(ItemData.Instance.GetEquipData((EEquipType)index), _uiParam);
  70. }
  71. index++;
  72. });
  73. }
  74. /// <summary>
  75. /// 更换装备
  76. /// </summary>
  77. /// <param name="type"></param>
  78. /// <param name="id"></param>
  79. private void OnChangeEquip(int eventId, object args)
  80. {
  81. if (args == null)
  82. {
  83. return;
  84. }
  85. ChangeEquipParam param = (ChangeEquipParam)args;
  86. CommonItemBaseView equipItem = _equipItemList[(int)param.equipType - 1];
  87. if (equipItem != null)
  88. {
  89. UiParam _uiParam = new UiParam();
  90. _uiParam.bShowBtn = true;
  91. _uiParam.bShowLevel = true;
  92. equipItem.Ctrl.ShowUI(ItemData.Instance.GetEquipData(param.equipType), _uiParam);
  93. }
  94. }
  95. }
  96. }