summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-31 21:37:07 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-31 21:37:07 +0300
commita1a404408a790623f518bcb2966b472622f39116 (patch)
tree03edd8016f4efe6d46082fcbe0936f5abd659056 /src/being
parent6a64f7e58501280751d6cbe4f3a474cdb1a93f46 (diff)
downloadmanaplus-a1a404408a790623f518bcb2966b472622f39116.tar.gz
manaplus-a1a404408a790623f518bcb2966b472622f39116.tar.bz2
manaplus-a1a404408a790623f518bcb2966b472622f39116.tar.xz
manaplus-a1a404408a790623f518bcb2966b472622f39116.zip
Precalculate badges position on each change time.
Diffstat (limited to 'src/being')
-rw-r--r--src/being/being.cpp107
-rw-r--r--src/being/being.h4
2 files changed, 68 insertions, 43 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index bf1b2db59..36badf728 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -257,6 +257,8 @@ Being::Being(const BeingId id,
mAreaSize(11),
mCastEndTime(0),
mLanguageId(-1),
+ mBadgesX(0),
+ mBadgesY(0),
mCreatorId(BeingId_zero),
mTeamId(0U),
mLook(0U),
@@ -2258,74 +2260,84 @@ void Being::updateBotDirection(const int dstX,
}
}
-void Being::drawEmotion(Graphics *restrict const graphics,
- const int offsetX,
- const int offsetY) const restrict2
+void Being::updateBadgesPosition()
{
- if (mErased)
- return;
-
- const int px = mPixelX - offsetX - mapTileSize / 2;
- const int py = mPixelY - offsetY - mapTileSize * 2 - mapTileSize;
- if (mAnimationEffect != nullptr)
- mAnimationEffect->draw(graphics, px, py);
+ const int px = mPixelX - mapTileSize / 2;
+ const int py = mPixelY - mapTileSize * 2 - mapTileSize;
if (mShowBadges != BadgeDrawType::Hide &&
mBadgesCount != 0u)
{
- int x;
- int y;
if (mDispName != nullptr &&
gui != nullptr)
{
if (mShowBadges == BadgeDrawType::Right)
{
const Font *restrict const font = gui->getFont();
- x = mDispName->getX() - offsetX + mDispName->getWidth();
- y = mDispName->getY() - offsetY - font->getHeight();
+ mBadgesX = mDispName->getX() + mDispName->getWidth();
+ mBadgesY = mDispName->getY() - font->getHeight();
}
else if (mShowBadges == BadgeDrawType::Bottom)
{
- x = px + 8 - mBadgesCount * 8;
+ mBadgesX = px + 8 - mBadgesCount * 8;
if (mVisibleNamePos == VisibleNamePos::Buttom)
{
- y = mDispName->getY() - offsetY;
+ mBadgesY = mDispName->getY();
}
else
{
- y = py + settings.playerNameOffset + 16;
+ mBadgesY = py + settings.playerNameOffset + 16;
}
}
else
{
- x = px + 8 - mBadgesCount * 8;
+ mBadgesX = px + 8 - mBadgesCount * 8;
if (mVisibleNamePos == VisibleNamePos::Top)
- y = py - mDispName->getHeight();
+ mBadgesY = py - mDispName->getHeight();
else
- y = py;
+ mBadgesY = py;
}
}
else
{
if (mShowBadges == BadgeDrawType::Right)
{
- x = px + settings.playerBadgeAtRightOffset;
- y = py;
+ mBadgesX = px + settings.playerBadgeAtRightOffset;
+ mBadgesY = py;
}
else if (mShowBadges == BadgeDrawType::Bottom)
{
- x = px + 8 - mBadgesCount * 8;
+ mBadgesX = px + 8 - mBadgesCount * 8;
const int height = settings.playerNameOffset;
if (mVisibleNamePos == VisibleNamePos::Buttom)
- y = py + height;
+ mBadgesY = py + height;
else
- y = py + height + 16;
+ mBadgesY = py + height + 16;
}
else
{
- x = px + 8 - mBadgesCount * 8;
- y = py;
+ mBadgesX = px + 8 - mBadgesCount * 8;
+ mBadgesY = py;
}
}
+ }
+}
+
+void Being::drawEmotion(Graphics *restrict const graphics,
+ const int offsetX,
+ const int offsetY) const restrict2
+{
+ if (mErased)
+ return;
+
+ const int px = mPixelX - offsetX - mapTileSize / 2;
+ const int py = mPixelY - offsetY - mapTileSize * 2 - mapTileSize;
+ if (mAnimationEffect != nullptr)
+ mAnimationEffect->draw(graphics, px, py);
+ if (mShowBadges != BadgeDrawType::Hide &&
+ mBadgesCount != 0u)
+ {
+ int x = mBadgesX - offsetX;
+ const int y = mBadgesY - offsetY;
for_each_badges()
{
const AnimatedSprite *restrict const sprite = mBadges[f];
@@ -2438,30 +2450,33 @@ int Being::getOffset() const restrict2
void Being::updateCoords() restrict2
{
- if (mDispName == nullptr)
- return;
-
- int offsetX = mPixelX;
- int offsetY = mPixelY;
- if (mInfo != nullptr)
- {
- offsetX += mInfo->getNameOffsetX();
- offsetY += mInfo->getNameOffsetY();
- }
- // Monster names show above the sprite instead of below it
- if (mType == ActorType::Monster ||
- mVisibleNamePos == VisibleNamePos::Top)
+ if (mDispName != nullptr)
{
- offsetY += - settings.playerNameOffset - mDispName->getHeight();
+ int offsetX = mPixelX;
+ int offsetY = mPixelY;
+ if (mInfo != nullptr)
+ {
+ offsetX += mInfo->getNameOffsetX();
+ offsetY += mInfo->getNameOffsetY();
+ }
+ // Monster names show above the sprite instead of below it
+ if (mType == ActorType::Monster ||
+ mVisibleNamePos == VisibleNamePos::Top)
+ {
+ offsetY += - settings.playerNameOffset - mDispName->getHeight();
+ }
+ mDispName->adviseXY(offsetX, offsetY, mMoveNames);
}
-
- mDispName->adviseXY(offsetX, offsetY, mMoveNames);
+ updateBadgesPosition();
}
void Being::optionChanged(const std::string &restrict value) restrict2
{
if (mType == ActorType::Player && value == "visiblenames")
+ {
setShowName(config.getIntValue("visiblenames") == VisibleName::Show);
+ updateBadgesPosition();
+ }
}
void Being::flashName(const int time) restrict2
@@ -3562,6 +3577,7 @@ void Being::showGmBadge(const bool show) restrict2
}
}
updateBadgesCount();
+ updateBadgesPosition();
}
void Being::setGM(const bool gm) restrict2
@@ -5079,6 +5095,7 @@ void Being::showTeamBadge(const bool show) restrict2
mBadges[BadgeIndex::Team] = AnimatedSprite::load(name);
}
updateBadgesCount();
+ updateBadgesPosition();
}
void Being::showBadges(const bool show) restrict2
@@ -5108,6 +5125,7 @@ void Being::showPartyBadge(const bool show) restrict2
}
}
updateBadgesCount();
+ updateBadgesPosition();
}
@@ -5135,6 +5153,7 @@ void Being::showShopBadge(const bool show) restrict2
}
}
updateBadgesCount();
+ updateBadgesPosition();
}
void Being::showInactiveBadge(const bool show) restrict2
@@ -5152,6 +5171,7 @@ void Being::showInactiveBadge(const bool show) restrict2
}
}
updateBadgesCount();
+ updateBadgesPosition();
}
void Being::showAwayBadge(const bool show) restrict2
@@ -5169,6 +5189,7 @@ void Being::showAwayBadge(const bool show) restrict2
}
}
updateBadgesCount();
+ updateBadgesPosition();
}
void Being::updateBadgesCount() restrict2
diff --git a/src/being/being.h b/src/being/being.h
index 0f652139d..cd5b0efff 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -1222,6 +1222,8 @@ class Being notfinal : public ActorSprite,
void postInit(const BeingTypeId subType,
Map *const map);
+ void updateBadgesPosition();
+
/**
* Calculates the offset in the given directions.
* If walking in direction 'neg' the value is negated.
@@ -1349,6 +1351,8 @@ class Being notfinal : public ActorSprite,
int mAreaSize;
int mCastEndTime;
int mLanguageId;
+ int mBadgesX;
+ int mBadgesY;
BeingId mCreatorId;
uint16_t mTeamId;
uint16_t mLook;