summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-30 14:40:15 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-30 14:40:15 +0300
commitfadafe160a52f47d9eeca88517562964a85499c2 (patch)
tree57dd234149a5100ba1adde53ebe2794d267790e1
parent4eeb20aae588b9c3d1c4ed4462306391e20e58fc (diff)
downloadmanaverse-fadafe160a52f47d9eeca88517562964a85499c2.tar.gz
manaverse-fadafe160a52f47d9eeca88517562964a85499c2.tar.bz2
manaverse-fadafe160a52f47d9eeca88517562964a85499c2.tar.xz
manaverse-fadafe160a52f47d9eeca88517562964a85499c2.zip
Add badges for player names.
-rw-r--r--src/being/being.cpp40
-rw-r--r--src/being/being.h3
-rw-r--r--src/resources/db/badgesdb.cpp12
-rw-r--r--src/resources/db/badgesdb.h2
4 files changed, 57 insertions, 0 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 0e1fbbc2f..a923d107e 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -136,6 +136,7 @@ Being::Being(const BeingId id,
mAnimationEffect(nullptr),
mGmBadge(nullptr),
mGuildBadge(nullptr),
+ mNameBadge(nullptr),
mPartyBadge(nullptr),
mTeamBadge(nullptr),
mSpriteAction(SpriteAction::STAND),
@@ -296,6 +297,7 @@ Being::~Being()
delete2(mAnimationEffect);
delete2(mGmBadge);
delete2(mGuildBadge);
+ delete2(mNameBadge);
delete2(mPartyBadge);
delete2(mTeamBadge);
mBadgesCount = 0;
@@ -974,6 +976,20 @@ void Being::handleSkill(Being *const victim, const int damage,
}
}
+void Being::showNameBadge(const bool show)
+{
+ delete2(mNameBadge);
+ if (show && !mName.empty() && mShowBadges)
+ {
+ const std::string badge = BadgesDB::getNameBadge(mName);
+ if (!badge.empty())
+ {
+ mNameBadge = AnimatedSprite::load(
+ paths.getStringValue("badges") + badge);
+ }
+ }
+}
+
void Being::setName(const std::string &name)
{
if (mType == ActorType::Npc)
@@ -981,6 +997,16 @@ void Being::setName(const std::string &name)
mName = name.substr(0, name.find('#', 0));
showName();
}
+ else if (mType == ActorType::Player)
+ {
+ if (mName != name)
+ {
+ mName = name;
+ showNameBadge(!mName.empty());
+ }
+ if (getShowName())
+ showName();
+ }
else
{
if (mType == ActorType::Portal)
@@ -1397,6 +1423,8 @@ void Being::setAction(const BeingActionT &action, const int attackId)
mGmBadge->play(currentAction);
if (mGuildBadge)
mGuildBadge->play(currentAction);
+ if (mNameBadge)
+ mNameBadge->play(currentAction);
if (mPartyBadge)
mPartyBadge->play(currentAction);
if (mTeamBadge)
@@ -1468,6 +1496,8 @@ void Being::setDirection(const uint8_t direction)
mGmBadge->setSpriteDirection(dir);
if (mGuildBadge)
mGuildBadge->setSpriteDirection(dir);
+ if (mNameBadge)
+ mNameBadge->setSpriteDirection(dir);
if (mPartyBadge)
mPartyBadge->setSpriteDirection(dir);
if (mTeamBadge)
@@ -1580,6 +1610,8 @@ void Being::logic()
mGmBadge->update(time);
if (mGuildBadge)
mGuildBadge->update(time);
+ if (mNameBadge)
+ mNameBadge->update(time);
if (mPartyBadge)
mPartyBadge->update(time);
if (mTeamBadge)
@@ -1916,6 +1948,11 @@ void Being::drawEmotion(Graphics *const graphics,
mTeamBadge->draw(graphics, x, y);
x += 16;
}
+ if (mNameBadge)
+ {
+ mNameBadge->draw(graphics, x, y);
+ x += 16;
+ }
if (mGmBadge)
{
mGmBadge->draw(graphics, x, y);
@@ -3817,6 +3854,7 @@ void Being::showBadges(const bool show)
showGuildBadge(show);
showGmBadge(show);
showPartyBadge(show);
+ showNameBadge(show);
}
void Being::showPartyBadge(const bool show)
@@ -3852,6 +3890,8 @@ void Being::updateBadgesCount()
mBadgesCount ++;
if (mGuildBadge)
mBadgesCount ++;
+ if (mNameBadge)
+ mBadgesCount ++;
if (mPartyBadge)
mBadgesCount ++;
}
diff --git a/src/being/being.h b/src/being/being.h
index 6850b2169..ff00d5bef 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -939,6 +939,8 @@ class Being notfinal : public ActorSprite,
void showPartyBadge(const bool show);
+ void showNameBadge(const bool show);
+
void showBadges(const bool show);
uint16_t getTeamId() const
@@ -971,6 +973,7 @@ class Being notfinal : public ActorSprite,
AnimatedSprite *mAnimationEffect;
AnimatedSprite *mGmBadge;
AnimatedSprite *mGuildBadge;
+ AnimatedSprite *mNameBadge;
AnimatedSprite *mPartyBadge;
AnimatedSprite *mTeamBadge;
diff --git a/src/resources/db/badgesdb.cpp b/src/resources/db/badgesdb.cpp
index cdf61b406..d7476c7f0 100644
--- a/src/resources/db/badgesdb.cpp
+++ b/src/resources/db/badgesdb.cpp
@@ -27,6 +27,7 @@
namespace
{
BadgesInfos mGuilds;
+ BadgesInfos mNames;
BadgesInfos mParties;
bool mLoaded = false;
}
@@ -48,12 +49,15 @@ void BadgesDB::load()
unload();
loadDB("guild", mGuilds);
+ loadDB("name", mNames);
loadDB("party", mParties);
}
void BadgesDB::unload()
{
mParties.clear();
+ mGuilds.clear();
+ mNames.clear();
mLoaded = false;
}
@@ -65,6 +69,14 @@ const std::string BadgesDB::getPartyBadge(const std::string &name)
return (*it).second;
}
+const std::string BadgesDB::getNameBadge(const std::string &name)
+{
+ BadgesInfosIter it = mNames.find(name);
+ if (it == mNames.end())
+ return std::string();
+ return (*it).second;
+}
+
const std::string BadgesDB::getGuildBadge(const std::string &name)
{
BadgesInfosIter it = mGuilds.find(name);
diff --git a/src/resources/db/badgesdb.h b/src/resources/db/badgesdb.h
index 5e53660b9..324eac6c0 100644
--- a/src/resources/db/badgesdb.h
+++ b/src/resources/db/badgesdb.h
@@ -37,6 +37,8 @@ namespace BadgesDB
const std::string getGuildBadge(const std::string &name);
+ const std::string getNameBadge(const std::string &name);
+
const std::string getPartyBadge(const std::string &name);
} // namespace BadgesDB