DOF/sqr/User/Asset/Character/ChatBubble.nut

60 lines
1.5 KiB
Plaintext

/*
文件名:ChatBubble.nut
路径:User/Asset/Character/ChatBubble.nut
创建日期:2025-01-24 19:04
文件用途:聊天气泡
*/
class Character_ChatBubble extends CL_CanvasObject {
RealWidth = null;
RealHeight = null;
constructor(Msg) {
base.constructor();
Init(Msg);
}
function Init(Msg) {
//渲染文本
local BoxWidth = 0;
local Tag = {
color = sq_RGBA(255, 255, 255, 250)
};
if (Msg.len() > 27) {
Tag.wrap_width <- 114;
BoxWidth = 130;
}
local Text = FontAssetManager.GenerateNormal(Msg, false, Tag);
//计算文本大小
local TextSize = Text.GetSize();
RealWidth = BoxWidth ? BoxWidth : TextSize.w + 18;
RealHeight = TextSize.h + 18;
//创建背景框 +18是 上下的空隙
local Bg = Yosin_NineBoxStretch(RealWidth, RealHeight, "sprite/interface/messageballoon.img", 20);
//重设大小
ResizeAndClear(TextSize.w + 20, TextSize.h + 40);
SetFillBrush(sq_RGBA(105, 212, 238, 250));
SetStrokeBrush(sq_RGBA(105, 212, 238, 250));
// 开始绘制
BeginDraw();
//绘制背景
DrawActor(Bg, 0, 0);
//绘制文字
DrawActor(Text, 9, 8);
// DrawRect(9, 8, TextSize.w + 9, TextSize.h + 8)
// 结束绘制
EndDraw();
}
function OnUpdate(Dt) {
base.OnUpdate(Dt);
if (ExistingTime >= 4000) {
Parent.ChatObject = null;
RemoveSelf();
}
}
}