源码资源网 发表于 2025-1-24 12:54:05

[传奇技术]NPC对话框文字显示设定

[传奇技术]NPC对话框文字显示设定
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;
                        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;
                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;
                                                        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));
}

页: [1]
查看完整版本: [传奇技术]NPC对话框文字显示设定

免责声明:
1、本站提供的所有资源仅供参考学习使用,版权归原著所有,禁止下载本站资源参与商业和非法行为,请在24小时之内自行删除!
2、本站所有内容均由互联网收集整理、网友上传,并且以计算机技术研究交流为目的,仅供大家参考、学习,请勿任何商业目的与商业用途。
3、若您需要商业运营或用于其他商业活动,请您购买正版授权并合法使用。
4、论坛的所有内容都不保证其准确性,完整性,有效性,由于源码具有复制性,一经售出,概不退换。阅读本站内容因误导等因素而造成的损失本站不承担连带责任。
5、用户使用本网站必须遵守适用的法律法规,对于用户违法使用本站非法运营而引起的一切责任,由用户自行承担
6、本站所有资源来自互联网转载,版权归原著所有,用户访问和使用本站的条件是必须接受本站“免责声明”,如果不遵守,请勿访问或使用本网站
7、本站使用者因为违反本声明的规定而触犯中华人民共和国法律的,一切后果自己负责,本站不承担任何责任。
8、凡以任何方式登陆本网站或直接、间接使用本网站资料者,视为自愿接受本网站声明的约束。
9、本站以《2013 中华人民共和国计算机软件保护条例》第二章 “软件著作权” 第十七条为原则:为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。若有学员需要商用本站资源,请务必联系版权方购买正版授权!
10、本网站如无意中侵犯了某个企业或个人的知识产权,请来信【站长信箱312337667@qq.com】告之,本站将立即删除。
郑重声明:
本站所有资源仅供用户本地电脑学习源代码的内含设计思想和原理,禁止任何其他用途!
本站所有资源、教程来自互联网转载,仅供学习交流,不得商业运营资源,不确保资源完整性,图片和资源仅供参考,不提供任何技术服务。
本站资源仅供本地编辑研究学习参考,禁止未经资源商正版授权参与任何商业行为,违法行为!如需商业请购买各资源商正版授权
本站仅收集资源,提供用户自学研究使用,本站不存在私自接受协助用户架设游戏或资源,非法运营资源行为。