Files
18xchat/assets/Scripts/chat18x/ui/panels/GirlDetailPanel.ts
T

213 lines
5.7 KiB
TypeScript
Raw Normal View History

2025-08-13 15:37:15 +08:00
import {
_decorator,
Label,
Node,
Sprite,
VideoPlayer,
instantiate,
UITransform,
} from "cc";
2025-07-25 18:27:30 +08:00
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
2025-08-01 18:28:36 +08:00
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import { DetailImageItem } from "../../uiitems/DetailImageItem";
2025-08-11 16:08:59 +08:00
import { NavigationManager } from "../../manager/NavigationManager";
2025-08-12 16:58:02 +08:00
import ConfigManager from "../../manager/ConfigManager";
2025-08-12 19:49:50 +08:00
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import Utils from "../../../Main/Common/Utils";
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
2025-08-25 20:15:42 +08:00
import { SimpleToggle } from "../components/SimpleToggle";
import { GirlDetail, purchase } from "../../../schema/schema";
2025-08-01 18:28:36 +08:00
2025-07-22 16:43:10 +08:00
const { ccclass, property } = _decorator;
@ccclass("GirlDetailPanel")
2025-07-25 18:27:30 +08:00
export class GirlDetailPanel extends li_BaseView {
2025-07-22 16:43:10 +08:00
@property(Sprite)
avatar: Sprite;
2025-08-01 18:28:36 +08:00
@property(VideoPlayer)
avatarVideo: VideoPlayer;
2025-07-22 16:43:10 +08:00
@property(Label)
girlName: Label;
2025-07-30 21:52:26 +08:00
2025-08-25 20:15:42 +08:00
@property(SimpleToggle)
imgToggle: SimpleToggle = null;
@property(SimpleToggle)
videoToggle: SimpleToggle = null;
2025-07-30 21:52:26 +08:00
@property(Node)
starParent: Node;
@property(Label)
tags: Label;
@property(Label)
descAge: Label;
2025-07-22 16:43:10 +08:00
@property(Label)
desc: Label;
@property(Node)
chatBtn: Node;
id = 0;
2025-07-25 15:20:02 +08:00
2025-08-01 18:28:36 +08:00
@property(DetailImageItem)
2025-08-12 16:58:02 +08:00
imgItemInst: DetailImageItem;
2025-08-01 18:28:36 +08:00
@property(Node)
2025-08-12 16:58:02 +08:00
imgsLayout: Node;
2025-08-01 18:28:36 +08:00
2025-08-12 16:58:02 +08:00
openUIDataCT(data) {
2025-07-25 18:27:30 +08:00
this.id = data;
2025-07-30 21:52:26 +08:00
}
onLoadCT() {
super.onLoadCT();
2025-08-12 16:58:02 +08:00
this.imgItemInst.node.active = false;
2025-07-25 18:27:30 +08:00
this.refresh(this.id);
2025-08-12 19:49:50 +08:00
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
2025-08-15 18:17:12 +08:00
this.girlName.string = LanguageUtils.getText(this.nameKey);
2025-08-12 19:49:50 +08:00
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-25 20:15:42 +08:00
this.imgToggle.callback = this.bindImgToggle.bind(this);
this.videoToggle.callback = this.bindVideoToggle.bind(this);
// 添加视频加载完成回调
this.avatarVideo.node.on(
VideoPlayer.EventType.READY_TO_PLAY,
() => {
this.adjustVideoScale();
},
this
);
2025-07-25 18:27:30 +08:00
}
2025-08-12 16:58:02 +08:00
setVideEnable(enable: boolean) {
2025-08-01 18:28:36 +08:00
this.avatarVideo.enabled = enable;
2025-08-12 16:58:02 +08:00
if (enable) {
2025-08-01 18:28:36 +08:00
this.avatarVideo.play();
}
}
2025-08-13 15:37:15 +08:00
adjustVideoScale() {
if (!this.avatarVideo || !this.avatarVideo.node.parent) {
return;
}
const tryAdjustScale = () => {
const parentTransform =
this.avatarVideo.node.parent.getComponent(UITransform);
const videoTransform = this.avatarVideo.node.getComponent(UITransform);
2025-08-26 14:23:02 +08:00
if (parentTransform && videoTransform && videoTransform.height > 0) {
const scale = parentTransform.height / videoTransform.height;
2025-08-13 15:37:15 +08:00
this.avatarVideo.node.setScale(scale, scale, 1);
2025-08-15 18:17:12 +08:00
console.log(
`Video scaled to: ${scale}, parent height: ${parentTransform.height}, video height: ${videoTransform.height}`
);
2025-08-13 15:37:15 +08:00
return true;
}
return false;
};
// 立即尝试一次
if (!tryAdjustScale()) {
// 如果失败,延迟尝试
this.scheduleOnce(() => {
if (!tryAdjustScale()) {
// 再次延迟尝试
this.scheduleOnce(() => {
tryAdjustScale();
}, 0.5);
}
}, 0.1);
}
}
2025-08-12 19:49:50 +08:00
nameKey: string;
tagKey: string;
2025-08-12 20:37:46 +08:00
category;
2025-08-12 16:58:02 +08:00
refresh(index: number) {
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
2025-08-25 20:15:42 +08:00
console.log(dataDetail);
2025-08-12 16:58:02 +08:00
const data = ConfigManager.tables.TbGirls.get(this.id);
2025-08-12 20:37:46 +08:00
this.category = data.category;
2025-08-12 19:49:50 +08:00
this.nameKey = data.nameKey;
2025-08-15 18:17:12 +08:00
this.girlName.string = LanguageUtils.getText(data.nameKey);
2025-08-01 18:28:36 +08:00
2025-08-12 16:58:02 +08:00
this.desc.string = dataDetail.detailDesc;
let desc = "";
2025-08-12 19:49:50 +08:00
this.tagKey = data.tagKey;
const tags = LanguageUtils.getText(data.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
2025-08-15 18:17:12 +08:00
if (i != 0) desc += "|";
2025-08-12 19:49:50 +08:00
desc += tags[i];
2025-07-30 21:52:26 +08:00
}
this.tags.string = desc;
2025-08-12 16:58:02 +08:00
for (let i = 0; i < 5; i++) {
this.starParent.children[i].active = i < 5;
2025-07-30 21:52:26 +08:00
}
this.descAge.string =
LanguageUtils.getText("girldetailpanel.age") + data.age.toString();
2025-08-12 16:58:02 +08:00
this.desc.string = dataDetail.detailDesc;
2025-07-30 21:52:26 +08:00
2025-08-25 20:15:42 +08:00
ResManager.I.changeBundleVideo(
this.avatarVideo,
dataDetail.commercialVideos[0].path,
2025-08-25 20:15:42 +08:00
"Chat18x"
);
// 也立即尝试调整(以防已经加载完成)
this.adjustVideoScale();
this.vids = dataDetail.commercialVideos.slice(0);
2025-08-29 16:23:59 +08:00
this.refreshImgs(dataDetail.commercialImages);
2025-07-22 16:43:10 +08:00
}
2025-08-25 20:15:42 +08:00
vids: purchase.CommercialVideo[];
2025-08-25 20:15:42 +08:00
bindImgToggle() {
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
2025-08-29 16:23:59 +08:00
const images = dataDetail.commercialImages;
2025-08-29 16:23:59 +08:00
this.refreshImgs(images);
2025-08-25 20:15:42 +08:00
}
bindVideoToggle() {
2025-08-29 16:23:59 +08:00
this.refreshImgs(this.vids);
2025-08-25 20:15:42 +08:00
}
2025-08-29 16:23:59 +08:00
refreshImgs(
resouces: purchase.CommercialImage[] | purchase.CommercialVideo[]
) {
2025-08-25 20:15:42 +08:00
for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) {
this.imgsLayout.children[i].destroy();
}
2025-08-29 16:23:59 +08:00
for (let i = 1; i < resouces.length; i++) {
const resource = resouces[i];
2025-08-25 20:15:42 +08:00
let newNode = instantiate(this.imgItemInst.node);
let item = newNode.getComponent(DetailImageItem);
2025-08-29 16:23:59 +08:00
item.refresh(resource, this);
2025-08-25 20:15:42 +08:00
newNode.active = true;
this.imgsLayout.addChild(newNode);
}
}
2025-07-22 16:43:10 +08:00
OnClickChatBtn() {
2025-08-25 20:15:42 +08:00
// 使用带过渡动画的导航方法
NavigationManager.Instance.navigateToChatWithTransition(this.id, this);
// 注意:不在这里直接调用onClose,而是在动画完成后由NavigationManager调用
2025-07-25 18:27:30 +08:00
}
2025-08-12 16:58:02 +08:00
returnBtn() {
2025-07-25 18:27:30 +08:00
this.onClose();
2025-08-12 20:37:46 +08:00
NavigationManager.Instance.navigateToGirlList(this.category);
2025-07-25 18:27:30 +08:00
//ViewManager.I.openBundlesView("GirlListPanel");
2025-07-22 16:43:10 +08:00
}
}