PetInfo.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import i18n from "../../../i18n/i18n";
  2. import ViewObject from "../../../main/ViewObject";
  3. import EquipViewAttr from "../../common/EquipViewAttr";
  4. import PetIcon from "../../common/PetIcon";
  5. import FFCalAttr, { FFAttr } from "../../data/FFCalAttr";
  6. /**
  7. * 宠物属性详情
  8. */
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class PetInfo extends ViewObject {
  12. @property(cc.Label)
  13. mZdl: cc.Label = null;
  14. @property(cc.Label)
  15. mAtk: cc.Label = null;
  16. @property(cc.Label)
  17. mDef: cc.Label = null;
  18. @property(cc.Label)
  19. mHp: cc.Label = null;
  20. @property(cc.Label)
  21. mSp: cc.Label = null;
  22. @property(cc.Node)
  23. mFAttrNode: cc.Node = null;//副属性节点
  24. @property(cc.Prefab)
  25. mFAttrItem: cc.Prefab = null;
  26. @property(cc.Node)
  27. mSkillNode: cc.Node = null;//技能节点
  28. @property(cc.Label)
  29. mSkillAbout: cc.Label = null;
  30. @property(cc.Sprite)
  31. mSkillIcon: cc.Sprite = null;
  32. /**
  33. *
  34. * @param prev 父界面
  35. */
  36. public show(prev?: ViewObject) {
  37. if (prev) {
  38. this.prev = prev;
  39. this.prev.__close();
  40. }
  41. this.main.viewManage.popView1(this.node);
  42. if (this.main && this.main.gameHttp) {
  43. this.main.gameHttp.pushEvent(this);
  44. }
  45. }
  46. public init(pi: PetIcon) {
  47. this.node.zIndex = 1
  48. let ffAttr: FFAttr = FFCalAttr.getAttr(this.main, pi.data)
  49. this.mZdl.string = '' + ffAttr.zdl;
  50. this.mAtk.string = '' + ffAttr.atk;
  51. this.mDef.string = '' + ffAttr.def;
  52. this.mHp.string = '' + ffAttr.hp;
  53. this.mSp.string = '' + ffAttr.sp;
  54. if (ffAttr.attrs.length <= 0) {
  55. this.mFAttrNode.active = false;
  56. } else {
  57. let nodes = this.mFAttrNode.children;
  58. nodes.forEach(node => {
  59. if (node.name != 'fsx_name') {
  60. node.destroy();
  61. }
  62. });
  63. this.mFAttrNode.active = true;
  64. for (let i = 0; i < ffAttr.attrs.length; i++) {
  65. const element = ffAttr.attrs[i];
  66. let node = cc.instantiate(this.mFAttrItem);
  67. let eAttr = node.getComponent(EquipViewAttr);
  68. eAttr.init(this.main, element);
  69. node.parent = this.mFAttrNode;
  70. }
  71. }
  72. if (ffAttr.weaponSkill > 0) {
  73. this.mSkillNode.active = true;
  74. let skillData = this.main.sManage.getSkillById(ffAttr.weaponSkill);
  75. this.mSkillAbout.string = i18n.t(skillData.about,
  76. {
  77. 'VAL1': skillData.value1,
  78. 'VAL2': skillData.value2,
  79. 'VAL3': skillData.value3,
  80. }
  81. );
  82. cc.resources.load('icon/skill/' + skillData.icon, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  83. if (err) {
  84. cc.error(err);
  85. } else {
  86. this.mSkillIcon.spriteFrame = spriteFrame;
  87. }
  88. });
  89. } else {
  90. this.mSkillNode.active = false;
  91. }
  92. }
  93. }