229 lines
6.9 KiB
TypeScript
229 lines
6.9 KiB
TypeScript
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: number;
|
|
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);
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
// 保存数据
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
girlData.setGirlDetails(this.category.toString(), res.data);
|
|
// 根据数据,刷新界面
|
|
this.nameKey = girlData.getGrilName(this.category.toString(), this.id);
|
|
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
|
this.desc.string = girlData.getGrilDesc(this.category.toString(), this.id);
|
|
|
|
let desc = "";
|
|
this.tagKey = girlData.getGrilTagKey(this.category.toString(), 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.toString(), this.id);
|
|
this.descAge.string =
|
|
LanguageUtils.getText("girldetailpanel.age") + age.toString();
|
|
|
|
const firstPath = girlData.getGrilVideoPath(this.category.toString(), this.id, 0);
|
|
ResManager.I.changeBundleVideo(
|
|
this.avatarVideo,
|
|
firstPath,
|
|
"Chat18x"
|
|
);
|
|
|
|
let allPhotoDataCount = girlData.getAllGrilPhotoDataCount(this.category.toString(), this.id);
|
|
// 也立即尝试调整(以防已经加载完成)
|
|
this.adjustVideoScale();
|
|
this.refreshImgs(1, this.category, this.id, allPhotoDataCount);
|
|
}
|
|
}
|
|
|
|
bindImgToggle() {
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
let allPhotoDataCount = girlData.getAllGrilPhotoDataCount(this.category.toString(), this.id);
|
|
this.refreshImgs(1, this.category, this.id, allPhotoDataCount);
|
|
}
|
|
|
|
bindVideoToggle() {
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
let allVideoDataCount = girlData.getAllGrilVideoDataCount(this.category.toString(), this.id);
|
|
this.refreshImgs(2, this.category, this.id, allVideoDataCount);
|
|
}
|
|
|
|
refreshImgs(
|
|
type: number,
|
|
category: number,
|
|
id: number,
|
|
count: number
|
|
) {
|
|
for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) {
|
|
this.imgsLayout.children[i].destroy();
|
|
}
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
let newNode = instantiate(this.imgItemInst.node);
|
|
let item = newNode.getComponent(DetailImageItem);
|
|
item.refresh(this, type, category, id, i);
|
|
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");
|
|
}
|
|
}
|