import { _decorator, Component, Node, RichText, SpriteFrame, Label, Sprite } from 'cc';
import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
import { WindowManager } from '../../core/ui/window/WindowManager';
import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
import { g } from '../../Data/g';
import { FsUtils } from '../../FsUtils/FsUtils';
const { ccclass, property } = _decorator;
@ccclass('BattleInfoWindow')
export class BattleInfoWindow extends Component {
@property({ type: Node, tooltip: "复仇按钮" })
avengeButton: Node;
@property({ type: RichText, tooltip: "玩家文本" })
userNameLabel: RichText;
@property({ type: Sprite, tooltip: "金币图标" })
iconSprite: Sprite;
@property({ type: Label, tooltip: "数量文本" })
numLabel: Label;
@property({ type: Label, tooltip: "损失信息文本" })
infoLabel: Label;
start() {
this.openHandler();
}
public async openHandler() {
let data = g.gameData.beAttackDatas[0];
if (data) {
this.userNameLabel.string = `${FsUtils.beautySub(data.attackUserName, 4)}攻击了你的队伍`;
if (data.beAttackLossType == 3) {//损失物品类型(1money,2diamond,3general)
this.numLabel.string = '';
this.iconSprite.node.active = false;
this.infoLabel.string = `你损失了1个${data.beAttackLossNum}级神将`;
} else {
this.iconSprite.node.active = true;
this.numLabel.string = FsUtils.moneyFormat(Number(data.beAttackLossNum));
let img: SpriteFrame;
if (data.beAttackLossType == 1) {
img = await ResourcesUtils.load("Images/Money/moneyIcon/spriteFrame", SpriteFrame, this.node);
} else if (data.beAttackLossType == 2) {
img = await ResourcesUtils.load("Images/Money/goldIcon/spriteFrame", SpriteFrame, this.node);
}
this.iconSprite.spriteFrame = img;
}
}
}
public onCloseButton() {
g.gameData.beAttackDatas.splice(0, 1);
WindowManager.close();
}
public onAvengeButton() {
g.gameData.beAttackDatas = [];
WindowManager.open("Prefabs/Battle/BattleUIWindow", WindowOpenMode.CloseAndCover, { tabIndex: 1 });//打开复仇面板
WindowManager.close();
}
}