EquipUpdate.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { _decorator, instantiate, Label, Node, Prefab, ProgressBar, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { CommonItem } from '../common/CommonItem';
  5. import List from '../../../framework/list/List';
  6. import { Equip } from '../../data/EquipData';
  7. import { EquipManager } from '../../manager/EquipManager';
  8. import { AttrAddTypeEnum, AttrEnum } from '../../common/InterfaceAddEnum';
  9. import { Framework } from '../../../framework/Framework';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('EquipUpdate')
  12. export class EquipUpdate extends BaseView {
  13. @property({ type: Label, tooltip: "关闭提示" })
  14. closeTips: Label = null;
  15. @property({ type: Label, tooltip: "标题" })
  16. titieTx: Label = null;
  17. @property({ type: Label, tooltip: "装备名" })
  18. equipNameTx: Label = null;
  19. @property({ type: Node, tooltip: "装备节点" })
  20. equipNode: Node = null;
  21. @property({ type: Label, tooltip: "当前等级" })
  22. equipNowLevel: Label = null;
  23. @property({ type: Label, tooltip: "目标等级" })
  24. equipNextLevel: Label = null;
  25. @property({ type: Label, tooltip: "当前属性" })
  26. equipNowAttr: Label = null;
  27. @property({ type: Label, tooltip: "目标属性" })
  28. equipNextAttr: Label = null;
  29. @property({ type: Label, tooltip: "目标属性加成" })
  30. equipNextAttrAdd: Label = null;
  31. @property({ type: Node, tooltip: "等级箭头" })
  32. levelArrow: Label = null;
  33. @property({ type: Node, tooltip: "属性箭头" })
  34. attrArrow: Node = null;
  35. @property({ type: Label, tooltip: "经验值标题" })
  36. expTitle: Label = null;
  37. @property({ type: ProgressBar, tooltip: "经验值进度" })
  38. expBar: ProgressBar = null;
  39. @property({ type: Label, tooltip: "经验值文字" })
  40. expBarTx: Label = null;
  41. @property({ type: List, tooltip: "材料列表" })
  42. itemSv: List = null;
  43. @property({ type: Label, tooltip: "升级按钮文字" })
  44. updateBtnTx: Label = null;
  45. @property({ type: Label, tooltip: "一键按钮文字" })
  46. autoBtnTx: Label = null;
  47. private _curRace: number = 0;
  48. private _curSlot: number = 0;
  49. private _curEquip: Equip = null;
  50. private _curExp: number = 0;
  51. private _otherExp: number = 0;
  52. private _equipsData = [];
  53. protected onLoad() {
  54. super.onLoad();
  55. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  56. this.titieTx.string = StringUtil.getLanguageData('装备升级');
  57. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  58. }
  59. protected onDestroy() {
  60. }
  61. //UI开打时会调用,如果有初始化代码应该放到此函数
  62. onOpen(data) {
  63. tween(this.closeTips.node.getComponent(UIOpacity))
  64. .to(1, { opacity: 255 })
  65. .to(1.2, { opacity: 10 })
  66. .union()
  67. .repeatForever()
  68. .start()
  69. this._curRace = data.race;
  70. this._curSlot = data.slot;
  71. this._curEquip = data.equip;
  72. this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => {
  73. let item = instantiate(pre);
  74. this.equipNode.addChild(item);
  75. item.getComponent(CommonItem).refreshItem(this._curEquip);
  76. })
  77. this.equipNameTx.string = StringUtil.getLanguageData(this._curEquip.conf['Name']);
  78. this._curExp = this._curEquip.exp;
  79. this._equipsData = EquipManager.getEquipRaceSlotAllGroup(data.race);
  80. this.itemSv.numItems = this._equipsData.length;
  81. this.initUI();
  82. // this.updateByExp();
  83. }
  84. //UI关闭时会调用,该函数在onDestroy前调用
  85. onClose() {
  86. }
  87. //框架管理UI层级时会调用,可根据UI情况修改
  88. onShow() {
  89. super.onShow();
  90. }
  91. //框架管理UI层级时会调用,可根据UI情况修改
  92. onHide() {
  93. super.onHide();
  94. }
  95. //UI事件处理
  96. private onTouchButton(event: Event) {
  97. //Framework.audio.playEffect(AudioID.Click);
  98. let target: any = event.target;
  99. if (target.name == 'mask') {
  100. Framework.layer.close(this);
  101. }
  102. }
  103. onEventList(item, idx) {
  104. item.getComponent(CommonItem).refreshItem();
  105. }
  106. initUI() {
  107. let curLvConf = EquipManager.getEquipLevelByExp(this._curExp);
  108. this.equipNowLevel.string = 'Lv.' + curLvConf.Id;
  109. let attr = this._curEquip.conf['Stat1'].split(':');
  110. let attrConf = AttrEnum[attr[0]]
  111. let attrStr = StringUtil.getLanguageData(attrConf.name);
  112. let nowAdd = null;
  113. let value = null;
  114. if (attrConf.type == AttrAddTypeEnum.reality) {
  115. nowAdd = attr[1] * (1 + curLvConf.AttackMod);
  116. value = " +" + attr[1] * (1 + curLvConf.AttackMod);
  117. } else {
  118. nowAdd = 100 * Number(attr[1]) * (1 + curLvConf.AttackMod);
  119. value = " +" + (100 * Number(attr[1]) * (1 + curLvConf.AttackMod)) + "%";
  120. }
  121. attrStr = attrStr + value;
  122. this.equipNowAttr.string = attrStr;
  123. let nextLvConf = EquipManager.getEquipNextLevel(this._curExp);
  124. this.equipNextLevel.string = 'Lv.' + nextLvConf.Id;
  125. let attrNextConf = AttrEnum[attr[0]]
  126. let attrNextStr = StringUtil.getLanguageData(attrNextConf.name);
  127. let nextAdd = null;
  128. let valueNext = null;
  129. if (attrConf.type == AttrAddTypeEnum.reality) {
  130. nextAdd = attr[1] * (1 + nextLvConf.AttackMod);
  131. valueNext = " +" + attr[1] * (1 + nextLvConf.AttackMod);
  132. } else {
  133. nextAdd = 100 * Number(attr[1]) * (1 + nextLvConf.AttackMod);
  134. valueNext = " +" + (100 * Number(attr[1]) * (1 + nextLvConf.AttackMod)) + "%";
  135. }
  136. attrNextStr = attrNextStr + valueNext;
  137. this.equipNextAttr.string = attrNextStr;
  138. this.equipNextAttrAdd.string = attrConf.type == AttrAddTypeEnum.reality ? (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + ")") :
  139. (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + "%)");
  140. this.expBar.progress = this._curExp / curLvConf.NeedExp;
  141. this.expBarTx.string = this._curExp + '/' + curLvConf.NeedExp;
  142. }
  143. }