This commit is contained in:
2025-10-27 17:36:15 +08:00
parent 441d823341
commit 6e01e5afd5
10 changed files with 6085 additions and 0 deletions
@@ -0,0 +1,177 @@
import {
_decorator,
Component,
Node,
instantiate,
tween,
Vec3,
Label,
} 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 { 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 { NavigationManager, PanelType } from "../../manager/NavigationManager";
import { ThemeData } from "../../data/ThemeData";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import HXZ_ScrollViewList from "db://assets/Scripts/Main/Common/ScrollViewList";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator;
@ccclass("GirlCollectionPanel")
export class GirlCollectionPanel extends li_BaseView {
private _nodeTab: any = {};
itemInst: GirlListItem;
scrollView: Node;
// 虚拟列表组件
private scrollViewList: HXZ_ScrollViewList = null;
// 收藏ID缓存(按收藏时间排序)
private cachedBookmarkIds: number[] = [];
private title1: Label;
private title2: Label;
onLoadCT() {
this.node.active = false;
this.scheduleOnce(() => {
this.node.active = true;
}, 0.1);
Utils.parseNode(this.node, this._nodeTab);
this.registerListener();
this.itemInst = this._nodeTab.BubbleItem.getComponent(GirlListItem);
this.itemInst.node.active = false;
this.scrollView = this._nodeTab.ScrollView;
this.title1 = this._nodeTab.title1.getComponent(Label);
this.title2 = this._nodeTab.title2.getComponent(Label);
// 获取虚拟列表组件
if (this.scrollView) {
this.scrollViewList = this.scrollView.getComponent(HXZ_ScrollViewList);
if (!this.scrollViewList) {
logger.warn(
"[GirlCollectionPanel] content 父节点缺少 HXZ_ScrollViewList 组件,请在编辑器中添加"
);
} else {
logger.log("[GirlCollectionPanel] 虚拟列表组件初始化成功");
}
}
this.refresh();
}
async refresh() {
logger.log("[GirlCollectionPanel] 开始刷新收藏列表");
// 获取收藏数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 获取按时间排序的收藏ID列表(最新的在前)
this.cachedBookmarkIds = girlData.getAllBookmarkGirlIdsSortedByTime();
logger.log(
`[GirlCollectionPanel] 收藏列表共 ${this.cachedBookmarkIds.length}`
);
// 更新标题为"我的收藏"
// TODO: 可以使用多语言key替换
// 使用虚拟列表:设置总数量,触发自动渲染
if (this.scrollViewList) {
this.scrollViewList.numItems = this.cachedBookmarkIds.length;
logger.log(
`[GirlCollectionPanel] 虚拟列表 numItems 已设置为 ${this.cachedBookmarkIds.length}`
);
} else {
logger.warn(
"[GirlCollectionPanel] scrollViewList 未初始化,无法显示列表"
);
}
}
/**
* 虚拟列表渲染回调
* 该方法需要在 Cocos Creator 编辑器中配置到 HXZ_ScrollViewList 的 renderEvent
* @param itemNode 虚拟列表传入的节点
* @param index 数据索引
*/
onRenderCollectionItem(itemNode: Node, index: number): void {
if (index < this.cachedBookmarkIds.length) {
const girlId = this.cachedBookmarkIds[index];
const item = itemNode.getComponent(GirlListItem);
if (!item) {
logger.error(
`[GirlCollectionPanel] 节点缺少 GirlListItem 组件,index: ${index}`
);
return;
}
// 获取女孩的分类
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
const category = girlData.getGrilCategoryById(girlId);
if (category === 0) {
logger.warn(
`[GirlCollectionPanel] 无法获取 girlId=${girlId} 的分类信息`
);
return;
}
// 刷新数据
item.refreshData(category, girlId, this);
itemNode.active = true;
logger.log(
`[GirlCollectionPanel] 渲染 item: index=${index}, girlId=${girlId}, category=${category}`
);
}
}
private addSlideInAnimation(itemNode: Node, index: number) {
// 保存节点的目标位置
const targetPosition = itemNode.getPosition();
// 设置初始位置为屏幕右侧外(偏移300像素)
const startPosition = new Vec3(
targetPosition.x + 300,
targetPosition.y,
targetPosition.z
);
itemNode.setPosition(startPosition);
// 添加递进延时,每个item延迟0.05秒
const delay = index * 0.05;
// 执行滑入动画
tween(itemNode)
.delay(delay)
.to(0.4, { position: targetPosition }, { easing: "cubicOut" })
.start();
}
hide() {
this.node.active = false;
}
private registerListener() {
GButton.BandClick(this._nodeTab.ReturnBtn, this.Return, this);
}
Return() {
NavigationManager.Instance.closeSubPanel(this);
}
onDestroy() {
// 虚拟列表会自动管理对象池,只需清理数据缓存
this.cachedBookmarkIds = [];
logger.log("[GirlCollectionPanel] 组件已销毁");
}
}
@@ -0,0 +1 @@
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"4338e1aa-c1fa-43e8-ac88-71d0f9c141d9","files":[],"subMetas":{},"userData":{}}
+247
View File
@@ -0,0 +1,247 @@
import {
_decorator,
Component,
Label,
Node,
Size,
Sprite,
UITransform,
} from "cc";
import Utils from "../../Main/Common/Utils";
import { GButton } from "../../Main/Common/GButton";
import { DataManager, DataId } from "../data/DataManager";
import { GirlData } from "../data/GirlData";
import LanguageUtils from "../../Main/Common/LanguageUtils";
import ResManager from "../../Main/Manager/ResManager";
import { EnvData } from "../data/EnvData";
import {
NavigationManager,
PanelType,
PageTransitionType,
} from "../manager/NavigationManager";
import { logger } from "../../Main/Common/Logger";
const { ccclass, property } = _decorator;
@ccclass("RankItem")
export class RankItem extends Component {
private _nodeTab: any = {};
private rankIndex: Label;
private lv1: Node;
private lv2: Node;
private lv3: Node;
private rankPic: Sprite;
private girlName: Label;
private tag: Label;
private heartParent: Node;
private hearts: Sprite[] = [];
private chatBtn: Node;
private detailBtn: Node;
private id: number;
// 标记是否已初始化(用于虚拟列表复用)
public _initialized: boolean = false;
// 兼容原有调用方式的 init 方法
init() {
if (this._initialized) {
return;
}
Utils.parseNode(this.node, this._nodeTab);
this.rankIndex = this._nodeTab.rankLabel?.getComponent(Label);
this.lv1 = this._nodeTab.lv1;
this.lv2 = this._nodeTab.lv2;
this.lv3 = this._nodeTab.lv3;
this.rankPic = this._nodeTab.avatar.getComponent(Sprite);
this.girlName = this._nodeTab.name?.getComponent(Label);
this.tag = this._nodeTab.tag?.getComponent(Label);
this.heartParent = this._nodeTab.heartBg;
if (this.heartParent) {
this.heartParent.children.forEach((a) =>
this.hearts.push(a.getComponent(Sprite))
);
}
this.chatBtn = this._nodeTab.chatBtn;
this.detailBtn = this._nodeTab.detailBtn;
if (this.chatBtn) {
GButton.BandClick(this.chatBtn, this.chatToHer, this);
}
if (this.detailBtn) {
GButton.BandClick(this.detailBtn, this.gotoDetail, this);
}
this._initialized = true;
}
// 节点回收到对象池时调用,重置状态
reset(): void {
this.id = -1;
this.node.active = false;
}
picSize: Size = new Size(100, 100);
/**
* 刷新排行榜项显示
* @param girlId 技师ID
* @param rankIndex 排名序号(从1开始)
*/
refresh(girlId: number, rankIndex: number) {
this.id = girlId;
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
const category = girlData.getGrilCategoryById(girlId);
// 显示排名
if (this.rankIndex) {
this.lv1.active = rankIndex === 1;
this.lv2.active = rankIndex === 2;
this.lv3.active = rankIndex === 3;
this.rankIndex.node.active = rankIndex > 3;
this.rankIndex.string = rankIndex.toString();
}
// 数据
let nameKey = girlData.getGrilName(category.toString(), this.id);
if (this.girlName) {
this.girlName.string = LanguageUtils.getText(nameKey);
}
let tagKey = girlData.getGrilTagKey(category.toString(), this.id);
if (this.tag) {
this.tag.string = LanguageUtils.getText(tagKey);
}
if (this.heartParent) {
this.heartParent.active = true;
}
// 加载头像
let avatarPath = girlData.getGrilAvatar(category.toString(), this.id);
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
let newPath = envData.cdn + "/" + "Girls/" + avatarPath + ".png";
if (this.rankPic) {
ResManager.I.changeRemoteSpriteFrame(this.rankPic, newPath, () => {
this.doScaleToFill(this.rankPic, this.picSize);
});
}
// 显示好感度
const star = girlData.getStar(category.toString(), this.id);
for (let i = 0; i < this.hearts.length; i++) {
const element = this.hearts[i];
if (star > i) {
ResManager.I.changeResourceSpriteFrame(
element,
"ui/common/heart/heart"
);
} else {
ResManager.I.changeResourceSpriteFrame(
element,
"ui/common/heart/heart_empty"
);
}
}
}
doScaleToFill(img: Sprite, size: Size) {
if (!img || !img.spriteFrame) return;
const itemSize = size;
const imageSize = img.spriteFrame.originalSize;
if (
itemSize.width === 0 ||
itemSize.height === 0 ||
imageSize.width === 0 ||
imageSize.height === 0
) {
return;
}
const scaleX = itemSize.width / imageSize.width;
const scaleY = itemSize.height / imageSize.height;
const scale = Math.max(scaleX, scaleY);
// 设置Sprite的sizeMode为CUSTOM,允许自定义大小
img.sizeMode = Sprite.SizeMode.CUSTOM;
// 获取图片节点的UITransform并设置大小
const imgTransform = img.node.getComponent(UITransform);
if (imgTransform) {
imgTransform.setContentSize(
imageSize.width * scale,
imageSize.height * scale
);
}
}
/**
* 聊天按钮点击事件
*/
chatToHer() {
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
NavigationManager.Instance.setSelectedGirlId(this.id);
NavigationManager.Instance.setSelectedCategoryId(
girlData.getGrilCategoryById(this.id)
);
// 直接在当前页面打开ChatPanel作为子页面
const currentPanel = NavigationManager.Instance.getCurrentActivePanelNode();
if (currentPanel) {
const chatData = { girlId: this.id, base: currentPanel };
NavigationManager.Instance.openSubPanel(
"ChatPanel",
currentPanel,
chatData,
{
openAnimation: PageTransitionType.NONE,
closeAnimation: PageTransitionType.NONE,
hideBasePanel: true,
}
);
} else {
logger.warn("[RankItem] 无法获取当前激活的主页面");
}
}
/**
* 详情按钮点击事件
*/
gotoDetail() {
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
NavigationManager.Instance.setSelectedGirlId(this.id);
NavigationManager.Instance.setSelectedCategoryId(
girlData.getGrilCategoryById(this.id)
);
// 以subpanel方式打开GirlDetailPanel
const currentPanel = NavigationManager.Instance.getCurrentActivePanelNode();
if (currentPanel) {
NavigationManager.Instance.openSubPanel(
"GirlDetailPanel",
currentPanel,
this.id,
{
openAnimation: PageTransitionType.NONE,
closeAnimation: PageTransitionType.NONE,
hideBasePanel: true, // 隐藏底层panel,实现全屏显示
}
);
} else {
logger.warn("[RankItem] 无法获取当前激活的主页面");
}
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "995c8b1c-a5b7-4e49-bf44-50a6a89fa4f8",
"files": [],
"subMetas": {},
"userData": {}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,13 @@
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "a0f75a36-ea81-4363-844e-fa21a437b182",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "GirlCollectionPanel"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "da34e8b7-59ca-4dc4-825d-d359b17be8c5",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "da34e8b7-59ca-4dc4-825d-d359b17be8c5@6c48a",
"displayName": "LT_UI_SC1",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "da34e8b7-59ca-4dc4-825d-d359b17be8c5",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "da34e8b7-59ca-4dc4-825d-d359b17be8c5@f9941",
"displayName": "LT_UI_SC1",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 46,
"height": 49,
"rawWidth": 46,
"rawHeight": 49,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-23,
-24.5,
0,
23,
-24.5,
0,
-23,
24.5,
0,
23,
24.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
49,
46,
49,
0,
0,
46,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-23,
-24.5,
0
],
"maxPos": [
23,
24.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "da34e8b7-59ca-4dc4-825d-d359b17be8c5@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "da34e8b7-59ca-4dc4-825d-d359b17be8c5@6c48a"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "7b9bf177-f5b8-4548-88d1-b0311ae5f387",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "7b9bf177-f5b8-4548-88d1-b0311ae5f387@6c48a",
"displayName": "LT_UI_SC2",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "7b9bf177-f5b8-4548-88d1-b0311ae5f387",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "7b9bf177-f5b8-4548-88d1-b0311ae5f387@f9941",
"displayName": "LT_UI_SC2",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 48,
"height": 47,
"rawWidth": 48,
"rawHeight": 47,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-24,
-23.5,
0,
24,
-23.5,
0,
-24,
23.5,
0,
24,
23.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
47,
48,
47,
0,
0,
48,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-24,
-23.5,
0
],
"maxPos": [
24,
23.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "7b9bf177-f5b8-4548-88d1-b0311ae5f387@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "7b9bf177-f5b8-4548-88d1-b0311ae5f387@6c48a"
}
}