GoodAbout.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 GoodAbout 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. baseAttNode: cc.Node = null;//基础属性节点
  34. @property(cc.Node)
  35. addAttNode: cc.Node = null;//附加属性节点
  36. @property(cc.Node)
  37. mSkillNode: cc.Node = null;//技能节点
  38. @property(cc.Node)
  39. descNode: cc.Node = null;//说明节点
  40. @property(cc.Label)
  41. lbdesc: cc.Label = null;
  42. @property(cc.Label)
  43. mSkillName: cc.Label = null;
  44. @property(cc.Label)
  45. mSkillAbout: cc.Label = null;
  46. @property(cc.Sprite)
  47. mSkillIcon: cc.Sprite = null;
  48. @property([cc.Node])
  49. mMainNode: Array<cc.Node> = [];//主属性节点
  50. @property(cc.Node)
  51. mEquipNode: cc.Node = null;//装备节点
  52. @property(cc.Node)
  53. mGoodNode: cc.Node = null;//道具节点
  54. @property(cc.Node)
  55. mUseNode: cc.Node = null;//使用节点
  56. @property(cc.Node)
  57. mQHNode: cc.Node = null;//强化按钮节点
  58. @property(cc.Node)
  59. mUnInstallNode: cc.Node = null;//卸下按钮节点
  60. /**
  61. * 装备强化回调
  62. */
  63. public qhCallback: (goodItem: GoodItem) => void;
  64. /**
  65. * 卸下
  66. */
  67. public unCallback: (goodItem: GoodItem) => void;
  68. public goodItem: GoodItem;
  69. public inGuide = false;//是否引导中
  70. public guideStep: number = 0; //指引步骤
  71. public showQH: boolean = true;
  72. public onLoad() {
  73. this.node.zIndex = 1
  74. }
  75. /**
  76. *
  77. * @param prev 父界面
  78. */
  79. public show(prev?: ViewObject) {
  80. if (prev) {
  81. this.prev = prev;
  82. this.prev.__close();
  83. }
  84. this.main.viewManage.popView1(this.node);
  85. if (this.main && this.main.gameHttp) {
  86. this.main.gameHttp.pushEvent(this);
  87. }
  88. }
  89. public init(goodItem: GoodItem, showQH: boolean = true) {
  90. this.showQH = showQH;
  91. if (goodItem.equip) {
  92. this.mEquipNode.active = true;
  93. this.mGoodNode.active = false;
  94. this.initEquip(goodItem)
  95. } else {
  96. this.mEquipNode.active = false;
  97. this.mGoodNode.active = true;
  98. this.initGood(goodItem)
  99. }
  100. if (this.inGuide) {
  101. if (this.guideStep == 1) {
  102. this.onGuide_1();
  103. }
  104. }
  105. }
  106. public initGood(goodItem: GoodItem) {
  107. this.mGoodItem.initGood(this.main, goodItem.data)
  108. this.mName.string = i18n.t(goodItem.good.name);
  109. this.mAbout.string = i18n.t(goodItem.good.about)
  110. this.mUseNode.active = goodItem.good.type == 3
  111. }
  112. public initEquip(goodItem: GoodItem) {
  113. this.goodItem = goodItem;
  114. let equip = this.goodItem.equip;
  115. this.mGoodItem.initEquip(this.main, equip)
  116. let equipData = this.goodItem.equipData;
  117. this.mName.string = i18n.t(equipData.name);
  118. this.mAbout.string = i18n.t(equipData.about);
  119. this.goodItem.equip = equip;
  120. this.goodItem.equipData = equipData;
  121. this.goodItem.flushEquip(this.main);
  122. this.mQHNode.active = equipData.type <= 4 && this.showQH;
  123. let fAttr = FFCalAttr.getEquipAttr(this.main, equip, equipData)
  124. this.mZdl.string = '' + fAttr.zdl
  125. if (equipData.atk > 0) {
  126. this.mAtk.string = '' + fAttr.atk;
  127. this.mMainNode[0].active = true;
  128. } else {
  129. this.mMainNode[0].active = false;
  130. }
  131. if (equipData.def > 0) {
  132. this.mDef.string = '' + fAttr.def;
  133. this.mMainNode[1].active = true;
  134. } else {
  135. this.mMainNode[1].active = false;
  136. }
  137. if (equipData.hp > 0) {
  138. this.mHp.string = '' + fAttr.hp;
  139. this.mMainNode[2].active = true;
  140. } else {
  141. this.mMainNode[2].active = false;
  142. }
  143. if (equipData.sp > 0) {
  144. this.mSp.string = '' + fAttr.sp;
  145. this.mMainNode[3].active = true;
  146. } else {
  147. this.mMainNode[3].active = false;
  148. }
  149. if (equipData.atk <= 0 && equipData.def <= 0 && equipData.hp <= 0 && equipData.sp <= 0) {
  150. this.baseAttNode.active = false;
  151. }
  152. if (equip.attr.length <= 0) {
  153. this.mFAttrNode.active = false;
  154. this.addAttNode.active = false;
  155. } else {
  156. let nodes = this.mFAttrNode.children;
  157. nodes.forEach(node => {
  158. if (node.name != 'fsx_name') {
  159. node.destroy();
  160. }
  161. });
  162. this.mFAttrNode.active = true;
  163. for (let i = 0; i < equip.attr.length; i++) {
  164. const element = equip.attr[i];
  165. let node = cc.instantiate(this.mFAttrItem);
  166. let eAttr = node.getComponent(EquipViewAttr);
  167. eAttr.init(this.main, element);
  168. node.parent = this.mFAttrNode;
  169. }
  170. }
  171. if (equipData.skill > 0) {
  172. this.mSkillNode.active = true;
  173. let skillData = this.main.sManage.getSkillById(equipData.skill);
  174. this.mSkillName.string = i18n.t(skillData.name);
  175. this.mSkillAbout.string = i18n.t(skillData.about,
  176. {
  177. 'VAL1': skillData.value1,
  178. 'VAL2': skillData.value2,
  179. 'VAL3': skillData.value3,
  180. }
  181. );
  182. cc.resources.load('icon/skill/' + skillData.icon, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  183. if (err) {
  184. cc.error(err);
  185. } else {
  186. this.mSkillIcon.spriteFrame = spriteFrame;
  187. }
  188. });
  189. } else {
  190. this.mSkillNode.active = false;
  191. }
  192. if (equipData.about != "") {
  193. this.lbdesc.string = i18n.t(equipData.about);
  194. } else {
  195. this.descNode.active = false;
  196. }
  197. }
  198. public setQHCallback(qhCallback: (goodItem: GoodItem) => void) {
  199. this.qhCallback = qhCallback
  200. }
  201. /**
  202. * 点击强化按钮
  203. */
  204. public onclickQH() {
  205. if (this.qhCallback) {
  206. this.qhCallback(this.goodItem)
  207. }
  208. if (this.guideCallback) {
  209. this.guideCallback();
  210. }
  211. }
  212. public setUnCallback(unCallback: (goodItem: GoodItem) => void) {
  213. this.unCallback = unCallback
  214. }
  215. /**
  216. * 点击强化按钮
  217. */
  218. public onclickUn() {
  219. if (this.unCallback) {
  220. this.unCallback(this.goodItem)
  221. }
  222. }
  223. /**
  224. * 引导中的点击回调
  225. */
  226. private guideCallback: () => void
  227. public setGuideCallback(guideCallback: () => void) {
  228. this.guideCallback = guideCallback
  229. }
  230. /**
  231. * 开始引导强化装备
  232. */
  233. private onGuide_1() {
  234. let guideMask = this.main.mGuideMask;
  235. let targetNode = this.mQHNode;
  236. guideMask.setTargetNode(targetNode);
  237. guideMask.show();
  238. this.setGuideCallback(() => {
  239. guideMask.close()
  240. })
  241. }
  242. }