diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-10-12 21:37:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-10-12 21:37:33 +0300 |
commit | 05d41da56882a14b44648c8daed5f50979154c16 (patch) | |
tree | 49a5cc44067e8b60dc0f2273c1be82b2585b61e0 | |
parent | 77e6c8639ae17554874d2de9fbdca35a99e51765 (diff) | |
download | manaplus-05d41da56882a14b44648c8daed5f50979154c16.tar.gz manaplus-05d41da56882a14b44648c8daed5f50979154c16.tar.bz2 manaplus-05d41da56882a14b44648c8daed5f50979154c16.tar.xz manaplus-05d41da56882a14b44648c8daed5f50979154c16.zip |
Add basic support for chat channels.
-rw-r--r-- | src/actions/chat.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/tabs/chat/whispertab.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/chatwindow.cpp | 107 | ||||
-rw-r--r-- | src/gui/windows/chatwindow.h | 14 |
4 files changed, 111 insertions, 23 deletions
diff --git a/src/actions/chat.cpp b/src/actions/chat.cpp index d838aac06..379d7d49c 100644 --- a/src/actions/chat.cpp +++ b/src/actions/chat.cpp @@ -223,9 +223,10 @@ impHandler(msg) impHandler(query) { + const std::string &args = event.args; if (chatWindow) { - if (chatWindow->addWhisperTab(event.args, true)) + if (chatWindow->addChatTab(args, true)) { chatWindow->saveState(); return true; @@ -234,10 +235,10 @@ impHandler(query) if (event.tab) { - // TRANSLATORS: new whisper query - event.tab->chatLog(strprintf(_("Cannot create a whisper tab for nick " - "\"%s\"! It either already exists, or is you."), - event.args.c_str()), ChatMsgType::BY_SERVER); + // TRANSLATORS: new whisper or channel query + event.tab->chatLog(strprintf(_("Cannot create a whisper tab " + "\"%s\"! It either already exists."), + args.c_str()), ChatMsgType::BY_SERVER); } return true; } diff --git a/src/gui/widgets/tabs/chat/whispertab.cpp b/src/gui/widgets/tabs/chat/whispertab.cpp index fc68cb222..e1740d808 100644 --- a/src/gui/widgets/tabs/chat/whispertab.cpp +++ b/src/gui/widgets/tabs/chat/whispertab.cpp @@ -38,7 +38,7 @@ WhisperTab::WhisperTab(const Widget2 *const widget, const std::string &nick) : - ChatTab(widget, nick, "", nick, ChatTabType::WHISPER), + ChatTab(widget, nick, nick, nick, ChatTabType::WHISPER), mNick(nick) { setWhisperTabColors(); diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index a6a96be5b..3a59279cc 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -49,17 +49,17 @@ #include "gui/windows/emotewindow.h" #include "gui/windows/setupwindow.h" -#include "gui/widgets/tabbedarea.h" #include "gui/windows/whoisonline.h" -#include "gui/widgets/tabs/chat/battletab.h" - #include "gui/widgets/button.h" #include "gui/widgets/chatinput.h" #include "gui/widgets/dropdown.h" #include "gui/widgets/itemlinkhandler.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/tabbedarea.h" +#include "gui/widgets/tabs/chat/battletab.h" +#include "gui/widgets/tabs/chat/channeltab.h" #include "gui/widgets/tabs/chat/langtab.h" #include "gui/widgets/tabs/chat/tradetab.h" #include "gui/widgets/tabs/chat/whispertab.h" @@ -67,6 +67,7 @@ #include "render/opengldebug.h" #include "net/chathandler.h" +#include "net/serverfeatures.h" #include "utils/copynpaste.h" #include "utils/delete2.h" @@ -94,6 +95,7 @@ ChatWindow::ChatWindow() : mChatInput(new ChatInput(this)), mRainbowColor(0), mWhispers(), + mChannels(), mHistory(), mCurHist(), mCommands(), @@ -200,6 +202,7 @@ ChatWindow::~ChatWindow() saveState(); config.setValue("ReturnToggles", mReturnToggles); removeAllWhispers(); + removeAllChannels(); delete2(mItemLinkHandler); delete2(mColorPicker); delete2(mColorListModel); @@ -559,6 +562,22 @@ void ChatWindow::removeAllWhispers() mWhispers.clear(); } +void ChatWindow::removeAllChannels() +{ + std::list<ChatTab*> tabs; + + FOR_EACH (ChannelMap::iterator, iter, mChannels) + tabs.push_back(iter->second); + + for (std::list<ChatTab*>::iterator it = tabs.begin(); + it != tabs.end(); ++it) + { + delete *it; + } + + mChannels.clear(); +} + void ChatWindow::ignoreAllWhispers() { for (TabMap::iterator iter = mWhispers.begin(); @@ -1149,6 +1168,46 @@ WhisperTab *ChatWindow::getWhisperTab(const std::string &nick) const return ret; } +ChannelTab *ChatWindow::addChannelTab(const std::string &name, + const bool switchTo) +{ + std::string tempName = name; + toLower(tempName); + + const ChannelMap::const_iterator i = mChannels.find(tempName); + ChannelTab *ret = nullptr; + + if (i != mChannels.end()) + { + ret = i->second; + } + else + { + ret = new ChannelTab(this, name); + mChannels[tempName] = ret; + if (config.getBoolValue("showChatHistory")) + ret->loadFromLogFile(name); + } + + if (switchTo) + mChatTabs->setSelectedTab(ret); + + return ret; +} + +ChatTab *ChatWindow::addChatTab(const std::string &name, + const bool switchTo) +{ + if (serverFeatures->haveChatChannels() && name.size() > 1 + && name[0] == '#') + { + return addChannelTab(name, switchTo); + } + else + { + return addWhisperTab(name, switchTo); + } +} #define changeColor(fun) \ { \ @@ -1636,7 +1695,7 @@ void ChatWindow::loadState() const int flags = serverConfig.getValue( "chatWhisperFlags" + toString(num), 1); - ChatTab *const tab = addWhisperTab(nick); + ChatTab *const tab = addChatTab(nick, false); if (tab) { tab->setAllowHighlight(flags & 1); @@ -1650,25 +1709,23 @@ void ChatWindow::loadState() void ChatWindow::saveState() const { int num = 0; + for (ChannelMap::const_iterator iter = mChannels.begin(), + iter_end = mChannels.end(); iter != iter_end && num < 50; ++iter) + { + if (!iter->second) + return; + if (!saveTab(num, iter->second)) + continue; + num ++; + } + for (TabMap::const_iterator iter = mWhispers.begin(), iter_end = mWhispers.end(); iter != iter_end && num < 50; ++iter) { if (!iter->second) return; - - const WhisperTab *const tab = static_cast<WhisperTab*>(iter->second); - - if (!tab) + if (!saveTab(num, iter->second)) continue; - - serverConfig.setValue("chatWhisper" + toString(num), - tab->getNick()); - - serverConfig.setValue("chatWhisperFlags" + toString(num), - static_cast<int>(tab->getAllowHighlight()) - + (2 * static_cast<int>(tab->getRemoveNames())) - + (4 * static_cast<int>(tab->getNoAway()))); - num ++; } @@ -1680,6 +1737,22 @@ void ChatWindow::saveState() const } } +bool ChatWindow::saveTab(const int num, ChatTab *const tab) const +{ + if (!tab) + return false; + + serverConfig.setValue("chatWhisper" + toString(num), + tab->getChannelName()); + + serverConfig.setValue("chatWhisperFlags" + toString(num), + static_cast<int>(tab->getAllowHighlight()) + + (2 * static_cast<int>(tab->getRemoveNames())) + + (4 * static_cast<int>(tab->getNoAway()))); + + return true; +} + std::string ChatWindow::doReplace(const std::string &msg) { std::string str = msg; diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index d6b89fbd1..313a65803 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -38,6 +38,7 @@ #include <set> class Button; +class ChannelTab; class ChatTab; class ChatInput; class ColorListModel; @@ -198,8 +199,16 @@ class ChatWindow final : public Window, WhisperTab *getWhisperTab(const std::string &nick) const A_WARN_UNUSED; + ChannelTab *addChannelTab(const std::string &name, + const bool switchTo = false) A_WARN_UNUSED; + + ChatTab *addChatTab(const std::string &name, + const bool switchTo = false) A_WARN_UNUSED; + void removeAllWhispers(); + void removeAllChannels(); + void ignoreAllWhispers(); bool resortChatLog(std::string line, ChatMsgType::Type own, @@ -219,6 +228,8 @@ class ChatWindow final : public Window, void saveState() const; + bool saveTab(const int num, ChatTab *const tab) const; + void loadCustomList(); void loadGMCommands(); @@ -332,8 +343,11 @@ class ChatWindow final : public Window, bool addCurrentToHistory(); typedef std::map<const std::string, WhisperTab*> TabMap; + typedef std::map<const std::string, ChannelTab*> ChannelMap; + /** Manage whisper tabs */ TabMap mWhispers; + ChannelMap mChannels; typedef History::iterator HistoryIterator; History mHistory; /**< Command history. */ |