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