summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-26 23:04:14 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-26 23:04:14 -0600
commite64b5a25a54f56bc836af57223e37449a1daffe8 (patch)
treef14f80a0bdc5268a2c4e2c70b6afcac080242ac5 /src/gui
parente03bd01fa02da71d41b85d3710a971da5a9c6c32 (diff)
downloadmana-client-e64b5a25a54f56bc836af57223e37449a1daffe8.tar.gz
mana-client-e64b5a25a54f56bc836af57223e37449a1daffe8.tar.bz2
mana-client-e64b5a25a54f56bc836af57223e37449a1daffe8.tar.xz
mana-client-e64b5a25a54f56bc836af57223e37449a1daffe8.zip
Major clean up of ChatTab handling
ChatTabs now manage their own adding/removal from the chat window, which lost most of it's chat related messages. Whisper handling is stil done by the ChatWindow, but it no longer manages any other tabs. ChannelTab handling is now the sole responsability of the Channels they are attached to. The general tab is handled by Game.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp56
-rw-r--r--src/gui/chat.h55
-rw-r--r--src/gui/guildwindow.cpp8
-rw-r--r--src/gui/npcpostdialog.cpp2
-rw-r--r--src/gui/partywindow.cpp6
-rw-r--r--src/gui/recorder.cpp11
-rw-r--r--src/gui/trade.cpp2
-rw-r--r--src/gui/widgets/channeltab.h9
-rw-r--r--src/gui/widgets/chattab.cpp10
-rw-r--r--src/gui/widgets/chattab.h20
-rw-r--r--src/gui/widgets/whispertab.h8
11 files changed, 69 insertions, 118 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 174285c9..8baf702e 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -96,7 +96,6 @@ ChatWindow::~ChatWindow()
config.setValue("ReturnToggles", mReturnToggles ? "1" : "0");
delete mRecorder;
#endif
- delete_all(mTabs);
delete_all(mWhispers);
delete mItemLinkHandler;
}
@@ -147,22 +146,6 @@ void ChatWindow::logic()
}
}
-void ChatWindow::chatLog(std::string line, int own, std::string channelName,
- bool ignoreRecord)
-{
- ChatTab *tab;
- if(!channelName.empty())
- tab = findTab(channelName);
- else
-#ifdef TMWSERV_SUPPORT
- tab = getFocused();
-#else
- tab = findTab("General");
-#endif
-
- tab->chatLog(line, own, ignoreRecord);
-}
-
ChatTab* ChatWindow::getFocused() const
{
return dynamic_cast<ChatTab*>(mChatTabs->getSelectedTab());
@@ -173,11 +156,6 @@ void ChatWindow::clearTab(ChatTab* tab)
if (tab) tab->clearText();
}
-void ChatWindow::clearTab(const std::string &tab)
-{
- clearTab(findTab(tab));
-}
-
void ChatWindow::clearTab()
{
clearTab(getFocused());
@@ -249,33 +227,21 @@ bool ChatWindow::isInputFocused()
return mChatInput->isFocused();
}
-ChatTab* ChatWindow::findTab(const std::string &tabName)
-{
- return mTabs[tabName];
-}
-
void ChatWindow::removeTab(ChatTab *tab)
{
- mTabs.erase(tab->getCaption());
- mChatTabs->removeTab(tab);
-}
-
-void ChatWindow::removeTab(const std::string &tabName)
-{
- ChatTab *tab = findTab(tabName);
- if (tab) removeTab(tab);
+ // Prevent removal of the local chat tab
+ if (tab != localChatTab) mChatTabs->removeTab(tab);
}
void ChatWindow::addTab(ChatTab *tab)
{
// Make sure we don't end up with duplicates in the gui
- removeTab(tab->getCaption());
-
- mTabs[tab->getCaption()] = tab;
+ // TODO
mChatTabs->addTab(tab, tab->mScrollArea);
- if (mTabs.size() == 1)
+ // Fix for layout issues when adding the first tab
+ if (tab == localChatTab)
adjustTabSize();
// Update UI
@@ -322,11 +288,12 @@ void ChatWindow::doPresent()
mRecorder->record(timeStr.str() + _("Present: ") + response + ".");
- chatLog(_("Attendance written to record log."), BY_SERVER, std::string(), true);
+ localChatTab->chatLog(_("Attendance written to record log."),
+ BY_SERVER, true);
}
else
{
- chatLog(_("Present: ") + response, BY_SERVER);
+ localChatTab->chatLog(_("Present: ") + response, BY_SERVER);
}
}
@@ -392,12 +359,6 @@ void ChatWindow::setVisible(bool isVisible)
mTmpVisible = false;
}
-bool ChatWindow::tabExists(const std::string &tabName)
-{
- Tab *tab = mChatTabs->getTab(tabName);
- return tab != 0;
-}
-
void ChatWindow::setRecordingFile(const std::string &msg)
{
mRecorder->setRecordingFile(msg);
@@ -424,7 +385,6 @@ void ChatWindow::whisper(std::string nick, std::string mes, bool own)
{
tab = new WhisperTab(tempNick);
mWhispers[tempNick] = tab;
- mChatTabs->addTab(tab, tab->mScrollArea);
}
if (own)
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 46358268..736f9284 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -47,21 +47,6 @@ class Network;
#endif
class WhisperTab;
-enum
-{
- BY_GM,
-#ifdef EATHENA_SUPPORT
- BY_PARTY,
-#endif
- BY_PLAYER,
- BY_OTHER,
- BY_SERVER,
- BY_CHANNEL,
- ACT_WHISPER, // getting whispered at
- ACT_IS, // equivalent to "/me" on IRC
- BY_LOGGER
-};
-
/**
* gets in between usernick and message text depending on
* message type
@@ -119,29 +104,11 @@ class ChatWindow : public Window,
void resetToDefaultSize();
/**
- * Adds a line of text to our message list. Parameters:
- *
- * @param line Text message.
- * @param own Type of message (usually the owner-type).
- * @param channelName which channel to send the message to.
- * @param ignoreRecord should this not be recorded?
- */
- void chatLog(std::string line,
- int own = BY_SERVER,
- std::string channelName = "",
- bool ignoreRecord = false);
-
- /**
* Gets the focused tab.
*/
ChatTab* getFocused() const;
/**
- * Clear the tab with the given name.
- */
- void clearTab(const std::string &tab);
-
- /**
* Clear the given tab.
*/
void clearTab(ChatTab* tab);
@@ -169,16 +136,6 @@ class ChatWindow : public Window,
*/
bool isInputFocused();
- ChatTab* findTab(const std::string &tabName);
-
- /** Remove the given tab from the window */
- void removeTab(ChatTab *tab);
-
- void removeTab(const std::string &tabName);
-
- /** Add the tab to the window */
- void addTab(ChatTab *tab);
-
/**
* Passes the text to the current tab as input
*
@@ -199,9 +156,6 @@ class ChatWindow : public Window,
/** Override to reset mTmpVisible */
void setVisible(bool visible);
- /** Check if tab with that name already exists */
- bool tabExists(const std::string &tabName);
-
/**
* Scrolls the chat window
*
@@ -234,6 +188,12 @@ class ChatWindow : public Window,
friend class ChatTab;
friend class WhisperTab;
+ /** Remove the given tab from the window */
+ void removeTab(ChatTab *tab);
+
+ /** Add the tab to the window */
+ void addTab(ChatTab *tab);
+
void adjustTabSize();
#ifdef EATHENA_SUPPORT
@@ -256,8 +216,7 @@ class ChatWindow : public Window,
Tab *currentTab;
typedef std::map<const std::string, ChatTab*> TabMap;
- /** Map each tab to its browser and scroll area. */
- TabMap mTabs;
+ /** Manage whisper tabs */
TabMap mWhispers;
typedef std::list<std::string> History;
diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp
index 263b8181..c8a1872f 100644
--- a/src/gui/guildwindow.cpp
+++ b/src/gui/guildwindow.cpp
@@ -127,7 +127,7 @@ void GuildWindow::action(const gcn::ActionEvent &event)
if (guild)
{
Net::ChatServer::Guild::quitGuild(guild);
- chatWindow->chatLog("Guild " + mGuildTabs->getSelectedTab()->getCaption() + " quit", BY_SERVER);
+ localChatTab->chatLog("Guild " + mGuildTabs->getSelectedTab()->getCaption() + " quit", BY_SERVER);
}
}
else if (eventId == "CREATE_GUILD_OK")
@@ -143,7 +143,7 @@ void GuildWindow::action(const gcn::ActionEvent &event)
// Defocus dialog
mFocus = false;
- chatWindow->chatLog("Creating Guild called " + name, BY_SERVER);
+ localChatTab->chatLog("Creating Guild called " + name, BY_SERVER);
guildDialog->scheduleDelete();
}
else if (eventId == "INVITE_USER_OK")
@@ -156,7 +156,7 @@ void GuildWindow::action(const gcn::ActionEvent &event)
// Defocus dialog
mFocus = false;
- chatWindow->chatLog("Invited user " + name, BY_SERVER);
+ localChatTab->chatLog("Invited user " + name, BY_SERVER);
inviteDialog->scheduleDelete();
}
else if (eventId == "yes")
@@ -233,7 +233,7 @@ void GuildWindow::openAcceptDialog(const std::string &inviterName,
const std::string &guildName)
{
std::string msg = inviterName + " has invited you to join the guild " + guildName;
- chatWindow->chatLog(msg, BY_SERVER);
+ localChatTab->chatLog(msg, BY_SERVER);
acceptDialog = new ConfirmDialog("Accept Guild Invite", msg, this);
acceptDialog->addActionListener(this);
diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp
index 9bda8a4c..278bc397 100644
--- a/src/gui/npcpostdialog.cpp
+++ b/src/gui/npcpostdialog.cpp
@@ -78,7 +78,7 @@ void NpcPostDialog::action(const gcn::ActionEvent &event)
{
if (mSender->getText().empty() || mText->getText().empty())
{
- chatWindow->chatLog("Failed to send as sender or letter invalid");
+ localChatTab->chatLog("Failed to send as sender or letter invalid");
}
else
{
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index ae2a5196..3f857b5c 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -111,14 +111,14 @@ void PartyWindow::showPartyInvite(const std::string &inviter)
// check there isnt already an invite showing
if (mPartyInviter != "")
{
- chatWindow->chatLog("Received party request, but one already exists",
+ localChatTab->chatLog("Received party request, but one already exists",
BY_SERVER);
return;
}
// log invite
std::string msg = inviter + " has invited you to join their party";
- chatWindow->chatLog(msg, BY_SERVER);
+ localChatTab->chatLog(msg, BY_SERVER);
// show invite
acceptDialog = new ConfirmDialog("Accept Party Invite", msg, this);
@@ -134,7 +134,7 @@ void PartyWindow::action(const gcn::ActionEvent &event)
// check if they accepted the invite
if (eventId == "yes")
{
- chatWindow->chatLog("Accepted invite from " + mPartyInviter);
+ localChatTab->chatLog("Accepted invite from " + mPartyInviter);
Net::ChatServer::Party::acceptInvite(mPartyInviter);
mPartyInviter = "";
}
diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp
index 0536188c..4f919bef 100644
--- a/src/gui/recorder.cpp
+++ b/src/gui/recorder.cpp
@@ -26,6 +26,7 @@
#include "recorder.h"
#include "windowcontainer.h"
+#include "widgets/chattab.h"
#include "widgets/layout.h"
#include "../utils/stringutils.h"
@@ -82,16 +83,16 @@ void Recorder::setRecordingFile(const std::string &msg)
* Message should go after mStream is closed so that it isn't
* recorded.
*/
- mChat->chatLog(_("Finishing recording."), BY_SERVER);
+ localChatTab->chatLog(_("Finishing recording."), BY_SERVER);
}
else
{
- mChat->chatLog(_("Not currently recording."), BY_SERVER);
+ localChatTab->chatLog(_("Not currently recording."), BY_SERVER);
}
}
else if (mStream.is_open())
{
- mChat->chatLog(_("Already recording."), BY_SERVER);
+ localChatTab->chatLog(_("Already recording."), BY_SERVER);
}
else
{
@@ -99,7 +100,7 @@ void Recorder::setRecordingFile(const std::string &msg)
* Message should go before mStream is opened so that it isn't
* recorded.
*/
- mChat->chatLog(_("Starting to record..."), BY_SERVER);
+ localChatTab->chatLog(_("Starting to record..."), BY_SERVER);
const std::string file =
std::string(PHYSFS_getUserDir()) + "/.tmw/" + msgCopy;
@@ -108,7 +109,7 @@ void Recorder::setRecordingFile(const std::string &msg)
if (mStream.is_open())
setVisible(true);
else
- mChat->chatLog(_("Failed to start recording."), BY_SERVER);
+ localChatTab->chatLog(_("Failed to start recording."), BY_SERVER);
}
}
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index a95e1d43..2d80d12d 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -309,7 +309,7 @@ void TradeWindow::action(const gcn::ActionEvent &event)
if (mMyInventory->contains(item))
{
- chatWindow->chatLog(_("Failed adding item. You can not "
+ localChatTab->chatLog(_("Failed adding item. You can not "
"overlap one kind of item on the window."),
BY_SERVER);
return;
diff --git a/src/gui/widgets/channeltab.h b/src/gui/widgets/channeltab.h
index 149eb5ec..91b4f7c6 100644
--- a/src/gui/widgets/channeltab.h
+++ b/src/gui/widgets/channeltab.h
@@ -32,6 +32,12 @@ class Channel;
class ChannelTab : public ChatTab
{
public:
+
+ Channel *getChannel() { return mChannel; }
+
+ protected:
+ friend class Channel;
+
/**
* Constructor.
*/
@@ -42,9 +48,6 @@ class ChannelTab : public ChatTab
*/
~ChannelTab();
- Channel *getChannel() { return mChannel; }
-
- protected:
void sendChat(std::string &msg);
private:
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index ff856361..120d4e21 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -62,15 +62,23 @@ ChatTab::ChatTab(const std::string &name) : Tab()
gcn::ScrollArea::SHOW_ALWAYS);
mScrollArea->setScrollAmount(0, 1);
mScrollArea->setOpaque(false);
+
+ chatWindow->addTab(this);
}
ChatTab::~ChatTab()
{
+ chatWindow->removeTab(this);
delete mTextOutput;
delete mScrollArea;
}
-void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
+void ChatTab::chatLog(const char* line, int own, bool ignoreRecord)
+{
+ chatLog(std::string(line), own, ignoreRecord);
+}
+
+void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
{
// Trim whitespace
trim(line);
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 9e2aff6b..a478abeb 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -32,6 +32,21 @@ class BrowserBox;
class Recorder;
class ScrollArea;
+enum
+{
+ BY_GM,
+#ifdef EATHENA_SUPPORT
+ BY_PARTY,
+#endif
+ BY_PLAYER,
+ BY_OTHER,
+ BY_SERVER,
+ BY_CHANNEL,
+ ACT_WHISPER, // getting whispered at
+ ACT_IS, // equivalent to "/me" on IRC
+ BY_LOGGER
+};
+
/**
* A tab for the chat window. This is special to ease chat handling.
*/
@@ -56,7 +71,8 @@ class ChatTab : public Tab
* @param channelName which channel to send the message to.
* @param ignoreRecord should this not be recorded?
*/
- void chatLog(std::string line, int own, bool ignoreRecord);
+ void chatLog(std::string line, int own = BY_SERVER, bool ignoreRecord = false);
+ void chatLog(const char* line, int own = BY_SERVER, bool ignoreRecord = false);
/**
* Adds the text to the message list
@@ -97,4 +113,6 @@ class ChatTab : public Tab
//Recorder *mRecorder;
};
+extern ChatTab *localChatTab;
+
#endif // CHATTAB_H
diff --git a/src/gui/widgets/whispertab.h b/src/gui/widgets/whispertab.h
index 66ec2720..059346fa 100644
--- a/src/gui/widgets/whispertab.h
+++ b/src/gui/widgets/whispertab.h
@@ -32,6 +32,11 @@ class Channel;
class WhisperTab : public ChatTab
{
public:
+ std::string getNick() { return mNick; }
+
+ protected:
+ friend class ChatWindow;
+
/**
* Constructor.
*/
@@ -42,9 +47,6 @@ class WhisperTab : public ChatTab
*/
~WhisperTab();
- std::string getNick() { return mNick; }
-
- protected:
void sendChat(std::string &msg);
private: