diff options
author | David Athay <ko2fan@gmail.com> | 2024-04-15 00:31:42 +0100 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2024-04-15 00:31:42 +0100 |
commit | b16e95ca94b709f6a19abedb51e2fb313422a4d5 (patch) | |
tree | 8b2a685ef201e4f8ce661adc61a0bd2bba8c3adb | |
parent | e235ab70bd1a41df8da06bf8e8913f04d2bb6465 (diff) | |
download | mana-b16e95ca94b709f6a19abedb51e2fb313422a4d5.tar.gz mana-b16e95ca94b709f6a19abedb51e2fb313422a4d5.tar.bz2 mana-b16e95ca94b709f6a19abedb51e2fb313422a4d5.tar.xz mana-b16e95ca94b709f6a19abedb51e2fb313422a4d5.zip |
WIP: Create avatars and populate the online player list - Currently names are blank or mangled
-rw-r--r-- | src/gui/socialwindow.cpp | 27 | ||||
-rw-r--r-- | src/gui/socialwindow.h | 4 | ||||
-rw-r--r-- | src/net/tmwa/playerlisthandler.cpp | 24 |
3 files changed, 53 insertions, 2 deletions
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 953d347a..85f08204 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -46,6 +46,7 @@ #include "resources/theme.h" +#include "socialwindow.h" #include "utils/gettext.h" #include "utils/stringutils.h" #include "widgets/avatarlistbox.h" @@ -237,6 +238,14 @@ class PlayerList : public AvatarListModel { public: + void addAvatar(Avatar *avatar) { + mPlayers.push_back(avatar); + } + + void clearPlayerList() { + mPlayers.clear(); + } + /** * Get size of members list. * @return Returns the number of members in the party. @@ -274,6 +283,14 @@ public: { delete mPlayerList; } + void clearPlayerList() + { + mPlayerList->clearPlayerList(); + } + void addOnlinePlayer(Avatar *avatar) + { + mPlayerList->addAvatar(avatar); + } protected: void invite() override {} @@ -667,6 +684,16 @@ void SocialWindow::showPartyCreate() mPartyCreateDialog->addActionListener(this); } +void SocialWindow::setPlayersOnline(const std::vector<Avatar*> &onlineUsers) +{ + mPlayerListTab->clearPlayerList(); + for (auto itr = onlineUsers.begin(); + itr != onlineUsers.end(); ++itr) + { + mPlayerListTab->addOnlinePlayer(*(itr)); + } +} + void SocialWindow::updateButtons() { bool hasTabs = mTabs->getNumberOfTabs() > 0; diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 9db8f020..0c269e26 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -28,7 +28,9 @@ #include <string> #include <map> +#include <vector> +class Avatar; class Button; class ConfirmDialog; class CreatePopup; @@ -75,6 +77,8 @@ public: void showPartyCreate(); + void setPlayersOnline(const std::vector<Avatar*> &onlineUsers); + protected: friend class SocialTab; diff --git a/src/net/tmwa/playerlisthandler.cpp b/src/net/tmwa/playerlisthandler.cpp index 530af4c7..fe0b7bab 100644 --- a/src/net/tmwa/playerlisthandler.cpp +++ b/src/net/tmwa/playerlisthandler.cpp @@ -24,8 +24,11 @@ #include "net/tmwa/messageout.h" #include "net/tmwa/protocol.h" +#include "gui/socialwindow.h" + #include "utils/gettext.h" +#include "avatar.h" #include "event.h" #include "log.h" @@ -53,8 +56,25 @@ void PlayerListHandler::handleMessage(MessageIn &msg) { case SMSG_ONLINE_LIST: { - SERVER_NOTICE(_("RECEIVED SMSG_ONLINE_LIST")) - logger->log("GOT SMSG_ONLINE_LIST"); + int length = msg.readInt16(); + int count = (length - 4) / 31; + std::vector<Avatar*> onlineUsers; + + SERVER_NOTICE(strprintf(_("%d players online."), count)) + for (int i = 0; i < count; i++) + { + int id = msg.readInt32(); + std::string nick = msg.readString(24); + msg.readInt32(); // level + msg.readInt32(); // gm level + msg.readInt8(); // gender + + Avatar *avatar = new Avatar(nick); + avatar->setOnline(true); + onlineUsers.push_back(avatar); + } + + socialWindow->setPlayersOnline(onlineUsers); } break; } |