void RichTextEx::SetText(string strIn, bool fromNpc) //NPC对话框文字显示设定
{
Reset();
StrReplace(strIn, "\r", "");
vector<string> strRow;
fastsplit(strRow, strIn, '\\');
if (fromNpc && strRow.size() > 10)
{
vector<string> strRowTemp;
bool removeEmptyRow = true;
for (size_t i = 0; i < strRow.size(); i++)
{
string& row = strRow[i];
if (!(removeEmptyRow && isEmptyRow(row)))
{
strRowTemp.push_back(row);
}
}
strRow = strRowTemp;
}
int LINE_SPACE = 2;
int textLineH = (m_fontDefinition._fontSize + LINE_SPACE);
int EMPTY_LINE_HIGHT = 4 + LINE_SPACE;
//if (!WIN_VERSION && fromNpc)
//{
// LINE_SPACE = 10;
// textLineH = (m_fontDefinition._fontSize + LINE_SPACE);
// EMPTY_LINE_HIGHT = textLineH;
//}
int endsign = 0;
int xxxxx = 0;
int yyyyy = 0;
int xStartFixed = 0;
int yCountByXStartFixed = 0;
int yCountByXStartFixedRaw = 0;
int iconH = 0;
int yEmptyLine = 0;
int oldY = 0;
for (size_t i = 0; i < strRow.size(); i++)
{
int tmpWidth = xStartFixed;
int curMaxWidth = 0;
string tmpstr = strRow[i];
if (tmpstr != " ")
{
if (tmpstr.empty())
{
if (yCountByXStartFixed > 0)
{
yCountByXStartFixed--;
}
continue;
}
while (!tmpstr.empty())
{
//判断是否特殊处理
int tmpsign1 = tmpstr.find('<');
endsign = tmpstr.find('>');
if (endsign < 0)
{
tmpsign1 = -1;
}
int tmpsign2 = tmpstr.find('{');
endsign = tmpstr.find('}');
if (endsign < 0)
{
tmpsign2 = -1;
}
int tmpsign = tmpsign1;
int tmpsignType = (tmpsign1 < 0) ? -1 : 1;
if ((tmpsign2 >= 0) && ((tmpsign1 < 0) || (tmpsign2 < tmpsign1)))
{
tmpsign = tmpsign2;
tmpsignType = 2;
}
if (tmpsignType == -1)
{
//没有特殊符号需要处理直接画
parsePlainText(tmpstr, xxxxx, yyyyy, tmpWidth);
break;
}
if (tmpsign == 0)
{
int startPos = (tmpsignType == 1) ? tmpsign1 : tmpsign2;
int endPos = 0;
if (tmpsignType == 1)
{
endPos = tmpstr.find('>');
}
else
{
endPos = tmpstr.find('}');
}
//处理颜色字体
string str = tmpstr.substr(startPos, endPos - startPos + 1);
size_t offset = 0;
bool flag = true;
while (flag)
{
flag = false;
static string imgMark = "<IMG:";
static string imgExMark = "<IMGEX:";
static string playImgMark = "<PlayIMG:";
static string playImgExMark = "<PlayIMGEX:";
if (!strncasecmp(str.c_str(), imgMark.c_str(), imgMark.size()))
{
tmpstr = tmpstr.substr(str.length(), tmpstr.length() - str.length());
str = str.substr(imgMark.size(), str.size() - imgMark.size() - 1);
parseImg(str, xxxxx, yyyyy, curMaxWidth);
break;
}
if (!strncasecmp(str.c_str(), imgExMark.c_str(), imgExMark.size()))
{
tmpstr = tmpstr.substr(str.length(), tmpstr.length() - str.length());
str = str.substr(imgExMark.size(), str.size() - imgExMark.size() - 1);
parseImgEx(str, xxxxx, yyyyy, curMaxWidth);
break;
}
if (!strncasecmp(str.c_str(), playImgMark.c_str(), playImgMark.size()))
{
tmpstr = tmpstr.substr(str.length(), tmpstr.length() - str.length());
str = str.substr(playImgMark.size(), str.size() - playImgMark.size() - 1);
parsePlayImg(str, xxxxx, yyyyy, curMaxWidth);
break;
}
if (!strncasecmp(str.c_str(), playImgExMark.c_str(), playImgExMark.size()))
{
tmpstr = tmpstr.substr(str.length(), tmpstr.length() - str.length());
str = str.substr(playImgExMark.size(), str.size() - playImgExMark.size() - 1);
parsePlayImgEx(str, xxxxx, yyyyy, curMaxWidth);
break;
}
int pos = str.find('/', offset);
if (pos == -1)
{
static string itemIconMark = "<ITEMICON:";
static string skillIconMark = "<SHOWICON:";
static string gemIconMark = "<GEMICON:";
//static string seperateBar = "<BAR>";
if (!strncasecmp(str.c_str(), itemIconMark.c_str(), itemIconMark.size()))
{
oldY = yyyyy;
parseItemIcon(str, xxxxx, yyyyy, tmpWidth, yCountByXStartFixed, tmpstr);
yEmptyLine = 0;
yCountByXStartFixedRaw = yCountByXStartFixed;
if (yCountByXStartFixed == 0)
{
xStartFixed = 0;
yyyyy += textLineH;
}
else
{
xStartFixed = xxxxx;
iconH = oldY - yyyyy;
yyyyy = oldY + textLineH;
yCountByXStartFixed++;
}
}
else if (!strncasecmp(str.c_str(), skillIconMark.c_str(), skillIconMark.size()))
{
oldY = yyyyy;
parseSkillIcon(str, xxxxx, yyyyy, tmpWidth, yCountByXStartFixed, tmpstr);
yEmptyLine = 0;
yCountByXStartFixedRaw = yCountByXStartFixed;
if (yCountByXStartFixed == 0)
{
xStartFixed = 0;
yyyyy += textLineH;
}
else
{
xStartFixed = xxxxx;
iconH = oldY - yyyyy;
yyyyy = oldY + textLineH;
yCountByXStartFixed++;
}
}
else if (!strncasecmp(str.c_str(), gemIconMark.c_str(), gemIconMark.size()))
{
oldY = yyyyy;
parseGemIcon(str, xxxxx, yyyyy, tmpWidth, yCountByXStartFixed, tmpstr);
yEmptyLine = 0;
yCountByXStartFixedRaw = yCountByXStartFixed;
if (yCountByXStartFixed == 0)
{
xStartFixed = 0;
yyyyy += textLineH;
}
else
{
xStartFixed = xxxxx;
iconH = oldY - yyyyy;
yyyyy = oldY + textLineH;
yCountByXStartFixed++;
}
}
//else if (!strncasecmp(str.c_str(), seperateBar.c_str(), seperateBar.size()))
//{
//}
else
{
parseSignText(str, xxxxx, yyyyy, tmpWidth, tmpstr);
}
}
else
{
char ch = str[pos + 1];
ch = (char)::tolower(ch);
if (g_colorFlags.find(ch) != g_colorFlags.end())
{
const char* pStr = str.c_str() + pos;
if (!strncasecmp(pStr, "/AUTOCOLOR", strlen("/AUTOCOLOR")) ||
!strncasecmp(pStr, "/#sCOLOR", strlen("/#sCOLOR")) ||
!strncasecmp(pStr, "/SCOLOR", strlen("/SCOLOR")) ||
!strncasecmp(pStr, "/FCOLOR", strlen("/FCOLOR"))
)
{
//case 'A'://AUTOCOLOR
//case '#'://#sCOLOR
//case 'S'://SCOLOR
//case 'F'://FCOLOR
//文字颜色
parseColorText(str, pos, ch, xxxxx, yyyyy, tmpWidth, tmpstr);
}
else
{
flag = true;
offset = pos + 1;
}
}
else if (ch == '@')
{
//点击类型
parseLinkText(str, pos, xxxxx, yyyyy, tmpWidth, tmpstr);
}
else
{
if (!g_colorFlags.empty())
{
flag = true;
offset = pos + 1;
}
}
}
}
}
else
{
int startPos = (tmpsignType == 1) ? tmpsign1 : tmpsign2;
parseBeforeSignText(tmpstr, startPos, xxxxx, yyyyy, tmpWidth);
}
}
yyyyy -= textLineH;
if (yCountByXStartFixed > 0)
{
yCountByXStartFixed--;
}
}
else
{
yEmptyLine++;
yyyyy -= EMPTY_LINE_HIGHT;
if (yCountByXStartFixed > 0)
{
yCountByXStartFixed--;
}
}
if (m_width < tmpWidth)
m_width = tmpWidth;
if (m_width < curMaxWidth)
m_width = curMaxWidth;
if (yCountByXStartFixed <= 0)
{
xStartFixed = 0;
if (iconH != 0)
{
int offsetY = (yCountByXStartFixedRaw - yEmptyLine) * textLineH + yEmptyLine * EMPTY_LINE_HIGHT;
if (offsetY < iconH)
{
yyyyy = oldY;
yyyyy -= iconH + EMPTY_LINE_HIGHT;
}
iconH = 0;
yEmptyLine = 0;
}
}
xxxxx = xStartFixed;
}
if (iconH != 0)
{
int offsetY = (yCountByXStartFixedRaw - yEmptyLine) * textLineH + yEmptyLine * EMPTY_LINE_HIGHT;
if (offsetY < iconH)
{
yyyyy = oldY;
yyyyy -= iconH + EMPTY_LINE_HIGHT;
}
iconH = 0;
yEmptyLine = 0;
}
m_height = -yyyyy;
this->setContentSize(Size(m_width, m_height));
}
声明:本文系互联网搜索而收集整理,不以盈利性为目的,文字、图文资料源于互联网且共享于互联网。
如有侵权,请联系 yao4fvip#qq.com (#改@) 删除。
如有侵权,请联系 yao4fvip#qq.com (#改@) 删除。