diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-08-22 03:07:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-08-22 03:07:13 +0300 |
commit | dddfb405de9d04f50d3a95cc3b0ebc3e49884a65 (patch) | |
tree | 4bb96a90cb585a65025533e512e7c3de7cffed00 | |
parent | 07c2eb8ffd62fe69f410cc045efc837441a6b6d4 (diff) | |
download | mv-dddfb405de9d04f50d3a95cc3b0ebc3e49884a65.tar.gz mv-dddfb405de9d04f50d3a95cc3b0ebc3e49884a65.tar.bz2 mv-dddfb405de9d04f50d3a95cc3b0ebc3e49884a65.tar.xz mv-dddfb405de9d04f50d3a95cc3b0ebc3e49884a65.zip |
Add highlight list option.
Before in highlight was only player nick.
-rw-r--r-- | src/gui/chatwindow.cpp | 20 | ||||
-rw-r--r-- | src/gui/chatwindow.h | 5 | ||||
-rw-r--r-- | src/gui/setup_chat.cpp | 8 | ||||
-rw-r--r-- | src/gui/widgets/chattab.cpp | 4 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 17 | ||||
-rw-r--r-- | src/utils/stringutils.h | 5 |
6 files changed, 52 insertions, 7 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 1ef3139db..8896ca028 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -211,6 +211,7 @@ ChatWindow::ChatWindow(): fillCommands(); initTradeFilter(); loadCustomList(); + parseHighlights(); } ChatWindow::~ChatWindow() @@ -1503,7 +1504,7 @@ void ChatWindow::addToAwayLog(std::string line) if (mAwayLog.size() > 20) mAwayLog.pop_front(); - if (line.find(player_node->getName()) != std::string::npos) + if (findI(line, mHighlights) != std::string::npos) mAwayLog.push_back("##9away:" + line); } @@ -1520,3 +1521,20 @@ void ChatWindow::displayAwayLog() ++i; } } + +void ChatWindow::parseHighlights() +{ + mHighlights.clear(); + if (!player_node) + return; + + splitToStringVector(mHighlights, config.getStringValue( + "highlightWords"), ','); + + mHighlights.push_back(player_node->getName()); +} + +bool ChatWindow::findHighlight(std::string &str) +{ + return findI(str, mHighlights) != std::string::npos; +}
\ No newline at end of file diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index b6a37ef79..6e1d548a3 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -260,6 +260,10 @@ class ChatWindow : public Window, void clearAwayLog() { mAwayLog.clear(); } + void parseHighlights(); + + bool findHighlight(std::string &str); + protected: friend class ChatTab; friend class WhisperTab; @@ -329,6 +333,7 @@ class ChatWindow : public Window, int mChatColor; unsigned int mChatHistoryIndex; std::list<std::string> mAwayLog; + std::vector<std::string> mHighlights; }; extern ChatWindow *chatWindow; diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 722a3f8b2..9e75b9c0a 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -120,6 +120,11 @@ Setup_Chat::Setup_Chat() new SetupItemCheckBox(_("Use local time"), "", "useLocalTime", this, "useLocalTimeEvent"); + new SetupItemLabel(_("Other"), "", this); + + new SetupItemTextField(_("Highlight words (separated by comma)"), "", + "highlightWords", this, "highlightWordsEvent"); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } @@ -128,5 +133,8 @@ void Setup_Chat::apply() SetupTabScroll::apply(); if (chatWindow) + { chatWindow->adjustTabSize(); + chatWindow->parseHighlights(); + } } diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 785bdd6be..81c0d277f 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -283,9 +283,7 @@ void ChatTab::chatLog(std::string line, Own own, { if (player_node) { - std::string::size_type pos - = tmp.text.find(player_node->getName()); - if (pos != std::string::npos) + if (chatWindow && chatWindow->findHighlight(tmp.text)) setFlash(2); else setFlash(1); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 13170092e..0243c4315 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -181,9 +181,9 @@ unsigned long findI(std::string str, std::string subStr) return str.find(subStr); } -unsigned long findI(std::string str, std::vector<std::string> &list) +unsigned long findI(std::string &text, std::vector<std::string> &list) { - str = toLower(str); + std::string str = toLower(text); unsigned long idx; for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) @@ -414,6 +414,19 @@ std::list<std::string> splitToStringList(const std::string &text, return tokens; } +void splitToStringVector(std::vector<std::string> &tokens, + const std::string &text, char separator) +{ + std::stringstream ss(text); + std::string item; + while(std::getline(ss, item, separator)) + { + item = trim(item); + if (!item.empty()) + tokens.push_back(item); + } +} + std::string combineDye(std::string file, std::string dye) { if (dye.empty()) diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 94747d2fe..4fe6369e9 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -133,7 +133,7 @@ bool isWordSeparator(char chr); unsigned long findI(std::string str, std::string subStr); -unsigned long findI(std::string str, std::vector<std::string> &list); +unsigned long findI(std::string &text, std::vector<std::string> &list); const std::string encodeStr(unsigned int value, unsigned int size = 0); @@ -176,6 +176,9 @@ std::list<int> splitToIntList(const std::string &text, char separator); std::list<std::string> splitToStringList(const std::string &text, char separator); +void splitToStringVector(std::vector<std::string> &tokens, + const std::string &text, char separator); + std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); |