PartnerCostLabelCtrl.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using XGame.Framework.UI;
  9. namespace FL.FGUI
  10. {
  11. /// <summary>
  12. /// UI逻辑处理类
  13. /// </summary>
  14. /// <typeparam name=""></typeparam>
  15. public partial class PartnerCostLabelCtrl : UIController<PartnerCostLabelVM>
  16. {
  17. protected override void OnEnable(object intent)
  18. {
  19. AddUIListenres();
  20. }
  21. protected override void OnDisable()
  22. {
  23. RemoveUIListenres();
  24. }
  25. #region UI事件
  26. private void AddUIListenres()
  27. {
  28. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
  29. }
  30. private void RemoveUIListenres()
  31. {
  32. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
  33. }
  34. private void OnItemUpdate(int eventId, object args)
  35. {
  36. ShowUI();
  37. }
  38. #endregion
  39. private int _id;
  40. private int _cost;
  41. public void SetData(int id, int costNum)
  42. {
  43. _id = id;
  44. _cost = costNum;
  45. ShowUI();
  46. }
  47. private void ShowUI()
  48. {
  49. var num = ItemData.Instance.GetItemNum(_id);
  50. VM.CountLabel.text = $"{num}/{_cost}";
  51. }
  52. }
  53. }