149 lines
4.4 KiB
TypeScript
149 lines
4.4 KiB
TypeScript
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 { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
|
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
|
import { ThemeItem } from "../../uiitems/ThemeItem";
|
|
import { NavigationManager } from "../../manager/NavigationManager";
|
|
import { GirlListItem } from "../../uiitems/GirlListItem";
|
|
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
|
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
|
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
|
import { ThemeService } from "db://assets/Scripts/chat18x/network/services/ThemeService";
|
|
import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService";
|
|
import { DataManager, DataId } from "../../data/DataManager";
|
|
import { ThemeData } from "../../data/ThemeData";
|
|
import { GirlData } from "../../data/GirlData";
|
|
|
|
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.allThemecontent;
|
|
|
|
this.Show();
|
|
}
|
|
|
|
rectNameKey: string;
|
|
async 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 reqData = {
|
|
|
|
};
|
|
let res = await ThemeService.I.reqHallTheme(reqData);
|
|
// 保存数据
|
|
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
|
|
themeData.themes = res.data;
|
|
// 根据数据,构建界面显示
|
|
const themeIds = themeData.themeIds;
|
|
for (let id of themeIds) {
|
|
let newNode = instantiate(this.itemInst.node);
|
|
let item = newNode.getComponent(ThemeItem);
|
|
item.refresh(id);
|
|
newNode.active = true;
|
|
this.cache.push(item);
|
|
this.content.addChild(newNode);
|
|
}
|
|
|
|
// 请求每日推荐
|
|
const reqData2 = {
|
|
|
|
};
|
|
let res2 = await GirlService.I.reqDailyRecommend(reqData2);
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
girlData.setDailyRecommend(res2.data);
|
|
// 根据数据,构建界面显示
|
|
this.recId = girlData.getRecommendGrilId(0);
|
|
this.rectNameKey = girlData.getRecommendGrilName(0);
|
|
let avatarPath = girlData.getRecommendGrilAvatar(0);
|
|
|
|
//this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
|
ResManager.I.changeBundleSpriteFrame(
|
|
this.recSprite,
|
|
avatarPath,
|
|
"Chat18x",
|
|
() => {
|
|
let sizeTran = this.recSprite.node.parent.getComponent(UITransform);
|
|
Utils.adjustBgPixelRatioToSize(
|
|
sizeTran.contentSize,
|
|
this.recSprite.node,
|
|
1
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
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);
|
|
|
|
GButton.BandClick(this._nodeTab.ShopPanelEntry, this.enterShop, this);
|
|
|
|
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
|
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
|
});
|
|
}
|
|
|
|
enterShop() {
|
|
ViewManager.I.openBundlesView("PurchasePanel");
|
|
}
|
|
|
|
chatWithRec() {
|
|
NavigationManager.Instance.navigateToChat(this.recId);
|
|
}
|
|
|
|
openSetting() {
|
|
ViewManager.I.openBundlesView("LanguagePanel");
|
|
}
|
|
|
|
openMsgBox() {
|
|
console.log("打开信箱");
|
|
}
|
|
|
|
onDestroy(): void {
|
|
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
|
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
|
});
|
|
}
|
|
}
|