| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { _decorator, Component, Sprite, Label, RichText, SpriteFrame, ImageAsset, Texture2D } from 'cc';
- import { Http } from '../core/net/Http';
- 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 { ISJSB } from '../Data/platform';
- import { FsUtils } from '../FsUtils/FsUtils';
- import { BattleType } from '../UI/Battle/BattleUIWindow';
- const { ccclass, property } = _decorator;
- @ccclass('BattleAvengeItem')
- export class BattleAvengeItem extends Component {
- @property({ type: Sprite, tooltip: "玩家头像" })
- headSprite: Sprite;
- @property({ type: Label, tooltip: "战斗时间文本" })
- battleTimeLabel: Label;
- @property({ type: RichText, tooltip: "玩家文本" })
- userNameLabel: RichText;
- @property({ type: Http, tooltip: "消息控制" })
- http: Http;
- private data: any;//attackUserID,attackUserLv,attackUserName,attackUserAvator,createTime
- start() {
- }
- public async setData(data: any) {
- this.data = data;
- if (ISJSB && data.attackUserAvator) {
- let img = await ResourcesUtils.loadRemote<ImageAsset>(data.attackUserAvator, { ext: ".png" }, this);
- const spriteFrame = new SpriteFrame();
- const texture = new Texture2D();
- texture.image = img;
- spriteFrame.texture = texture;
- this.headSprite.spriteFrame = spriteFrame;
- }
- this.battleTimeLabel.string = FsUtils.formatBattleTime(Date.now() / 1000 - data.createTime) + '前';
- this.userNameLabel.string = `<color=#ff0000>${FsUtils.beautySub(data.attackUserName, 4)}</color><color=#b7331f>攻击了你的[队伍]</color>`;
- }
- /**复仇*/
- public async onRevengeTouch() {
- let result = await this.http.send("/api/battle/ReadyBattle", { type: BattleType.avengeBattle, enemyID: this.data.attackUserID });
- if (!result.code) {
- g.battleData.setData(result.data);
- WindowManager.open("Prefabs/Battle/BattleWindow", WindowOpenMode.NotCloseAndAdd, { type: BattleType.avengeBattle });//打开战斗准备窗口
- } else {
- WindowManager.showTips(g.CodeMsg[result.code]);
- }
- }
- }
|