Files
18xchat/assets/Scripts/chat18x/uiitems/GirlListItem.ts
T
xionglijia 7722ccf694 ui模块优化 全部navigationmanager管理
实现pastgirllistpanel逻辑
完善图集
2025-09-21 12:05:34 +08:00

227 lines
6.5 KiB
TypeScript

import {
_decorator,
AssetManager,
Component,
Label,
Node,
randomRangeInt,
Sprite,
UITransform,
} from "cc";
import { Config18x } from "db://assets/Scripts/Main/Config/Config18x";
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 { PriceType } from "../../schema/schema";
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("GirlListItem")
export class GirlListItem extends Component {
@property(Sprite)
avatar: Sprite;
@property(Label)
girlName: Label;
@property(Label)
tags: Label;
@property(Label)
price: Label;
@property(Node)
freeNode: Node;
@property(Node)
unreleaseCover: Node;
@property(Node)
chatIcon: Node;
@property(Node)
starParent: Node;
@property(Node)
loading: Node;
stars: Sprite[];
id: number = -1;
nameKey: string;
tagKey: string;
category: number;
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
);
}
baseNode: Node;
refreshData(category: number, girlId: number, baseNode: Node) {
if (!this.stars) {
this.stars = this.starParent.getComponentsInChildren(Sprite);
}
this.category = category;
this.baseNode = baseNode;
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);
// 是否已经解锁
const isRelease = girlData.getIsRelease(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;
let priceType = girlData.getGrilPriceType(
this.category.toString(),
this.id
);
this.price.string = girlData
.getGrilOriginalPrice(this.category.toString(), this.id)
.toString();
if (isRelease) {
this.price.node.active = false;
this.freeNode.active = false;
this.starParent.active = true;
this.chatIcon.active = true;
this.unreleaseCover.active = false;
} else {
this.unreleaseCover.active = true;
this.chatIcon.active = false;
if (priceType == PriceType.free) {
this.price.node.active = false;
this.freeNode.active = true;
this.starParent.active = true;
} else {
this.price.node.active = true;
this.freeNode.active = false;
this.starParent.active = false;
}
}
// this.price.node.active = priceType == PriceType.pay;
// this.freeNode.active = priceType == PriceType.free;
//this.tryNode.active = priceType == PriceType.first_time_free;
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";
//listAvatarPath = listAvatarPath.replace("Avatar", "avatar"); //临时
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);
console.log("好感度:" + star);
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"
);
}
}
}
refreshBuy(success: boolean) {
if (success) {
this.refreshData(this.category, this.id, this.baseNode);
}
}
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.price) this.price.string = "";
// 重置可见性状态
if (this.price?.node) this.price.node.active = false;
if (this.freeNode) this.freeNode.active = false;
if (this.starParent) this.starParent.active = false;
if (this.chatIcon) this.chatIcon.active = false;
if (this.unreleaseCover) this.unreleaseCover.active = false;
// 清理头像
if (this.avatar) {
this.avatar.spriteFrame = null;
}
// 清理星级显示
if (this.stars) {
for (let star of this.stars) {
star.spriteFrame = null;
}
}
}
onClickDetail() {
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 是否已经解锁
const isRelease = girlData.getIsRelease(this.category.toString(), this.id);
if (isRelease) {
// 先设置选中的角色ID
NavigationManager.Instance.setSelectedGirlId(this.id);
// 通过switchToPanel切换到角色详情面板,保持动画和状态同步
NavigationManager.Instance.switchToPanel(PanelType.GIRL_DETAIL);
} else {
//未解锁
NavigationManager.Instance.openPopupPanel("GirlListPopupPanel", {
base: this,
category: this.category,
id: this.id,
});
}
}
}