update 音效 - 主题图
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
UITransform,
|
||||
VideoPlayer,
|
||||
Size,
|
||||
Vec3,
|
||||
} from "cc";
|
||||
// 首先加载 polyfills 以确保兼容性
|
||||
import "../../utils/polyfills";
|
||||
@@ -29,6 +30,7 @@ import { PayToTalkSubpanel } from "./PayToTalkSubpanel";
|
||||
import { DataId, DataManager } from "../../data/DataManager";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
import { SceneBgVideoLayer } from "../../../Sub/UI/SceneBgVideoLayer";
|
||||
import { NavigationManager } from "../../manager/NavigationManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ChatPanel")
|
||||
@@ -70,7 +72,6 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
private _nodeTab: any = {};
|
||||
|
||||
nameKey: string;
|
||||
private commercialVideos: purchase.CommercialVideo[] = [];
|
||||
private currentEmotion: VideoEmotion | null = null;
|
||||
|
||||
private onLanguageChangeCallback = () => {
|
||||
@@ -83,7 +84,6 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
typeof data === "object" && data.roleId !== undefined
|
||||
? data.roleId
|
||||
: data;
|
||||
const withAnimation = typeof data === "object" && data.withSlideTransition;
|
||||
|
||||
// 检查是否是切换角色
|
||||
const isRoleSwitch = this.id && this.id !== newRoleId;
|
||||
@@ -91,12 +91,10 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
this.id = newRoleId;
|
||||
this.categoryId = data.categoryId;
|
||||
// 如果标记了需要滑入动画,则执行动画
|
||||
if (withAnimation && this.node && this.node.isValid) {
|
||||
// 延迟一帧执行动画,确保节点已正确加载到场景中
|
||||
this.scheduleOnce(() => {
|
||||
UITransitionHelper.slideInFromRight(this.node, 0.3);
|
||||
}, 0);
|
||||
}
|
||||
// 延迟一帧执行动画,确保节点已正确加载到场景中
|
||||
this.scheduleOnce(() => {
|
||||
UITransitionHelper.slideInFromRight(this.node, 0.3);
|
||||
}, 0);
|
||||
|
||||
// 获取ChatController单例并绑定当前Panel
|
||||
this.chatController = ChatController.Instance;
|
||||
@@ -122,10 +120,15 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetSize;
|
||||
videoAreaPos;
|
||||
onLoadCT() {
|
||||
Utils.parseNode(this.node, this._nodeTab);
|
||||
|
||||
// 获取 videoArea 的尺寸和位置
|
||||
this.targetSize = this.videoArea.contentSize;
|
||||
this.videoAreaPos = new Vec3(540, 1170, 0);
|
||||
|
||||
this.register();
|
||||
this.refresh();
|
||||
this.payToTalkPanel.node.active = false;
|
||||
@@ -186,15 +189,6 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
this.onEmotionInitialized
|
||||
);
|
||||
|
||||
// Cleanup video event listeners
|
||||
if (this.videoLayer && this.videoLayer.node) {
|
||||
this.videoLayer.node.off(
|
||||
VideoPlayer.EventType.READY_TO_PLAY,
|
||||
this.adjustVideoScale,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
// 解绑ChatController(不销毁,因为它是单例)
|
||||
if (this.chatController) {
|
||||
this.chatController.unbindView();
|
||||
@@ -202,31 +196,10 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
}
|
||||
}
|
||||
refresh() {
|
||||
//this.id = id;
|
||||
|
||||
// 通过ChatController获取角色数据
|
||||
//const roleData = this.chatController.getRoleData();
|
||||
//if (!roleData || !roleData.basic) return;
|
||||
|
||||
//const data = roleData.basic;
|
||||
//const dataDetail = roleData.detail;
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
|
||||
this.nameKey = girlData.getGrilName(this.categoryId, this.id);
|
||||
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
||||
// ResManager.I.changeBundleSpriteFrame(
|
||||
// this.girlImg,
|
||||
// data.avatarPath,
|
||||
// "Girls",
|
||||
// () => {
|
||||
// let sizeTran = this.girlImg.node.parent.getComponent(UITransform);
|
||||
// Utils.adjustBgPixelRatioToSize(
|
||||
// sizeTran.contentSize,
|
||||
// this.girlImg.node,
|
||||
// 2
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
|
||||
// 通过ChatController获取商业视频数据
|
||||
const chatModel = this.chatController.getChatModel();
|
||||
@@ -249,84 +222,35 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
`Loading initial video: ${initialVideo} (emotion: ${VideoEmotion[initialVideo]})`
|
||||
);
|
||||
|
||||
// 获取 videoArea 的尺寸
|
||||
const targetSize = this.videoArea
|
||||
? new Size(this.videoArea.width, this.videoArea.height)
|
||||
: new Size(600, 800);
|
||||
|
||||
// Set current emotion to the loaded video's emotion
|
||||
this.currentEmotion = this.chatController.getCurrentEmotion();
|
||||
|
||||
// 使用新的统一 playVideo 方法
|
||||
const videoAreaPos = this.videoArea
|
||||
? this.videoArea.node.getWorldPosition()
|
||||
: undefined;
|
||||
// 使用新的统一 playVideo 方法,现在它会自动处理缩放和位置
|
||||
|
||||
this.videoLayer.playVideo(initialVideo, {
|
||||
loop: true,
|
||||
size: targetSize,
|
||||
position: videoAreaPos,
|
||||
size: this.targetSize,
|
||||
position: this.videoAreaPos,
|
||||
});
|
||||
|
||||
// 延迟调整视频缩放
|
||||
this.scheduleOnce(() => {
|
||||
this.adjustVideoScale();
|
||||
}, 0.1);
|
||||
// 注意:移除了 adjustVideoScale() 调用,因为 playVideo 现在会自动处理缩放和位置
|
||||
}
|
||||
} else {
|
||||
this.commercialVideos = [];
|
||||
this.currentEmotion = null; // Reset current emotion when no videos available
|
||||
console.log("No SceneBgVideoLayer available for role", this.id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 此方法已废弃,现在由 SceneBgVideoLayer.playVideo() 自动处理缩放和位置
|
||||
* 保留此方法仅为了兼容性,但不再主动调用
|
||||
*/
|
||||
adjustVideoScale() {
|
||||
if (!this.videoLayer || !this.videoArea) {
|
||||
console.error("ChatPanel: SceneBgVideoLayer 或 videoArea 不可用");
|
||||
return;
|
||||
}
|
||||
|
||||
const tryAdjustScale = () => {
|
||||
const videoPlayer = this.videoLayer.getVideoPlayer();
|
||||
if (!videoPlayer) return false;
|
||||
|
||||
const videoTransform = videoPlayer.node.getComponent(UITransform);
|
||||
if (videoTransform && videoTransform.height > 0) {
|
||||
// 计算缩放比例,使视频高度填满 videoArea
|
||||
const scale = this.videoArea.height / videoTransform.height;
|
||||
|
||||
// 设置视频缩放
|
||||
this.videoLayer.setVideoScale(scale);
|
||||
|
||||
// 获取 videoArea 的世界坐标中心点
|
||||
const videoAreaWorldPos = this.videoArea.node.getWorldPosition();
|
||||
|
||||
// 使用新的 playVideo 方法的位置参数,如果需要更新位置
|
||||
// 由于视频已经在播放,这里只调整缩放
|
||||
// 位置调整已在 playVideo 中处理
|
||||
|
||||
console.log(
|
||||
`ChatPanel: 视频缩放到 ${scale}, videoArea高度: ${this.videoArea.height}, 视频高度: ${videoTransform.height}`
|
||||
);
|
||||
console.log(
|
||||
`ChatPanel: 视频世界位置设置为 (${videoAreaWorldPos.x}, ${videoAreaWorldPos.y})`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// 立即尝试一次
|
||||
if (!tryAdjustScale()) {
|
||||
// 如果失败,延迟尝试
|
||||
this.scheduleOnce(() => {
|
||||
if (!tryAdjustScale()) {
|
||||
// 再次延迟尝试
|
||||
this.scheduleOnce(() => {
|
||||
tryAdjustScale();
|
||||
}, 0.5);
|
||||
}
|
||||
}, 0.1);
|
||||
}
|
||||
console.log(
|
||||
"ChatPanel: adjustVideoScale() 方法已废弃,缩放和位置由 playVideo() 自动处理"
|
||||
);
|
||||
// 如果确实需要手动调整,可以重新调用 playVideo
|
||||
// this.videoLayer.playVideo(currentVideo, { size, position });
|
||||
}
|
||||
onChatCountChange() {
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
@@ -382,27 +306,16 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
})`
|
||||
);
|
||||
|
||||
// Load the new video with the unified playVideo method
|
||||
// 获取 videoArea 的尺寸和位置
|
||||
const targetSize = this.videoArea
|
||||
? new Size(this.videoArea.width, this.videoArea.height)
|
||||
: new Size(600, 800);
|
||||
const videoAreaPos = this.videoArea
|
||||
? this.videoArea.node.getWorldPosition()
|
||||
: undefined;
|
||||
|
||||
this.videoLayer.playVideo(matchingVideo, {
|
||||
loop: true,
|
||||
size: targetSize,
|
||||
position: videoAreaPos,
|
||||
size: this.targetSize,
|
||||
position: this.videoAreaPos, // 修复:使用正确的位置而不是 Vec3.ZERO
|
||||
});
|
||||
//ResManager.I.changeBundleVideo(this.girlVideo, matchingVideo, "Girls");
|
||||
|
||||
// Update current emotion state
|
||||
this.currentEmotion = emotion;
|
||||
|
||||
// Adjust scale and enable playback
|
||||
this.adjustVideoScale();
|
||||
// 注意:移除了 adjustVideoScale() 调用,因为 playVideo 现在会自动处理缩放和位置
|
||||
this.setVideoEnable(true);
|
||||
} else {
|
||||
console.warn(
|
||||
@@ -416,23 +329,16 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
`Loading fallback video: ${fallbackVideo} (emotion: ${VideoEmotion[fallbackVideo]})`
|
||||
);
|
||||
|
||||
// 获取 videoArea 的尺寸和位置
|
||||
const targetSize = this.videoArea
|
||||
? new Size(this.videoArea.width, this.videoArea.height)
|
||||
: new Size(600, 800);
|
||||
const videoAreaPos = this.videoArea
|
||||
? this.videoArea.node.getWorldPosition()
|
||||
: undefined;
|
||||
|
||||
this.videoLayer.playVideo(fallbackVideo, {
|
||||
loop: true,
|
||||
size: targetSize,
|
||||
position: videoAreaPos,
|
||||
size: this.targetSize,
|
||||
position: this.videoAreaPos,
|
||||
});
|
||||
|
||||
// Update current emotion state to the fallback video's emotion
|
||||
this.currentEmotion = this.chatController.getCurrentEmotion();
|
||||
this.adjustVideoScale();
|
||||
|
||||
// 注意:移除了 adjustVideoScale() 调用,因为 playVideo 现在会自动处理缩放和位置
|
||||
this.setVideoEnable(true);
|
||||
}
|
||||
}
|
||||
@@ -558,10 +464,12 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
|
||||
}
|
||||
|
||||
returnBtn() {
|
||||
this.onClose();
|
||||
GameRootUI.I.showDefaultView();
|
||||
|
||||
//ViewManager.I.openBundlesView("GirlListPanel");
|
||||
// Navigate back to GirlDetailPanel with current girlId using smooth transition
|
||||
NavigationManager.Instance.navigateToGirlDetail(
|
||||
this.id,
|
||||
NavigationManager.getTransitionPresets().SLIDE_RIGHT_TO_LEFT,
|
||||
this
|
||||
);
|
||||
}
|
||||
onClickRecord() {
|
||||
ViewManager.I.openBundlesView("RecordPanel", this.id);
|
||||
|
||||
Reference in New Issue
Block a user