summaryrefslogtreecommitdiff
path: root/src/gui/socialwindow.cpp
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2024-06-25 23:05:31 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-06-25 23:05:31 +0000
commit452ebe4c4a0199fd07848a27f176723d3acf5704 (patch)
tree438fba5b1fa68b79b76cd7dc6a6b3036a22add13 /src/gui/socialwindow.cpp
parentcd6a29b5e50e26d03436e18e52fd0bb7a7f60bb9 (diff)
downloadmana-452ebe4c4a0199fd07848a27f176723d3acf5704.tar.gz
mana-452ebe4c4a0199fd07848a27f176723d3acf5704.tar.bz2
mana-452ebe4c4a0199fd07848a27f176723d3acf5704.tar.xz
mana-452ebe4c4a0199fd07848a27f176723d3acf5704.zip
Added online player list to Social window
The online list refreshes every 18 seconds, which matches ManaVerse behavior. It's not ideal, but to improve this would mean diving into TMWA. The client version was bumped to 8 to get a SMSG_ONLINE_LIST reply. Further changes needed related to the client version are tracked by #71. This also changes the TabbedArea to take into account the frame size for its tab widgets, to make sure those frames are not clipped by the TabbedArea widget (as happened in the Social window). The horizontal scroll bar is now disabled in all social tabs, with the vertical one appearing only when necessary. Closes #61
Diffstat (limited to 'src/gui/socialwindow.cpp')
-rw-r--r--src/gui/socialwindow.cpp91
1 files changed, 87 insertions, 4 deletions
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 9ba64e9f..76235306 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -20,6 +20,7 @@
#include "gui/socialwindow.h"
+#include "client.h"
#include "event.h"
#include "guild.h"
#include "localplayer.h"
@@ -40,6 +41,7 @@
#include "gui/widgets/tabbedarea.h"
#include "net/net.h"
+#include "net/chathandler.h"
#include "net/guildhandler.h"
#include "net/partyhandler.h"
@@ -98,8 +100,8 @@ public:
mList = std::make_unique<AvatarListBox>(guild);
mScroll = std::make_unique<ScrollArea>(mList.get());
- mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
- mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS);
+ mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
}
void action(const gcn::ActionEvent &event) override
@@ -173,7 +175,7 @@ public:
mList = std::make_unique<AvatarListBox>(party);
mScroll = std::make_unique<ScrollArea>(mList.get());
- mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
+ mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
}
@@ -231,6 +233,64 @@ private:
Party *mParty;
};
+class PlayerList : public AvatarListModel
+{
+public:
+ void setPlayers(const std::vector<Avatar*> &players)
+ {
+ delete_all(mPlayers);
+ mPlayers = players;
+ }
+
+ /**
+ * Returns the number of players in the list.
+ */
+ int getNumberOfElements() override
+ {
+ return mPlayers.size();
+ }
+
+ Avatar *getAvatarAt(int index) override
+ {
+ return mPlayers[index];
+ }
+
+private:
+ std::vector<Avatar*> mPlayers;
+};
+
+class PlayerListTab : public SocialTab
+{
+public:
+ PlayerListTab()
+ {
+ mPlayerList = new PlayerList;
+
+ mList = std::make_unique<AvatarListBox>(mPlayerList);
+ mScroll = std::make_unique<ScrollArea>(mList.get());
+
+ mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
+ }
+
+ ~PlayerListTab()
+ {
+ delete mPlayerList;
+ }
+
+ void setPlayers(const std::vector<Avatar*> &players)
+ {
+ mPlayerList->setPlayers(players);
+ }
+
+protected:
+ void invite() override {}
+ void leave() override {}
+
+private:
+ PlayerList *mPlayerList;
+};
+
/*class BuddyTab : public SocialTab
{
// TODO?
@@ -314,7 +374,12 @@ SocialWindow::SocialWindow() :
widgetResized(nullptr);
- mCreatePopup = new CreatePopup();
+ mCreatePopup = new CreatePopup;
+
+ mPlayerListTab = new PlayerListTab;
+ mPlayerListTab->setCaption(strprintf(_("Online (%zu)"), 0ul));
+
+ mTabs->addTab(mPlayerListTab, mPlayerListTab->mScroll.get());
if (local_player->getParty())
{
@@ -345,6 +410,7 @@ SocialWindow::~SocialWindow()
mPartyInviter.clear();
}
delete mCreatePopup;
+ delete mPlayerListTab;
}
bool SocialWindow::addTab(Guild *guild)
@@ -605,6 +671,23 @@ void SocialWindow::showPartyCreate()
mPartyCreateDialog->addActionListener(this);
}
+void SocialWindow::setPlayersOnline(const std::vector<Avatar*> &players)
+{
+ mPlayerListTab->setPlayers(players);
+ mPlayerListTab->setCaption(strprintf(_("Online (%zu)"), players.size()));
+}
+
+void SocialWindow::logic()
+{
+ if (mLastOnlineListUpdate == 0 || get_elapsed_time(mLastOnlineListUpdate) >= 18000)
+ {
+ Net::getChatHandler()->requestOnlineList();
+ mLastOnlineListUpdate = tick_time;
+ }
+
+ Window::logic();
+}
+
void SocialWindow::updateButtons()
{
bool hasTabs = mTabs->getNumberOfTabs() > 0;