function MainScene:parseString(str, spTb)
local function Split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
local function createMyRichText(fieldSize,spTb)
local rc=ccui.RichText:create():pos(100, 200)
rc:ignoreContentAdaptWithSize(false)
rc:setContentSize(fieldSize)
for key, var in pairs(spTb) do
var:setContentSize(var:getBoundingBox())
local rcItem=ccui.RichElementCustomNode:create(key,cc.c3b(0,255,255),255,var)
rc:pushBackElement(rcItem)
end
return rc
end
local t = string.sub(str, 2, 2)
local modeString = string.format("<%s.-</%s>", t, t)
local w = string.match(str, modeString)
if w == nil then
local richText=createMyRichText(cc.size(500,400), spTb)
richText:setPosition(cc.p(480,120))
self:addChild(richText)
return
end
local as = string.find(w, ">")
local bs = string.find(w, "</"..t..">")
local p = string.sub(w, as+1, bs-1)
local cl = string.match(w, "%d+,%d+,%d+")
local co = cc.c3b(255, 255, 255)
if cl ~= nil then
local dcl = Split(cl, ",")
co = cc.c3b(dcl[1], dcl[2], dcl[3])
end
local text = cc.Label:createWithSystemFont(p, "宋体", 30)
text:setColor(co)
if t == "b" then
text = cc.Label:createWithSystemFont(p, "黑体", 30)
text:setColor(co)
elseif t == "l" then
text:setSkewX(20)
end
table.insert(spTb, text)
local leftString = string.sub(str, string.len(w)+1, -1)
self:parseString(leftString, spTb)
end
local function Split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
local function createMyRichText(fieldSize,spTb)
local rc=ccui.RichText:create():pos(100, 200)
rc:ignoreContentAdaptWithSize(false)
rc:setContentSize(fieldSize)
for key, var in pairs(spTb) do
var:setContentSize(var:getBoundingBox())
local rcItem=ccui.RichElementCustomNode:create(key,cc.c3b(0,255,255),255,var)
rc:pushBackElement(rcItem)
end
return rc
end
local t = string.sub(str, 2, 2)
local modeString = string.format("<%s.-</%s>", t, t)
local w = string.match(str, modeString)
if w == nil then
local richText=createMyRichText(cc.size(500,400), spTb)
richText:setPosition(cc.p(480,120))
self:addChild(richText)
return
end
local as = string.find(w, ">")
local bs = string.find(w, "</"..t..">")
local p = string.sub(w, as+1, bs-1)
local cl = string.match(w, "%d+,%d+,%d+")
local co = cc.c3b(255, 255, 255)
if cl ~= nil then
local dcl = Split(cl, ",")
co = cc.c3b(dcl[1], dcl[2], dcl[3])
end
local text = cc.Label:createWithSystemFont(p, "宋体", 30)
text:setColor(co)
if t == "b" then
text = cc.Label:createWithSystemFont(p, "黑体", 30)
text:setColor(co)
elseif t == "l" then
text:setSkewX(20)
end
table.insert(spTb, text)
local leftString = string.sub(str, string.len(w)+1, -1)
self:parseString(leftString, spTb)
end