summaryrefslogtreecommitdiff
path: root/src/gui/socialwindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-13 23:54:06 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-13 23:54:06 +0300
commit6065690856ffc750404c9c0940d9a1f3a0cdd42c (patch)
tree5c9982c794c5631a967436032f9a6d55a0dacd08 /src/gui/socialwindow.cpp
parent424ed0b25065cc5ecc4b8464db2581a03189ef60 (diff)
downloadmv-6065690856ffc750404c9c0940d9a1f3a0cdd42c.tar.gz
mv-6065690856ffc750404c9c0940d9a1f3a0cdd42c.tar.bz2
mv-6065690856ffc750404c9c0940d9a1f3a0cdd42c.tar.xz
mv-6065690856ffc750404c9c0940d9a1f3a0cdd42c.zip
Add player/item/other counter in social window.
Diffstat (limited to 'src/gui/socialwindow.cpp')
-rw-r--r--src/gui/socialwindow.cpp166
1 files changed, 164 insertions, 2 deletions
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index edbd5a0d3..38f8d22f5 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -117,7 +117,8 @@ protected:
mInviteDialog(nullptr),
mConfirmDialog(nullptr),
mScroll(nullptr),
- mList(nullptr)
+ mList(nullptr),
+ mCounterString()
{
}
@@ -139,10 +140,27 @@ protected:
}
}
+ void setCurrent() override
+ {
+ updateCounter();
+ }
+
+ void updateCounter()
+ {
+ if (socialWindow)
+ socialWindow->setCounter(this, mCounterString);
+ }
+
+ virtual void buildCounter(const int online A_UNUSED = 0,
+ const int total A_UNUSED = 0)
+ {
+ }
+
TextDialog *mInviteDialog;
ConfirmDialog *mConfirmDialog;
ScrollArea *mScroll;
AvatarListBox *mList;
+ std::string mCounterString;
};
class SocialGuildTab final : public SocialTab, public gcn::ActionListener
@@ -243,6 +261,38 @@ public:
mConfirmDialog->addActionListener(this);
}
+ void buildCounter(const int online0, const int total0)
+ {
+ if (online0 || total0)
+ {
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Members: %u/%u"), online0, total0);
+ }
+ else
+ {
+ if (!player_node)
+ return;
+
+ const Guild *const guild = player_node->getGuild();
+ if (!guild)
+ return;
+
+ const Guild::MemberList *const members = guild->getMembers();
+ int online = 0;
+ int total = 0;
+ FOR_EACHP (Guild::MemberList::const_iterator, it, members)
+ {
+ if ((*it)->getOnline())
+ online ++;
+ total ++;
+ }
+
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Players: %u/%u"), online, total);
+ }
+ updateCounter();
+ }
+
private:
Guild *mGuild;
};
@@ -287,6 +337,30 @@ public:
void action(const gcn::ActionEvent &event A_UNUSED) override
{
}
+
+ void buildCounter(const int online0, const int total0)
+ {
+ if (!player_node)
+ return;
+
+ const Guild *const guild = player_node->getGuild();
+ if (!guild)
+ return;
+
+ const Guild::MemberList *const members = guild->getMembers();
+ int online = 0;
+ int total = 0;
+ FOR_EACHP (Guild::MemberList::const_iterator, it, members)
+ {
+ if ((*it)->getOnline())
+ online ++;
+ total ++;
+ }
+
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Players: %u/%u"), online, total);
+ updateCounter();
+ }
};
class SocialPartyTab final : public SocialTab, public gcn::ActionListener
@@ -386,6 +460,30 @@ public:
mConfirmDialog->addActionListener(this);
}
+ void buildCounter(const int online0 A_UNUSED, const int total0 A_UNUSED)
+ {
+ if (!player_node)
+ return;
+
+ const Party *const party = player_node->getParty();
+ if (!party)
+ return;
+
+ const Party::MemberList *const members = party->getMembers();
+ int online = 0;
+ int total = 0;
+ FOR_EACHP (Party::MemberList::const_iterator, it, members)
+ {
+ if ((*it)->getOnline())
+ online ++;
+ total ++;
+ }
+
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Players: %u/%u"), online, total);
+ updateCounter();
+ }
+
private:
Party *mParty;
};
@@ -579,6 +677,10 @@ public:
++i;
}
}
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Visible players: %d"),
+ static_cast<int>(avatars->size()));
+ updateCounter();
}
private:
@@ -645,6 +747,9 @@ public:
avatars->clear();
+ int online = 0;
+ int total = 0;
+
int idx = 0;
while (i != portals.end())
{
@@ -669,6 +774,10 @@ public:
ava->setY(y);
avatars->push_back(ava);
+ if (ava->getOnline())
+ online ++;
+ total ++;
+
if (config.getBoolValue("drawHotKeys") && idx < 80 && outfitWindow)
{
Being *const being = actorSpriteManager
@@ -695,6 +804,10 @@ public:
}
if (socialWindow)
socialWindow->setProcessedPortals(true);
+
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Portals: %u/%u"), online, total);
+ updateCounter();
}
@@ -1055,6 +1168,9 @@ public:
if (!players)
return;
+ int online = 0;
+ int total = 0;
+
FOR_EACHP (StringVectCIter, it, players)
{
Avatar *const ava = new Avatar(*it);
@@ -1062,11 +1178,17 @@ public:
|| players2.find(*it) != players2.end())
{
ava->setOnline(true);
+ online ++;
}
+ total ++;
avatars->push_back(ava);
}
std::sort(avatars->begin(), avatars->end(), friendSorter);
delete players;
+
+ // TRANSLATORS: social window label
+ mCounterString = strprintf(_("Friends: %u/%u"), online, total);
+ updateCounter();
}
private:
@@ -1162,6 +1284,7 @@ SocialWindow::SocialWindow() :
mInviteButton(new Button(this, _("Invite"), "invite", this)),
// TRANSLATORS: social window button
mLeaveButton(new Button(this, _("Leave"), "leave", this)),
+ mCountLabel(new Label(this, "1000 / 1000")),
mTabs(new TabbedArea(this)),
mMap(nullptr),
mLastUpdateTime(0),
@@ -1184,7 +1307,8 @@ SocialWindow::SocialWindow() :
place(0, 0, mCreateButton);
place(1, 0, mInviteButton);
place(2, 0, mLeaveButton);
- place(0, 1, mTabs, 4, 4);
+ place(0, 1, mCountLabel);
+ place(0, 2, mTabs, 4, 4);
widgetResized(gcn::Event(nullptr));
@@ -1702,6 +1826,20 @@ void SocialWindow::updatePickupFilter()
mPickupFilter->updateList();
}
+void SocialWindow::updateParty()
+{
+ if (!player_node)
+ return;
+
+ Party *const party = player_node->getParty();
+ PartyMap::iterator it = mParties.find(party);
+ if (it != mParties.end())
+ {
+ SocialTab *const tab = (*it).second;
+ tab->buildCounter();
+ }
+}
+
void SocialWindow::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
@@ -1709,6 +1847,30 @@ void SocialWindow::widgetResized(const gcn::Event &event)
mTabs->adjustSize();
}
+void SocialWindow::setCounter(const SocialTab *const tab,
+ const std::string &str)
+{
+ if (mTabs->getSelectedTab() == tab)
+ {
+ mCountLabel->setCaption(str);
+ mCountLabel->adjustSize();
+ }
+}
+
+void SocialWindow::updateGuildCounter(const int online, const int total)
+{
+ if (!player_node)
+ return;
+
+ Guild *const guild = player_node->getGuild();
+ GuildMap::iterator it = mGuilds.find(guild);
+ if (it != mGuilds.end())
+ {
+ SocialTab *const tab = (*it).second;
+ tab->buildCounter(online, total);
+ }
+}
+
#ifdef USE_PROFILER
void SocialWindow::logicChildren()
{