代码结构整理
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { _decorator, Component, Node, instantiate } from "cc";
|
||||
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
|
||||
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
||||
import { GirlsData } from "db://assets/Scripts/Main/Config/cfg/characters";
|
||||
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
||||
import { GirlListItem } from "./GirlListItem";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GirlListPanel")
|
||||
export class GirlListPanel extends li_BaseView {
|
||||
private _nodeTab: any = {};
|
||||
|
||||
itemInst: GirlListItem;
|
||||
content: Node;
|
||||
|
||||
cache: GirlListItem[] = [];
|
||||
|
||||
id: number;
|
||||
openUIDataCT(data) {
|
||||
this.id = data;
|
||||
}
|
||||
onLoadCT() {
|
||||
Utils.parseNode(this.node, this._nodeTab);
|
||||
this.registerListener();
|
||||
this.itemInst = this._nodeTab.BubbleItem.getComponent(GirlListItem);
|
||||
this.itemInst.node.active = false;
|
||||
this.content = this._nodeTab.content;
|
||||
this.refresh(this.id);
|
||||
}
|
||||
|
||||
refresh(index: number) {
|
||||
if (this.cache) {
|
||||
for (let i = this.cache.length - 1; i >= 0; i--) {
|
||||
this.cache[i].node.destroy();
|
||||
}
|
||||
}
|
||||
const config = GirlsData.filter((value) => value.category == index);
|
||||
for (let i = 0; i < config.length; i++) {
|
||||
const cfg = config[i];
|
||||
let newNode = instantiate(this.itemInst.node);
|
||||
let item = newNode.getComponent(GirlListItem);
|
||||
item.refreshData(cfg, this.node);
|
||||
newNode.active = true;
|
||||
this.cache.push(item);
|
||||
this.content.addChild(newNode);
|
||||
}
|
||||
}
|
||||
|
||||
private registerListener() {
|
||||
GButton.BandClick(this._nodeTab.ReturnBtn, this.Return, this);
|
||||
}
|
||||
Return() {
|
||||
this.onClose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user