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

102 lines
2.9 KiB
TypeScript
Raw Normal View History

2025-08-11 16:08:59 +08:00
import { _decorator, Component, Label, Node, Sprite, UITransform } from "cc";
2025-08-12 16:58:02 +08:00
import { Config18x } from "db://assets/Scripts/Main/Config/Config18x";
2025-08-11 16:08:59 +08:00
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
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 } from "../manager/NavigationManager";
import { Girl, PriceType } from "../../schema/schema";
import LanguageUtils from "../../Main/Common/LanguageUtils";
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
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-07-22 16:43:10 +08:00
@property(Label)
price: Label;
@property(Node)
2025-07-30 21:52:26 +08:00
freeNode: Node;
@property(Node)
tryNode: Node;
@property(Node)
2025-07-22 16:43:10 +08:00
chatBtn: Node;
2025-07-30 21:52:26 +08:00
@property(Node)
2025-08-11 16:08:59 +08:00
starParent: Node;
2025-07-22 16:43:10 +08:00
id: number = -1;
2025-08-12 19:49:50 +08:00
nameKey: string;
tagKey: string;
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;
};
2025-08-12 19:49:50 +08:00
protected onLoad(): void {
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, this.onLanguageChangeCallback);
2025-08-12 19:49:50 +08:00
}
2025-08-12 19:49:50 +08:00
protected onDestroy(): void {
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-08-12 16:58:02 +08:00
refreshData(data: Girl, baseNode: Node) {
2025-07-30 21:52:26 +08:00
this.baseNode = baseNode;
2025-07-25 15:20:02 +08:00
this.id = data.id;
2025-08-12 19:49:50 +08:00
this.nameKey = data.nameKey;
this.girlName.string = LanguageUtils.getText(data.nameKey);
this.tagKey = data.tagKey;
2025-08-11 16:08:59 +08:00
let desc = "";
2025-08-12 19:49:50 +08:00
const tags = LanguageUtils.getText(data.tagKey).split("|");
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-08-12 16:58:02 +08:00
this.price.node.active = data.priceType == PriceType.pay;
this.freeNode.active = data.priceType == PriceType.free;
this.tryNode.active = data.priceType == PriceType.first_time_free;
2025-07-30 21:52:26 +08:00
2025-08-11 16:08:59 +08:00
ResManager.I.changeBundleSpriteFrame(
this.avatar,
2025-08-12 16:58:02 +08:00
data.avatarPath,
2025-08-11 16:08:59 +08:00
"Chat18x",
() => {
let sizeTran = this.avatar.node.parent.getComponent(UITransform);
Utils.adjustBgPixelRatioToSize(
sizeTran.contentSize,
this.avatar.node,
2
);
}
);
2025-08-01 18:28:36 +08:00
2025-08-11 16:08:59 +08:00
for (let i = 0; i < 5; i++) {
this.starParent.children[i].active = i < data.starCount;
2025-07-30 21:52:26 +08:00
}
2025-07-25 15:20:02 +08:00
}
2025-07-22 16:43:10 +08:00
onClickDetail() {
2025-08-11 16:08:59 +08:00
NavigationManager.Instance.navigateToGirlDetail(this.id);
2025-07-30 21:52:26 +08:00
ViewManager.I.closeView(this.baseNode);
2025-07-22 16:43:10 +08:00
}
update(deltaTime: number) {}
}