update 历史聊天妹子页
This commit is contained in:
@@ -120,6 +120,20 @@ export default class Utils {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串左侧填充到指定长度
|
||||
* @param str 要填充的字符串
|
||||
* @param length 目标长度
|
||||
* @param padChar 填充字符,默认为 "0"
|
||||
* @returns 填充后的字符串
|
||||
*/
|
||||
static padStart(str: string, length: number, padChar: string = "0"): string {
|
||||
while (str.length < length) {
|
||||
str = padChar + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**截取字符串,超过长度的用...代替
|
||||
* @param str 要处理的字符串
|
||||
* @param labelLimit 字符串长度限制
|
||||
@@ -367,13 +381,62 @@ export default class Utils {
|
||||
const days = Math.floor(diffSeconds / (60 * 60 * 24));
|
||||
const hours = Math.floor((diffSeconds % (60 * 60 * 24)) / 3600);
|
||||
const minutes = Math.floor((diffSeconds % 3600) / 60);
|
||||
console.log("vip失效剩余时间差(秒):", diffSeconds, "天:", days, "小时:", hours, "分钟:", minutes);
|
||||
console.log(
|
||||
"vip失效剩余时间差(秒):",
|
||||
diffSeconds,
|
||||
"天:",
|
||||
days,
|
||||
"小时:",
|
||||
hours,
|
||||
"分钟:",
|
||||
minutes
|
||||
);
|
||||
if (days > 0) {
|
||||
return `${days}${LanguageUtils.getText("purchasepanel.day")}`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours}${LanguageUtils.getText("purchasepanel.hour")}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
|
||||
return `${hours}${LanguageUtils.getText(
|
||||
"purchasepanel.hour"
|
||||
)}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
|
||||
}
|
||||
return `${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化聊天时间显示
|
||||
* @param timestamp 时间戳(毫秒),如果为null则显示"暂无聊天记录"
|
||||
* @returns 格式化的时间字符串
|
||||
* 格式规则:
|
||||
* - 一日内:显示时和分(HH:mm)
|
||||
* - 一周内:显示x天前
|
||||
* - 一个月内:显示x周前
|
||||
* - 一个月以上:显示"一个月以上"
|
||||
*/
|
||||
public static formatChatTime(timestamp: number | null): string {
|
||||
if (!timestamp) {
|
||||
return "暂无聊天记录";
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const chatDate = new Date(timestamp);
|
||||
const diffMs = now.getTime() - chatDate.getTime();
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (diffDays === 0) {
|
||||
// 一日内:显示时和分
|
||||
const hours = Utils.padStart(chatDate.getHours().toString(), 2);
|
||||
const minutes = Utils.padStart(chatDate.getMinutes().toString(), 2);
|
||||
return `${hours}:${minutes}`;
|
||||
} else if (diffDays < 7) {
|
||||
// 一周内:显示x天前
|
||||
return `${diffDays}${LanguageUtils.getText("purchasepanel.day")}}`;
|
||||
} else if (diffDays < 30) {
|
||||
// 一个月内:显示x周前
|
||||
const weeks = Math.floor(diffDays / 7);
|
||||
return `${weeks}${LanguageUtils.getText("purchasepanel.week")}`;
|
||||
} else {
|
||||
// 一个月以上:显示"一个月以上"
|
||||
return LanguageUtils.getText("purchasepanel.months");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
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";
|
||||
|
||||
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;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
// 从缓存池获取节点
|
||||
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[] {
|
||||
// TODO: 实现获取已解锁女孩列表逻辑
|
||||
// 需要实现的逻辑:
|
||||
// 1. 遍历 GirlData 中的所有分类
|
||||
// 2. 对每个分类中的每个女孩检查 getIsRelease 状态
|
||||
// 3. 返回所有已解锁女孩的 {category, id} 列表
|
||||
console.log("TODO: 实现获取已解锁女孩列表逻辑");
|
||||
return [10001, 10002];
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// 根据数据,刷新界面
|
||||
for (let id of ids) {
|
||||
let item = this.getItemFromPool();
|
||||
item.refreshData(id, this.node);
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "311c4e83-620c-41e2-9c37-623f4971f005",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -235,9 +235,15 @@ export class Web3PopPanel extends li_BaseView {
|
||||
const secs = seconds % 60;
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
||||
return `${Utils.padStart(hours.toString(), 2)}:${Utils.padStart(
|
||||
minutes.toString(),
|
||||
2
|
||||
)}:${Utils.padStart(secs.toString(), 2)}`;
|
||||
} else {
|
||||
return `${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
||||
return `${Utils.padStart(minutes.toString(), 2)}:${Utils.padStart(
|
||||
secs.toString(),
|
||||
2
|
||||
)}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +292,7 @@ export class Web3PopPanel extends li_BaseView {
|
||||
private resetButtonStates(): void {
|
||||
const copyBtn = this._nodeTab.CopyBtn;
|
||||
if (copyBtn) {
|
||||
const btnComponent = copyBtn.getComponent('Button');
|
||||
const btnComponent = copyBtn.getComponent("Button");
|
||||
if (btnComponent) {
|
||||
btnComponent.interactable = true;
|
||||
}
|
||||
@@ -294,7 +300,7 @@ export class Web3PopPanel extends li_BaseView {
|
||||
|
||||
const coinTypeSelectBtn = this._nodeTab.CoinTypeSelectBtn;
|
||||
if (coinTypeSelectBtn) {
|
||||
const btnComponent = coinTypeSelectBtn.getComponent('Button');
|
||||
const btnComponent = coinTypeSelectBtn.getComponent("Button");
|
||||
if (btnComponent) {
|
||||
btnComponent.interactable = true;
|
||||
}
|
||||
@@ -304,7 +310,7 @@ export class Web3PopPanel extends li_BaseView {
|
||||
private disableButtons(): void {
|
||||
const copyBtn = this._nodeTab.CopyBtn;
|
||||
if (copyBtn) {
|
||||
const btnComponent = copyBtn.getComponent('Button');
|
||||
const btnComponent = copyBtn.getComponent("Button");
|
||||
if (btnComponent) {
|
||||
btnComponent.interactable = false;
|
||||
}
|
||||
@@ -312,7 +318,7 @@ export class Web3PopPanel extends li_BaseView {
|
||||
|
||||
const coinTypeSelectBtn = this._nodeTab.CoinTypeSelectBtn;
|
||||
if (coinTypeSelectBtn) {
|
||||
const btnComponent = coinTypeSelectBtn.getComponent('Button');
|
||||
const btnComponent = coinTypeSelectBtn.getComponent("Button");
|
||||
if (btnComponent) {
|
||||
btnComponent.interactable = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
import { _decorator, Component, Label, Node, Sprite, UITransform } from "cc";
|
||||
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
||||
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
||||
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
||||
import { NavigationManager, PanelType } from "../manager/NavigationManager";
|
||||
import LanguageUtils from "../../Main/Common/LanguageUtils";
|
||||
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
|
||||
import { DataManager, DataId } from "../data/DataManager";
|
||||
import { GirlData } from "../data/GirlData";
|
||||
import { EnvData } from "../data/EnvData";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PastGirlListItem")
|
||||
export class PastGirlListItem extends Component {
|
||||
@property(Sprite)
|
||||
avatar: Sprite;
|
||||
@property(Label)
|
||||
girlName: Label;
|
||||
@property(Label)
|
||||
tags: Label;
|
||||
@property(Label)
|
||||
lastChatTime: Label; // 新增:最近聊天时间
|
||||
|
||||
@property(Node)
|
||||
starParent: Node;
|
||||
@property(Node)
|
||||
loading: Node;
|
||||
stars: Sprite[];
|
||||
|
||||
id: number = -1;
|
||||
nameKey: string;
|
||||
tagKey: string;
|
||||
category: number;
|
||||
baseNode: Node;
|
||||
|
||||
private onLanguageChangeCallback = () => {
|
||||
if (!this.girlName || !this.tags) return;
|
||||
|
||||
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
||||
let desc = "";
|
||||
const tags = LanguageUtils.getText(this.tagKey).split("|");
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
if (i != 0) desc += "\n";
|
||||
desc += tags[i];
|
||||
}
|
||||
this.tags.string = desc;
|
||||
};
|
||||
|
||||
protected onLoad(): void {
|
||||
Utils.addInnerEL(
|
||||
InnerMsgCode.LanguageChange,
|
||||
this,
|
||||
this.onLanguageChangeCallback
|
||||
);
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
Utils.removeInnerEL(
|
||||
InnerMsgCode.LanguageChange,
|
||||
this,
|
||||
this.onLanguageChangeCallback
|
||||
);
|
||||
}
|
||||
|
||||
refreshData( girlId: number, baseNode: Node) {
|
||||
if (!this.stars) {
|
||||
this.stars = this.starParent.getComponentsInChildren(Sprite);
|
||||
}
|
||||
|
||||
this.baseNode = baseNode;
|
||||
this.id = girlId;
|
||||
|
||||
// 数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
this.category = girlData.getGrilCategoryById(girlId);
|
||||
this.nameKey = girlData.getGrilName(this.category.toString(), this.id);
|
||||
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
||||
this.tagKey = girlData.getGrilTagKey(this.category.toString(), this.id);
|
||||
|
||||
// 标签显示
|
||||
let desc = "";
|
||||
const tags = LanguageUtils.getText(this.tagKey).split("|");
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
if (i != 0) desc += "|";
|
||||
desc += tags[i];
|
||||
}
|
||||
this.tags.string = desc;
|
||||
|
||||
// 由于都是已解锁的,直接显示聊天图标
|
||||
this.starParent.active = true;
|
||||
|
||||
// 加载头像
|
||||
let avatarPath = girlData.getGrilAvatar(this.category.toString(), this.id);
|
||||
this.loading.active = true;
|
||||
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
let newPath = envData.cdn + "/" + "Girls/" + avatarPath + ".png";
|
||||
ResManager.I.changeRemoteSpriteFrame(this.avatar, newPath, () => {
|
||||
let sizeTran = this.avatar.node.parent.getComponent(UITransform);
|
||||
Utils.adjustBgPixelRatioToSize(sizeTran.contentSize, this.avatar.node, 2);
|
||||
this.loading.active = false;
|
||||
});
|
||||
|
||||
// 显示星级(好感度)
|
||||
const star = girlData.getStar(this.category.toString(), this.id);
|
||||
for (let i = 0; i < this.stars.length; i++) {
|
||||
const element = this.stars[i];
|
||||
if (star > i) {
|
||||
ResManager.I.changeResourceSpriteFrame(element, "ui/common/heart");
|
||||
} else {
|
||||
ResManager.I.changeResourceSpriteFrame(
|
||||
element,
|
||||
"ui/common/heart_empty"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示最近聊天时间
|
||||
this.updateLastChatTime();
|
||||
}
|
||||
|
||||
// TODO: 实现获取最近聊天时间的逻辑
|
||||
// 需要从聊天记录中获取最后一条消息的时间戳
|
||||
private getLastChatTime(category: number, id: number): number | null {
|
||||
// TODO: 实现获取最近聊天时间的逻辑
|
||||
// 需要实现的逻辑:
|
||||
// 1. 获取该女孩的聊天记录
|
||||
// 2. 找到最后一条消息的时间戳
|
||||
// 3. 返回时间戳或null(如果没有聊天记录)
|
||||
console.log("TODO: 实现获取最近聊天时间逻辑");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新最近聊天时间显示
|
||||
private updateLastChatTime() {
|
||||
const lastTime = this.getLastChatTime(this.category, this.id);
|
||||
this.lastChatTime.string = Utils.formatChatTime(lastTime);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.id = -1;
|
||||
this.category = 0;
|
||||
this.nameKey = "";
|
||||
this.tagKey = "";
|
||||
this.baseNode = null;
|
||||
|
||||
// 重置UI状态
|
||||
this.node.active = false;
|
||||
this.loading.active = false;
|
||||
|
||||
// 清理文本内容
|
||||
if (this.girlName) this.girlName.string = "";
|
||||
if (this.tags) this.tags.string = "";
|
||||
if (this.lastChatTime) this.lastChatTime.string = "";
|
||||
|
||||
// 重置可见性状态
|
||||
if (this.starParent) this.starParent.active = false;
|
||||
|
||||
// 清理头像
|
||||
if (this.avatar) {
|
||||
this.avatar.spriteFrame = null;
|
||||
}
|
||||
|
||||
// 清理星级显示
|
||||
if (this.stars) {
|
||||
for (let star of this.stars) {
|
||||
star.spriteFrame = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClickDetail() {
|
||||
// 由于都是已解锁的女孩,直接跳转到角色详情
|
||||
// 先设置选中的角色ID
|
||||
NavigationManager.Instance.setSelectedGirlId(this.id);
|
||||
|
||||
// 通过switchToPanel切换到角色详情面板,保持动画和状态同步
|
||||
NavigationManager.Instance.switchToPanel(PanelType.GIRL_DETAIL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b311c230-da37-4205-8214-338a3a3286e7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user