HeroAttr.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. this.data = data.heroDate;
  58. if (data.tag) {
  59. this.selectTag = data.tag;
  60. }
  61. this[`${this.selectTag}Toggle`].isChecked = false;
  62. this[`${this.selectTag}Toggle`].isChecked = true;
  63. this.updateAttr();
  64. }
  65. //UI关闭时会调用,该函数在onDestroy前调用
  66. onClose() {
  67. }
  68. //框架管理UI层级时会调用,可根据UI情况修改
  69. onShow() {
  70. super.onShow();
  71. }
  72. //框架管理UI层级时会调用,可根据UI情况修改
  73. onHide() {
  74. super.onHide();
  75. }
  76. //UI事件处理
  77. private onTouchButton(event: Event) {
  78. //Framework.audio.playEffect(AudioID.Click);
  79. let target: any = event.target;
  80. if (target.name == 'close_btn') {
  81. Framework.layer.close(this)
  82. } else if (target.name == 'update_btn') {
  83. let gConf = RolegradeConf.data[String(this.data['grade'] + 1)];
  84. let costData = GoodsManager.getGoodsLocalInfo(5000 + this.data['id'], gConf.SelfNum1);
  85. let ownData = GoodsManager.getGoodsById(5000 + this.data['id']);
  86. if (ownData.count < costData.count) {
  87. Framework.tips.setTips(StringUtil.getLanguageData('升级所需材料不足!'));
  88. return;
  89. }
  90. RoleManager.sendRoleAdvance({ hid: this.data['id'] }, () => {
  91. Framework.tips.setTips(StringUtil.getLanguageData('升级成功!'));
  92. let rData = RoleData.getRoleDataByID(this.data['id']);
  93. this.data = {}
  94. this.data = rData;
  95. this.updateAttr();
  96. });
  97. }
  98. }
  99. onEventSelectTag(target: Toggle, customEventData: string) {
  100. if (target.isChecked) {
  101. let nodes = ['attr', 'dna', 'exclusive', 'skin']
  102. for (const element of nodes) {
  103. if (element == customEventData) {
  104. this[`${element}Node`].active = true;
  105. } else {
  106. this[`${element}Node`].active = false;
  107. }
  108. }
  109. }
  110. }
  111. updateAttr() {
  112. let attrNode = this.attrNode.getChildByName('msg_bg').getChildByName('attr_node');
  113. let attackNumTx = attrNode.getChildByName('attr_bg').getChildByName('attack_node').getChildByName('num_tx');
  114. let speedNumTx = attrNode.getChildByName('attr_bg').getChildByName('speed_node').getChildByName('num_tx')
  115. let scopeTx = attrNode.getChildByName('attr_bg').getChildByName('scope_node').getChildByName('num_tx')
  116. let skillNode = this.attrNode.getChildByName('msg_bg').getChildByName('skill_node');
  117. let updateNode = this.attrNode.getChildByName('msg_bg').getChildByName('update_node');
  118. let updateBg = updateNode.getChildByName('update_bg');
  119. let beforeStarNode = updateBg.getChildByName('star_bg').getChildByName('before_star');
  120. let starUpdatrArrow = updateBg.getChildByName('star_bg').getChildByName('arrow_ico');
  121. let afterStarNode = updateBg.getChildByName('star_bg').getChildByName('after_star');
  122. let addAttrName = updateBg.getChildByName('attack_node').getChildByName('name_tx');
  123. addAttrName.getComponent(Label).string = StringUtil.getLanguageData('攻击');
  124. let beforeAddAttr = updateBg.getChildByName('attack_node').getChildByName('before_num');
  125. let addAttrArrow = updateBg.getChildByName('attack_node').getChildByName('arrow_ico');
  126. let afterAddAttr = updateBg.getChildByName('attack_node').getChildByName('after_num');
  127. let costBg = updateNode.getChildByName('cost');
  128. let costIco = costBg.getChildByName('ico').getComponent(Sprite);
  129. let costNumTx = costBg.getChildByName('num_tx').getComponent(Label);
  130. let gradeConf = RolegradeConf.data;
  131. let beforeGConf = gradeConf[String(this.data['grade'])];
  132. let afterGConf = gradeConf[String(this.data['grade'] + 1)];
  133. for (let index = 1; index <= 5; index++) {
  134. const star = beforeStarNode.getChildByName('star_' + index);
  135. if (beforeGConf.StarUrl) {
  136. this.load('common', `texture/image/${beforeGConf.StarUrl}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  137. star.getComponent(Sprite).spriteFrame = res;
  138. })
  139. star.active = index <= beforeGConf.StarNum;
  140. } else {
  141. star.active = false;
  142. }
  143. }
  144. let atkNum = this.data['conf']['Damage'];
  145. atkNum = atkNum * beforeGConf[`LvAttrMod${this.data['conf']['Quantity']}`]
  146. attackNumTx.getComponent(Label).string = atkNum;
  147. speedNumTx.getComponent(Label).string = this.data['conf']['Speed'];
  148. scopeTx.getComponent(Label).string = this.data['conf']['Radius'];
  149. beforeAddAttr.getComponent(Label).string = atkNum;
  150. if (!afterGConf) {
  151. beforeStarNode.active = true;
  152. beforeStarNode.position = v3(0, 0);
  153. starUpdatrArrow.active = false;
  154. afterStarNode.active = false;
  155. costBg.active = false;
  156. beforeAddAttr.active = true;
  157. beforeStarNode.position = v3(356, 0);
  158. addAttrArrow.active = false;
  159. afterAddAttr.active = false;
  160. } else {
  161. beforeStarNode.active = true;
  162. beforeStarNode.position = v3(-120, 0);
  163. starUpdatrArrow.active = true;
  164. afterStarNode.active = true;
  165. beforeAddAttr.active = true;
  166. beforeAddAttr.position = v3(205, 0);
  167. addAttrArrow.active = true;
  168. afterAddAttr.active = true;
  169. for (let index = 1; index <= 5; index++) {
  170. const star = afterStarNode.getChildByName('star_' + index);
  171. this.load('common', `texture/image/${afterGConf.StarUrl}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  172. star.getComponent(Sprite).spriteFrame = res;
  173. })
  174. star.active = index <= afterGConf.StarNum;
  175. }
  176. let afterAddAtkNum = this.data['conf']['Damage'];
  177. afterAddAtkNum = afterAddAtkNum * afterGConf[`LvAttrMod${this.data['conf']['Quantity']}`]
  178. afterAddAttr.getComponent(Label).string = afterAddAtkNum;
  179. costBg.active = true;
  180. let costData = GoodsManager.getGoodsLocalInfo(5000 + this.data['id'], afterGConf.SelfNum1);
  181. let ownData = GoodsManager.getGoodsById(5000 + this.data['id']);
  182. this.load('common', `texture/icon/hero/head_${this.data['id']}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  183. costIco.spriteFrame = res;
  184. })
  185. costNumTx.string = ownData.count + '/' + costData.count;
  186. }
  187. }
  188. }