ItemRewardItemCtrl.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FL.Data.Items;
  7. using FL.Network;
  8. using XGame.Database;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. public class ItemParam
  13. {
  14. public long id;
  15. public int tableId;
  16. public int count;
  17. public int level;
  18. }
  19. /// <summary>
  20. /// UI逻辑处理类
  21. /// </summary>
  22. /// <typeparam name=""></typeparam>
  23. public partial class ItemRewardItemCtrl : UIController<ItemRewardItemVM>
  24. {
  25. private long _equipId; // 装备的uid
  26. protected override void OnEnable(object intent)
  27. {
  28. AddUIListenres();
  29. }
  30. protected override void OnDisable()
  31. {
  32. RemoveUIListenres();
  33. }
  34. #region UI事件
  35. private void AddUIListenres()
  36. {
  37. }
  38. private void RemoveUIListenres()
  39. {
  40. }
  41. #endregion
  42. public void OnRefresh(int index, KindItem param)
  43. {
  44. EquipItem equipData = null;
  45. Item _item = new Item();
  46. bool bEquip = param.count == 0;
  47. int itemId = param.id;
  48. if (bEquip)
  49. {
  50. equipData = EquipData.Instance.GetTemporaryEquipItem(itemId);
  51. itemId = equipData.TableId;
  52. _item.Level = equipData.Level;
  53. _equipId = itemId;
  54. }
  55. else
  56. _equipId = 0;
  57. ShowCompareEquip(bEquip, equipData);
  58. var itemInfo = ItemTableRepo.Get(itemId);
  59. if (itemInfo != null)
  60. {
  61. _item.Count = param.count.ToString();
  62. _item.Init(itemInfo, bEquip ? param.id : 0);
  63. UiParam _uiParam = new UiParam();
  64. _uiParam.bShowBtn = true;
  65. _uiParam.bShowName = false;
  66. _uiParam.bShowCount = param.count > 1;
  67. _uiParam.bShowLevel = bEquip;
  68. _uiParam.bShowBaseInfo = true;
  69. VM.ItemBtn.Ctrl.ShowUI(_item, _uiParam);
  70. }
  71. }
  72. /// <summary>
  73. /// 装备战力比较标识
  74. /// </summary>
  75. private void ShowCompareEquip(bool bEquip, EquipItem equipData)
  76. {
  77. ShowEquipCtrlIndex(bEquip ? GetCompareValue(equipData) : 0);
  78. }
  79. private void ShowEquipCtrlIndex(int index)
  80. {
  81. VM.EquipCtrl.selectedIndex = index;
  82. }
  83. /// <summary>
  84. /// 与身上穿戴部位战力比较
  85. /// </summary>
  86. /// <param name="equipData"></param>
  87. /// <returns></returns>
  88. private int GetCompareValue(EquipItem equipData)
  89. {
  90. int compareFlag = 0;
  91. if (equipData?.Table?.Part > 0)
  92. {
  93. var wearEquipItem = EquipData.Instance.GetWearEquipData(equipData.Table.Part);
  94. long wearFightingPower = wearEquipItem?.FightingPower ?? 0;
  95. if (equipData.FightingPower > wearFightingPower)
  96. compareFlag = 1;
  97. else if (equipData.FightingPower < wearFightingPower)
  98. compareFlag = 2;
  99. }
  100. return compareFlag;
  101. }
  102. }
  103. }