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