summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp59
-rw-r--r--src/being.h47
-rw-r--r--src/beingmanager.cpp9
-rw-r--r--src/beingmanager.h7
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/localplayer.cpp5
-rw-r--r--src/localplayer.h9
-rw-r--r--src/map.cpp2
-rw-r--r--src/monster.cpp13
-rw-r--r--src/monster.h2
-rw-r--r--src/npc.cpp16
-rw-r--r--src/npc.h4
-rw-r--r--src/player.cpp14
-rw-r--r--src/text.cpp5
-rw-r--r--src/text.h5
15 files changed, 91 insertions, 108 deletions
diff --git a/src/being.cpp b/src/being.cpp
index b0666e8a..5d840333 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -68,9 +68,6 @@ int Being::mNumberOfHairColors = 1;
int Being::mNumberOfHairstyles = 1;
std::vector<std::string> Being::hairColors;
-static const int X_SPEECH_OFFSET = 18;
-static const int Y_SPEECH_OFFSET = 60;
-
static const int DEFAULT_WIDTH = 32;
static const int DEFAULT_HEIGHT = 32;
@@ -147,6 +144,10 @@ void Being::setPosition(const Vector &pos)
mPy = (int) pos.y;
updateCoords();
+
+ if (mText)
+ mText->adviseXY(mPx,
+ mPy - getHeight() - mText->getHeight());
}
#ifdef EATHENA_SUPPORT
@@ -396,6 +397,18 @@ void Being::setSpeech(const std::string &text, int time)
if (!mSpeech.empty())
mSpeechTime = time <= SPEECH_MAX_TIME ? time : SPEECH_MAX_TIME;
+
+ const int speech = (int) config.getValue("speech", NAME_IN_BUBBLE);
+ if (speech == TEXT_OVERHEAD) {
+ if (mText)
+ delete mText;
+
+ mText = new Text(mSpeech,
+ mPx, mPy - getHeight(),
+ gcn::Graphics::CENTER,
+ &guiPalette->getColor(Palette::PARTICLE),
+ true);
+ }
}
void Being::takeDamage(Being *attacker, int amount, AttackType type)
@@ -672,8 +685,8 @@ void Being::logic()
}
#else
// Update pixel coordinates
- setPosition(mX * 32 + getXOffset(),
- mY * 32 + getYOffset());
+ setPosition(mX * 32 + 16 + getXOffset(),
+ mY * 32 + 32 + getYOffset());
#endif
if (mEmotion != 0)
@@ -710,8 +723,11 @@ void Being::logic()
void Being::draw(Graphics *graphics, int offsetX, int offsetY) const
{
- const int px = mPx + offsetX;
- const int py = mPy + offsetY;
+ // TODO: Eventually, we probably should fix all sprite offsets so that
+ // these translations aren't necessary anymore. The sprites know
+ // best where their centerpoint should be.
+ const int px = mPx + offsetX - 16;
+ const int py = mPy + offsetY - 32;
if (mUsedTargetCursor)
mUsedTargetCursor->draw(graphics, px, py);
@@ -720,13 +736,7 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const
{
if (mSprites[i])
{
-#ifdef TMWSERV_SUPPORT
- // TODO: Eventually, we probably should fix all sprite offsets so
- // that this translation isn't necessary anymore.
- mSprites[i]->draw(graphics, px - 16, py - 32);
-#else
mSprites[i]->draw(graphics, px, py);
-#endif
}
}
}
@@ -769,27 +779,22 @@ void Being::drawSpeech(int offsetX, int offsetY)
mSpeechBubble->setCaption(showName ? mName : "", mNameColor);
- // Not quite centered, but close enough. However, it's not too important
- // to get it right right now, as it doesn't take bubble collision into
- // account yet.
mSpeechBubble->setText(mSpeech, showName);
- mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() * 4 / 11),
- py - 40 - (mSpeechBubble->getHeight()));
+ mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2),
+ py - getHeight() - (mSpeechBubble->getHeight()));
mSpeechBubble->setVisible(true);
}
else if (mSpeechTime > 0 && speech == TEXT_OVERHEAD)
{
mSpeechBubble->setVisible(false);
- // don't introduce a memory leak
- if (mText)
- delete mText;
-
- mText = new Text(mSpeech,
- mPx + X_SPEECH_OFFSET,
- mPy - Y_SPEECH_OFFSET,
- gcn::Graphics::CENTER,
- &guiPalette->getColor(Palette::PARTICLE));
+ if (! mText) {
+ mText = new Text(mSpeech,
+ mPx, mPy - getHeight(),
+ gcn::Graphics::CENTER,
+ &guiPalette->getColor(Palette::PARTICLE),
+ true);
+ }
}
else if (speech == NO_SPEECH)
{
diff --git a/src/being.h b/src/being.h
index 0faf794e..daedcf33 100644
--- a/src/being.h
+++ b/src/being.h
@@ -163,12 +163,13 @@ class Being : public Sprite
/**
* Constructor.
+ *
+ * @param id a unique being id
+ * @param job partly determines the type of the being
+ * @param map the map the being is on
*/
Being(int id, int job, Map *map);
- /**
- * Destructor.
- */
virtual ~Being();
/**
@@ -276,9 +277,6 @@ class Being : public Sprite
*/
virtual void setGender(Gender gender) { mGender = gender; }
- /**
- * Gets the gender of this being.
- */
Gender getGender() const { return mGender; }
#ifdef EATHENA_SUPPORT
@@ -290,9 +288,6 @@ class Being : public Sprite
/**
* Triggers whether or not to show the name as a GM name.
- * NOTE: This doesn't mean that just anyone can use this.
- * If the server doesn't acknowlege you, you won't be shown
- * as a GM on other people's clients.
*/
virtual void setGM() { mIsGM = true; }
@@ -317,26 +312,19 @@ class Being : public Sprite
virtual Type getType() const;
/**
- * Gets the walk speed.
- * @see setWalkSpeed(int)
- */
- int getWalkSpeed() const { return mWalkSpeed; }
-
- /**
* Sets the walk speed (in pixels per second).
*/
void setWalkSpeed(int speed) { mWalkSpeed = speed; }
- /**
- * Gets the being id.
- */
- int getId() const { return mId; }
+ int getWalkSpeed() const { return mWalkSpeed; }
/**
* Sets the sprite id.
*/
void setId(int id) { mId = id; }
+ int getId() const { return mId; }
+
/**
* Sets the map the being is on
*/
@@ -348,9 +336,9 @@ class Being : public Sprite
virtual void setAction(Action action, int attackType = 0);
/**
- * Gets the current action.
+ * Returns whether this being is still alive.
*/
- bool isAlive() { return mAction != DEAD; }
+ bool isAlive() const { return mAction != DEAD; }
/**
* Returns the current direction.
@@ -364,9 +352,9 @@ class Being : public Sprite
#ifdef EATHENA_SUPPORT
/**
- * Gets the current action.
+ * Returns the walk time.
*/
- int getWalkTime() { return mWalkTime; }
+ int getWalkTime() const { return mWalkTime; }
#endif
/**
@@ -515,17 +503,14 @@ class Being : public Sprite
internalTriggerEffect(effectId, false, true);
}
- // Target cursor being used by the being
- Image *mTargetCursor;
-
static int getHairColorCount();
static int getHairStyleCount();
static std::string getHairColor(int index);
- virtual AnimatedSprite* getSprite(int index) const
- { return mSprites[index]; }
+ virtual AnimatedSprite *getSprite(int index) const
+ { return mSprites[index]; }
static void load();
@@ -556,7 +541,7 @@ class Being : public Sprite
void internalTriggerEffect(int effectId, bool sfx, bool gfx);
/**
- * Notify self that the stun mode has been updated. Invoked by
+ * Notify self that the stun mode has been updated. Invoked by
* setStunMode if something changed.
*/
virtual void updateStunMode(int oldMode, int newMode);
@@ -623,7 +608,7 @@ class Being : public Sprite
/** Reset particle status effects on next redraw? */
bool mMustResetParticles;
- // Speech Bubble components
+ /** Speech Bubble components */
SpeechBubble *mSpeechBubble;
int mWalkSpeed; /**< Walking speed (pixels/sec) */
@@ -632,7 +617,7 @@ class Being : public Sprite
Vector mDest;
int mPx, mPy; /**< Position in pixels */
- // Target cursor being used
+ /** Target cursor being used */
SimpleAnimation* mUsedTargetCursor;
};
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index af968bdb..d72c4ee4 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -188,7 +188,7 @@ Being *BeingManager::findBeingByPixel(int x, int y)
return NULL;
}
-Being *BeingManager::findBeingByName(std::string name, Being::Type type)
+Being *BeingManager::findBeingByName(const std::string &name, Being::Type type)
{
for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
{
@@ -321,11 +321,12 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist,
return (maxdist >= dist) ? closestBeing : NULL;
}
-bool BeingManager::hasBeing(Being *being)
+bool BeingManager::hasBeing(Being *being) const
{
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
+ for (Beings::const_iterator i = mBeings.begin(); i != mBeings.end(); i++)
{
- if (being == *i) return true;
+ if (being == *i)
+ return true;
}
return false;
diff --git a/src/beingmanager.h b/src/beingmanager.h
index 05821bcf..109564fa 100644
--- a/src/beingmanager.h
+++ b/src/beingmanager.h
@@ -92,7 +92,8 @@ class BeingManager
/**
* Finds a being by name and (optionally) by type.
*/
- Being *findBeingByName(std::string name, Being::Type type = Being::UNKNOWN);
+ Being *findBeingByName(const std::string &name,
+ Being::Type type = Being::UNKNOWN);
/**
* Returns a being nearest to another being.
@@ -106,7 +107,7 @@ class BeingManager
/**
* Returns the whole list of beings
*/
- Beings& getAll();
+ Beings &getAll();
/**
* Returns true if the given being is in the manager's list, false
@@ -114,7 +115,7 @@ class BeingManager
*
* \param being the being to search for
*/
- bool hasBeing(Being *being);
+ bool hasBeing(Being *being) const;
/**
* Logic.
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index c840e456..7b797d5b 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -289,7 +289,7 @@ void Viewport::drawPath(Graphics *graphics, const Path &path)
void Viewport::mousePressed(gcn::MouseEvent &event)
{
// Check if we are alive and kickin'
- if (!mMap || !player_node || player_node->mAction == Being::DEAD)
+ if (!mMap || !player_node || !player_node->isAlive())
return;
// Check if we are busy
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 14b32415..f8fad1e8 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -71,9 +71,6 @@ const short walkingKeyboardDelay = 100;
LocalPlayer *player_node = NULL;
-static const int NAME_X_OFFSET = 15;
-static const int NAME_Y_OFFSET = 30;
-
#ifdef TMWSERV_SUPPORT
LocalPlayer::LocalPlayer():
Player(65535, 0, NULL),
@@ -86,7 +83,7 @@ LocalPlayer::LocalPlayer():
mCorrectionPoints(-1),
mLevelProgress(0),
#else
-LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
+LocalPlayer::LocalPlayer(int id, int job, Map *map):
Player(id, job, map),
mCharId(0),
mJobXp(0),
diff --git a/src/localplayer.h b/src/localplayer.h
index 99cb00d6..77e9ac02 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -145,7 +145,7 @@ class LocalPlayer : public Player
#ifdef TMWSERV_SUPPORT
LocalPlayer();
#else
- LocalPlayer(Uint32 id, Uint16 job, Map *map);
+ LocalPlayer(int id, int job, Map *map);
#endif
/**
@@ -170,13 +170,13 @@ class LocalPlayer : public Player
/**
* Returns the player's inventory.
*/
- Inventory* getInventory() const { return mInventory; }
+ Inventory *getInventory() const { return mInventory; }
#ifdef EATHENA_SUPPORT
/**
* Returns the player's storage
*/
- Inventory* getStorage() const { return mStorage; }
+ Inventory *getStorage() const { return mStorage; }
#endif
#ifdef TMWSERV_SUPPORT
@@ -275,9 +275,6 @@ class LocalPlayer : public Player
/**
* Triggers whether or not to show the name as a GM name.
- * NOTE: This doesn't mean that just anyone can use this.
- * If the server doesn't acknowlege you, you won't be shown
- * as a GM on other people's clients.
*/
virtual void setGM();
diff --git a/src/map.cpp b/src/map.cpp
index 551c10f3..59e6201f 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -144,7 +144,7 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY,
#ifdef TMWSERV_SUPPORT
while (si != sprites.end() && (*si)->getPixelY() <= y * 32)
#else
- while (si != sprites.end() && (*si)->getPixelY() <= y * 32 - 32)
+ while (si != sprites.end() && (*si)->getPixelY() <= y * 32)
#endif
{
(*si)->draw(graphics, -scrollX, -scrollY);
diff --git a/src/monster.cpp b/src/monster.cpp
index f786471d..c2632028 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -32,10 +32,7 @@
#include "resources/monsterdb.h"
#include "resources/monsterinfo.h"
-static const int NAME_X_OFFSET = 16;
-static const int NAME_Y_OFFSET = 16;
-
-Monster::Monster(int id, Uint16 job, Map *map):
+Monster::Monster(int id, int job, Map *map):
Being(id, job, map),
mText(0)
{
@@ -218,8 +215,8 @@ void Monster::setShowName(bool show)
if (show)
{
mText = new Text(getInfo().getName(),
- getPixelX() + NAME_X_OFFSET,
- getPixelY() + NAME_Y_OFFSET - getHeight(),
+ getPixelX(),
+ getPixelY() - getHeight(),
gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::MONSTER));
}
@@ -233,7 +230,7 @@ void Monster::updateCoords()
{
if (mText)
{
- mText->adviseXY(getPixelX() + NAME_X_OFFSET,
- getPixelY() + NAME_Y_OFFSET - getHeight());
+ mText->adviseXY(getPixelX(),
+ getPixelY() - getHeight() - mText->getHeight());
}
}
diff --git a/src/monster.h b/src/monster.h
index cd2a8f0c..bf52ed6d 100644
--- a/src/monster.h
+++ b/src/monster.h
@@ -30,7 +30,7 @@ class Text;
class Monster : public Being
{
public:
- Monster(int id, Uint16 job, Map *map);
+ Monster(int id, int job, Map *map);
~Monster();
diff --git a/src/npc.cpp b/src/npc.cpp
index 133f11c6..b75d74b3 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -40,14 +40,11 @@
bool NPC::isTalking = false;
int current_npc = 0;
-static const int NAME_X_OFFSET = 15;
-static const int NAME_Y_OFFSET = 30;
-
#ifdef TMWSERV_SUPPORT
-NPC::NPC(Uint16 id, int job, Map *map):
+NPC::NPC(int id, int job, Map *map):
Player(id, job, map)
#else
-NPC::NPC(int id, Uint16 job, Map *map, Network *network):
+NPC::NPC(int id, int job, Map *map, Network *network):
Player(id, job, map),
mNetwork(network)
#endif
@@ -96,8 +93,8 @@ void NPC::setName(const std::string &name)
delete mName;
mName = new Text(displayName,
- getPixelX() + NAME_X_OFFSET,
- getPixelY() + NAME_Y_OFFSET,
+ getPixelX(),
+ getPixelY(),
gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::NPC));
Being::setName(displayName + " (NPC)");
@@ -134,7 +131,6 @@ void NPC::talk()
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_TALK);
- //outMsg.writeInt16(CMSG_NPC_TALK);
outMsg.writeInt32(mId);
outMsg.writeInt8(0);
#endif
@@ -144,8 +140,6 @@ void NPC::updateCoords()
{
if (mName)
{
- const int px = getPixelX() + NAME_X_OFFSET;
- const int py = getPixelY() + NAME_Y_OFFSET;
- mName->adviseXY(px, py);
+ mName->adviseXY(getPixelX(), getPixelY());
}
}
diff --git a/src/npc.h b/src/npc.h
index fed03b51..c2cab6f0 100644
--- a/src/npc.h
+++ b/src/npc.h
@@ -34,9 +34,9 @@ class NPC : public Player
{
public:
#ifdef TMWSERV_SUPPORT
- NPC(Uint16 id, int sprite, Map *map);
+ NPC(int id, int sprite, Map *map);
#else
- NPC(int id, Uint16 job, Map *map, Network *network);
+ NPC(int id, int job, Map *map, Network *network);
#endif
~NPC();
diff --git a/src/player.cpp b/src/player.cpp
index b966e891..a75d4e35 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -37,9 +37,6 @@
#include "utils/strprintf.h"
-static const int NAME_X_OFFSET = 15;
-static const int NAME_Y_OFFSET = 30;
-
Player::Player(int id, int job, Map *map):
Being(id, job, map)
{
@@ -59,8 +56,8 @@ void Player::setName(const std::string &name)
{
mNameColor = &guiPalette->getColor(Palette::GM);
mName = new FlashText("(GM) " + name,
- getPixelX() + NAME_X_OFFSET,
- getPixelY() + NAME_Y_OFFSET,
+ getPixelX(),
+ getPixelY(),
gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::GM_NAME));
}
@@ -68,8 +65,8 @@ void Player::setName(const std::string &name)
{
mNameColor = &guiPalette->getColor(Palette::PLAYER);
mName = new FlashText(name,
- getPixelX() + NAME_X_OFFSET,
- getPixelY() + NAME_Y_OFFSET,
+ getPixelX(),
+ getPixelY(),
gcn::Graphics::CENTER,
(this == player_node) ?
&guiPalette->getColor(Palette::SELF) :
@@ -237,8 +234,7 @@ void Player::setSprite(int slot, int id, const std::string &color)
void Player::updateCoords()
{
if (mName)
- mName->adviseXY(getPixelX() + NAME_X_OFFSET,
- getPixelY() + NAME_Y_OFFSET);
+ mName->adviseXY(getPixelX(), getPixelY());
}
#ifdef TMWSERV_SUPPORT
diff --git a/src/text.cpp b/src/text.cpp
index 83bd6c24..57aaa54f 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -109,6 +109,11 @@ Text::~Text()
}
}
+void Text::setColor(const gcn::Color *color)
+{
+ mColor = color;
+}
+
void Text::adviseXY(int x, int y)
{
textManager->moveText(this, x - mXOffset, y);
diff --git a/src/text.h b/src/text.h
index a96096cc..d52e4b65 100644
--- a/src/text.h
+++ b/src/text.h
@@ -47,6 +47,11 @@ class Text
*/
virtual ~Text();
+ void setColor(const gcn::Color *color);
+
+ int getWidth() const { return mWidth; }
+ int getHeight() const { return mHeight; }
+
/**
* Allows the originator of the text to specify the ideal coordinates.
*/