Files
18xchat/assets/Scripts/chat18x/uiitems/GirlListItem.ts
T

194 lines
5.3 KiB
TypeScript
Raw Normal View History

2025-09-09 14:31:47 +08:00
import {
_decorator,
AssetManager,
Component,
Label,
Node,
randomRangeInt,
Sprite,
UITransform,
} from "cc";
2025-08-01 18:28:36 +08:00
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import Utils from "db://assets/Scripts/Main/Common/Utils";
import { NavigationManager, PanelType } from "../manager/NavigationManager";
2025-09-05 10:56:26 +08:00
import { PriceType } from "../../schema/schema";
import LanguageUtils from "../../Main/Common/LanguageUtils";
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
2025-09-02 16:38:01 +08:00
import { DataManager, DataId } from "../data/DataManager";
import { GirlData } from "../data/GirlData";
2025-09-16 15:58:44 +08:00
import { EnvData } from "../data/EnvData";
2025-09-21 20:18:24 +08:00
import { logger } from "db://assets/Scripts/Main/Common/Logger";
2025-07-30 21:52:26 +08:00
2025-07-22 16:43:10 +08:00
const { ccclass, property } = _decorator;
@ccclass("GirlListItem")
export class GirlListItem extends Component {
@property(Sprite)
avatar: Sprite;
@property(Label)
girlName: Label;
@property(Label)
2025-07-30 21:52:26 +08:00
tags: Label;
2025-09-09 14:31:47 +08:00
2025-07-30 21:52:26 +08:00
@property(Node)
2025-09-09 14:31:47 +08:00
chatIcon: Node;
2025-07-30 21:52:26 +08:00
@property(Node)
2025-08-11 16:08:59 +08:00
starParent: Node;
2025-09-11 15:01:03 +08:00
@property(Node)
loading: Node;
2025-09-09 14:31:47 +08:00
stars: Sprite[];
2025-07-22 16:43:10 +08:00
id: number = -1;
2025-08-12 19:49:50 +08:00
nameKey: string;
tagKey: string;
2025-09-02 16:38:01 +08:00
category: number;
2025-08-29 14:21:46 +08:00
private onLanguageChangeCallback = () => {
if (!this.girlName || !this.tags) return;
2025-08-29 14:21:46 +08:00
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;
};
2025-08-12 19:49:50 +08:00
protected onLoad(): void {
2025-08-29 14:21:46 +08:00
Utils.addInnerEL(
InnerMsgCode.LanguageChange,
this,
this.onLanguageChangeCallback
);
2025-08-12 19:49:50 +08:00
}
2025-08-29 14:21:46 +08:00
2025-08-12 19:49:50 +08:00
protected onDestroy(): void {
2025-08-29 14:21:46 +08:00
Utils.removeInnerEL(
InnerMsgCode.LanguageChange,
this,
this.onLanguageChangeCallback
);
2025-08-12 19:49:50 +08:00
}
2025-07-25 18:27:30 +08:00
baseNode: Node;
2025-09-02 16:38:01 +08:00
refreshData(category: number, girlId: number, baseNode: Node) {
2025-09-09 14:31:47 +08:00
if (!this.stars) {
this.stars = this.starParent.getComponentsInChildren(Sprite);
}
2025-09-02 16:38:01 +08:00
this.category = category;
2025-07-30 21:52:26 +08:00
this.baseNode = baseNode;
2025-09-02 16:38:01 +08:00
this.id = girlId;
// 数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
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);
2025-09-09 18:16:13 +08:00
// 是否已经解锁
const isRelease = girlData.getIsRelease(this.category.toString(), this.id);
2025-08-11 16:08:59 +08:00
let desc = "";
2025-09-02 16:38:01 +08:00
const tags = LanguageUtils.getText(this.tagKey).split("|");
2025-08-12 19:49:50 +08:00
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "|";
desc += tags[i];
2025-07-30 21:52:26 +08:00
}
this.tags.string = desc;
2025-09-09 14:31:47 +08:00
let priceType = girlData.getGrilPriceType(
this.category.toString(),
this.id
);
2025-09-09 23:19:28 +08:00
2025-09-26 17:53:19 +08:00
this.starParent.active = true;
this.chatIcon.active = true;
let avatarPath = girlData.getGrilAvatar(this.category.toString(), this.id);
2025-09-11 15:01:03 +08:00
this.loading.active = true;
2025-09-11 13:29:08 +08:00
2025-09-16 15:58:44 +08:00
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
let newPath = envData.cdn + "/" + "Girls/" + avatarPath + ".png";
2025-09-11 00:03:22 +08:00
//listAvatarPath = listAvatarPath.replace("Avatar", "avatar"); //临时
2025-09-17 18:51:08 +08:00
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;
});
2025-08-01 18:28:36 +08:00
2025-09-10 15:48:27 +08:00
const star = girlData.getStar(this.category.toString(), this.id);
2025-09-21 20:18:24 +08:00
logger.log("好感度:" + star);
2025-09-09 14:31:47 +08:00
for (let i = 0; i < this.stars.length; i++) {
const element = this.stars[i];
2025-09-10 15:48:27 +08:00
if (star > i) {
2025-09-09 14:31:47 +08:00
ResManager.I.changeResourceSpriteFrame(element, "ui/common/heart");
} else {
ResManager.I.changeResourceSpriteFrame(
element,
"ui/common/heart_empty"
);
}
}
2025-07-25 15:20:02 +08:00
}
2025-07-22 16:43:10 +08:00
2025-09-09 16:09:10 +08:00
refreshBuy(success: boolean) {
if (success) {
this.refreshData(this.category, this.id, this.baseNode);
}
}
2025-09-15 11:46:55 +08:00
reset() {
this.id = -1;
this.category = 0;
this.nameKey = "";
this.tagKey = "";
this.baseNode = null;
2025-09-17 18:51:08 +08:00
2025-09-15 11:46:55 +08:00
// 重置UI状态
this.node.active = false;
this.loading.active = false;
2025-09-17 18:51:08 +08:00
2025-09-15 11:46:55 +08:00
// 清理文本内容
if (this.girlName) this.girlName.string = "";
if (this.tags) this.tags.string = "";
2025-09-17 18:51:08 +08:00
2025-09-15 11:46:55 +08:00
if (this.starParent) this.starParent.active = false;
if (this.chatIcon) this.chatIcon.active = false;
2025-09-17 18:51:08 +08:00
2025-09-15 11:46:55 +08:00
// 清理头像
if (this.avatar) {
this.avatar.spriteFrame = null;
}
2025-09-17 18:51:08 +08:00
2025-09-15 11:46:55 +08:00
// 清理星级显示
if (this.stars) {
for (let star of this.stars) {
star.spriteFrame = null;
}
}
}
2025-07-22 16:43:10 +08:00
onClickDetail() {
2025-09-09 18:16:13 +08:00
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 是否已经解锁
const isRelease = girlData.getIsRelease(this.category.toString(), this.id);
NavigationManager.Instance.setSelectedGirlId(this.id);
// 通过switchToPanel切换到角色详情面板,保持动画和状态同步
NavigationManager.Instance.switchToPanel(PanelType.GIRL_DETAIL);
// if (isRelease) {
// // 先设置选中的角色ID
// } else {
// //未解锁
// NavigationManager.Instance.openPopupPanel("GirlListPopupPanel", {
// base: this,
// category: this.category,
// id: this.id,
// });
// }
2025-07-22 16:43:10 +08:00
}
}