diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | src/gui/chat.cpp | 7 | ||||
-rw-r--r-- | src/gui/guildlistbox.cpp | 17 | ||||
-rw-r--r-- | src/gui/guildlistbox.h | 3 | ||||
-rw-r--r-- | src/gui/guildwindow.cpp | 10 | ||||
-rw-r--r-- | src/gui/guildwindow.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 10 | ||||
-rw-r--r-- | src/guild.cpp | 34 | ||||
-rw-r--r-- | src/guild.h | 20 | ||||
-rw-r--r-- | src/net/guildhandler.cpp | 3 |
10 files changed, 90 insertions, 31 deletions
@@ -1,12 +1,20 @@ +2008-04-16 David Athay <ko2fan@gmail.com> + + * src/gui/guildlistbox.cpp, src/gui/guildwindow.h, + src/gui/widgets/tabbedarea.cpp, src/gui/chat.cpp, + src/gui/guildlistbox.h, src/gui/guildwindow.cpp, src/guild.cpp, + src/guild.h, src/net/guildhandler.cpp: Fixed online status so that + users are shown as online. + 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/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 + data/graphics/gui/circle-gray.png, tmw.cbp: Added online status of guild members. 2008-04-14 Yohann Ferreira <bertram@cegetel.net> diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 0602c671..f6e95059 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -475,6 +475,7 @@ ChatWindow::removeChannel(short channelId) void ChatWindow::createNewChannelTab(std::string channelName) { + // Create new channel BrowserBox *textOutput = new BrowserBox(BrowserBox::AUTO_WRAP); textOutput->setOpaque(false); textOutput->disableLinksAndUserColors(); @@ -483,11 +484,17 @@ ChatWindow::createNewChannelTab(std::string channelName) scrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); scrollArea->setOpaque(false); + // Add channel to the tabbed area mChatTabs->addTab(channelName, scrollArea); mChannelOutput[channelName] = textOutput; mChannelScroll[channelName] = scrollArea; mScrollArea = scrollArea; mTextOutput = textOutput; + + // Ask for channel users + Net::ChatServer::getUserList(channelName); + + // Update UI logic(); } diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp index 1c14fd55..3f540cc5 100644 --- a/src/gui/guildlistbox.cpp +++ b/src/gui/guildlistbox.cpp @@ -61,7 +61,12 @@ void GuildListBox::draw(gcn::Graphics *gcnGraphics) ++i, y += fontHeight) { // Draw online status - bool online = mUsers[mListModel->getElementAt(i)]; + bool online = false; + UserMap::iterator itr = mUsers.find(mListModel->getElementAt(i)); + if (itr != mUsers.end()) + { + online = itr->second; + } Image *icon = online ? onlineIcon : offlineIcon; if (icon) graphics->drawImage(icon, 1, y); @@ -110,5 +115,13 @@ void GuildListBox::mousePressed(gcn::MouseEvent &event) void GuildListBox::setOnlineStatus(const std::string &user, bool online) { - mUsers[user] = online; + UserMap::iterator itr = mUsers.find(user); + if (itr == mUsers.end()) + { + mUsers.insert(std::pair<std::string, bool>(user, online)); + } + else + { + itr->second = online; + } } diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h index 0f030d0a..b3892955 100644 --- a/src/gui/guildlistbox.h +++ b/src/gui/guildlistbox.h @@ -60,7 +60,8 @@ public: private: Image *onlineIcon; Image *offlineIcon; - std::map<std::string, bool> mUsers; + typedef std::map<std::string, bool> UserMap; + UserMap mUsers; }; #endif diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 7237a870..0e9a066a 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -170,13 +170,15 @@ void GuildWindow::action(const gcn::ActionEvent &event) void GuildWindow::newGuildTab(const std::string &guildName) { - // Create new tab GuildListBox *list = new GuildListBox(); list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); + // Add the listbox to the map + mGuildLists.insert(std::pair<std::string, GuildListBox*>(guildName, list)); + mGuildTabs->addTab(guildName, sa); mGuildTabs->setDimension(gcn::Rectangle(28,35,140,250)); @@ -257,9 +259,9 @@ void GuildWindow::removeTab(int guildId) void GuildWindow::setOnline(const std::string &guildName, const std::string &member, bool online) { - GuildListBox *box = dynamic_cast<GuildListBox*>(mGuildTabs->getWidget(guildName)); - if (box) + GuildListMap::iterator itr = mGuildLists.find(guildName); + if (itr != mGuildLists.end()) { - box->setOnlineStatus(member, online); + itr->second->setOnlineStatus(member, online); } } diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index b85ca3a5..7e7a313a 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -32,6 +32,7 @@ #define _TMW_GUI_GUILDWINDOW_H #include <iosfwd> +#include <map> #include <vector> #include <guichan/actionlistener.hpp> @@ -134,6 +135,8 @@ private: ScrollArea *mScrollArea; bool mFocus; std::string invitedGuild; + typedef std::map<std::string, GuildListBox*> GuildListMap; + GuildListMap mGuildLists; }; extern GuildWindow *guildWindow; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 20c100e5..a22c795c 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -73,13 +73,15 @@ void TabbedArea::draw(gcn::Graphics *graphics) gcn::Widget* TabbedArea::getWidget(const std::string &name) { - unsigned int i; - for (i = 0; i < mTabs.size(); i++) + std::vector< std::pair<gcn::Tab*, gcn::Widget*> >::iterator itr = mTabs.begin(), + itr_end = mTabs.end(); + while (itr != itr_end) { - if (mTabs[i].first->getCaption() == name) + if ((*itr).first->getCaption() == name) { - return mTabs[i].second; + return (*itr).second; } + ++itr; } return NULL; diff --git a/src/guild.cpp b/src/guild.cpp index e2f9d097..0141db2f 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -28,25 +28,43 @@ Guild::Guild(short id, bool inviteRights) : mId(id), mCanInviteUsers(inviteRights) { - + } void Guild::addMember(const std::string &name) { - mMembers.push_back(name); + if (!isMember(name)) + { + mMembers.push_back(name); + } } void Guild::removeMember(const std::string &name) { - for(std::vector<std::string>::iterator itr = mMembers.begin(); - itr != mMembers.end(); - ++itr) + std::vector<std::string>::iterator itr = mMembers.begin(), + itr_end = mMembers.end(); + while(itr != itr_end) { - std::string member = (*itr); - if(member == name) + if((*itr) == name) { mMembers.erase(itr); } + ++itr; } - +} + +bool Guild::isMember(const std::string &name) +{ + std::vector<std::string>::iterator itr = mMembers.begin(), + itr_end = mMembers.end(); + while(itr != itr_end) + { + if((*itr) == name) + { + return true; + } + ++itr; + } + + return false; } diff --git a/src/guild.h b/src/guild.h index 19cfd99c..68806eec 100644 --- a/src/guild.h +++ b/src/guild.h @@ -13,7 +13,7 @@ public: * Constructor with guild id passed to it */ Guild(short id, bool inviteRights); - + /** * Set the guild's name */ @@ -21,12 +21,12 @@ public: { mName = name; } - + /** * Add member to the list */ void addMember(const std::string &name); - + /** * Get the name of the guild * @return returns name of the guild @@ -35,7 +35,7 @@ public: { return mName; } - + /** * Get the id of the guild * @return Returns the id of the guild @@ -44,12 +44,12 @@ public: { return mId; } - + /** * Remove member from the guild */ void removeMember(const std::string &name); - + /** * Get size of members list * @return Returns the number of members in the guild. @@ -57,7 +57,7 @@ public: int getNumberOfElements() { return mMembers.size(); } - + /** * Get member at i * @return Returns the name of member. @@ -65,7 +65,7 @@ public: std::string getElementAt(int i) { return mMembers[i]; } - + /** * Get whether user can invite users to this guild * @return Returns true if user can invite users @@ -74,7 +74,9 @@ public: { return mCanInviteUsers; } - + + bool isMember(const std::string &name); + private: std::string mName; short mId; diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index fd23546c..3fecf9b2 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -137,8 +137,11 @@ void GuildHandler::handleMessage(MessageIn &msg) { guild->addMember(guildMember); guildWindow->setOnline(guild->getName(), guildMember, false); + Net::ChatServer::getUserList(guild->getName()); } guildWindow->updateTab(); + + } break; case CPMSG_GUILD_INVITED: |