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"; import { DataManager, DataId } from "../../data/DataManager"; import { GirlData } from "../../data/GirlData"; import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService"; import proto from 'db://assets/Scripts/proto/proto.pb.js'; 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; async refresh(index: number) { // TODO,暂时这样获取,修改后从GirlData获取 const girlConfig = ConfigManager.tables.TbGirls.get(this.id); this.category = girlConfig.category; // 请求详细数据 const reqData = { id: this.id, }; // let res = await GirlService.I.reqGetGirlDetail(reqData); // console.log("看看响应数据:", res); // if (res && res.code === proto.cs.EnmRetCode.SUCCESS) { // // 保存数据 // const girlData = DataManager.I.getDataById(DataId.Girl); // girlData.setGirlDetails(this.category.toString(), res.data); // // 根据数据,刷新界面 // this.nameKey = girlData.getGrilName(this.category, this.id); // this.girlName.string = LanguageUtils.getText(this.nameKey); // this.desc.string = girlData.getGrilDesc(this.category, this.id); // let desc = ""; // this.tagKey = girlData.getGrilTagKey(this.category, this.id); // 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; // for (let i = 0; i < 5; i++) { // this.starParent.children[i].active = i < 5; // } // let age = girlData.getGrilAge(this.category, this.id); // this.descAge.string = // LanguageUtils.getText("girldetailpanel.age") + age.toString(); // // TODO // const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id); // ResManager.I.changeBundleVideo( // this.avatarVideo, // dataDetail.commercialVideos[0].path, // "Chat18x" // ); // // 也立即尝试调整(以防已经加载完成) // this.adjustVideoScale(); // this.vids = dataDetail.commercialVideos.slice(0); // this.refreshImgs(dataDetail.commercialImages); // } const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id); console.log(dataDetail); const data = ConfigManager.tables.TbGirls.get(this.id); 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); this.refreshImgs(dataDetail.commercialImages); } vids: purchase.CommercialVideo[]; bindImgToggle() { const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id); const images = dataDetail.commercialImages; this.refreshImgs(images); } bindVideoToggle() { this.refreshImgs(this.vids); } refreshImgs( resouces: purchase.CommercialImage[] | purchase.CommercialVideo[] ) { for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) { this.imgsLayout.children[i].destroy(); } for (let i = 1; i < resouces.length; i++) { const resource = resouces[i]; let newNode = instantiate(this.imgItemInst.node); let item = newNode.getComponent(DetailImageItem); item.refresh(resource, this); 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"); } }