update
This commit is contained in:
@@ -32,6 +32,7 @@ import { EnvData } from "../../data/EnvData";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import { MainController } from "../../core/MainController";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
import { RecomandItem } from "../../uiitems/RecomandItem";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -40,15 +41,20 @@ export class ThemePanel extends li_BaseView {
|
||||
private _nodeTab: any = {};
|
||||
|
||||
coinNum: Label;
|
||||
|
||||
itemInst: ThemeItem;
|
||||
content: Node;
|
||||
recItemInst: RecomandItem;
|
||||
|
||||
themeContent: Node;
|
||||
recGirlContent: Node;
|
||||
private vipLeftTime: Label;
|
||||
recId: number;
|
||||
recName: Label;
|
||||
recSprite: Sprite;
|
||||
//recName: Label;
|
||||
//recSprite: Sprite;
|
||||
|
||||
cache: ThemeItem[] = [];
|
||||
|
||||
recItemCache: RecomandItem[] = [];
|
||||
|
||||
// 子页面管理
|
||||
|
||||
// 加载状态保护
|
||||
@@ -56,23 +62,38 @@ export class ThemePanel extends li_BaseView {
|
||||
private loadingPromise: Promise<void> | null = null;
|
||||
private abortController: AbortController | null = null;
|
||||
|
||||
private recomandListBtn: Node;
|
||||
private moreThemeBtn: Node;
|
||||
|
||||
private themeScroll: Node;
|
||||
private recomandScroll: Node;
|
||||
|
||||
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.recPic.getComponent(Sprite);
|
||||
//this.recName = this._nodeTab.characterNameText.getComponent(Label);
|
||||
//this.recSprite = this._nodeTab.recPic.getComponent(Sprite);
|
||||
this.vipLeftTime = this._nodeTab.vipText.getComponent(Label);
|
||||
|
||||
this.recomandListBtn = this._nodeTab.recomandList;
|
||||
this.moreThemeBtn = this._nodeTab.moreTheme;
|
||||
this.themeScroll = this._nodeTab.themeScroll;
|
||||
this.recomandScroll = this._nodeTab.recomandScroll;
|
||||
|
||||
this.registerListener();
|
||||
this.itemInst = this._nodeTab.ThemeItem.getComponent(ThemeItem);
|
||||
this.itemInst.node.active = false;
|
||||
this.content = this._nodeTab.allThemecontent;
|
||||
|
||||
this.recItemInst = this._nodeTab.recItem.getComponent(RecomandItem);
|
||||
this.recItemInst.node.active = false;
|
||||
|
||||
this.themeContent = this._nodeTab.allThemecontent;
|
||||
this.recGirlContent = this._nodeTab.allRecGirlContent;
|
||||
|
||||
this.Show();
|
||||
}
|
||||
|
||||
rectNameKey: string;
|
||||
async Show(forceRefresh: boolean = false) {
|
||||
// 防止重复加载
|
||||
if (this.isLoading) {
|
||||
@@ -84,7 +105,7 @@ export class ThemePanel extends li_BaseView {
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
this.loadingPromise = this._showInternal(forceRefresh);
|
||||
this.loadingPromise = this._refreshDataInternal(forceRefresh);
|
||||
|
||||
try {
|
||||
await this.loadingPromise;
|
||||
@@ -92,9 +113,11 @@ export class ThemePanel extends li_BaseView {
|
||||
this.isLoading = false;
|
||||
this.loadingPromise = null;
|
||||
}
|
||||
|
||||
this.openRecomandList();
|
||||
}
|
||||
|
||||
private async _showInternal(forceRefresh: boolean = false) {
|
||||
private async _refreshDataInternal(forceRefresh: boolean = false) {
|
||||
// 创建新的AbortController用于取消操作
|
||||
this.abortController = new AbortController();
|
||||
const signal = this.abortController.signal;
|
||||
@@ -108,7 +131,6 @@ export class ThemePanel extends li_BaseView {
|
||||
DataId.Account
|
||||
);
|
||||
//this.uid.string = "uid: " + accountData.accId;
|
||||
this.recId = 1;
|
||||
|
||||
// 检查是否已被取消
|
||||
if (signal.aborted) {
|
||||
@@ -146,7 +168,7 @@ export class ThemePanel extends li_BaseView {
|
||||
}
|
||||
|
||||
// 处理每日推荐数据
|
||||
await this.handleDailyRecommendData(preloadStatus.dailyRecommend);
|
||||
await this.handleRecommendData(preloadStatus.dailyRecommend);
|
||||
|
||||
// 检查是否已被取消
|
||||
if (signal.aborted) {
|
||||
@@ -180,7 +202,6 @@ export class ThemePanel extends li_BaseView {
|
||||
// 直接使用预加载的数据渲染界面
|
||||
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
|
||||
if (themeData && themeData.themes) {
|
||||
this.renderThemeData(themeData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -193,14 +214,16 @@ export class ThemePanel extends li_BaseView {
|
||||
// 保存数据
|
||||
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
|
||||
themeData.themes = res.data;
|
||||
this.renderThemeData(themeData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染主题数据
|
||||
*/
|
||||
private renderThemeData(themeData: ThemeData): void {
|
||||
private renderThemeData(): void {
|
||||
if (this.cache.length > 0) return;
|
||||
|
||||
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
|
||||
const themeIds = themeData.themeIds;
|
||||
for (let id of themeIds) {
|
||||
let newNode = instantiate(this.itemInst.node);
|
||||
@@ -208,20 +231,19 @@ export class ThemePanel extends li_BaseView {
|
||||
item.refresh(id, this.node);
|
||||
newNode.active = true;
|
||||
this.cache.push(item);
|
||||
this.content.addChild(newNode);
|
||||
this.themeContent.addChild(newNode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理每日推荐数据
|
||||
* 处理推荐数据
|
||||
*/
|
||||
private async handleDailyRecommendData(isPreloaded: boolean): Promise<void> {
|
||||
private async handleRecommendData(isPreloaded: boolean): Promise<void> {
|
||||
if (isPreloaded) {
|
||||
logger.log("[ThemePanel] 使用预加载的每日推荐数据");
|
||||
// 直接使用预加载的数据渲染界面
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
if (girlData) {
|
||||
this.renderDailyRecommendData(girlData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -233,29 +255,30 @@ export class ThemePanel extends li_BaseView {
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
girlData.setDailyRecommend(res.data);
|
||||
this.renderDailyRecommendData(girlData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染每日推荐数据
|
||||
*/
|
||||
private renderDailyRecommendData(girlData: GirlData): void {
|
||||
this.recId = girlData.getRecommendGirlId();
|
||||
this.rectNameKey = girlData.getRecommendGrilName();
|
||||
let avatarPath = girlData.getRecommendGrilAvatar();
|
||||
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
||||
// 加载远程资源
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
let newPath = envData.cdn + "/" + "Girls/" + avatarPath + ".png";
|
||||
ResManager.I.changeRemoteSpriteFrame(this.recSprite, newPath, () => {
|
||||
let sizeTran = this.recSprite.node.parent.getComponent(UITransform);
|
||||
Utils.adjustBgPixelRatioToSize(
|
||||
sizeTran.contentSize,
|
||||
this.recSprite.node,
|
||||
1
|
||||
);
|
||||
});
|
||||
private renderRecommendData(): void {
|
||||
if (this.recItemCache.length > 0) return;
|
||||
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
|
||||
let girlIDs = [];
|
||||
girlIDs.push(girlData.getRecommendGirlId());
|
||||
for (let id of girlIDs) {
|
||||
let newNode = instantiate(this.recItemInst.node);
|
||||
let item = newNode.getComponent(RecomandItem);
|
||||
item.init();
|
||||
item.refresh(id);
|
||||
newNode.active = true;
|
||||
this.recItemCache.push(item);
|
||||
this.recGirlContent.addChild(newNode);
|
||||
}
|
||||
|
||||
console.error("未实现每日推荐数据渲染");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,13 +297,11 @@ export class ThemePanel extends li_BaseView {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
GButton.BandClick(this.recomandListBtn, this.openRecomandList, this);
|
||||
GButton.BandClick(this.moreThemeBtn, this.openMoreTheme, this);
|
||||
|
||||
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, this.onLanguageChange);
|
||||
Utils.addInnerEL(InnerMsgCode.BalanceChange, this, this.onBalanceChange);
|
||||
Utils.addInnerEL(
|
||||
@@ -302,43 +323,32 @@ export class ThemePanel extends li_BaseView {
|
||||
);
|
||||
}
|
||||
|
||||
chatWithRec() {
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
openRecomandList() {
|
||||
this.themeScroll.active = false;
|
||||
this.recomandScroll.active = true;
|
||||
|
||||
// 是否已经解锁
|
||||
const isRelease = girlData.getIsRelease(
|
||||
girlData.getGrilCategoryById(this.recId).toString(),
|
||||
this.recId
|
||||
);
|
||||
const isFree =
|
||||
girlData.getGrilPrice(
|
||||
girlData.getGrilCategoryById(this.recId).toString(),
|
||||
this.recId
|
||||
) == 0;
|
||||
//if (isRelease || isFree) {
|
||||
NavigationManager.Instance.setSelectedGirlId(this.recId);
|
||||
NavigationManager.Instance.setSelectedCategoryId(
|
||||
girlData.getGrilCategoryById(this.recId)
|
||||
);
|
||||
NavigationManager.Instance.switchToPanel(PanelType.GIRL_DETAIL);
|
||||
// } else {
|
||||
// //未解锁
|
||||
//todo:是否需要刷新数据
|
||||
this.renderRecommendData();
|
||||
|
||||
// NavigationManager.Instance.openPopupPanel("GirlListPopupPanel", {
|
||||
// base: this,
|
||||
// category: girlData.getGrilCategoryById(this.recId),
|
||||
// id: this.recId,
|
||||
// });
|
||||
// }
|
||||
this.updateTagState(true);
|
||||
}
|
||||
openMoreTheme() {
|
||||
this.themeScroll.active = true;
|
||||
this.recomandScroll.active = false;
|
||||
|
||||
//todo:是否需要刷新数据
|
||||
|
||||
this.renderThemeData();
|
||||
|
||||
this.updateTagState(false);
|
||||
}
|
||||
|
||||
openSetting() {
|
||||
// 通过NavigationManager切换到个人信息面板,保持动画和状态同步
|
||||
NavigationManager.Instance.openSubPanel("SettingPanel", this.node);
|
||||
}
|
||||
updateTagState(isRecomnend: boolean) {
|
||||
this.recomandListBtn.children[0].active = !isRecomnend;
|
||||
this.recomandListBtn.children[1].active = isRecomnend;
|
||||
|
||||
openMsgBox() {
|
||||
logger.log("打开信箱");
|
||||
this.moreThemeBtn.children[0].active = isRecomnend;
|
||||
this.moreThemeBtn.children[1].active = !isRecomnend;
|
||||
}
|
||||
|
||||
// 刷新余额
|
||||
@@ -445,7 +455,7 @@ export class ThemePanel extends li_BaseView {
|
||||
|
||||
// 事件回调函数(避免匿名函数导致的内存泄漏)
|
||||
private onLanguageChange = () => {
|
||||
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
||||
//this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
||||
this.refreshVipExpire();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user