EquipAbout.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import i18n from "../../i18n/i18n";
  2. import ViewObject from "../../main/ViewObject";
  3. import GoodItem from "./GoodItem";
  4. import EquipViewAttr from "./EquipViewAttr";
  5. import FFCalAttr from "../data/FFCalAttr";
  6. /**
  7. * 装备说明
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class EquipAbout extends ViewObject {
  12. @property(cc.Label)
  13. mName: cc.Label = null;
  14. @property(cc.Label)
  15. mAbout: cc.Label = null;
  16. @property(GoodItem)
  17. mGoodItem: GoodItem = null;
  18. @property(cc.Label)
  19. mZdl: cc.Label = null;
  20. @property(cc.Label)
  21. mAtk: cc.Label = null;
  22. @property(cc.Label)
  23. mDef: cc.Label = null;
  24. @property(cc.Label)
  25. mHp: cc.Label = null;
  26. @property(cc.Label)
  27. mSp: cc.Label = null;
  28. @property(cc.Node)
  29. mFAttrNode: cc.Node = null;//副属性节点
  30. @property(cc.Prefab)
  31. mFAttrItem: cc.Prefab = null;
  32. @property(cc.Node)
  33. mSkillNode: cc.Node = null;//技能节点
  34. @property(cc.Label)
  35. mSkillName: cc.Label = null;
  36. @property(cc.Label)
  37. mSkillAbout: cc.Label = null;
  38. @property(cc.Sprite)
  39. mSkillIcon: cc.Sprite = null;
  40. @property([cc.Node])
  41. mMainNode: Array<cc.Node> = [];//主属性节点
  42. public goodItem:GoodItem;
  43. public onLoad(){
  44. }
  45. /**
  46. * initEquip
  47. */
  48. public initEquip(goodItem:GoodItem) {
  49. this.goodItem = goodItem;
  50. let equip = this.goodItem.equip;
  51. let equipData = this.goodItem.equipData;
  52. this.mName.string = i18n.t(equipData.name);
  53. this.mAbout.string = i18n.t(equipData.about);
  54. this.goodItem.equip = equip;
  55. this.goodItem.equipData = equipData;
  56. this.goodItem.flushEquip(this.main);
  57. this.mZdl.string = ''+FFCalAttr.getZdl(equipData)
  58. if(equipData.atk > 0){
  59. this.mAtk.string = i18n.t('攻击')+':'+equipData.atk;
  60. this.mMainNode[0].active = true;
  61. }else{
  62. this.mMainNode[0].active = false;
  63. }
  64. if(equipData.def > 0){
  65. this.mDef.string = i18n.t('防御')+':'+equipData.def;
  66. this.mMainNode[1].active = true;
  67. }else{
  68. this.mMainNode[1].active = false;
  69. }
  70. if(equipData.hp > 0){
  71. this.mHp.string = i18n.t('气血')+':'+equipData.hp;
  72. this.mMainNode[2].active = true;
  73. }else{
  74. this.mMainNode[2].active = false;
  75. }
  76. if(equipData.sp > 0){
  77. this.mSp.string = i18n.t('速度')+':'+equipData.sp;
  78. this.mMainNode[3].active = true;
  79. }else{
  80. this.mMainNode[3].active = false;
  81. }
  82. if(equip.attr.length <= 0){
  83. this.mFAttrNode.active = false;
  84. }else{
  85. let nodes = this.mFAttrNode.children;
  86. nodes.forEach(node => {
  87. if(node.name != 'fsx_name'){
  88. node.destroy();
  89. }
  90. });
  91. this.mFAttrNode.active = true;
  92. for (let i = 0; i < equip.attr.length; i++) {
  93. const element = equip.attr[i];
  94. let node = cc.instantiate(this.mFAttrItem);
  95. let eAttr = node.getComponent(EquipViewAttr);
  96. eAttr.init(this.main,element);
  97. node.parent = this.mFAttrNode;
  98. }
  99. }
  100. if(equipData.skill > 0){
  101. this.mSkillNode.active = true;
  102. let skillData = this.main.sManage.getSkillById(equipData.skill);
  103. this.mSkillName.string = i18n.t(skillData.name);
  104. this.mSkillAbout.string = i18n.t(skillData.about,
  105. {
  106. 'VAL1':skillData.value1,
  107. 'VAL2':skillData.value2,
  108. 'VAL3':skillData.value3,
  109. }
  110. );
  111. cc.resources.load('icon/skill/'+skillData.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  112. if(err){
  113. cc.error(err);
  114. }else{
  115. this.mSkillIcon.spriteFrame = spriteFrame;
  116. }
  117. } );
  118. }else{
  119. this.mSkillNode.active = false;
  120. }
  121. }
  122. }