Files
18xchat/assets/Scripts/chat18x/ui/panels/GirlListPanel.ts
T

113 lines
3.8 KiB
TypeScript

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 { GButton } from "db://assets/Scripts/Main/Common/GButton";
import { GirlListItem } from "../../uiitems/GirlListItem";
import { ConfigManager } from "../../manager/ConfigManager";
import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService";
import { DataManager, DataId } from "../../data/DataManager";
import { GirlData } from "../../data/GirlData";
import proto from "db://assets/Scripts/proto/proto.pb.js";
import GameRootUI from "../../../Main/Common/GameRootUI";
import { UITransitionHelper } from "../../utils/UITransitionHelper";
const { ccclass, property } = _decorator;
@ccclass("GirlListPanel")
export class GirlListPanel extends li_BaseView {
private _nodeTab: any = {};
itemInst: GirlListItem;
content: Node;
cache: GirlListItem[] = [];
category: number;
openUIDataCT(data) {
// 支持新的数据格式:既可以是单纯的数字,也可以是包含过渡动画信息的对象
this.category =
typeof data === "object" && data.category !== undefined
? data.category
: data;
const withAnimation = typeof data === "object" && data.withTransition;
}
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.category);
}
async refresh(category: number) {
if (this.cache) {
for (let i = this.cache.length - 1; i >= 0; i--) {
this.cache[i].node.destroy();
}
}
// 请求列表
const reqData = {
category,
page: 1,
limit: 10,
};
let res = await GirlService.I.reqGetGirlList(reqData);
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
// 保存数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
girlData.setGirlList(category.toString(), res.data);
// 根据数据,刷新界面
const allId = girlData.getGirlIds(category.toString());
for (let id of allId) {
let newNode = instantiate(this.itemInst.node);
let item = newNode.getComponent(GirlListItem);
item.refreshData(category, id, this.node);
newNode.active = true;
this.cache.push(item);
this.content.addChild(newNode);
}
}
}
private registerListener() {
GButton.BandClick(this._nodeTab.ReturnBtn, this.Return, this);
}
Return() {
console.log("GirlListPanel: Return button clicked");
// 执行同步的过渡动画:GirlListPanel向右滑出,ThemePanel从左滑入
const duration = 0.1;
let animationsCompleted = 0;
const totalAnimations = 2;
const onAnimationComplete = (source: string) => {
console.log(`GirlListPanel: Animation completed from ${source}`);
animationsCompleted++;
console.log(
`GirlListPanel: ${animationsCompleted}/${totalAnimations} animations completed`
);
if (animationsCompleted >= totalAnimations) {
console.log("GirlListPanel: All animations completed, closing panel");
// 所有动画完成后关闭当前面板
this.onClose();
}
};
// 1. GirlListPanel向右滑出
console.log("GirlListPanel: Starting slideOutToRight animation");
UITransitionHelper.slideOutToRight(this.node, duration, () =>
onAnimationComplete("slideOutToRight")
);
// 2. ThemePanel从左侧滑入
console.log("GirlListPanel: Starting ThemePanel slide_left animation");
GameRootUI.I.showDefaultViewWithTransition("slide_left", duration, () =>
onAnimationComplete("ThemePanel_slide_left")
);
}
}