mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-31 22:15:33 +00:00
dialogue fixes
This commit is contained in:
parent
d7af9fbec6
commit
1d7e92b6b3
2 changed files with 24 additions and 33 deletions
|
@ -110,14 +110,7 @@ namespace MWDialogue
|
||||||
size_t pos = find_str_ci(text,*it,0);
|
size_t pos = find_str_ci(text,*it,0);
|
||||||
if(pos !=std::string::npos)
|
if(pos !=std::string::npos)
|
||||||
{
|
{
|
||||||
if(pos==0)
|
mKnownTopics[*it] = true;
|
||||||
{
|
|
||||||
mKnownTopics[*it] = true;
|
|
||||||
}
|
|
||||||
else if(text.substr(pos -1,1) == " ")
|
|
||||||
{
|
|
||||||
mKnownTopics[*it] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateTopics();
|
updateTopics();
|
||||||
|
|
|
@ -48,6 +48,11 @@ std::string::size_type find_str_ci(const std::string& str, const std::string& su
|
||||||
return lower_string(str).find(lower_string(substr),pos);
|
return lower_string(str).find(lower_string(substr),pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sortByLength (const std::string& left, const std::string& right)
|
||||||
|
{
|
||||||
|
return left.size() > right.size();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,7 +292,7 @@ void DialogueWindow::setKeywords(std::list<std::string> keyWords)
|
||||||
if (mServices & Service_Training)
|
if (mServices & Service_Training)
|
||||||
mTopicsList->addItem(gmst.find("sServiceTrainingTitle")->getString());
|
mTopicsList->addItem(gmst.find("sServiceTrainingTitle")->getString());
|
||||||
|
|
||||||
if (anyService)
|
if (anyService || mPtr.getTypeName() == typeid(ESM::NPC).name())
|
||||||
mTopicsList->addSeparator();
|
mTopicsList->addSeparator();
|
||||||
|
|
||||||
for(std::list<std::string>::iterator it = keyWords.begin(); it != keyWords.end(); ++it)
|
for(std::list<std::string>::iterator it = keyWords.begin(); it != keyWords.end(); ++it)
|
||||||
|
@ -311,43 +316,36 @@ void addColorInString(std::string& str, const std::string& keyword,std::string c
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while((pos = find_str_ci(str,keyword, pos)) != std::string::npos)
|
while((pos = find_str_ci(str,keyword, pos)) != std::string::npos)
|
||||||
{
|
{
|
||||||
if(pos==0)
|
str.insert(pos,color1);
|
||||||
{
|
pos += color1.length();
|
||||||
str.insert(pos,color1);
|
pos += keyword.length();
|
||||||
pos += color1.length();
|
str.insert(pos,color2);
|
||||||
pos += keyword.length();
|
pos+= color2.length();
|
||||||
str.insert(pos,color2);
|
|
||||||
pos+= color2.length();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(str.substr(pos -1,1) == " ")
|
|
||||||
{
|
|
||||||
str.insert(pos,color1);
|
|
||||||
pos += color1.length();
|
|
||||||
pos += keyword.length();
|
|
||||||
str.insert(pos,color2);
|
|
||||||
pos+= color2.length();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pos += keyword.length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DialogueWindow::parseText(std::string text)
|
std::string DialogueWindow::parseText(std::string text)
|
||||||
{
|
{
|
||||||
bool separatorReached = false; // only parse topics that are below the separator (this prevents actions like "Barter" that are not topics from getting blue-colored)
|
bool separatorReached = false; // only parse topics that are below the separator (this prevents actions like "Barter" that are not topics from getting blue-colored)
|
||||||
|
|
||||||
|
std::vector<std::string> topics;
|
||||||
|
|
||||||
for(unsigned int i = 0;i<mTopicsList->getItemCount();i++)
|
for(unsigned int i = 0;i<mTopicsList->getItemCount();i++)
|
||||||
{
|
{
|
||||||
std::string keyWord = mTopicsList->getItemNameAt(i);
|
std::string keyWord = mTopicsList->getItemNameAt(i);
|
||||||
if (separatorReached && keyWord != "")
|
if (separatorReached && keyWord != "")
|
||||||
addColorInString(text,keyWord,"#686EBA","#B29154");
|
topics.push_back(keyWord);
|
||||||
else
|
else
|
||||||
separatorReached = true;
|
separatorReached = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort by length to make sure longer topics are replaced first
|
||||||
|
std::sort(topics.begin(), topics.end(), sortByLength);
|
||||||
|
|
||||||
|
for(std::vector<std::string>::const_iterator it = topics.begin(); it != topics.end(); ++it)
|
||||||
|
{
|
||||||
|
addColorInString(text,*it,"#686EBA","#B29154");
|
||||||
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue