优化聊天部分
This commit is contained in:
@@ -5,14 +5,21 @@ import {
|
||||
Node,
|
||||
Overflow,
|
||||
Size,
|
||||
Sprite,
|
||||
UITransform,
|
||||
view,
|
||||
} from "cc";
|
||||
import Tools from "../../utils/tools";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
import { DataId, DataManager } from "../../data/DataManager";
|
||||
import { NavigationManager } from "../../manager/NavigationManager";
|
||||
import ResManager from "../../../Main/Manager/ResManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("DialogBubble")
|
||||
export class DialogBubble extends Component {
|
||||
@property(Sprite)
|
||||
avatar: Sprite = null;
|
||||
@property(UITransform)
|
||||
bg: UITransform = null;
|
||||
@property(Label)
|
||||
@@ -21,8 +28,12 @@ export class DialogBubble extends Component {
|
||||
contentT: UITransform = null;
|
||||
|
||||
fixMaxWidth: number;
|
||||
private loadingAnimationId: number = null;
|
||||
|
||||
uiTransform: UITransform;
|
||||
|
||||
init(maxWidth?: number) {
|
||||
this.uiTransform = this.node.getComponent(UITransform);
|
||||
|
||||
// 如果没有提供maxWidth,使用屏幕宽度的80%
|
||||
if (maxWidth === undefined) {
|
||||
this.fixMaxWidth = view.getVisibleSize().width * 0.8;
|
||||
@@ -33,6 +44,7 @@ export class DialogBubble extends Component {
|
||||
|
||||
updateBubbleContent(
|
||||
str: string,
|
||||
isPlayer: boolean = false,
|
||||
callback?: (actualHeight: number) => void,
|
||||
isLoading: boolean = false
|
||||
) {
|
||||
@@ -80,7 +92,7 @@ export class DialogBubble extends Component {
|
||||
// 设置内容区域宽度,让Label自动计算高度
|
||||
this.contentT.setContentSize(new Size(contentWidth, 0));
|
||||
this.bg.setContentSize(new Size(contentWidth + 37, 0));
|
||||
|
||||
this.uiTransform.setContentSize(new Size(contentWidth + 37, 0));
|
||||
// 强制更新Label的渲染数据以获取正确的高度
|
||||
this.content.updateRenderData(true);
|
||||
|
||||
@@ -95,6 +107,9 @@ export class DialogBubble extends Component {
|
||||
// 根据内容大小调整背景大小,添加适当的内边距
|
||||
//const bgHeight = actualHeight + 17;
|
||||
this.bg.setContentSize(new Size(actualSize.x + 40, actualSize.y + 30));
|
||||
this.uiTransform.setContentSize(
|
||||
new Size(actualSize.x + 40, actualSize.y + 30)
|
||||
);
|
||||
|
||||
// 回调通知实际高度
|
||||
if (callback) {
|
||||
@@ -104,6 +119,19 @@ export class DialogBubble extends Component {
|
||||
|
||||
// 返回预估的背景高度(用于同步计算)
|
||||
const estimatedHeight = Math.max(lines.length * 35 + 20, 60); // 最小高度60
|
||||
|
||||
//设置头像
|
||||
if (isPlayer) {
|
||||
//获取玩家头像,等接入luffa
|
||||
} else {
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const path = girlData.getGrilAvatar(
|
||||
NavigationManager.Instance.getSelectedCategoryId().toString(),
|
||||
NavigationManager.Instance.getSelectedGirlId()
|
||||
);
|
||||
ResManager.I.changeBundleSpriteFrame(this.avatar, path, "Girls");
|
||||
}
|
||||
|
||||
return estimatedHeight;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user