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 | |
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
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | data/graphics/gui/circle-gray.png | bin | 0 -> 295 bytes | |||
-rw-r--r-- | data/graphics/gui/circle-green.png | bin | 0 -> 299 bytes | |||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-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 | ||||
-rw-r--r-- | src/net/chathandler.cpp | 23 | ||||
-rw-r--r-- | src/net/chatserver/chatserver.cpp | 9 | ||||
-rw-r--r-- | src/net/chatserver/chatserver.h | 2 | ||||
-rw-r--r-- | src/net/guildhandler.cpp | 11 | ||||
-rw-r--r-- | src/net/protocol.h | 2 | ||||
-rw-r--r-- | tmw.cbp | 5 |
16 files changed, 144 insertions, 28 deletions
@@ -1,3 +1,14 @@ +2008-04-15 David Athay <ko2fan@gmail.com> + + * src/gui/guildlistbox.cpp, src/gui/guildwindow.h + src/gui/widgets/tabbedarea.h, src/gui/widgets/tabbedarea.cpp, + src/gui/guildlistbox.h, src/gui/guildwindow.cpp, + src/net/guildhandler.cpp, src/net/protocol.h, src/net/chathandler.cpp, + src/net/chatserver/chatserver.cpp, src/net/chatserver/chatserver.h, + src/Makefile.am, data/graphics/gui/circle-green.png + data/graphics/gui/circle-gray.png, tmw.cbp: Added online status of + guild members. + 2008-04-14 Yohann Ferreira <bertram@cegetel.net> * src/CMakeLists.txt: Fixed (again) a compilation error using CMake. diff --git a/data/graphics/gui/circle-gray.png b/data/graphics/gui/circle-gray.png Binary files differnew file mode 100644 index 00000000..719b0b10 --- /dev/null +++ b/data/graphics/gui/circle-gray.png diff --git a/data/graphics/gui/circle-green.png b/data/graphics/gui/circle-green.png Binary files differnew file mode 100644 index 00000000..bab39e05 --- /dev/null +++ b/data/graphics/gui/circle-green.png diff --git a/src/Makefile.am b/src/Makefile.am index c46fe481..3cfa64ea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ + gui/widgets/tabbedarea.cpp \ + gui/widgets/tabbedarea.h \ gui/box.h \ gui/box.cpp \ gui/browserbox.cpp \ 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 diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 4d48865a..d8a228ea 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -35,6 +35,7 @@ #include "../game.h" #include "../gui/chat.h" +#include "../gui/guildwindow.h" #include "../utils/tostring.h" @@ -49,6 +50,7 @@ ChatHandler::ChatHandler() CPMSG_LIST_CHANNELS_RESPONSE, CPMSG_PUBMSG, CPMSG_QUIT_CHANNEL_RESPONSE, + CPMSG_LIST_CHANNELUSERS_RESPONSE, /* SMSG_BEING_CHAT, SMSG_PLAYER_CHAT, @@ -106,9 +108,13 @@ void ChatHandler::handleMessage(MessageIn &msg) channelName = msg.readString(); std::string announcement = msg.readString(); std::vector<std::string> userList; + std::string user; while(msg.getUnreadLength()) { - userList.push_back(msg.readString()); + user = msg.readString(); + if (user == "") + break; + userList.push_back(user); } chatWindow->addChannel(channelId, channelName); chatWindow->createNewChannelTab(channelName); @@ -125,6 +131,8 @@ void ChatHandler::handleMessage(MessageIn &msg) while(msg.getUnreadLength()) { channelName = msg.readString(); + if (channelName == "") + break; std::ostringstream numUsers; numUsers << msg.readInt16(); if(channelName != "") @@ -164,6 +172,19 @@ void ChatHandler::handleMessage(MessageIn &msg) chatWindow->removeChannel(channelId); } break; + + case CPMSG_LIST_CHANNELUSERS_RESPONSE: + channelName = msg.readString(); + while(msg.getUnreadLength()) + { + userNick = msg.readString(); + if (userNick == "") + { + break; + } + guildWindow->setOnline(channelName, userNick, true); + } + break; /* // Received speech from being case SMSG_BEING_CHAT: diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp index 93fdc828..67cb5796 100644 --- a/src/net/chatserver/chatserver.cpp +++ b/src/net/chatserver/chatserver.cpp @@ -128,3 +128,12 @@ void Net::ChatServer::getChannelList() connection->send(msg); } + +void Net::ChatServer::getUserList(const std::string &channel) +{ + MessageOut msg(PCMSG_LIST_CHANNELUSERS); + + msg.writeString(channel); + + connection->send(msg); +} diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h index c4e0003d..b49d0c9e 100644 --- a/src/net/chatserver/chatserver.h +++ b/src/net/chatserver/chatserver.h @@ -54,6 +54,8 @@ namespace Net void getChannelList(); + void getUserList(const std::string &channel); + } } diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 494dcdc0..fd23546c 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -99,20 +99,30 @@ void GuildHandler::handleMessage(MessageIn &msg) if(msg.readInt8() == ERRMSG_OK) { std::string guildMember; + std::string guildName; Guild *guild; + short guildId = msg.readInt16(); guild = player_node->getGuild(guildId); + if (!guild) return; + + guildName = guild->getName(); + while(msg.getUnreadLength()) { guildMember = msg.readString(); if(guildMember != "") { guild->addMember(guildMember); + guildWindow->setOnline(guildName, guildMember, false); } } + guildWindow->updateTab(); + + Net::ChatServer::getUserList(guildName); } } break; @@ -126,6 +136,7 @@ void GuildHandler::handleMessage(MessageIn &msg) if (guild) { guild->addMember(guildMember); + guildWindow->setOnline(guild->getName(), guildMember, false); } guildWindow->updateTab(); } break; diff --git a/src/net/protocol.h b/src/net/protocol.h index 748a4e11..79e1f2ca 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -171,7 +171,7 @@ enum { CPMSG_USERJOINED = 0x0450, // W channel, S name CPMSG_USERLEFT = 0x0451, // W channel, S name PCMSG_LIST_CHANNELUSERS = 0x0460, // S channel - CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S users + CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S channel, S users XXMSG_INVALID = 0x7FFF }; @@ -303,9 +303,6 @@ <Unit filename="src/gui/sdlinput.h"> <Option target="default" /> </Unit> - <Unit filename="src/gui/selectionlistener.h"> - <Option target="default" /> - </Unit> <Unit filename="src/gui/sell.cpp" /> <Unit filename="src/gui/sell.h"> <Option target="default" /> @@ -409,6 +406,8 @@ <Unit filename="src/gui/widgets/resizegrip.h"> <Option target="default" /> </Unit> + <Unit filename="src/gui/widgets/tabbedarea.cpp" /> + <Unit filename="src/gui/widgets/tabbedarea.h" /> <Unit filename="src/gui/window.cpp" /> <Unit filename="src/gui/window.h"> <Option target="default" /> |