From 40f34b7ba7317f5f5c3dfbed0b291be9555d3137 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 28 Jan 2012 00:31:48 +0300 Subject: Add basic support for extended online list on evol server. --- src/gui/socialwindow.cpp | 2 +- src/gui/whoisonline.cpp | 135 ++++++++++++++++++++++++++++++----------------- src/gui/whoisonline.h | 76 +++++++++++++++++++++++--- 3 files changed, 156 insertions(+), 57 deletions(-) (limited to 'src/gui') diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index a1a6c1cee..59ace1685 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1143,7 +1143,7 @@ public: std::vector *players = player_relations.getPlayersByRelation(PlayerRelation::FRIEND); - std::set players2 = whoIsOnline->getOnlinePlayers(); + const std::set &players2 = whoIsOnline->getOnlineNicks(); if (!players) return; diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index a80fb4c89..34cfc1a57 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -48,6 +48,7 @@ #include "gui/chatwindow.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -68,21 +69,10 @@ class NameFunctuator { public: - bool operator()(const std::string &left, - const std::string &right) const + bool operator()(const OnlinePlayer *left, + const OnlinePlayer *right) const { - for (std::string::const_iterator lit = left.begin(), - rit = right.begin(); - lit != left.end() && rit != right.end(); ++lit, ++rit) - { - if (tolower(*lit) < tolower(*rit)) - return true; - else if (tolower(*lit) > tolower(*rit)) - return false; - } - if (left.size() < right.size()) - return true; - return false; + return (compareStrI(left->getNick(), right->getNick()) < 0); } } nameCompare; @@ -149,6 +139,14 @@ WhoIsOnline::~WhoIsOnline() // Remove possibly leftover temporary download delete[] mCurlError; + + std::set::iterator itd = mOnlinePlayers.begin(); + std::set::iterator itd_end = mOnlinePlayers.end(); + + for (; itd != itd_end; ++ itd) + delete *itd; + mOnlinePlayers.clear(); + mOnlineNicks.clear(); } void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) @@ -186,10 +184,10 @@ void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) } } -void WhoIsOnline::updateWindow(std::vector &friends, - std::vector &neutral, - std::vector &disregard, - std::vector enemy, +void WhoIsOnline::updateWindow(std::vector &friends, + std::vector &neutral, + std::vector &disregard, + std::vector enemy, int numOnline) { //Set window caption @@ -202,7 +200,7 @@ void WhoIsOnline::updateWindow(std::vector &friends, bool addedFromSection(false); for (int i = 0; i < static_cast(friends.size()); i++) { - mBrowserBox->addRow(friends.at(i)); + mBrowserBox->addRow(friends.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true) @@ -212,7 +210,7 @@ void WhoIsOnline::updateWindow(std::vector &friends, } for (int i = 0; i < static_cast(enemy.size()); i++) { - mBrowserBox->addRow(enemy.at(i)); + mBrowserBox->addRow(enemy.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true) @@ -222,7 +220,7 @@ void WhoIsOnline::updateWindow(std::vector &friends, } for (int i = 0; i < static_cast(neutral.size()); i++) { - mBrowserBox->addRow(neutral.at(i)); + mBrowserBox->addRow(neutral.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true && !disregard.empty()) @@ -232,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector &friends, } for (int i = 0; i < static_cast(disregard.size()); i++) { - mBrowserBox->addRow(disregard.at(i)); + mBrowserBox->addRow(disregard.at(i)->getText()); } if (mScrollArea->getVerticalMaxScroll() < @@ -243,43 +241,59 @@ void WhoIsOnline::updateWindow(std::vector &friends, } } -void WhoIsOnline::loadList(std::vector &list) +void WhoIsOnline::loadList(std::vector &list) { mBrowserBox->clearRows(); int numOnline = list.size(); - std::vector friends; - std::vector neutral; - std::vector disregard; - std::vector enemy; + std::vector friends; + std::vector neutral; + std::vector disregard; + std::vector enemy; + + std::set::iterator itd = mOnlinePlayers.begin(); + std::set::iterator itd_end = mOnlinePlayers.end(); + for (; itd != itd_end; ++ itd) + delete *itd; mOnlinePlayers.clear(); + mOnlineNicks.clear(); + mShowLevel = config.getBoolValue("showlevel"); - std::vector::const_iterator it = list.begin(); - std::vector::const_iterator it_end = list.end(); + std::vector::iterator it = list.begin(); + std::vector::iterator it_end = list.end(); for (; it != it_end; ++ it) { - std::string nick = *it; - mOnlinePlayers.insert(nick); + OnlinePlayer *player = *it; + std::string nick = player->getNick(); + mOnlinePlayers.insert(player); + mOnlineNicks.insert(nick); + + if (!mShowLevel) + player->setLevel(0); switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: default: - neutral.push_back(prepareNick(nick, 0, "0")); + player->setText("0"); + neutral.push_back(player); break; case PlayerRelation::FRIEND: - friends.push_back(prepareNick(nick, 0, "2")); + player->setText("2"); + neutral.push_back(player); break; case PlayerRelation::DISREGARDED: case PlayerRelation::BLACKLISTED: - disregard.push_back(prepareNick(nick, 0, "8")); + player->setText("8"); + disregard.push_back(player); break; case PlayerRelation::ENEMY2: - enemy.push_back(prepareNick(nick, 0, "1")); + player->setText("1"); + enemy.push_back(player); break; case PlayerRelation::IGNORED: @@ -290,10 +304,10 @@ void WhoIsOnline::loadList(std::vector &list) } updateWindow(friends, neutral, disregard, enemy, numOnline); - if (!mOnlinePlayers.empty()) + if (!mOnlineNicks.empty()) { if (chatWindow) - chatWindow->updateOnline(mOnlinePlayers); + chatWindow->updateOnline(mOnlineNicks); if (socialWindow) socialWindow->updateActiveList(); } @@ -313,15 +327,16 @@ void WhoIsOnline::loadWebList() bool listStarted(false); std::string lineStr; int numOnline(0); - std::vector friends; - std::vector neutral; - std::vector disregard; - std::vector enemy; + std::vector friends; + std::vector neutral; + std::vector disregard; + std::vector enemy; // Tokenize and add each line separately char *line = strtok(mMemoryBuffer, "\n"); const std::string gmText = "(GM)"; mOnlinePlayers.clear(); + mOnlineNicks.clear(); mShowLevel = config.getBoolValue("showlevel"); @@ -383,27 +398,37 @@ void WhoIsOnline::loadWebList() } } - mOnlinePlayers.insert(nick); + + if (!mShowLevel) + level = 0; + + OnlinePlayer *player = new OnlinePlayer(nick, -1, level, -1); + mOnlinePlayers.insert(player); + mOnlineNicks.insert(nick); numOnline++; switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: default: - neutral.push_back(prepareNick(nick, level, "0")); + player->setText("0"); + neutral.push_back(player); break; case PlayerRelation::FRIEND: - friends.push_back(prepareNick(nick, level, "2")); + player->setText("2"); + friends.push_back(player); break; case PlayerRelation::DISREGARDED: case PlayerRelation::BLACKLISTED: - disregard.push_back(prepareNick(nick, level, "8")); + player->setText("8"); + disregard.push_back(player); break; case PlayerRelation::ENEMY2: - enemy.push_back(prepareNick(nick, level, "1")); + player->setText("1"); + enemy.push_back(player); break; case PlayerRelation::IGNORED: @@ -596,10 +621,10 @@ void WhoIsOnline::logic() mUpdateButton->setEnabled(true); mUpdateTimer = 0; updateSize(); - if (!mOnlinePlayers.empty()) + if (!mOnlineNicks.empty()) { if (chatWindow) - chatWindow->updateOnline(mOnlinePlayers); + chatWindow->updateOnline(mOnlineNicks); if (socialWindow) socialWindow->updateActiveList(); } @@ -681,3 +706,17 @@ void WhoIsOnline::optionChanged(const std::string &name) if (name == "updateOnlineList") mUpdateOnlineList = config.getBoolValue("updateOnlineList"); } + +void OnlinePlayer::setText(std::string color) +{ + mText = strprintf("@@%s|##%s%s", mNick.c_str(), + color.c_str(), mNick.c_str()); + + if (mLevel > 0) + mText += strprintf(" (%d)", mLevel); + + if (mVersion > 0) + mText += strprintf(" - %d", mVersion); + + mText += strprintf("@@"); +} diff --git a/src/gui/whoisonline.h b/src/gui/whoisonline.h index ade391d5a..ef25257da 100644 --- a/src/gui/whoisonline.h +++ b/src/gui/whoisonline.h @@ -42,6 +42,62 @@ class ScrollArea; struct SDL_Thread; +class OnlinePlayer +{ + public: + OnlinePlayer(std::string nick, int status, int level, int version) : + mNick(nick), + mText(""), + mStatus(status), + mLevel(level), + mVersion(version) + { + } + + const std::string getNick() const + { + return mNick; + } + + int getStaus() const + { + return mStatus; + } + + int getVersion() const + { + return mVersion; + } + + int getLevel() const + { + return mLevel; + } + + const std::string getText() + { + return mText; + } + + void setText(std::string str); + + void setLevel(int level) + { + mLevel = level; + } + + private: + std::string mNick; + + std::string mText; + + int mStatus; + + int mLevel; + + int mVersion; +}; + /** * Update progress window GUI * @@ -52,7 +108,7 @@ class WhoIsOnline : public Window, public gcn::ActionListener, public ConfigListener { - public: +public: /** * Constructor. */ @@ -68,7 +124,7 @@ class WhoIsOnline : public Window, */ void loadWebList(); - void loadList(std::vector &list); + void loadList(std::vector &list); void handleLink(const std::string& link, gcn::MouseEvent *event); @@ -78,9 +134,12 @@ class WhoIsOnline : public Window, void widgetResized(const gcn::Event &event); - std::set &getOnlinePlayers() + const std::set &getOnlinePlayers() { return mOnlinePlayers; } + const std::set &getOnlineNicks() + { return mOnlineNicks; } + void setAllowUpdate(bool n) { mAllowUpdate = n; } @@ -109,10 +168,10 @@ private: const std::string prepareNick(std::string nick, int level, std::string color) const; - void updateWindow(std::vector &friends, - std::vector &neutral, - std::vector &disregard, - std::vector enemy, + void updateWindow(std::vector &friends, + std::vector &neutral, + std::vector &disregard, + std::vector enemy, int numOnline); enum DownloadStatus @@ -143,7 +202,8 @@ private: BrowserBox *mBrowserBox; ScrollArea *mScrollArea; time_t mUpdateTimer; - std::set mOnlinePlayers; + std::set mOnlinePlayers; + std::set mOnlineNicks; gcn::Button *mUpdateButton; bool mAllowUpdate; -- cgit v1.2.3-70-g09d2