适配效果优化

This commit is contained in:
2025-08-13 16:17:44 +08:00
parent 8048584f38
commit 5300d68462
10 changed files with 1482 additions and 216 deletions
+67 -13
View File
@@ -117,24 +117,78 @@ export class SceneBgVideoLayer extends li_BaseView {
playLocalLoopVideo(data:any) {
ResManager.I.changeBundleVideo(this.videoPlayer,data.path,"Chat18x",(res:VideoClip)=>{
this.videoPlayer.play();
let uiT:UITransform = this.videoPlayer.node.getComponent(UITransform);
const videoSize = uiT.contentSize;
const targetSize = data.size;
console.log('Video size:', videoSize, 'Target size:', targetSize);
// 计算宽度和高度的缩放比例
const scaleX = targetSize.width / videoSize.width;
const scaleY = targetSize.height / videoSize.height;
// 选择较大的缩放比例以填满整个区域(可能超出但不会有黑边)
const scale = Math.max(scaleX, scaleY);
// 移除之前的事件监听器,避免重复绑定
this.videoPlayer.node.off(VideoPlayer.EventType.READY_TO_PLAY, this.onVideoReadyToPlay, this);
console.log(`Video scaling: scaleX=${scaleX}, scaleY=${scaleY}, final scale=${scale}`);
this.videoPlayer.node.setScale(new Vec3(scale, scale, 1));
// 添加视频准备完成事件监听
this.videoPlayer.node.on(VideoPlayer.EventType.READY_TO_PLAY, this.onVideoReadyToPlay, this);
// 保存当前数据供回调使用
this.currentVideoData = data;
// 也立即尝试调整(以防已经准备好)
this.adjustVideoToFillFrame(data.size, data.bgFrameNode);
});
}
private currentVideoData: any = null;
private onVideoReadyToPlay = () => {
if (this.currentVideoData) {
this.adjustVideoToFillFrame(this.currentVideoData.size, this.currentVideoData.bgFrameNode);
}
}
adjustVideoToFillFrame(targetSize: any, bgFrameNode?: Node) {
if (!this.videoPlayer) return;
const tryAdjust = () => {
let uiT: UITransform = this.videoPlayer.node.getComponent(UITransform);
const videoSize = uiT.contentSize;
console.log('Video size:', videoSize, 'Target size:', targetSize);
if (videoSize.width > 0 && videoSize.height > 0) {
// 计算宽度和高度的缩放比例
const scaleX = targetSize.width / videoSize.width;
const scaleY = targetSize.height / videoSize.height;
// 选择较大的缩放比例以填满整个区域(可能超出但不会有黑边)
const scale = Math.max(scaleX, scaleY);
console.log(`Video scaling: scaleX=${scaleX}, scaleY=${scaleY}, final scale=${scale}`);
this.videoPlayer.node.setScale(new Vec3(scale, scale, 1));
// 只有传入bgFrameNode时才调整位置
if (bgFrameNode && isValid(bgFrameNode) && bgFrameNode.position) {
this.videoPlayer.node.setPosition(
bgFrameNode.position.x,
bgFrameNode.position.y,
bgFrameNode.position.z
);
console.log(`Video positioned to bgFrame center: ${bgFrameNode.position}`);
}
return true;
}
return false;
};
// 立即尝试一次
if (!tryAdjust()) {
// 如果失败,延迟尝试
this.scheduleOnce(() => {
if (!tryAdjust()) {
// 再次延迟尝试
this.scheduleOnce(() => {
tryAdjust();
}, 0.5);
}
}, 0.1);
}
}
/**播放循环视频 */
playLoopVideo(path: string, force = false) {
if (this.remoteLoopPath == path && !force) {
+9 -15
View File
@@ -12,6 +12,7 @@ import {
import li_BaseView from "../../Main/Common/li_BaseView";
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
import AudioManager from "../../Main/Manager/AudioManager";
import ConfigManager from "../../chat18x/manager/ConfigManager";
const { ccclass, property } = _decorator;
@@ -28,6 +29,9 @@ export class SimpleLanguagePanel extends li_BaseView {
@property(Button)
private closeBtn: Button = null;
@property(Node)
private languageDrawdown: Node = null;
@property(Label)
private titleLabel: Label = null;
@@ -62,13 +66,14 @@ export class SimpleLanguagePanel extends li_BaseView {
onEnable() {
this.currentSelectedLang = LanguageUtils.CurrentLanguage;
this.updateSelection();
this.languageDrawdown.active = false;
}
public onClickLanguageSelect() {
this.languageDrawdown.active = true;
}
private initUI() {
if (this.titleLabel) {
this.titleLabel.string = this.getMultiLangTitle();
}
// 初始化语言按钮数组
this.initLanguageButton(this.btnEnglish, LanguageType.EN, "English");
this.initLanguageButton(this.btnChinese, LanguageType.CN, "中文");
@@ -77,17 +82,6 @@ export class SimpleLanguagePanel extends li_BaseView {
this.initLanguageButton(this.btnGerman, LanguageType.DE, "Deutsch");
}
private getMultiLangTitle(): string {
const titles = [
"Select Language",
"选择语言",
"भाषा चुनें",
"Choisir la langue",
"Sprache wählen",
];
return titles.join(" / ");
}
private initLanguageButton(
button: Button,
language: LanguageType,
@@ -105,6 +105,7 @@ export class ChatPanel extends li_BaseView {
Utils.sendInnerMsg(InnerMsgCode.SimplePlayVide, {
path: dataDetail.pics[0],
size: uiTransform.contentSize,
bgFrameNode: this._nodeTab.BgFrame,
});
}
onDialogUpdate() {
@@ -1,4 +1,4 @@
import { _decorator, Component, math, Node, Sprite } from "cc";
import { _decorator, Component, math, Node, Sprite, UITransform } from "cc";
import { Config18x } from "db://assets/Scripts/Main/Config/Config18x";
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
@@ -20,8 +20,11 @@ export class DetailImageItem extends Component {
base: GirlDetailPanel;
url: string;
uitransform: UITransform;
onLoad() {
GButton.BandClick(this.node, this.onClickThis, this);
this.uitransform = this.node.getComponent(UITransform);
}
onClickThis() {
@@ -36,6 +39,54 @@ export class DetailImageItem extends Component {
this.base.setVideEnable(false);
}
}
scaleToFillItem() {
if (!this.img || !this.img.spriteFrame) return;
// 延迟一帧确保UI布局完成
this.scheduleOnce(() => {
this.doScaleToFill();
}, 0);
}
doScaleToFill() {
if (!this.img || !this.img.spriteFrame) return;
const itemSize = this.uitransform.contentSize;
const imageSize = this.img.spriteFrame.originalSize;
console.log("DetailImageItem doScaleToFill:", {
itemSize,
imageSize,
url: this.url
});
if (
itemSize.width === 0 ||
itemSize.height === 0 ||
imageSize.width === 0 ||
imageSize.height === 0
) {
console.log("DetailImageItem: Invalid size, skipping scale");
return;
}
const scaleX = itemSize.width / imageSize.width;
const scaleY = itemSize.height / imageSize.height;
const scale = Math.max(scaleX, scaleY);
console.log("DetailImageItem scale values:", { scaleX, scaleY, finalScale: scale });
// 设置Sprite的sizeMode为CUSTOM,允许自定义大小
this.img.sizeMode = Sprite.SizeMode.CUSTOM;
// 获取图片节点的UITransform并设置大小
const imgTransform = this.img.node.getComponent(UITransform);
if (imgTransform) {
imgTransform.setContentSize(imageSize.width * scale, imageSize.height * scale);
console.log("DetailImageItem: Set image size to", imgTransform.contentSize);
}
}
refresh(path: string, base: GirlDetailPanel) {
this.base = base;
this.lock.active = false;
@@ -54,7 +105,14 @@ export class DetailImageItem extends Component {
// this.img.color = new math.Color(255, 255, 255, 255);
// }
ResManager.I.changeBundleSpriteFrame(this.img, this.url, "Chat18x");
ResManager.I.changeBundleSpriteFrame(
this.img,
this.url,
"Chat18x",
() => {
this.scaleToFillItem();
}
);
}
}
}