| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import { _decorator, Component, Prefab, UITransform, instantiate } from 'cc';
- import { IFDataSource, InfiniteList } from '../../core/InfiniteList/InfiniteList';
- import { Http } from '../../core/net/Http';
- import { BitmapFont } from '../../core/ui/BitmapFont';
- import { Utils } from '../../core/utils/Utils';
- import { TaskActive } from './TaskActive';
- import { TaskWindowItem } from './TaskWindowItem';
- const { ccclass, property } = _decorator;
- @ccclass('TaskWindow')
- export class TaskWindow extends Component implements IFDataSource {
- @property({ type: BitmapFont, tooltip: "倒计时文本" }) countDownLabel: BitmapFont;
- @property({ type: InfiniteList, tooltip: "任务列表" }) list: InfiniteList;
- @property({ type: Prefab, tooltip: "Item预制体" }) item: Prefab;
- @property({ tooltip: "网络请求对象", type: Http }) http: Http;
- @property({ type: TaskActive, tooltip: "活跃度脚本" }) taskActive: TaskActive;
- private endTime = 0;
- private prefabHeight: number = 0;
- private taskData = [];
- async start() {
- this.endTime = new Date().setHours(24, 0, 0, 0);
- let prefab = instantiate(this.item);
- this.prefabHeight = prefab.getComponent(UITransform).height;
- prefab.destroy();
- this.list.Init(this);
- await this.reloadList();
- }
- public async reloadList() {
- this.taskData = [];
- let result = await this.http.send("/api/task/taskList");
- if (result.code == 0) {
- this.taskActive.setData(result.data.active);
- for (let i = result.data.taskList.length - 1; i >= 0; i--) {
- let obj = { data: result.data.taskList[i], window: this }
- if (result.data.taskList[i].progress > result.data.taskList[i].num) {
- this.taskData.push(obj);
- } else {
- this.taskData.unshift(obj);
- }
- }
- this.list.Reload(true);
- }
- }
- update() {
- if (this.countDownLabel.string != Utils.formatCountDown(this.endTime - Date.now())) {
- this.countDownLabel.string = Utils.formatCountDown(this.endTime - Date.now());
- }
- }
- //#region IFDataSource
- public GetCellData(dataIndex: number): any {
- return this.taskData[dataIndex];
- }
- public GetCellNumber(): number {
- return this.taskData.length;
- }
- public GetCellSize(index: number): number {
- return this.prefabHeight;
- }
- public GetCellView(index: number): TaskWindowItem {
- let node = instantiate(this.item);
- return node.getComponent(TaskWindowItem);
- }
- public GetCellIdentifer(index: number): string {
- return "taskWindowItem";
- }
- //#endregion
- }
|