PlayerAttributeItemCtrl.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using XGame.Database;
  7. using XGame.Framework.UI;
  8. namespace FL.FGUI
  9. {
  10. public class AttributeParam
  11. {
  12. public EAttributeType attributeType;
  13. public long attributeValue;
  14. }
  15. /// <summary>
  16. /// UI逻辑处理类
  17. /// </summary>
  18. /// <typeparam name=""></typeparam>
  19. public partial class PlayerAttributeItemCtrl : UIController<PlayerAttributeItemVM>
  20. {
  21. protected override void OnEnable(object intent)
  22. {
  23. AddUIListenres();
  24. }
  25. protected override void OnDisable()
  26. {
  27. RemoveUIListenres();
  28. }
  29. #region UI事件
  30. private void AddUIListenres()
  31. {
  32. }
  33. private void RemoveUIListenres()
  34. {
  35. }
  36. #endregion
  37. public void OnRefresh(int index, AttributeParam attrParam)
  38. {
  39. var attributeInfo = AttrDescTableRepo.Get((int)attrParam.attributeType);
  40. if (attributeInfo != null)
  41. {
  42. //生命属性 [color=#33CCFF]123456789[/color]
  43. // 0_固定值(攻击速度比较特殊用万分比形式展示) 1_万分比
  44. bool bPercentage = attrParam.attributeType == EAttributeType.AtkSpeed || attributeInfo.Num_type == 1;
  45. string desc = bPercentage ? attrParam.attributeValue.ToRealDoublePercentage() : GetFixedValue(attrParam.attributeValue);
  46. VM.AttributeLabel.text = $"{attributeInfo.ShowName} [color=#6699CC]{desc}[/color]";
  47. }
  48. }
  49. /// <summary>
  50. /// 固值显示
  51. /// </summary>
  52. /// <returns></returns>
  53. private string GetFixedValue(long attrValue)
  54. {
  55. return attrValue == 0 ? "0" : attrValue.ToString();
  56. }
  57. }
  58. }