2025-09-20 16:05:57 +08:00
|
|
|
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 { PastGirlListItem } from "../../uiitems/PastGirlListItem";
|
|
|
|
|
import { DataManager, DataId } from "../../data/DataManager";
|
|
|
|
|
import { GirlData } from "../../data/GirlData";
|
2025-09-21 14:28:17 +08:00
|
|
|
import { ChatHistoryManager } from "../../manager/ChatHistoryManager";
|
2025-09-21 20:25:36 +08:00
|
|
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
2025-09-22 18:41:59 +08:00
|
|
|
import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService";
|
|
|
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
2025-09-20 16:05:57 +08:00
|
|
|
|
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
|
|
@ccclass("PastGirlListPanel")
|
|
|
|
|
export class PastGirlListPanel extends li_BaseView {
|
|
|
|
|
private _nodeTab: any = {};
|
|
|
|
|
|
|
|
|
|
itemInst: PastGirlListItem;
|
|
|
|
|
content: Node;
|
|
|
|
|
|
|
|
|
|
cache: PastGirlListItem[] = [];
|
|
|
|
|
|
|
|
|
|
// 缓存池相关属性
|
|
|
|
|
private itemPool: PastGirlListItem[] = [];
|
|
|
|
|
private maxPoolSize: number = 20;
|
|
|
|
|
|
|
|
|
|
onLoadCT() {
|
|
|
|
|
Utils.parseNode(this.node, this._nodeTab);
|
|
|
|
|
this.registerListener();
|
|
|
|
|
this.itemInst = this._nodeTab.BubbleItem.getComponent(PastGirlListItem);
|
|
|
|
|
this.itemInst.node.active = false;
|
|
|
|
|
this.content = this._nodeTab.content;
|
2025-09-21 14:39:01 +08:00
|
|
|
//this.refresh();
|
2025-09-20 16:05:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从缓存池获取节点
|
|
|
|
|
private getItemFromPool(): PastGirlListItem {
|
|
|
|
|
if (this.itemPool.length > 0) {
|
|
|
|
|
return this.itemPool.pop();
|
|
|
|
|
} else {
|
|
|
|
|
// 缓存池为空,检查是否有隐藏的节点可以复用
|
|
|
|
|
for (let i = 0; i < this.content.children.length; i++) {
|
|
|
|
|
let childNode = this.content.children[i];
|
|
|
|
|
if (!childNode.active && childNode !== this.itemInst.node) {
|
|
|
|
|
let item = childNode.getComponent(PastGirlListItem);
|
|
|
|
|
if (item) {
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 没有可复用的节点,创建新节点
|
|
|
|
|
let newNode = instantiate(this.itemInst.node);
|
|
|
|
|
let item = newNode.getComponent(PastGirlListItem);
|
|
|
|
|
this.content.addChild(newNode);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将节点回收到缓存池
|
|
|
|
|
private returnItemToPool(item: PastGirlListItem) {
|
|
|
|
|
if (this.itemPool.length < this.maxPoolSize) {
|
|
|
|
|
item.reset();
|
|
|
|
|
this.itemPool.push(item);
|
|
|
|
|
} else {
|
|
|
|
|
// 缓存池已满,隐藏节点但不销毁
|
|
|
|
|
item.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: 实现获取已解锁女孩列表的逻辑
|
|
|
|
|
// 这个方法需要遍历所有分类,找出 isRelease === true 的女孩
|
|
|
|
|
private getUnlockedGirls(): number[] {
|
2025-09-21 14:28:17 +08:00
|
|
|
const GirlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
|
|
|
const allids = GirlData.getAllReleaseGirlIds();
|
2025-09-21 20:25:36 +08:00
|
|
|
logger.log(allids);
|
2025-09-21 14:28:17 +08:00
|
|
|
return allids;
|
2025-09-20 16:05:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
|
// 回收当前显示的节点到缓存池
|
|
|
|
|
if (this.cache) {
|
|
|
|
|
for (let i = this.cache.length - 1; i >= 0; i--) {
|
|
|
|
|
let item = this.cache[i];
|
|
|
|
|
this.returnItemToPool(item);
|
|
|
|
|
}
|
|
|
|
|
this.cache = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取已解锁女孩列表
|
|
|
|
|
const ids = this.getUnlockedGirls();
|
|
|
|
|
|
2025-09-21 14:28:17 +08:00
|
|
|
// 创建带时间戳的数组用于排序
|
2025-09-21 14:39:01 +08:00
|
|
|
const girlsWithTime: { id: number; lastTime: number }[] = [];
|
2025-09-21 14:28:17 +08:00
|
|
|
|
|
|
|
|
// 收集每个女孩的最后聊天时间
|
2025-09-20 16:05:57 +08:00
|
|
|
for (let id of ids) {
|
2025-09-21 14:28:17 +08:00
|
|
|
const lastTime = ChatHistoryManager.Instance.getLastChatTime(id) || 0;
|
2025-09-21 14:39:01 +08:00
|
|
|
girlsWithTime.push({ id, lastTime });
|
2025-09-21 14:28:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 按最后聊天时间降序排序(最近的在前)
|
|
|
|
|
girlsWithTime.sort((a, b) => b.lastTime - a.lastTime);
|
|
|
|
|
|
|
|
|
|
// 根据排序后的数据刷新界面
|
|
|
|
|
for (let girlData of girlsWithTime) {
|
2025-09-20 16:05:57 +08:00
|
|
|
let item = this.getItemFromPool();
|
2025-09-21 14:28:17 +08:00
|
|
|
item.refreshData(girlData.id, this.node);
|
2025-09-20 16:05:57 +08:00
|
|
|
item.node.active = true;
|
|
|
|
|
this.cache.push(item);
|
|
|
|
|
|
|
|
|
|
// 确保节点在 content 中(可能已经在了)
|
|
|
|
|
if (item.node.parent !== this.content) {
|
|
|
|
|
this.content.addChild(item.node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
|
this.node.active = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private registerListener() {
|
|
|
|
|
GButton.BandClick(this._nodeTab.ReturnBtn, this.Return, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return() {
|
|
|
|
|
// 直接关闭,不需要动画
|
|
|
|
|
this.node.active = false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 18:41:59 +08:00
|
|
|
// 获取可聊天的技师数据
|
|
|
|
|
private async reqCanChatGirlData() {
|
|
|
|
|
const reqData = {
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 20,
|
|
|
|
|
};
|
|
|
|
|
let res = await GirlService.I.reqCanChatGirlData(reqData);
|
|
|
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
|
|
|
const resData = res.data;
|
|
|
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
|
|
|
girlData.setCanChatGirlData(resData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 16:05:57 +08:00
|
|
|
onDestroy() {
|
|
|
|
|
// 清理缓存池,销毁所有缓存的节点
|
|
|
|
|
for (let item of this.itemPool) {
|
|
|
|
|
if (item && item.node) {
|
|
|
|
|
item.node.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.itemPool = [];
|
|
|
|
|
|
|
|
|
|
// 清理当前显示的节点
|
|
|
|
|
for (let item of this.cache) {
|
|
|
|
|
if (item && item.node) {
|
|
|
|
|
item.node.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.cache = [];
|
|
|
|
|
|
|
|
|
|
// 清理 content 中所有的 GirlListItem 节点
|
|
|
|
|
for (let i = this.content.children.length - 1; i >= 0; i--) {
|
|
|
|
|
let child = this.content.children[i];
|
|
|
|
|
if (child !== this.itemInst.node) {
|
|
|
|
|
let item = child.getComponent(PastGirlListItem);
|
|
|
|
|
if (item) {
|
|
|
|
|
child.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|