diff options
author | David Athay <ko2fan@gmail.com> | 2008-04-15 15:42:04 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-04-15 15:42:04 +0000 |
commit | e2e4ceb9fa8a72ad94853f74724676fff82b15c0 (patch) | |
tree | 5336955366e76266f92dbef4da6e632b84714cdf /src/gui | |
parent | d4cc1ded15daa0677e710013640c90b1aadd6bd0 (diff) | |
download | mana-e2e4ceb9fa8a72ad94853f74724676fff82b15c0.tar.gz mana-e2e4ceb9fa8a72ad94853f74724676fff82b15c0.tar.bz2 mana-e2e4ceb9fa8a72ad94853f74724676fff82b15c0.tar.xz mana-e2e4ceb9fa8a72ad94853f74724676fff82b15c0.zip |
Added online status of guild members
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/guildlistbox.cpp | 35 | ||||
-rw-r--r-- | src/gui/guildlistbox.h | 26 | ||||
-rw-r--r-- | src/gui/guildwindow.cpp | 18 | ||||
-rw-r--r-- | src/gui/guildwindow.h | 7 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 15 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.h | 6 |
6 files changed, 84 insertions, 23 deletions
diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp index 11661235..1c14fd55 100644 --- a/src/gui/guildlistbox.cpp +++ b/src/gui/guildlistbox.cpp @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -18,25 +18,32 @@ * 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$ + * $Id $ */ #include "guildlistbox.h" #include "../graphics.h" +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + #include <guichan/font.hpp> GuildListBox::GuildListBox(): ListBox(NULL) { + onlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png"); + offlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png"); } -void GuildListBox::draw(gcn::Graphics *graphics) +void GuildListBox::draw(gcn::Graphics *gcnGraphics) { if (!mListModel) return; + Graphics *graphics = static_cast<Graphics*>(gcnGraphics); + graphics->setColor(gcn::Color(110, 160, 255)); graphics->setFont(getFont()); @@ -48,17 +55,22 @@ void GuildListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); } - // TODO: Add online status image - // Draw the list elements for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { - graphics->drawText(mListModel->getElementAt(i), 1, y); + // Draw online status + bool online = mUsers[mListModel->getElementAt(i)]; + Image *icon = online ? onlineIcon : offlineIcon; + if (icon) + graphics->drawImage(icon, 1, y); + // Draw Name + graphics->setColor(gcn::Color(0, 0, 0)); + graphics->drawText(mListModel->getElementAt(i), 33, y); } } - +/* void GuildListBox::setSelected(int selected) { if (!mListModel) @@ -84,14 +96,19 @@ void GuildListBox::setSelected(int selected) distributeValueChangedEvent(); } - +*/ void GuildListBox::mousePressed(gcn::MouseEvent &event) { if (event.getButton() == gcn::MouseEvent::LEFT) { - // TODO: Add guild functions, ie private messaging int y = event.getY(); setSelected(y / getFont()->getHeight()); distributeActionEvent(); } + // TODO: Add guild functions, ie private messaging +} + +void GuildListBox::setOnlineStatus(const std::string &user, bool online) +{ + mUsers[user] = online; } diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h index 262012a4..0f030d0a 100644 --- a/src/gui/guildlistbox.h +++ b/src/gui/guildlistbox.h @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -18,17 +18,20 @@ * 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$ + * $Id $ */ #ifndef _TMW_GUI_GUILDLISTBOX_H #define _TMW_GUI_GUILDLISTBOX_H +#include <map> #include <string> #include <vector> #include "listbox.h" +class Image; + class GuildListBox : public ListBox { public: @@ -38,21 +41,26 @@ public: GuildListBox(); /** - * Set ListModel - */ - void setList(gcn::ListModel *listModel); - - /** * Draws the list box. */ - void draw(gcn::Graphics *graphics); + void draw(gcn::Graphics *gcnGraphics); void mousePressed(gcn::MouseEvent &event); /** * Sets the index of the selected element. */ - void setSelected(int selected); +// void setSelected(int selected); + + /** + * Set whether a member is online or offline + */ + void setOnlineStatus(const std::string &user, bool online); + +private: + Image *onlineIcon; + Image *offlineIcon; + std::map<std::string, bool> mUsers; }; #endif diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 7b69f9bf..7237a870 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -84,7 +84,7 @@ GuildWindow::~GuildWindow() void GuildWindow::update() { - + updateTab(); } void GuildWindow::draw(gcn::Graphics *g) @@ -172,7 +172,7 @@ void GuildWindow::newGuildTab(const std::string &guildName) { // Create new tab - ListBox *list = new ListBox(); + GuildListBox *list = new GuildListBox(); list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); @@ -224,7 +224,8 @@ short GuildWindow::getSelectedGuild() return 0; } -void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName) +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); @@ -248,6 +249,17 @@ void GuildWindow::removeTab(int guildId) { gcn::Tab *tab = mGuildTabs->getTab(guild->getName()); mGuildTabs->removeTab(tab); + updateTab(); } mGuildTabs->logic(); } + +void GuildWindow::setOnline(const std::string &guildName, const std::string &member, + bool online) +{ + GuildListBox *box = dynamic_cast<GuildListBox*>(mGuildTabs->getWidget(guildName)); + if (box) + { + box->setOnlineStatus(member, online); + } +} diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index f6cb38fd..b85ca3a5 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -112,6 +112,12 @@ public: */ void removeTab(int guildId); + /** + * Set guild member status in userlist + */ + void setOnline(const std::string &guildName, const std::string &member, + bool online); + protected: /** * Get selected guild tab @@ -125,7 +131,6 @@ private: TextDialog *inviteDialog; ConfirmDialog *acceptDialog; TabbedArea *mGuildTabs; - GuildListBox *mGuildMembersList; ScrollArea *mScrollArea; bool mFocus; std::string invitedGuild; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 6ba27622..20c100e5 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -56,7 +56,6 @@ void TabbedArea::draw(gcn::Graphics *graphics) return; } - std::vector< std::pair<gcn::Tab*, gcn::Widget*> >::iterator itr; unsigned int i; for (i = 0; i < mTabs.size(); i++) { @@ -71,3 +70,17 @@ void TabbedArea::draw(gcn::Graphics *graphics) gcn::TabbedArea::draw(graphics); } + +gcn::Widget* TabbedArea::getWidget(const std::string &name) +{ + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first->getCaption() == name) + { + return mTabs[i].second; + } + } + + return NULL; +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 42275fae..3f58acde 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -24,6 +24,7 @@ #ifndef _TMW_TABBEDAREA_H #define _TMW_TABBEDAREA_H +#include <guichan/widget.hpp> #include <guichan/widgets/tab.hpp> #include <guichan/widgets/tabbedarea.hpp> @@ -54,6 +55,11 @@ class TabbedArea : public gcn::TabbedArea * Return tab with specified name as caption */ gcn::Tab* getTab(const std::string &name); + + /** + * Return selected tab's widget + */ + gcn::Widget* getWidget(const std::string &name); }; #endif |