From fc4a12470adde2502f37f22b86f58560e416f3e4 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 15 Apr 2009 09:12:07 -0600 Subject: Make whisper tabs optional --- src/gui/chat.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- src/gui/chat.h | 2 ++ src/gui/widgets/chattab.cpp | 6 +++--- 3 files changed, 42 insertions(+), 11 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 48acefee..30511ef9 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -35,8 +35,12 @@ #include "configuration.h" #include "localplayer.h" +#include "net/chathandler.h" +#include "net/net.h" + #include "utils/dtor.h" #include "utils/stringutils.h" +#include "utils/strprintf.h" #include #include @@ -417,19 +421,44 @@ void ChatWindow::whisper(std::string nick, std::string mes, bool own) toLower(playerName); toLower(tempNick); - if (!own && tempNick.compare(playerName) == 0) + if (tempNick.compare(playerName) == 0) return; ChatTab *tab = mWhispers[tempNick]; - if (!tab) + if (tab) { - tab = new WhisperTab(tempNick); - mWhispers[tempNick] = tab; + if (own) + tab->chatInput(mes); + else + tab->chatLog(nick, mes); } - - if (own) - tab->chatInput(mes); else - tab->chatLog(nick, mes); + { + if (own) + { + Net::getChatHandler()->privateMessage(nick, mes); + + localChatTab->chatLog(strprintf(_("Whispering to %s: %s"), + nick.c_str(), mes.c_str()), BY_PLAYER); + } + else + localChatTab->chatLog(nick + " : " + mes, ACT_WHISPER, false); + } +} + +bool ChatWindow::addWhisperTab(std::string nick) +{ + std::string playerName = player_node->getName(); + std::string tempNick = nick; + + toLower(playerName); + toLower(tempNick); + + if (mWhispers[tempNick] || tempNick.compare(playerName) == 0) + return false; + + mWhispers[tempNick] = new WhisperTab(nick); + + return true; } diff --git a/src/gui/chat.h b/src/gui/chat.h index 65281c37..f5af7558 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -173,6 +173,8 @@ class ChatWindow : public Window, void whisper(std::string nick, std::string mes, bool own = false); + bool addWhisperTab(std::string nick); + protected: friend class ChatTab; friend class WhisperTab; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 1879a918..0e3ae423 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -144,9 +144,9 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord) lineColor = "##2"; // Equiv. to BrowserBox::GREEN break; case ACT_WHISPER: - // Resend whisper through normal mechanism - chatWindow->whisper(tmp.nick, tmp.text); - return; + tmp.nick = strprintf(_("%s whispers: "), tmp.nick.c_str()); + lineColor = "##W"; + break; case ACT_IS: tmp.nick += CAT_IS; lineColor = "##I"; -- cgit v1.2.3-70-g09d2