PartnerSbStarUpBtnCtrl.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FL.Data;
  7. using XGame.Database;
  8. using XGame.Framework.UI;
  9. namespace FL.FGUI
  10. {
  11. /// <summary>
  12. /// UI逻辑处理类
  13. /// </summary>
  14. /// <typeparam name=""></typeparam>
  15. public partial class PartnerSbStarUpBtnCtrl : UIController<PartnerSbStarUpBtnVM>
  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. Context.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
  29. }
  30. private void RemoveUIListenres()
  31. {
  32. Context.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
  33. }
  34. private void OnItemUpdate(int eventId, object args)
  35. {
  36. ShowUI();
  37. }
  38. #endregion
  39. private int _sbId;
  40. public void SetData(int sbId)
  41. {
  42. _sbId = sbId;
  43. ShowUI();
  44. }
  45. private void ShowUI()
  46. {
  47. var attr = PartnersData.Instance.GetPartnerAttrByTableId(_sbId);
  48. var star = attr?.RisingStarLv ?? 1;
  49. var starUpTable = partnerStarUpTableRepo.GetPartnerStarTable(_sbId, star);
  50. XGame.Framework.Assert.IsNotNull(
  51. starUpTable,
  52. $"圣兵升星表不存在,id:{_sbId},starlv:{star}"
  53. );
  54. var num = ItemData.Instance.GetItemNum(starUpTable.PetId);
  55. VM.SpPbar.max = starUpTable.StarUpCost;
  56. VM.SpPbar.value = num;
  57. VM.Grayed.selectedIndex = num >= starUpTable.StarUpCost ? 0 : 1;
  58. }
  59. }
  60. }