最近在写聊天对话框,使用CEGUI,就是游戏中左下角聊天模块,主要功能就是显示用户的名称,聊天的内容,表情,以及一些装备格式像下面这个样子
[莫压枯枯地]:大家晚上好[表情],这是我新穿的衣服[装备].
在此记录一下我遇到的问题及解决方案
整个聊天列表是使用StaticText控件完成的,即,所以有聊天信息都是这个StaticText的Text属性值
用户名,[莫压枯枯地]如果只是要求使用与聊天内容不同的字体、不同颜色的话,那就可以直接设置这段内容属性值,像这样,插入一段新的聊天内容:s
local
infoWin
=
CEGUI.WindowManager:getSingleton():getWindow(
"
ChatWindow/Infolist
"
);
local priTxtFont = infoWin:getFont(); -- 保留原来的字体
local priTxtColour = infoWin:getProperty( " TextColours " ); -- 保留原来的颜色
local newInfo = " [font='字体'][colour='FFFF0000'][莫压枯枯地] " ..
" [font=' " .. priTxtFont .. " '][colour=' " .. priTxtColour .. " ']:hallow. " ;
infoWin:setProperty( " Text " , infoWin:getText() .. newInfo)
local priTxtFont = infoWin:getFont(); -- 保留原来的字体
local priTxtColour = infoWin:getProperty( " TextColours " ); -- 保留原来的颜色
local newInfo = " [font='字体'][colour='FFFF0000'][莫压枯枯地] " ..
" [font=' " .. priTxtFont .. " '][colour=' " .. priTxtColour .. " ']:hallow. " ;
infoWin:setProperty( " Text " , infoWin:getText() .. newInfo)
function
lua_computeStringWH(win, contentString)
--
width && height
local font = win:getFont();
local ps = font:getProperty( " PointSize " );
local width = string.len (contentString) * ps + 6 ;
local height = ps + 6 ;
return " {{0,0},{0,0},{0, " .. width .. " },{0, " .. height .. " }} "
end
local font = win:getFont();
local ps = font:getProperty( " PointSize " );
local width = string.len (contentString) * ps + 6 ;
local height = ps + 6 ;
return " {{0,0},{0,0},{0, " .. width .. " },{0, " .. height .. " }} "
end
hscrollbarName
=
infoWin:getName() ..
"
__auto_vscrollbar__
"
;
hscrollbar = winMgr:getWindow(hscrollbarName);
hscrollbar = winMgr:getWindow(hscrollbarName);
这样就得到了这个滚动条控件,你可以通过ScrollPosition这个属性来设置滚动条的位置,如hscrollbar:setProperty("ScrollPosition", "20");
我遇到的问题基本上就这些,明天写,在聊天框中显示动态表情