HeroFateItem.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { _decorator, Color, instantiate, Label, Layout, Node, Prefab, ScrollView, Sprite } from 'cc';
  2. import { ResKeeper } from '../../../framework/res/ResKeeper';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import List from '../../../framework/list/List';
  5. import { FateattridConf } from '../../config/FateattridConf';
  6. import { AttrAddTypeEnum, AttrConf, ItemEnum } from '../../common/InterfaceAddEnum';
  7. import { RoleManager } from '../../manager/RoleManager';
  8. import { CommonItem } from '../common/CommonItem';
  9. import { Framework } from '../../../framework/Framework';
  10. import { GameEvent } from '../../data/GameEvent';
  11. import { GoodsData } from '../../data/GoodsData';
  12. import { GoodsManager } from '../../manager/GoodsManager';
  13. import { GlobalConf } from '../../config/GlobalConf';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('HeroFateItem')
  16. export class HeroFateItem extends ResKeeper {
  17. @property({ type: Sprite, tooltip: "名称背景" })
  18. titleBg: Sprite = null;
  19. @property({ type: Label, tooltip: "名称文字" })
  20. titleTx: Label = null;
  21. @property({ type: Node, tooltip: "英雄节点" })
  22. itemNode: Node = null;
  23. @property({ type: Node, tooltip: "升级按钮" })
  24. updateBtn: Node = null;
  25. @property({ type: Label, tooltip: "升级按钮文字" })
  26. updateBtnTx: Label = null;
  27. @property({ type: Node, tooltip: "激活按钮" })
  28. activeBtn: Node = null;
  29. @property({ type: Label, tooltip: "激活按钮文字" })
  30. activeBtnTx: Label = null;
  31. @property({ type: List, tooltip: "描述列表" })
  32. svDesc: List = null;
  33. private _data = {};
  34. private canActive = false;
  35. private _descData = [];
  36. private _costNum = 0;
  37. protected onLoad() {
  38. this.updateBtnTx.string = StringUtil.getLanguageData('升级');
  39. this.activeBtnTx.string = StringUtil.getLanguageData('激活');
  40. }
  41. protected onDestroy() {
  42. //如果该组件有事件自行取消注释
  43. //Framework.event.removeEvent(this);
  44. super.onDestroy();
  45. }
  46. //如果使用了池中的节点,在该函数内归还,该函数会在onDestroy前调用
  47. onClose() {
  48. }
  49. //UI事件处理
  50. private onTouchButton(event: Event) {
  51. //Framework.audio.playEffect(AudioID.Click);
  52. let target: any = event.target;
  53. if (target.name == 'update_btn') {
  54. let cost = GoodsManager.getGoodsById(String(GlobalConf.data.FateMatId.Value));
  55. if (cost.count < this._costNum) {
  56. Framework.tips.setTips(StringUtil.getLanguageData('升级所需材料不足'));
  57. return;
  58. }
  59. let args = {
  60. id: this._data['conf']['Id']
  61. }
  62. RoleManager.sendFateLevelUp(args, () => {
  63. Framework.event.fireEvent(GameEvent.FateChange);
  64. })
  65. } else if (target.name == 'active_btn') {
  66. let cost = GoodsManager.getGoodsById(String(GlobalConf.data.FateMatId.Value));
  67. if (cost.count < this._costNum) {
  68. Framework.tips.setTips(StringUtil.getLanguageData('激活所需材料不足'));
  69. return;
  70. }
  71. if (!this.canActive) {
  72. Framework.tips.setTips(StringUtil.getLanguageData('至少需要获得两个英雄!'));
  73. return;
  74. }
  75. let args = {
  76. id: this._data['conf']['Id']
  77. }
  78. RoleManager.sendFateLevelUp(args, () => {
  79. Framework.event.fireEvent(GameEvent.FateChange);
  80. })
  81. }
  82. }
  83. refreshItem(data) {
  84. this._data = data;
  85. let color = '#ffffff'
  86. if (data.conf.Grade == 1) {
  87. color = '#7CE680'
  88. } else if (data.conf.Grade == 2) {
  89. color = '#306AFF'
  90. } else if (data.conf.Grade == 3) {
  91. color = '#A46DEB'
  92. } else if (data.conf.Grade == 4) {
  93. color = '#EB9A6D'
  94. } else if (data.conf.Grade == 5) {
  95. color = '#EB6D6D'
  96. }
  97. this.titleBg.color = new Color(color);
  98. this.canActive = false;
  99. let activeRole = 0
  100. for (const element of data.conf.FateRidArray) {
  101. let role = RoleManager.getRoleById(element);
  102. if (role) {
  103. if (role['id']) {
  104. activeRole = activeRole + 1
  105. }
  106. this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => {
  107. let item = instantiate(pre);
  108. this.itemNode.addChild(item);
  109. item.getComponent(CommonItem).setClickEnable(false);
  110. item.getComponent(CommonItem).setNumShow(false);
  111. item.getComponent(CommonItem).setGray(role['id'] ? false : true);
  112. item.getComponent(CommonItem).refreshItem(role);
  113. })
  114. }
  115. }
  116. this.canActive = (activeRole >= 2);
  117. this._descData = [];
  118. this.itemNode.removeAllChildren();
  119. let atteConf = FateattridConf.data;
  120. for (let lv = 1; lv <= 4; lv++) {
  121. let arr = ['', '', ''];
  122. for (let index = 0; index < data.conf.AttrIdArray.length; index++) {
  123. const element = atteConf[data.conf.AttrIdArray[index]];
  124. let attr = element['AttrLevel' + lv].split(':');
  125. let attrConf = AttrConf[attr[0]]
  126. let value = attrConf.type == AttrAddTypeEnum.reality ? attr[1] + '' :
  127. parseFloat((100 * Number(attr[1])).toFixed(2)) + '%'
  128. arr[1] = StringUtil.getLanguageData(attrConf.name);
  129. if (arr[0] == '') {
  130. arr[0] = arr[0] + element.Num
  131. } else {
  132. arr[0] = arr[0] + '/' + element.Num
  133. }
  134. if (arr[2] == '') {
  135. arr[2] = arr[2] + value
  136. } else {
  137. arr[2] = arr[2] + '/' + value
  138. }
  139. }
  140. if (this._costNum <= 0) {
  141. if (lv > data.level) {
  142. this._costNum = data.conf['LevelCost' + lv]
  143. }
  144. }
  145. let t = {
  146. str: 'Lv.' + lv + ' ' + StringUtil.getLanguageData(`{0}人同时上阵,羁绊中英雄{1}提升{2}`, arr),
  147. state: lv <= data.level
  148. }
  149. this._descData.push(t);
  150. }
  151. this.svDesc.numItems = this._descData.length;
  152. let name = StringUtil.getLanguageData(data.conf.Name);
  153. if (data.level > 0) {
  154. this.titleTx.string = name + ' Lv.' + data.level;
  155. this.updateBtn.active = true;
  156. this.activeBtn.active = false;
  157. } else {
  158. this.titleTx.string = name + ` (${StringUtil.getLanguageData('未激活')})`;
  159. this.updateBtn.active = false;
  160. this.activeBtn.active = true;
  161. }
  162. }
  163. onEventList(item, idx) {
  164. item.getComponent(Label).string = this._descData[idx].str;
  165. if (this._descData[idx].state) {
  166. item.getComponent(Label).color = new Color('#8A6230');
  167. } else {
  168. item.getComponent(Label).color = new Color('#C5B29A');
  169. }
  170. if (idx == this._descData.length - 1) {
  171. this.scheduleOnce(() => {
  172. this.svDesc.getComponent(ScrollView).content.getComponent(Layout).updateLayout(true);
  173. }, 0.1);
  174. }
  175. }
  176. }