summaryrefslogtreecommitdiff
path: root/src/gui/chat.cpp
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-04-14 17:05:29 +0000
committerDavid Athay <ko2fan@gmail.com>2008-04-14 17:05:29 +0000
commitbbb40f595e6e20e5106a23e6aa606b825b1e62b4 (patch)
treedbfe4adf16eb49be93c031587c2ff1694ac0d0e4 /src/gui/chat.cpp
parent1ace3a1cec2ea8490af5af0b7d131394543fea11 (diff)
downloadmana-bbb40f595e6e20e5106a23e6aa606b825b1e62b4.tar.gz
mana-bbb40f595e6e20e5106a23e6aa606b825b1e62b4.tar.bz2
mana-bbb40f595e6e20e5106a23e6aa606b825b1e62b4.tar.xz
mana-bbb40f595e6e20e5106a23e6aa606b825b1e62b4.zip
Added new TabbedArea which extends gui::TabbedArea. Changed Guild and
Chat windows to use new TabbedArea. Added private messaging.
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r--src/gui/chat.cpp68
1 files changed, 38 insertions, 30 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 1efee8ed..0602c671 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -30,12 +30,12 @@
#include "browserbox.h"
#include "chatinput.h"
-#include "gccontainer.h"
#include "scrollarea.h"
#include "sdlinput.h"
-#include "tabbedcontainer.h"
#include "windowcontainer.h"
+#include "widgets/tabbedarea.h"
+
#include "../channelmanager.h"
#include "../channel.h"
#include "../configuration.h"
@@ -53,7 +53,7 @@ ChatWindow::ChatWindow():
mTmpVisible(false)
{
setResizable(true);
- setDefaultSize(0, (windowContainer->getHeight() - 123), 600, 100);
+ setDefaultSize(0, (windowContainer->getHeight() - 105), 600, 100);
setTitleBarHeight(5);
loadWindowState("Chat");
@@ -72,24 +72,18 @@ ChatWindow::ChatWindow():
gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS);
scrollArea->setOpaque(false);
- GCContainer *tab = new GCContainer();
- tab->setWidth(getWidth() - 2 * tab->getFrameSize());
- tab->setHeight(getHeight() - 2 * tab->getFrameSize());
- tab->setOpaque(false);
- tab->add(scrollArea);
+ mChatTabs = new TabbedArea();
+ mChatTabs->addTab("General", scrollArea);
+ mChatTabs->setWidth(getWidth());
+ mChatTabs->setHeight(getHeight());
- mContainer = new TabbedContainer();
- mContainer->addTab(tab, "General");
- mContainer->setOpaque(false);
mChannelOutput["General"] = textOutput;
mChannelScroll["General"] = scrollArea;
- mTabs["General"] = tab;
-
mTextOutput = textOutput;
mScrollArea = scrollArea;
- add(mContainer);
+ add(mChatTabs);
add(mChatInput);
// Add key listener to chat input to be able to respond to up/down
@@ -99,23 +93,20 @@ ChatWindow::ChatWindow():
ChatWindow::~ChatWindow()
{
- for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs));
+ delete mChatTabs;
}
void
ChatWindow::logic()
{
// todo: only do this when the size changes (updateWidgets?)
-
const gcn::Rectangle area = getChildrenArea();
mChatInput->setPosition(mChatInput->getFrameSize(),
area.height - mChatInput->getHeight() -
mChatInput->getFrameSize());
mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize());
- mContainer->setWidth(area.width - 2 * mContainer->getFrameSize());
- mContainer->setHeight(area.height - 2 * mContainer->getFrameSize() -
- mChatInput->getHeight() - 5);
+
mScrollArea->setWidth(area.width - 2 * mScrollArea->getFrameSize());
mScrollArea->setHeight(area.height - 2 * mScrollArea->getFrameSize() -
mChatInput->getHeight() - 26);
@@ -225,7 +216,8 @@ ChatWindow::action(const gcn::ActionEvent &event)
mCurHist = mHistory.end();
// Send the message to the server
- chatSend(player_node->getName(), message, mContainer->getActiveWidget());
+ gcn::Tab *tab = mChatTabs->getSelectedTab();
+ chatSend(player_node->getName(), message, tab->getCaption());
// Clear the text from the chat input
mChatInput->setText("");
@@ -280,7 +272,8 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg,
// Prepare ordinary message
if (msg[0] != '/') {
- if (mContainer->getActiveWidget() == "General")
+ gcn::Tab *tab = mChatTabs->getSelectedTab();
+ if (tab->getCaption() == "General")
{
Net::GameServer::Player::say(msg);
}
@@ -311,6 +304,7 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg,
chatLog("/announce > Global announcement (GM only)", BY_SERVER, channelName);
chatLog("/where > Display map name", BY_SERVER, channelName);
chatLog("/who > Display number of online users", BY_SERVER, channelName);
+ chatLog("/msg > Send a private message to a user", BY_SERVER, channelName);
chatLog("/list > Display all public channels", BY_SERVER, channelName);
chatLog("/register > Register a new channel", BY_SERVER, channelName);
chatLog("/join > Join an already registered channel", BY_SERVER, channelName);
@@ -328,6 +322,14 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg,
MessageOut outMsg(0x00c1);
*/
}
+ else if (command == "msg")
+ {
+ std::string::size_type pos = arg.find(' ', 1);
+ std::string recipient(arg, 0, pos-1);
+ std::string text(arg, pos+1);
+ chatLog("* " + text, BY_SERVER);
+ Net::ChatServer::privMsg(recipient, text);
+ }
else if (command == "register")
{
chatLog("Requesting to register channel " + arg, BY_SERVER);
@@ -458,8 +460,10 @@ ChatWindow::removeChannel(short channelId)
Channel* channel = channelManager->findById(channelId);
if(channel)
{
- mContainer->removeTab(channel->getName());
- mTabs.erase(channel->getName());
+ gcn::Tab *tab = mChatTabs->getTab(channel->getName());
+ if (!tab)
+ return;
+ mChatTabs->removeTab(tab);
mChannelOutput.erase(channel->getName());
mChannelScroll.erase(channel->getName());
channelManager->removeChannel(channel);
@@ -478,13 +482,8 @@ ChatWindow::createNewChannelTab(std::string channelName)
scrollArea->setPosition(scrollArea->getFrameSize(), scrollArea->getFrameSize());
scrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS);
scrollArea->setOpaque(false);
- GCContainer *tab = new GCContainer();
- tab->setWidth(getWidth() - 2 * tab->getFrameSize());
- tab->setHeight(getHeight() - 2 * tab->getFrameSize());
- tab->add(scrollArea);
- tab->setOpaque(false);
- mContainer->addTab(tab, channelName);
- mTabs[channelName] = tab;
+
+ mChatTabs->addTab(channelName, scrollArea);
mChannelOutput[channelName] = textOutput;
mChannelScroll[channelName] = scrollArea;
mScrollArea = scrollArea;
@@ -553,3 +552,12 @@ ChatWindow::setVisible(bool isVisible)
*/
mTmpVisible = false;
}
+
+bool
+ChatWindow::tabExists(const std::string &tabName)
+{
+ gcn::Tab *tab = mChatTabs->getTab(tabName);
+ if (tab)
+ return true;
+ return false;
+}