diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 31cef7f70..a97cf98de 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -110,14 +110,7 @@ namespace MWDialogue size_t pos = find_str_ci(text,*it,0); if(pos !=std::string::npos) { - if(pos==0) - { - mKnownTopics[*it] = true; - } - else if(text.substr(pos -1,1) == " ") - { - mKnownTopics[*it] = true; - } + mKnownTopics[*it] = true; } } updateTopics(); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index e4c9945b4..ff2ecb4c6 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -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); } +bool sortByLength (const std::string& left, const std::string& right) +{ + return left.size() > right.size(); +} + } @@ -287,7 +292,7 @@ void DialogueWindow::setKeywords(std::list keyWords) if (mServices & Service_Training) mTopicsList->addItem(gmst.find("sServiceTrainingTitle")->getString()); - if (anyService) + if (anyService || mPtr.getTypeName() == typeid(ESM::NPC).name()) mTopicsList->addSeparator(); for(std::list::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; while((pos = find_str_ci(str,keyword, pos)) != std::string::npos) { - if(pos==0) - { - str.insert(pos,color1); - pos += color1.length(); - pos += keyword.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(); - } - } + str.insert(pos,color1); + pos += color1.length(); + pos += keyword.length(); + str.insert(pos,color2); + pos+= color2.length(); } } 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) + + std::vector topics; + for(unsigned int i = 0;igetItemCount();i++) { std::string keyWord = mTopicsList->getItemNameAt(i); if (separatorReached && keyWord != "") - addColorInString(text,keyWord,"#686EBA","#B29154"); + topics.push_back(keyWord); else separatorReached = true; } + + // sort by length to make sure longer topics are replaced first + std::sort(topics.begin(), topics.end(), sortByLength); + + for(std::vector::const_iterator it = topics.begin(); it != topics.end(); ++it) + { + addColorInString(text,*it,"#686EBA","#B29154"); + } return text; }