ugui 图文混编 (方法一)

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值