import { _decorator, Component, Node, Sprite, Label, 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 { Utils } from '../core/utils/Utils'; 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('FriendChallengeItem') export class FriendChallengeItem extends Component { @property({ type: Sprite, tooltip: "好友头像" }) headSprite: Sprite; @property({ type: Label, tooltip: "好友名字文本" }) nameLabel: Label; @property({ type: Node, tooltip: "挑战按钮节点" }) challengeButtonNode: Node; @property({ type: Label, tooltip: "胜利文本" }) winLabel: Label; @property({ type: Http, tooltip: "Http服务" }) http: Http; private data: any; start() { } public async setData(data: any, logs: any) { this.data = data; this.nameLabel.string = FsUtils.beautySub(data.nickName, 4); // 找出当前用户ID今天的挑战红包判断是否挑战胜利 this.headSprite.spriteFrame = img; if (ISJSB && data.avator) { let img = await ResourcesUtils.loadRemote(data.avator, { ext: ".png" }, this); const spriteFrame = new SpriteFrame(); const texture = new Texture2D(); texture.image = img; spriteFrame.texture = texture; this.headSprite.spriteFrame = spriteFrame; } for (let i = 0; i < logs.length; i++) { if (logs[i].win && logs[i].beAttackUserID == data.id && logs[i].createTime > FsUtils.getTodayTime()) { //今天已经挑战过胜利了 this.winLabel.node.active = true; this.challengeButtonNode.active = false; return; } } this.winLabel.node.active = false; this.challengeButtonNode.active = true; } /**挑战 */ private async onChallengeButton() { let result = await this.http.send("/api/battle/ReadyBattle", { type: BattleType.ChallengeBattle, enemyID: this.data.id }); if (!result.code) { g.battleData.setData(result.data); WindowManager.open("Prefabs/Battle/BattleWindow", WindowOpenMode.NotCloseAndAdd, { type: BattleType.ChallengeBattle });//打开战斗准备窗口 } } }