代码结构整理
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Node,
|
||||
instantiate,
|
||||
Label,
|
||||
Sprite,
|
||||
UITransform,
|
||||
} from "cc";
|
||||
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
|
||||
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
||||
import {
|
||||
GirlsData,
|
||||
themes,
|
||||
} from "db://assets/Scripts/Main/Config/cfg/characters";
|
||||
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
||||
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
||||
import { ThemeItem } from "./ThemeItem";
|
||||
import { NavigationManager } from "../../manager/NavigationManager";
|
||||
import { GirlListItem } from "./GirlListItem";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ThemePanel")
|
||||
export class ThemePanel extends li_BaseView {
|
||||
private _nodeTab: any = {};
|
||||
|
||||
coinNum: Label;
|
||||
itemInst: GirlListItem;
|
||||
content: Node;
|
||||
|
||||
recId: number;
|
||||
recName: Label;
|
||||
recSprite: Sprite;
|
||||
|
||||
cache: ThemeItem[] = [];
|
||||
|
||||
onLoadCT() {
|
||||
Utils.parseNode(this.node, this._nodeTab);
|
||||
|
||||
this.coinNum = this._nodeTab.coinNum.getComponent(Label);
|
||||
this.recName = this._nodeTab.characterNameText.getComponent(Label);
|
||||
this.recSprite = this._nodeTab.recPicSlot.getComponent(Sprite);
|
||||
|
||||
this.registerListener();
|
||||
this.itemInst = this._nodeTab.ThemeItem.getComponent(ThemeItem);
|
||||
this.itemInst.node.active = false;
|
||||
this.content = this._nodeTab.AllThemesLayout;
|
||||
this.Show();
|
||||
}
|
||||
|
||||
Show() {
|
||||
//some temp data
|
||||
this.coinNum.string = (50.0).toString();
|
||||
this.recId = 1;
|
||||
|
||||
if (this.cache) {
|
||||
for (let i = this.cache.length - 1; i >= 0; i--) {
|
||||
this.cache[i].node.destroy();
|
||||
}
|
||||
}
|
||||
const config = themes;
|
||||
for (let i = 0; i < config.length; i++) {
|
||||
const cfg = config[i];
|
||||
let newNode = instantiate(this.itemInst.node);
|
||||
let item = newNode.getComponent(ThemeItem);
|
||||
item.refresh(cfg);
|
||||
newNode.active = true;
|
||||
this.cache.push(item);
|
||||
this.content.addChild(newNode);
|
||||
}
|
||||
|
||||
const rectInfo = GirlsData[0];
|
||||
this.recId = rectInfo.id;
|
||||
this.recName.string = rectInfo.name;
|
||||
ResManager.I.changeBundleSpriteFrame(
|
||||
this.recSprite,
|
||||
rectInfo.pic.url,
|
||||
"Chat18x",
|
||||
() => {
|
||||
let sizeTran = this.recSprite.node.parent.getComponent(UITransform);
|
||||
Utils.adjustBgPixelRatioToSize(
|
||||
sizeTran.contentSize,
|
||||
this.recSprite.node,
|
||||
2
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private registerListener() {
|
||||
GButton.BandClick(this._nodeTab.settingBtn, this.openSetting, this);
|
||||
GButton.BandClick(this._nodeTab.msgBoxBtn, this.openMsgBox, this);
|
||||
|
||||
GButton.BandClick(this._nodeTab.ChatWithRecBtn, this.chatWithRec, this);
|
||||
}
|
||||
|
||||
chatWithRec() {
|
||||
NavigationManager.Instance.navigateToChat(this.recId);
|
||||
}
|
||||
|
||||
openSetting() {
|
||||
console.log("Setting");
|
||||
}
|
||||
|
||||
openMsgBox() {
|
||||
console.log("打开信箱");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user