import { _decorator, instantiate, Label, Node, Prefab, ProgressBar, tween, UIOpacity } from 'cc'; import { BaseView } from '../../../framework/layer/BaseView'; import { StringUtil } from '../../../framework/util/StringUtil'; import { CommonItem } from '../common/CommonItem'; import List from '../../../framework/list/List'; import { Equip } from '../../data/EquipData'; import { EquipManager } from '../../manager/EquipManager'; import { AttrAddTypeEnum, AttrEnum } from '../../common/InterfaceAddEnum'; import { Framework } from '../../../framework/Framework'; const { ccclass, property } = _decorator; @ccclass('EquipUpdate') export class EquipUpdate extends BaseView { @property({ type: Label, tooltip: "关闭提示" }) closeTips: Label = null; @property({ type: Label, tooltip: "标题" }) titieTx: Label = null; @property({ type: Label, tooltip: "装备名" }) equipNameTx: Label = null; @property({ type: Node, tooltip: "装备节点" }) equipNode: Node = null; @property({ type: Label, tooltip: "当前等级" }) equipNowLevel: Label = null; @property({ type: Label, tooltip: "目标等级" }) equipNextLevel: Label = null; @property({ type: Label, tooltip: "当前属性" }) equipNowAttr: Label = null; @property({ type: Label, tooltip: "目标属性" }) equipNextAttr: Label = null; @property({ type: Label, tooltip: "目标属性加成" }) equipNextAttrAdd: Label = null; @property({ type: Node, tooltip: "等级箭头" }) levelArrow: Label = null; @property({ type: Node, tooltip: "属性箭头" }) attrArrow: Node = null; @property({ type: Label, tooltip: "经验值标题" }) expTitle: Label = null; @property({ type: ProgressBar, tooltip: "经验值进度" }) expBar: ProgressBar = null; @property({ type: Label, tooltip: "经验值文字" }) expBarTx: Label = null; @property({ type: List, tooltip: "材料列表" }) itemSv: List = null; @property({ type: Label, tooltip: "升级按钮文字" }) updateBtnTx: Label = null; @property({ type: Label, tooltip: "一键按钮文字" }) autoBtnTx: Label = null; private _curRace: number = 0; private _curSlot: number = 0; private _curEquip: Equip = null; private _curExp: number = 0; private _otherExp: number = 0; private _equipsData = []; protected onLoad() { super.onLoad(); this.closeTips.string = StringUtil.getLanguageData('点击空白关闭'); this.titieTx.string = StringUtil.getLanguageData('装备升级'); this.closeTips.node.getComponent(UIOpacity).opacity = 0; } protected onDestroy() { } //UI开打时会调用,如果有初始化代码应该放到此函数 onOpen(data) { tween(this.closeTips.node.getComponent(UIOpacity)) .to(1, { opacity: 255 }) .to(1.2, { opacity: 10 }) .union() .repeatForever() .start() this._curRace = data.race; this._curSlot = data.slot; this._curEquip = data.equip; this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => { let item = instantiate(pre); this.equipNode.addChild(item); item.getComponent(CommonItem).refreshItem(this._curEquip); }) this.equipNameTx.string = StringUtil.getLanguageData(this._curEquip.conf['Name']); this._curExp = this._curEquip.exp; this._equipsData = EquipManager.getEquipRaceSlotAllGroup(data.race); this.itemSv.numItems = this._equipsData.length; this.initUI(); // this.updateByExp(); } //UI关闭时会调用,该函数在onDestroy前调用 onClose() { } //框架管理UI层级时会调用,可根据UI情况修改 onShow() { super.onShow(); } //框架管理UI层级时会调用,可根据UI情况修改 onHide() { super.onHide(); } //UI事件处理 private onTouchButton(event: Event) { //Framework.audio.playEffect(AudioID.Click); let target: any = event.target; if (target.name == 'mask') { Framework.layer.close(this); } } onEventList(item, idx) { item.getComponent(CommonItem).refreshItem(); } initUI() { let curLvConf = EquipManager.getEquipLevelByExp(this._curExp); this.equipNowLevel.string = 'Lv.' + curLvConf.Id; let attr = this._curEquip.conf['Stat1'].split(':'); let attrConf = AttrEnum[attr[0]] let attrStr = StringUtil.getLanguageData(attrConf.name); let nowAdd = null; let value = null; if (attrConf.type == AttrAddTypeEnum.reality) { nowAdd = attr[1] * (1 + curLvConf.AttackMod); value = " +" + attr[1] * (1 + curLvConf.AttackMod); } else { nowAdd = 100 * Number(attr[1]) * (1 + curLvConf.AttackMod); value = " +" + (100 * Number(attr[1]) * (1 + curLvConf.AttackMod)) + "%"; } attrStr = attrStr + value; this.equipNowAttr.string = attrStr; let nextLvConf = EquipManager.getEquipNextLevel(this._curExp); this.equipNextLevel.string = 'Lv.' + nextLvConf.Id; let attrNextConf = AttrEnum[attr[0]] let attrNextStr = StringUtil.getLanguageData(attrNextConf.name); let nextAdd = null; let valueNext = null; if (attrConf.type == AttrAddTypeEnum.reality) { nextAdd = attr[1] * (1 + nextLvConf.AttackMod); valueNext = " +" + attr[1] * (1 + nextLvConf.AttackMod); } else { nextAdd = 100 * Number(attr[1]) * (1 + nextLvConf.AttackMod); valueNext = " +" + (100 * Number(attr[1]) * (1 + nextLvConf.AttackMod)) + "%"; } attrNextStr = attrNextStr + valueNext; this.equipNextAttr.string = attrNextStr; this.equipNextAttrAdd.string = attrConf.type == AttrAddTypeEnum.reality ? (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + ")") : (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + "%)"); this.expBar.progress = this._curExp / curLvConf.NeedExp; this.expBarTx.string = this._curExp + '/' + curLvConf.NeedExp; } }