require "Common/define"
require "System/class"
UIChatItem = class("UIChatItem")
local transform;
local gameObject;
local height = 42
-- 第一个表情/文字 的初始位置 x y
local posx = 14
local posy = -10
local width = 380
function UIChatItem:Create(obj,behaviour)
if obj == nil then
return nil
end
local tmp = UIChatItem.New("UIChatItem")
gameObject = obj
transform = obj.transform
tmp.mbehaviour = behaviour
tmp.m_bg = GetChild(obj,"bg")
tmp.m_text = GetChild(obj,"text")
tmp.m_lable = GetChild(obj,"prefab_text")
tmp.m_face = GetChild(obj,"prefab_face")
SetActive(tmp.m_lable,false)
SetActive(tmp.m_face,false)
tmp.m_Parent = obj
tmp.arg = {} -- 解析后表情和文字后的数组进行创建
tmp.m_Listener = nil
tmp.m_LisIsSelf = nil
tmp.m_labelCaches = {} --label缓存区
tmp.m_labelCur = {} --label当前使用的数据
tmp.m_prefabCeches = {} --表情缓存区
tmp.m_prefabCur = {} --face当前使用的数据
tmp.m_maxWidth = 350 ;-- 这句话最大宽度,否则换行
tmp.m_addValue = 10 ; -- 为了美观,每行头尾加上这个值
tmp.cellHeight = 0; -- 格子高
tmp.cellWidth = 0; -- 格子宽
tmp.m_posx = 0 ; -- 位置
tmp.m_posy = 0 ;
tmp.m_faceWidth = 30 ; -- 表情宽
tmp.m_faceHeight = 30 ;-- 表情高
tmp.m_hangju = 5; -- 行距是5
tmp.m_isHaveFace = false;-- 默认没有表情,行距是5 有表情,行距是表情的高度
tmp.m_words = nil
return tmp
end
function UIChatItem:Reset()
self.m_posx = posx
self.m_posy = posy
if (table.getCount(self.m_labelCur) > 0) then
local obj = self.m_labelCur[1]
table.remove(self.m_labelCur,1)
table.insert(self.m_labelCaches,obj)
SetActive(obj,false)
end
if (table.getCount(self.m_prefabCur) > 0) then
local obj = self.m_prefabCur[1]
table.remove(self.m_prefabCur,1)
table.insert(self.m_prefabCeches,obj)
SetActive(obj,false)
end
end
function UIChatItem:freshData(str)
SetActive(self.m_text,false)
self:Reset()
self.cellHeight = height -- 初始高度
self
ugui 图文混编 (方法一)
最新推荐文章于 2023-03-14 12:00:38 发布