HeroAttr.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import { _decorator, Label, Node, Sprite, SpriteFrame, Toggle, v2, v3 } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { Framework } from '../../../framework/Framework';
  5. import { RoleManager } from '../../manager/RoleManager';
  6. import { RolegradeConf } from '../../config/RolegradeConf';
  7. import { GoodsManager } from '../../manager/GoodsManager';
  8. import { RoleData } from '../../data/RoleData';
  9. const { ccclass, property } = _decorator;
  10. interface TagBtn {
  11. key: string;
  12. btn: Node;
  13. }
  14. @ccclass('HeroAttr')
  15. export class HeroAttr extends BaseView {
  16. @property({ type: Label, tooltip: "标题" })
  17. titleTx: Label = null;
  18. @property({ type: Toggle, tooltip: "属性按钮" })
  19. attrToggle: Toggle = null;
  20. @property({ type: Label, tooltip: "属性按钮文字" })
  21. attrToggleTx: Label = null;
  22. @property({ type: Node, tooltip: "属性节点" })
  23. attrNode: Node = null
  24. @property({ type: Toggle, tooltip: "基因按钮" })
  25. dnaToggle: Toggle = null;
  26. @property({ type: Label, tooltip: "基因按钮文字" })
  27. dnaToggleTx: Label = null;
  28. @property({ type: Node, tooltip: "基因节点" })
  29. dnaNode: Node = null
  30. @property({ type: Toggle, tooltip: "专属按钮" })
  31. exclusiveToggle: Toggle = null;
  32. @property({ type: Label, tooltip: "专属按钮文字" })
  33. exclusiveToggleTx: Label = null;
  34. @property({ type: Node, tooltip: "专属节点" })
  35. exclusiveNode: Node = null
  36. @property({ type: Toggle, tooltip: "皮肤按钮" })
  37. skinToggle: Toggle = null;
  38. @property({ type: Label, tooltip: "皮肤按钮文字" })
  39. skinToggleTx: Label = null;
  40. @property({ type: Node, tooltip: "皮肤节点" })
  41. skinNode: Node = null;
  42. private selectTag = 'attr';
  43. private data = {};
  44. // heroIco: Sprite = null;
  45. protected onLoad() {
  46. super.onLoad();
  47. this.titleTx.string = StringUtil.getLanguageData('英雄详情');
  48. this.attrToggleTx.string = StringUtil.getLanguageData('属性');
  49. this.dnaToggleTx.string = StringUtil.getLanguageData('基因');
  50. this.exclusiveToggleTx.string = StringUtil.getLanguageData('专属');
  51. this.skinToggleTx.string = StringUtil.getLanguageData('皮肤');
  52. }
  53. protected onDestroy() {
  54. }
  55. //UI开打时会调用,如果有初始化代码应该放到此函数
  56. onOpen(data) {
  57. console.log('=============== onOpen', data)
  58. this.data = data.heroDate;
  59. if (data.tag) {
  60. this.selectTag = data.tag;
  61. }
  62. this[`${this.selectTag}Toggle`].isChecked = false;
  63. this[`${this.selectTag}Toggle`].isChecked = true;
  64. this.updateAttr();
  65. }
  66. //UI关闭时会调用,该函数在onDestroy前调用
  67. onClose() {
  68. }
  69. //框架管理UI层级时会调用,可根据UI情况修改
  70. onShow() {
  71. super.onShow();
  72. }
  73. //框架管理UI层级时会调用,可根据UI情况修改
  74. onHide() {
  75. super.onHide();
  76. }
  77. //UI事件处理
  78. private onTouchButton(event: Event) {
  79. //Framework.audio.playEffect(AudioID.Click);
  80. let target: any = event.target;
  81. if (target.name == 'close_btn') {
  82. Framework.layer.close(this)
  83. } else if (target.name == 'update_btn') {
  84. let gConf = RolegradeConf.data[String(this.data['grade'] + 1)];
  85. let costData = GoodsManager.getGoodsLocalInfo(5000 + this.data['id'], gConf.SelfNum1);
  86. let ownData = GoodsManager.getGoodsById(5000 + this.data['id']);
  87. if (ownData.count < costData.count) {
  88. Framework.tips.setTips(StringUtil.getLanguageData('升级所需材料不足!'));
  89. return;
  90. }
  91. RoleManager.sendRoleAdvance({ hid: this.data['id'] }, () => {
  92. Framework.tips.setTips(StringUtil.getLanguageData('升级成功!'));
  93. let rData = RoleData.getRoleDataByID(this.data['id']);
  94. console.log('=============== 11', this.data)
  95. this.data = {}
  96. this.data = rData;
  97. console.log('=============== 22', this.data)
  98. this.updateAttr();
  99. });
  100. }
  101. }
  102. onEventSelectTag(target: Toggle, customEventData: string) {
  103. if (target.isChecked) {
  104. let nodes = ['attr', 'dna', 'exclusive', 'skin']
  105. for (const element of nodes) {
  106. if (element == customEventData) {
  107. this[`${element}Node`].active = true;
  108. } else {
  109. this[`${element}Node`].active = false;
  110. }
  111. }
  112. }
  113. }
  114. updateAttr() {
  115. let attrNode = this.attrNode.getChildByName('msg_bg').getChildByName('attr_node');
  116. let attackNumTx = attrNode.getChildByName('attr_bg').getChildByName('attack_node').getChildByName('num_tx');
  117. let speedNumTx = attrNode.getChildByName('attr_bg').getChildByName('speed_node').getChildByName('num_tx')
  118. let scopeTx = attrNode.getChildByName('attr_bg').getChildByName('scope_node').getChildByName('num_tx')
  119. let skillNode = this.attrNode.getChildByName('msg_bg').getChildByName('skill_node');
  120. let updateNode = this.attrNode.getChildByName('msg_bg').getChildByName('update_node');
  121. let updateBg = updateNode.getChildByName('update_bg');
  122. let beforeStarNode = updateBg.getChildByName('star_bg').getChildByName('before_star');
  123. let starUpdatrArrow = updateBg.getChildByName('star_bg').getChildByName('arrow_ico');
  124. let afterStarNode = updateBg.getChildByName('star_bg').getChildByName('after_star');
  125. let addAttrName = updateBg.getChildByName('attack_node').getChildByName('name_tx');
  126. addAttrName.getComponent(Label).string = StringUtil.getLanguageData('攻击');
  127. let beforeAddAttr = updateBg.getChildByName('attack_node').getChildByName('before_num');
  128. let addAttrArrow = updateBg.getChildByName('attack_node').getChildByName('arrow_ico');
  129. let afterAddAttr = updateBg.getChildByName('attack_node').getChildByName('after_num');
  130. let costBg = updateNode.getChildByName('cost');
  131. let costIco = costBg.getChildByName('ico').getComponent(Sprite);
  132. let costNumTx = costBg.getChildByName('num_tx').getComponent(Label);
  133. let gradeConf = RolegradeConf.data;
  134. let beforeGConf = gradeConf[String(this.data['grade'])];
  135. let afterGConf = gradeConf[String(this.data['grade'] + 1)];
  136. for (let index = 1; index <= 5; index++) {
  137. const star = beforeStarNode.getChildByName('star_' + index);
  138. if (beforeGConf.StarUrl) {
  139. this.load('common', `texture/image/${beforeGConf.StarUrl}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  140. star.getComponent(Sprite).spriteFrame = res;
  141. })
  142. star.active = index <= beforeGConf.StarNum;
  143. } else {
  144. star.active = false;
  145. }
  146. }
  147. let atkNum = this.data['conf']['Damage'];
  148. atkNum = atkNum * beforeGConf[`LvAttrMod${this.data['conf']['Quantity']}`]
  149. attackNumTx.getComponent(Label).string = atkNum;
  150. speedNumTx.getComponent(Label).string = this.data['conf']['Speed'];
  151. scopeTx.getComponent(Label).string = this.data['conf']['Radius'];
  152. beforeAddAttr.getComponent(Label).string = atkNum;
  153. if (!afterGConf) {
  154. beforeStarNode.active = true;
  155. beforeStarNode.position = v3(0, 0);
  156. starUpdatrArrow.active = false;
  157. afterStarNode.active = false;
  158. costBg.active = false;
  159. beforeAddAttr.active = true;
  160. beforeStarNode.position = v3(356, 0);
  161. addAttrArrow.active = false;
  162. afterAddAttr.active = false;
  163. } else {
  164. beforeStarNode.active = true;
  165. beforeStarNode.position = v3(-120, 0);
  166. starUpdatrArrow.active = true;
  167. afterStarNode.active = true;
  168. beforeAddAttr.active = true;
  169. beforeAddAttr.position = v3(205, 0);
  170. addAttrArrow.active = true;
  171. afterAddAttr.active = true;
  172. for (let index = 1; index <= 5; index++) {
  173. const star = afterStarNode.getChildByName('star_' + index);
  174. this.load('common', `texture/image/${afterGConf.StarUrl}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  175. star.getComponent(Sprite).spriteFrame = res;
  176. })
  177. star.active = index <= afterGConf.StarNum;
  178. }
  179. let afterAddAtkNum = this.data['conf']['Damage'];
  180. afterAddAtkNum = afterAddAtkNum * afterGConf[`LvAttrMod${this.data['conf']['Quantity']}`]
  181. afterAddAttr.getComponent(Label).string = afterAddAtkNum;
  182. costBg.active = true;
  183. let costData = GoodsManager.getGoodsLocalInfo(5000 + this.data['id'], afterGConf.SelfNum1);
  184. let ownData = GoodsManager.getGoodsById(5000 + this.data['id']);
  185. this.load('common', `texture/icon/hero/head_${this.data['id']}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  186. costIco.spriteFrame = res;
  187. })
  188. costNumTx.string = ownData.count + '/' + costData.count;
  189. }
  190. }
  191. }