页面h5适配

This commit is contained in:
2025-08-15 18:17:12 +08:00
parent 599c98f135
commit 92277f0ff1
9 changed files with 4975 additions and 4580 deletions
+3 -3
View File
@@ -175,7 +175,7 @@
"_priority": 0, "_priority": 0,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 667, "_orthoHeight": 666.9999999999999,
"_near": 0, "_near": 0,
"_far": 2000, "_far": 2000,
"_color": { "_color": {
@@ -2018,7 +2018,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 750,
"height": 1334 "height": 1333.9999999999998
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -2082,7 +2082,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 750,
"height": 1334 "height": 1333.9999999999998
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
+2 -2
View File
@@ -178,11 +178,11 @@ export default class Utils {
//let windowSize = view.getVisibleSize(); //let windowSize = view.getVisibleSize();
let bgTf = node.getComponent(UITransform); let bgTf = node.getComponent(UITransform);
if (bgTf) { if (bgTf) {
if (mod == 1 && bgTf.height <= windowSize.height) { if (mod == 1) {
let scale = windowSize.height / bgTf.height; let scale = windowSize.height / bgTf.height;
bgTf.height = bgTf.height * scale; bgTf.height = bgTf.height * scale;
bgTf.width = bgTf.width * scale; bgTf.width = bgTf.width * scale;
} else if (mod == 2 && bgTf.width <= windowSize.width) { } else if (mod == 2) {
let scale = windowSize.width / bgTf.width; let scale = windowSize.width / bgTf.width;
bgTf.height = bgTf.height * scale; bgTf.height = bgTf.height * scale;
bgTf.width = bgTf.width * scale; bgTf.width = bgTf.width * scale;
@@ -1,15 +1,23 @@
import { _decorator, Component, instantiate, Node, Vec3 } from "cc"; import {
_decorator,
Component,
instantiate,
Node,
UITransform,
Vec3,
} from "cc";
import { DialogManager } from "../../manager/DialogManager"; import { DialogManager } from "../../manager/DialogManager";
import { DialogBubble } from "./DialogBubble"; import { DialogBubble } from "./DialogBubble";
import { Dialog } from "../../data/DialogData"; import { Dialog } from "../../data/DialogData";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
const BUTTOM_Y = -955.571;
@ccclass("ChatContentsLayout") @ccclass("ChatContentsLayout")
export class ChatContentsLayout extends Component { export class ChatContentsLayout extends Component {
manager: DialogManager = null; manager: DialogManager = null;
@property(Node)
initPos: Node = null;
@property(DialogBubble) @property(DialogBubble)
lBubble: DialogBubble = null; lBubble: DialogBubble = null;
@property(DialogBubble) @property(DialogBubble)
@@ -18,9 +26,12 @@ export class ChatContentsLayout extends Component {
bubbles: DialogBubble[] = []; bubbles: DialogBubble[] = [];
cachedBubbles: DialogBubble[] = []; cachedBubbles: DialogBubble[] = [];
fixMaxWidth: number;
protected start(): void { protected start(): void {
this.lBubble.node.active = false; this.lBubble.node.active = false;
this.rBubble.node.active = false; this.rBubble.node.active = false;
this.fixMaxWidth = this.node.getComponent(UITransform).contentSize.y * 0.6;
} }
protected onEnable(): void { protected onEnable(): void {
@@ -46,7 +57,7 @@ export class ChatContentsLayout extends Component {
} }
private updateDialogLayout(dialogs: Dialog[]) { private updateDialogLayout(dialogs: Dialog[]) {
let initPosY: number = BUTTOM_Y; let initPosY: number = this.initPos.position.y;
let pendingUpdates = 0; let pendingUpdates = 0;
const updateNextBubble = (index: number) => { const updateNextBubble = (index: number) => {
@@ -64,7 +75,10 @@ export class ChatContentsLayout extends Component {
if (cached && cached.node) { if (cached && cached.node) {
// 检查气泡类型是否匹配(通过位置判断左右气泡) // 检查气泡类型是否匹配(通过位置判断左右气泡)
const isRightBubble = cached.node.position.x > 0; const isRightBubble = cached.node.position.x > 0;
if ((isPlayerBubble && isRightBubble) || (!isPlayerBubble && !isRightBubble)) { if (
(isPlayerBubble && isRightBubble) ||
(!isPlayerBubble && !isRightBubble)
) {
newBubble = cached; newBubble = cached;
this.cachedBubbles.splice(j, 1); this.cachedBubbles.splice(j, 1);
break; break;
@@ -78,6 +92,7 @@ export class ChatContentsLayout extends Component {
? instantiate(this.rBubble.node) ? instantiate(this.rBubble.node)
: instantiate(this.lBubble.node); : instantiate(this.lBubble.node);
newBubble = newBubbleNode.getComponent(DialogBubble); newBubble = newBubbleNode.getComponent(DialogBubble);
newBubble.init(this.fixMaxWidth);
newBubbleNode.setParent(this.node); newBubbleNode.setParent(this.node);
} }
@@ -1,4 +1,12 @@
import { _decorator, Component, Label, Node, Size, UITransform } from "cc"; import {
_decorator,
Component,
Label,
Node,
Overflow,
Size,
UITransform,
} from "cc";
import Tools from "../../utils/tools"; import Tools from "../../utils/tools";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@@ -11,7 +19,13 @@ export class DialogBubble extends Component {
@property(UITransform) @property(UITransform)
contentT: UITransform = null; contentT: UITransform = null;
fixMaxWidth: number;
init(maxWidth: number = 650) {
this.fixMaxWidth = maxWidth;
}
updateBubbleContent(str: string, callback?: (actualHeight: number) => void) { updateBubbleContent(str: string, callback?: (actualHeight: number) => void) {
this.content.overflow = Overflow.NONE;
// 设置文本内容 // 设置文本内容
this.content.string = str; this.content.string = str;
@@ -22,38 +36,40 @@ export class DialogBubble extends Component {
for (const line of lines) { for (const line of lines) {
let lineWidth = 0; let lineWidth = 0;
if (Tools.IsChinese(line)) { if (Tools.IsChinese(line)) {
lineWidth = 35 * line.length; lineWidth = 30 * line.length;
} else { } else {
lineWidth = 21 * line.length; lineWidth = 18 * line.length;
} }
maxWidth = Math.max(maxWidth, lineWidth); maxWidth = Math.max(maxWidth, lineWidth);
} }
if (maxWidth > this.fixMaxWidth)
this.content.overflow = Overflow.RESIZE_HEIGHT;
// 限制最大宽度 // 限制最大宽度
const contentWidth = Math.min(maxWidth, 950); const contentWidth = Math.min(maxWidth, this.fixMaxWidth);
// 设置内容区域宽度,让Label自动计算高度 // 设置内容区域宽度,让Label自动计算高度
this.contentT.setContentSize(new Size(contentWidth, 0)); this.contentT.setContentSize(new Size(contentWidth, 0));
this.bg.setContentSize(new Size(contentWidth + 20, 0)); this.bg.setContentSize(new Size(contentWidth + 17, 0));
// 强制更新Label的渲染数据以获取正确的高度 // 强制更新Label的渲染数据以获取正确的高度
this.content.updateRenderData(true); this.content.updateRenderData(true);
// 等待一帧后获取Label的实际高度 // 等待一帧后获取Label的实际高度
this.scheduleOnce(() => { this.scheduleOnce(() => {
const actualHeight = const actualSize =
this.content.node.getComponent(UITransform).contentSize.height; this.content.node.getComponent(UITransform).contentSize;
// 更新内容区域的实际大小 // 更新内容区域的实际大小
this.contentT.setContentSize(new Size(contentWidth, actualHeight)); //this.contentT.setContentSize(new Size(contentWidth, actualHeight));
// 根据内容大小调整背景大小,添加适当的内边距 // 根据内容大小调整背景大小,添加适当的内边距
const bgHeight = actualHeight + 20; //const bgHeight = actualHeight + 17;
this.bg.setContentSize(new Size(contentWidth + 50, bgHeight)); this.bg.setContentSize(new Size(actualSize.x + 30, actualSize.y + 10));
// 回调通知实际高度 // 回调通知实际高度
if (callback) { if (callback) {
callback(bgHeight); callback(actualSize.y);
} }
}, 0); }, 0);
@@ -33,8 +33,6 @@ export class GirlDetailPanel extends li_BaseView {
@property(Label) @property(Label)
tags: Label; tags: Label;
@property(Label)
descName: Label;
@property(Label) @property(Label)
descAge: Label; descAge: Label;
@property(Label) @property(Label)
@@ -60,9 +58,7 @@ export class GirlDetailPanel extends li_BaseView {
this.refresh(this.id); this.refresh(this.id);
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => { Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.girlName.string = this.descName.string = LanguageUtils.getText( this.girlName.string = LanguageUtils.getText(this.nameKey);
this.nameKey
);
let desc = ""; let desc = "";
const tags = LanguageUtils.getText(this.tagKey).split("|"); const tags = LanguageUtils.getText(this.tagKey).split("|");
for (let i = 0; i < tags.length; i++) { for (let i = 0; i < tags.length; i++) {
@@ -93,7 +89,9 @@ export class GirlDetailPanel extends li_BaseView {
if (parentTransform && videoTransform && videoTransform.height > 0) { if (parentTransform && videoTransform && videoTransform.height > 0) {
const scale = parentTransform.height / videoTransform.height; const scale = parentTransform.height / videoTransform.height;
this.avatarVideo.node.setScale(scale, scale, 1); this.avatarVideo.node.setScale(scale, scale, 1);
console.log(`Video scaled to: ${scale}, parent height: ${parentTransform.height}, video height: ${videoTransform.height}`); console.log(
`Video scaled to: ${scale}, parent height: ${parentTransform.height}, video height: ${videoTransform.height}`
);
return true; return true;
} }
return false; return false;
@@ -121,9 +119,7 @@ export class GirlDetailPanel extends li_BaseView {
const data = ConfigManager.tables.TbGirls.get(this.id); const data = ConfigManager.tables.TbGirls.get(this.id);
this.category = data.category; this.category = data.category;
this.nameKey = data.nameKey; this.nameKey = data.nameKey;
this.girlName.string = this.descName.string = LanguageUtils.getText( this.girlName.string = LanguageUtils.getText(data.nameKey);
data.nameKey
);
if (dataDetail.pics[0].endsWith("video")) { if (dataDetail.pics[0].endsWith("video")) {
ResManager.I.changeBundleVideo( ResManager.I.changeBundleVideo(
@@ -133,9 +129,13 @@ export class GirlDetailPanel extends li_BaseView {
); );
// 添加视频加载完成回调 // 添加视频加载完成回调
this.avatarVideo.node.on(VideoPlayer.EventType.READY_TO_PLAY, () => { this.avatarVideo.node.on(
this.adjustVideoScale(); VideoPlayer.EventType.READY_TO_PLAY,
}, this); () => {
this.adjustVideoScale();
},
this
);
// 也立即尝试调整(以防已经加载完成) // 也立即尝试调整(以防已经加载完成)
this.adjustVideoScale(); this.adjustVideoScale();
@@ -160,7 +160,7 @@ export class GirlDetailPanel extends li_BaseView {
this.tagKey = data.tagKey; this.tagKey = data.tagKey;
const tags = LanguageUtils.getText(data.tagKey).split("|"); const tags = LanguageUtils.getText(data.tagKey).split("|");
for (let i = 0; i < tags.length; i++) { for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "\n"; if (i != 0) desc += "|";
desc += tags[i]; desc += tags[i];
} }
this.tags.string = desc; this.tags.string = desc;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+34 -34
View File
@@ -228,7 +228,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -355, "x": -355,
"y": -31.12200000000007, "y": 5.685999999999922,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -401,7 +401,7 @@
"_target": null, "_target": null,
"_left": 20, "_left": 20,
"_right": 0, "_right": 0,
"_top": 55.12200000000007, "_top": 18.314000000000078,
"_bottom": 61.5, "_bottom": 61.5,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
@@ -923,7 +923,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 42.47199999999998, "x": 42.47199999999998,
"y": -47.09699999999998, "y": -57.613000000000056,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -1237,7 +1237,7 @@
"_left": 194.1, "_left": 194.1,
"_right": 282.528, "_right": 282.528,
"_top": 0, "_top": 0,
"_bottom": 63.90300000000002, "_bottom": 53.386999999999944,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
"_isAbsLeft": true, "_isAbsLeft": true,
@@ -1303,7 +1303,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 200.84699999999998, "x": 200.84699999999998,
"y": -48.011999999999944, "y": -58.52800000000002,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -1815,7 +1815,7 @@
"_left": 194.1, "_left": 194.1,
"_right": 124.15300000000002, "_right": 124.15300000000002,
"_top": 0, "_top": 0,
"_bottom": 62.988000000000056, "_bottom": 52.47199999999998,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
"_isAbsLeft": true, "_isAbsLeft": true,
@@ -2094,7 +2094,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -104.79999999999995, "y": -86.60000000000002,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -2154,7 +2154,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 423.62100000000004, "y": 441.82099999999986,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -3880,8 +3880,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 340, "width": 2,
"height": 230 "height": 2
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -3920,9 +3920,9 @@
"__uuid__": "7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca@f9941", "__uuid__": "7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca@f9941",
"__expectedType__": "cc.SpriteFrame" "__expectedType__": "cc.SpriteFrame"
}, },
"_type": 1, "_type": 0,
"_fillType": 0, "_fillType": 0,
"_sizeMode": 0, "_sizeMode": 1,
"_fillCenter": { "_fillCenter": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 0, "x": 0,
@@ -4163,7 +4163,7 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 128, "width": 310.3,
"height": 77.048 "height": 77.048
}, },
"_anchorPoint": { "_anchorPoint": {
@@ -4202,11 +4202,11 @@
"_string": "熟女", "_string": "熟女",
"_horizontalAlign": 0, "_horizontalAlign": 0,
"_verticalAlign": 2, "_verticalAlign": 2,
"_actualFontSize": 60, "_actualFontSize": 61,
"_fontSize": 60, "_fontSize": 60,
"_fontFamily": "NotoSans-Regular", "_fontFamily": "NotoSans-Regular",
"_lineHeight": 54.8, "_lineHeight": 54.8,
"_overflow": 0, "_overflow": 2,
"_enableWrapText": true, "_enableWrapText": true,
"_font": null, "_font": null,
"_isSystemFontUsed": true, "_isSystemFontUsed": true,
@@ -4943,7 +4943,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -145.1905, "y": -134.18999999999988,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -5053,7 +5053,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 358.493, "y": 432.114,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -5094,7 +5094,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 750,
"height": 80 "height": 0
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -5127,12 +5127,12 @@
"height": 450 "height": 450
}, },
"_startAxis": 0, "_startAxis": 0,
"_paddingLeft": 30, "_paddingLeft": 10,
"_paddingRight": 30, "_paddingRight": 30,
"_paddingTop": 80, "_paddingTop": 0,
"_paddingBottom": 0, "_paddingBottom": 0,
"_spacingX": 25, "_spacingX": 50,
"_spacingY": 80, "_spacingY": 20,
"_verticalDirection": 1, "_verticalDirection": 1,
"_horizontalDirection": 0, "_horizontalDirection": 0,
"_constraint": 2, "_constraint": 2,
@@ -5172,8 +5172,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 730,
"height": 834.0190000000001 "height": 802.319
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -5317,8 +5317,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 730,
"height": 834.0190000000001 "height": 802.319
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -5421,10 +5421,10 @@
}, },
"_alignFlags": 45, "_alignFlags": 45,
"_target": null, "_target": null,
"_left": 0, "_left": 10,
"_right": 0, "_right": 10,
"_top": 290.381, "_top": 313.43049999999977,
"_bottom": 0, "_bottom": 45.0505,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
"_isAbsLeft": true, "_isAbsLeft": true,
@@ -5471,7 +5471,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 750,
"height": 1124.4 "height": 1160.7999999999997
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -5545,7 +5545,7 @@
"_target": null, "_target": null,
"_left": 0, "_left": 0,
"_right": 0, "_right": 0,
"_top": 209.6, "_top": 173.2,
"_bottom": 0, "_bottom": 0,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
@@ -5593,7 +5593,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 750,
"height": 1334 "height": 1333.9999999999998
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -5715,7 +5715,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 750, "width": 750,
"height": 1334 "height": 1333.9999999999998
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",