CommonComCurrencyNestedCtrl.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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;
  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 CommonComCurrencyNestedCtrl : UIController<CommonComCurrencyNestedVM>
  18. {
  19. protected override void OnEnable(object intent)
  20. {
  21. AddUIListenres();
  22. }
  23. protected override void OnDisable()
  24. {
  25. RemoveUIListenres();
  26. }
  27. #region UI事件
  28. private void AddUIListenres()
  29. {
  30. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum);
  31. }
  32. private void RemoveUIListenres()
  33. {
  34. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum);
  35. }
  36. #endregion
  37. private int _id;
  38. private void OnUpdateItemNum(int eventId, object args)
  39. {
  40. ShowItemNum();
  41. }
  42. public void ShowUI(int currencyId, long count)
  43. {
  44. var currencyInfo = ItemTableRepo.Get(currencyId);
  45. if (currencyInfo != null)
  46. VM.IconLoader.icon = currencyInfo?.Icon;
  47. VM.NumLabel.text = count.ToString();
  48. }
  49. private void SetItem(int id)
  50. {
  51. _id = id;
  52. ShowItemNum();
  53. }
  54. private void ShowItemNum()
  55. {
  56. if (_id == 0)
  57. return;
  58. var currencyInfo = ItemTableRepo.Get(_id);
  59. if (currencyInfo == null)
  60. {
  61. Log.Error($"道具表不存在,id:{_id}");
  62. return;
  63. }
  64. var num = ItemData.Instance.GetItemNum(_id);
  65. VM.IconLoader.icon = currencyInfo?.Icon;
  66. VM.NumLabel.text = num.ToString();
  67. }
  68. }
  69. }