diff options
author | David Athay <ko2fan@gmail.com> | 2008-04-14 17:05:29 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-04-14 17:05:29 +0000 |
commit | bbb40f595e6e20e5106a23e6aa606b825b1e62b4 (patch) | |
tree | dbfe4adf16eb49be93c031587c2ff1694ac0d0e4 /src/gui | |
parent | 1ace3a1cec2ea8490af5af0b7d131394543fea11 (diff) | |
download | mana-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')
-rw-r--r-- | src/gui/chat.cpp | 68 | ||||
-rw-r--r-- | src/gui/chat.h | 14 | ||||
-rw-r--r-- | src/gui/guildwindow.cpp | 45 | ||||
-rw-r--r-- | src/gui/guildwindow.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 73 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.h | 60 |
6 files changed, 205 insertions, 60 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; +} diff --git a/src/gui/chat.h b/src/gui/chat.h index 19795dd3..d605def0 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -37,8 +37,9 @@ class BrowserBox; class ScrollArea; -class TabbedContainer; -class GCContainer; +//class TabbedContainer; +//class GCContainer; +class TabbedArea; enum { @@ -213,6 +214,10 @@ class ChatWindow : public Window, public gcn::ActionListener, void setVisible(bool visible); + /** Check if tab with that name already exists */ + bool + tabExists(const std::string &tabName); + private: bool mTmpVisible; @@ -229,11 +234,12 @@ class ChatWindow : public Window, public gcn::ActionListener, #if 0 /** Constructs failed messages for actions */ std::string const_msg(CHATSKILL); -#endif - std::map<std::string, GCContainer*> mTabs; TabbedContainer *mContainer; /**< Tabbed container for tabbing between channels */ GCContainer *mTab; /**< Tabs */ +#endif + + TabbedArea *mChatTabs; /** < Chat Tabbed area for holding each channel */ gcn::TextField *mChatInput; /**< Input box for typing chat messages */ std::map<std::string, BrowserBox*> mChannelOutput; /**< Map each TextOutput to a tab */ std::map<std::string, ScrollArea*> mChannelScroll; /**< Map each ScrollArea to a tab */ diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index eb0faa35..7b69f9bf 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -26,14 +26,13 @@ #include "button.h" #include "chat.h" #include "confirm_dialog.h" -#include "gccontainer.h" #include "guildlistbox.h" #include "scrollarea.h" -#include "tabbedcontainer.h" #include "textdialog.h" #include "windowcontainer.h" #include "widgets/layout.h" +#include "widgets/tabbedarea.h" #include "../guild.h" #include "../log.h" @@ -45,12 +44,14 @@ #include <algorithm> +#include <guichan/widgets/tab.hpp> + GuildWindow::GuildWindow(): Window(player_node->getName()), mFocus(false) { setCaption("Guild"); - setResizable(true); + setResizable(false); setCloseButton(true); setMinWidth(200); setMinHeight(280); @@ -63,14 +64,12 @@ GuildWindow::GuildWindow(): mGuildButton[1]->setEnabled(false); mGuildButton[2]->setEnabled(false); - mGuildsContainer = new TabbedContainer(); - - mGuildsContainer->setOpaque(false); + mGuildTabs = new TabbedArea(); place(0, 0, mGuildButton[0]); place(1, 0, mGuildButton[1]); place(2, 0, mGuildButton[2]); - place(0, 1, mGuildsContainer); + place(0, 1, mGuildTabs); Layout &layout = getLayout(); layout.setColWidth(0, 48); layout.setColWidth(1, 65); @@ -80,7 +79,7 @@ GuildWindow::GuildWindow(): GuildWindow::~GuildWindow() { - for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); + delete mGuildTabs; } void GuildWindow::update() @@ -102,13 +101,14 @@ void GuildWindow::action(const gcn::ActionEvent &event) // Stats Part if (eventId == "CREATE_GUILD") { - if (mGuildsContainer->getNumberOfTabs() > 1) + if (mGuildTabs->getNumberOfTabs() > 1) { // This is just to limit the number of guild tabs that are created // TODO: Either limit this server side, or fix the interface issue chatWindow->chatLog("Current maximum number of guilds ownable is 2", BY_SERVER); return; } + // Set focus so that guild name to be created can be typed. mFocus = true; guildDialog = new TextDialog("Guild Name", "Choose your guild's name", this); @@ -129,7 +129,7 @@ void GuildWindow::action(const gcn::ActionEvent &event) if (guild) { Net::ChatServer::Guild::quitGuild(guild); - chatWindow->chatLog("Guild " + mGuildsContainer->getActiveWidget() + " quit", BY_SERVER); + chatWindow->chatLog("Guild " + mGuildTabs->getSelectedTab()->getCaption() + " quit", BY_SERVER); } } else if (eventId == "CREATE_GUILD_OK") @@ -172,27 +172,25 @@ void GuildWindow::newGuildTab(const std::string &guildName) { // Create new tab - GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getFrameSize()); - tab->setHeight(getHeight() - 2 * tab->getFrameSize()); - tab->setOpaque(false); ListBox *list = new ListBox(); list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); - tab->add(sa); - mGuildsContainer->addTab(tab, guildName); - mGuildsContainer->setDimension(gcn::Rectangle(28,35,280,250)); - - mTabs.push_back(tab); + mGuildTabs->addTab(guildName, sa); + mGuildTabs->setDimension(gcn::Rectangle(28,35,140,250)); updateTab(); } void GuildWindow::updateTab() { - setTab(mGuildsContainer->getActiveWidget()); + gcn::Tab *tab = mGuildTabs->getSelectedTab(); + if (tab) + { + setTab(tab->getCaption()); + } + mGuildTabs->logic(); } void GuildWindow::setTab(const std::string &guildName) @@ -217,7 +215,7 @@ bool GuildWindow::isFocused() short GuildWindow::getSelectedGuild() { - Guild *guild = player_node->getGuild(mGuildsContainer->getActiveWidget()); + Guild *guild = player_node->getGuild(mGuildTabs->getSelectedTab()->getCaption()); if (guild) { return guild->getId(); @@ -248,7 +246,8 @@ void GuildWindow::removeTab(int guildId) Guild* guild = player_node->getGuild(guildId); if (guild) { - mGuildsContainer->removeTab(guild->getName()); + gcn::Tab *tab = mGuildTabs->getTab(guild->getName()); + mGuildTabs->removeTab(tab); } - mGuildsContainer->logic(); + mGuildTabs->logic(); } diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index 5f7600e5..f6cb38fd 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -45,9 +45,9 @@ class LocalPlayer; class TextDialog; class ConfirmDialog; class GuildListBox; -class TabbedContainer; class ScrollArea; class GCContainer; +class TabbedArea; class GuildWindow : public Window, public gcn::ActionListener { @@ -124,10 +124,9 @@ private: TextDialog *guildDialog; TextDialog *inviteDialog; ConfirmDialog *acceptDialog; - TabbedContainer *mGuildsContainer; + TabbedArea *mGuildTabs; GuildListBox *mGuildMembersList; ScrollArea *mScrollArea; - std::vector<GCContainer*> mTabs; bool mFocus; std::string invitedGuild; }; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp new file mode 100644 index 00000000..6ba27622 --- /dev/null +++ b/src/gui/widgets/tabbedarea.cpp @@ -0,0 +1,73 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#include "tabbedarea.h" + +#include <guichan/widgets/container.hpp> + +TabbedArea::TabbedArea() : gcn::TabbedArea() +{ + mWidgetContainer->setOpaque(false); +} + +int TabbedArea::getNumberOfTabs() +{ + return mTabs.size(); +} + +gcn::Tab* TabbedArea::getTab(const std::string &name) +{ + std::vector< std::pair<gcn::Tab*, gcn::Widget*> >::iterator itr = mTabs.begin(), + itr_end = mTabs.end(); + while (itr != itr_end) + { + if ((*itr).first->getCaption() == name) + { + return (*itr).first; + } + ++itr; + } +} + +void TabbedArea::draw(gcn::Graphics *graphics) +{ + if (mTabs.empty()) + { + return; + } + + std::vector< std::pair<gcn::Tab*, gcn::Widget*> >::iterator itr; + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == mSelectedTab) + { + mTabs[i].second->setWidth(getWidth()); + mTabs[i].second->setHeight(getHeight()); + mTabs[i].second->logic(); + break; + } + } + + gcn::TabbedArea::draw(graphics); +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h new file mode 100644 index 00000000..42275fae --- /dev/null +++ b/src/gui/widgets/tabbedarea.h @@ -0,0 +1,60 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#ifndef _TMW_TABBEDAREA_H +#define _TMW_TABBEDAREA_H + +#include <guichan/widgets/tab.hpp> +#include <guichan/widgets/tabbedarea.hpp> + +#include <string> + +/** + * A tabbed area, the same as the guichan tabbed area in 0.8, but extended + */ +class TabbedArea : public gcn::TabbedArea +{ + public: + /** + * Constructor. + */ + TabbedArea(); + + /** + * Draw the tabbed area. + */ + void draw(gcn::Graphics *graphics); + + /** + * Return how many tabs have been created + */ + int getNumberOfTabs(); + + /** + * Return tab with specified name as caption + */ + gcn::Tab* getTab(const std::string &name); +}; + +#endif + |