import { _decorator, Component, Node, Label, SystemEvent, Sprite, SpriteFrame } from 'cc'; import { DataSystem } from '../core/data/DataSystem'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { Sound } from '../core/sound/Sound'; import { UserData } from '../data/UserData'; import { FightData } from '../fight/FightData'; const { ccclass, property } = _decorator; @ccclass('PVPResult') export class PVPResult extends Component { @property({ type: Node, tooltip: "关闭节点" }) mask: Node; @property({ type: [Node], tooltip: "结算显示节点集合" }) nodesList: Array = []; @property({ type: Label, tooltip: "失败昵称" }) failName: Label; @property({ type: Node, tooltip: "胜利奖励显示" }) winShowNode: Node; @property({ type: Label, tooltip: "失败数量" }) failCount: Label; @property({ type: Label, tooltip: "胜利昵称" }) winName: Label; @property({ type: Label, tooltip: "胜利数量" }) winCount: Label; @property({ type: Sprite, tooltip: "奖励道具图标" }) winIconSprite: Sprite; @property({ type: Sprite, tooltip: "奖励道具图标" }) lossIconSprite: Sprite; public closehandler: Function; private sound: Sound; start() { this.mask.on(SystemEvent.EventType.TOUCH_END, () => { this.node.destroy(); }, this); } onDestroy() { this.winShowNode.active = true; this.closehandler && this.closehandler(); } public async setData(data: any) { let icon = 5; if (data.rewardType == 'money') { icon = 5; } else if (data.rewardType == 'diamond') { icon = 7; } else if (data.rewardType == 'bonus') { icon = 2; } else { icon = 8; } let img = await this.getComponent(ResourceLoader).load("image/icons/icon" + icon + "/spriteFrame", SpriteFrame); this.nodesList[0].active = this.nodesList[1].active = this.nodesList[2].active = false; this.sound = this.getComponent(Sound); if (data.isWin) { data.type == 3 && (this.winShowNode.active = false); this.nodesList[2].active = true; this.winName.string = data.bonus.nickName; this.winIconSprite.spriteFrame = img; this.winCount.string = "x" + (!data.rewardNum ? "0" : data.rewardNum + ""); if (this.sound) { this.sound.play(0); } if (data.type == 2) { DataSystem.getData(FightData).revengeSuccessEnemyId = data.bonus.enemyID; } else if (data.type == 3) { DataSystem.getData(FightData).challengeSuccessFriendId = data.bonus.enemyID; } } else { if (data.type == 2) { this.nodesList[0].active = true; } else { this.nodesList[1].active = true; this.failName.string = data.bonus.nickName; this.lossIconSprite.spriteFrame = img; this.failCount.string = "x" + (!data.rewardNum ? "0" : data.rewardNum + ""); } if (this.sound) { this.sound.play(1); } } DataSystem.getData(UserData)[data.rewardType] += data.rewardNum; data.bonus.key != "0" && DataSystem.getData(FightData).attackBonusList.push(data.bonus); } }