import { _decorator, Node, Label, RichText, ProgressBar, Sprite, SpriteFrame, Vec3, find, v3 } from 'cc'; import InfiniteCell from '../../core/InfiniteList/InfiniteCell'; 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 { platform } from '../../Data/platform'; import { FarmManager } from '../../Main/FarmManager'; import { MoveToCenter } from '../../Map/MoveToCenter'; import { GetType } from '../GetWindow/GetType'; import { UIEffect } from '../UIEffect'; import { TaskWindow } from './TaskWindow'; const { ccclass, property } = _decorator; @ccclass('TaskWindowItem') export class TaskWindowItem extends InfiniteCell { @property({ type: RichText, tooltip: "任务描述" }) taskLabel: RichText; @property({ type: ProgressBar, tooltip: "任务进度条" }) taskProgress: ProgressBar; @property({ type: Label, tooltip: "进度文本" }) taskProgressLabel: Label; @property({ type: Label, tooltip: "奖励数量" }) taskRewardLabel: Label; @property({ type: Sprite, tooltip: "奖励图标" }) taskRewardSprite: Sprite; @property({ type: Node, tooltip: "领取按钮" }) getButton: Node; @property({ type: Node, tooltip: "前往按钮" }) gotoButton: Node; @property({ type: Node, tooltip: "任务完成图标" }) completeNode: Node; @property({ tooltip: "网络请求对象", type: Http }) http: Http; private window: TaskWindow = null; private iconPath = ""; private data: any; async UpdateContent(itemData: any) { this.window = itemData.window; this.data = itemData.data; let strs = this.data.name.split('/'); let str = ""; for (let i = 0; i < strs.length; i++) { if (i % 2 == 0) { str += `${strs[i]}`; } else { str += `${strs[i]}`; } } this.taskLabel.string = str; this.taskProgress.progress = this.data.progress / this.data.num; this.taskProgressLabel.string = `${this.data.progress} / ${this.data.num}`; this.taskRewardLabel.string = this.data.value + ""; switch (this.data.reward_type) { case "exp": this.iconPath = "Images/Turntable/star_small/spriteFrame"; this.taskRewardSprite.spriteFrame = await ResourcesUtils.load(this.iconPath, SpriteFrame, this.node); break; case "diamond": this.iconPath = "Images/Turntable/diamond_small/spriteFrame"; this.taskRewardSprite.spriteFrame = await ResourcesUtils.load(this.iconPath, SpriteFrame, this.node); break; } this.gotoButton.active = !(this.getButton.active = this.data.progress == this.data.num); if (this.data.progress > this.data.num) { this.getButton.active = this.gotoButton.active = false; this.completeNode.active = true; this.taskProgressLabel.string = `${this.data.num} / ${this.data.num}`; } else { this.completeNode.active = false; } } public async onGetReward() { let result = await this.http.send("/api/task/taskReceive", { taskID: this.data.id }); if (result.code == 0) { platform.reportThinking("quest", JSON.stringify({ quest_id: this.data.id, quest_name: this.data.name, award_id: this.data.reward_type, award_no: this.data.value })); let ui = find("Canvas/UI"); switch (this.data.reward_type) { case "exp": WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: this.data.value, type: GetType.exp, needBezierEffect: true }], this.window.node); break; case "diamond": platform.reportThinking("diamond_increase", JSON.stringify({ previous_number: g.userData.diamond, increase_number: this.data.value, current_number: g.userData.diamond + this.data.value, reasons: "taskReceive" })); WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: this.data.value, type: GetType.Diamond, needBezierEffect: true }], this.window.node); break; } this.window.reloadList(); } } public onGoto(): void { WindowManager.close(); switch (this.data.type) { case 3: FarmManager.selectFristFarm(); break; case 7: WindowManager.open("Prefabs/Turntable/Turntable", WindowOpenMode.CloseAndCover); break; case 13: WindowManager.open("Prefabs/AddDiamond", WindowOpenMode.CloseAndCover); break; } } }