219 lines
6.1 KiB
TypeScript
219 lines
6.1 KiB
TypeScript
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,
|
|
PageTransitionType,
|
|
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";
|
|
import { ChatHistoryManager } from "../manager/ChatHistoryManager";
|
|
import { ThemeData } from "../data/ThemeData";
|
|
|
|
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)
|
|
freeTag: Node;
|
|
|
|
@property(UITransform)
|
|
categoryBg: UITransform;
|
|
@property(Label)
|
|
categoryTxt: Label;
|
|
|
|
@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): number {
|
|
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);
|
|
|
|
this.freeTag.active = girlData.isGirlFreeType(
|
|
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"
|
|
);
|
|
}
|
|
}
|
|
|
|
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
|
|
const cat = girlData.getGrilCategoryById(this.id);
|
|
let key = themeData.getLanKeyById(1001 + cat);
|
|
this.categoryTxt.string = LanguageUtils.getText(key);
|
|
this.scheduleOnce(() => {
|
|
const size = this.categoryTxt.getComponent(UITransform).contentSize;
|
|
this.categoryBg.setContentSize(
|
|
size.x + 60,
|
|
this.categoryBg.contentSize.y
|
|
);
|
|
}, 0);
|
|
|
|
// 显示最近聊天时间
|
|
return this.updateLastChatTime();
|
|
}
|
|
|
|
private getLastChatTime(id: number): number | null {
|
|
const GirlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
return GirlData.getLatestChatRecordTimestamp(
|
|
this.category.toString(),
|
|
this.id
|
|
);
|
|
}
|
|
|
|
// 更新最近聊天时间显示
|
|
private updateLastChatTime(): number {
|
|
const lastTime = this.getLastChatTime(this.id);
|
|
this.lastChatTime.string = Utils.formatChatTime(lastTime);
|
|
return 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
onClickGirl() {
|
|
// 由于都是已解锁的女孩,直接打开聊天面板作为子面板
|
|
// 先设置选中的角色ID
|
|
NavigationManager.Instance.setSelectedGirlId(this.id);
|
|
|
|
// 通过openSubPanel打开ChatPanel作为子面板
|
|
const chatData = { base: this.baseNode };
|
|
NavigationManager.Instance.openSubPanel(
|
|
"ChatPanel",
|
|
this.baseNode,
|
|
chatData,
|
|
{
|
|
openAnimation: PageTransitionType.SLIDE_LEFT,
|
|
closeAnimation: PageTransitionType.SLIDE_RIGHT,
|
|
}
|
|
);
|
|
}
|
|
}
|