summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-29 02:06:59 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-29 02:07:25 +0300
commitf612e40c96f370282971d3a5795da4fb8d99bea1 (patch)
treee8741515ff407b510f15477da39eb13c356467d6 /src
parent0de50d314ca7705024d1035802eaea2c43eb2848 (diff)
downloadManaVerse-f612e40c96f370282971d3a5795da4fb8d99bea1.tar.gz
ManaVerse-f612e40c96f370282971d3a5795da4fb8d99bea1.tar.bz2
ManaVerse-f612e40c96f370282971d3a5795da4fb8d99bea1.tar.xz
ManaVerse-f612e40c96f370282971d3a5795da4fb8d99bea1.zip
Add bages db. Add badges support for parties.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being/being.cpp71
-rw-r--r--src/being/being.h7
-rw-r--r--src/client.cpp3
-rw-r--r--src/resources/db/badgesdb.cpp64
-rw-r--r--src/resources/db/badgesdb.h40
7 files changed, 178 insertions, 11 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b3974bf4b..d50299f2b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -591,6 +591,8 @@ SET(SRCS
resources/attack.h
resources/db/avatardb.cpp
resources/db/avatardb.h
+ resources/db/badgesdb.cpp
+ resources/db/badgesdb.h
resources/beingcommon.cpp
resources/beingcommon.h
resources/beinginfo.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index c877c37f5..3e4495dc4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -738,6 +738,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/attack.h \
resources/db/avatardb.cpp \
resources/db/avatardb.h \
+ resources/db/badgesdb.cpp \
+ resources/db/badgesdb.h \
resources/beingcommon.cpp \
resources/beingcommon.h \
resources/beinginfo.cpp \
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 363ff6c5f..ef5412d0a 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -71,6 +71,7 @@
#include "resources/spriteaction.h"
#include "resources/db/avatardb.h"
+#include "resources/db/badgesdb.h"
#include "resources/db/emotedb.h"
#include "resources/db/homunculusdb.h"
#include "resources/db/horsedb.h"
@@ -134,6 +135,7 @@ Being::Being(const BeingId id,
mInfo(BeingInfo::unknown),
mEmotionSprite(nullptr),
mAnimationEffect(nullptr),
+ mPartyBadge(nullptr),
mTeamBadge(nullptr),
mSpriteAction(SpriteAction::STAND),
mName(),
@@ -221,6 +223,7 @@ Being::Being(const BeingId id,
mAreaSize(11),
mTeamId(0U),
mLook(0U),
+ mBadgesCount(0U),
mHairColor(0),
mErased(false),
mEnemy(false),
@@ -290,7 +293,9 @@ Being::~Being()
delete2(mText);
delete2(mEmotionSprite);
delete2(mAnimationEffect);
+ delete2(mPartyBadge);
delete2(mTeamBadge);
+ mBadgesCount = 0;
#ifdef EATHENA_SUPPORT
delete2(mChat);
#endif
@@ -1366,6 +1371,8 @@ void Being::setAction(const BeingActionT &action, const int attackId)
mEmotionSprite->play(currentAction);
if (mAnimationEffect)
mAnimationEffect->play(currentAction);
+ if (mPartyBadge)
+ mPartyBadge->play(currentAction);
if (mTeamBadge)
mTeamBadge->play(currentAction);
#ifdef EATHENA_SUPPORT
@@ -1431,6 +1438,8 @@ void Being::setDirection(const uint8_t direction)
mEmotionSprite->setSpriteDirection(dir);
if (mAnimationEffect)
mAnimationEffect->setSpriteDirection(dir);
+ if (mPartyBadge)
+ mPartyBadge->setSpriteDirection(dir);
if (mTeamBadge)
mTeamBadge->setSpriteDirection(dir);
#ifdef EATHENA_SUPPORT
@@ -1537,6 +1546,8 @@ void Being::logic()
if (mAnimationEffect->isTerminated())
delete2(mAnimationEffect)
}
+ if (mPartyBadge)
+ mPartyBadge->update(time);
if (mTeamBadge)
mTeamBadge->update(time);
@@ -1848,18 +1859,30 @@ void Being::drawEmotion(Graphics *const graphics,
mEmotionSprite->draw(graphics, px, py);
if (mAnimationEffect)
mAnimationEffect->draw(graphics, px, py);
- if (mTeamBadge && mShowBadges)
+ if (mShowBadges && mBadgesCount)
{
+ int x;
+ int y;
if (!mShowBadgesTop && mDispName && gui)
{
Font *const font = gui->getFont();
- mTeamBadge->draw(graphics,
- mDispName->getX() - offsetX + mDispName->getWidth(),
- mDispName->getY() - offsetY - font->getHeight());
+ x = mDispName->getX() - offsetX + mDispName->getWidth();
+ y = mDispName->getY() - offsetY - font->getHeight();
}
else
{
- mTeamBadge->draw(graphics, px, py);
+ x = px + 8 - mBadgesCount * 8;
+ y = py;
+ }
+ if (mTeamBadge)
+ {
+ mTeamBadge->draw(graphics, x, y);
+ x += 16;
+ }
+ if (mPartyBadge)
+ {
+ mPartyBadge->draw(graphics, x, y);
+// x += 16;
}
}
}
@@ -3710,15 +3733,45 @@ void Being::setTeamId(const uint16_t teamId)
void Being::showBadges(const bool show)
{
delete2(mTeamBadge);
- if (show && mTeamId)
+ if (show && mTeamId && mShowBadges)
{
- mTeamBadge = AnimatedSprite::load(
- paths.getStringValue("badges") +
+ const std::string name = paths.getStringValue("badges") +
paths.getStringValue(strprintf("team%dbadge",
- mTeamId)));
+ mTeamId));
+ if (!name.empty())
+ mTeamBadge = AnimatedSprite::load(name);
+ }
+ updateBadgesCount();
+}
+
+void Being::setPartyName(const std::string &name)
+{
+ if (mPartyName != name)
+ {
+ delete2(mPartyBadge);
+ mPartyName = name;
+ if (!mPartyName.empty() && mShowBadges)
+ {
+ const std::string badge = BadgesDB::getPartyBadge(mPartyName);
+ if (!badge.empty())
+ {
+ mPartyBadge = AnimatedSprite::load(
+ paths.getStringValue("badges") + badge);
+ }
+ }
+ updateBadgesCount();
}
}
+void Being::updateBadgesCount()
+{
+ mBadgesCount = 0;
+ if (mTeamBadge)
+ mBadgesCount ++;
+ if (mPartyBadge)
+ mBadgesCount ++;
+}
+
#ifdef EATHENA_SUPPORT
void Being::setChat(ChatObject *const obj)
{
diff --git a/src/being/being.h b/src/being/being.h
index e58cbcb90..2f8796ba7 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -227,8 +227,7 @@ class Being notfinal : public ActorSprite,
/**
* Sets the name of the party the being is in. Shown in BeingPopup.
*/
- void setPartyName(const std::string &name)
- { mPartyName = name; }
+ void setPartyName(const std::string &name);
const std::string &getPartyName() const A_WARN_UNUSED
{ return mPartyName; }
@@ -955,11 +954,14 @@ class Being notfinal : public ActorSprite,
void setDefaultNameColor(const UserColorIdT defaultColor);
+ void updateBadgesCount();
+
static int getDefaultEffectId(const AttackTypeT &type);
BeingInfo *mInfo;
AnimatedSprite *mEmotionSprite;
AnimatedSprite *mAnimationEffect;
+ AnimatedSprite *mPartyBadge;
AnimatedSprite *mTeamBadge;
std::string mSpriteAction;
@@ -1124,6 +1126,7 @@ class Being notfinal : public ActorSprite,
int mAreaSize;
uint16_t mTeamId;
uint16_t mLook;
+ uint16_t mBadgesCount;
unsigned char mHairColor;
bool mErased;
bool mEnemy;
diff --git a/src/client.cpp b/src/client.cpp
index a47abae18..f1a6a2396 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -98,6 +98,7 @@
#include "resources/spritereference.h"
#include "resources/db/avatardb.h"
+#include "resources/db/badgesdb.h"
#include "resources/db/chardb.h"
#include "resources/db/colordb.h"
#include "resources/db/deaddb.h"
@@ -561,6 +562,7 @@ void Client::gameClear()
MonsterDB::unload();
NPCDB::unload();
AvatarDB::unload();
+ BadgesDB::unload();
WeaponsDB::unload();
PaletteDB::unload();
PETDB::unload();
@@ -1233,6 +1235,7 @@ int Client::gameExec()
HomunculusDB::load();
MonsterDB::load();
AvatarDB::load();
+ BadgesDB::load();
WeaponsDB::load();
NPCDB::load();
PETDB::load();
diff --git a/src/resources/db/badgesdb.cpp b/src/resources/db/badgesdb.cpp
new file mode 100644
index 000000000..80b480ee0
--- /dev/null
+++ b/src/resources/db/badgesdb.cpp
@@ -0,0 +1,64 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2014-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/db/badgesdb.h"
+
+#include "utils/xmlutils.h"
+
+#include "debug.h"
+
+namespace
+{
+ BadgesInfos mParties;
+ bool mLoaded = false;
+}
+
+static void loadDB(const std::string &name, BadgesInfos &arr)
+{
+ readXmlStringMap("badges.xml",
+ "badges",
+ name,
+ "badge",
+ "name",
+ "image",
+ arr);
+}
+
+void BadgesDB::load()
+{
+ if (mLoaded)
+ unload();
+
+ loadDB("party", mParties);
+}
+
+void BadgesDB::unload()
+{
+ mParties.clear();
+ mLoaded = false;
+}
+
+const std::string BadgesDB::getPartyBadge(const std::string &name)
+{
+ BadgesInfosIter it = mParties.find(name);
+ if (it == mParties.end())
+ return std::string();
+ return (*it).second;
+}
diff --git a/src/resources/db/badgesdb.h b/src/resources/db/badgesdb.h
new file mode 100644
index 000000000..2a5bb91f1
--- /dev/null
+++ b/src/resources/db/badgesdb.h
@@ -0,0 +1,40 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2014-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_DB_BADGESDB_H
+#define RESOURCES_DB_BADGESDB_H
+
+#include <map>
+
+#include "localconsts.h"
+
+typedef std::map<std::string, std::string> BadgesInfos;
+typedef BadgesInfos::const_iterator BadgesInfosIter;
+
+namespace BadgesDB
+{
+ void load();
+
+ void unload();
+
+ const std::string getPartyBadge(const std::string &name);
+} // namespace BadgesDB
+
+#endif // RESOURCES_DB_BADGESDB_H