From 1dcaa196fd8339dbdd28f9c09c62636b663a3846 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 27 Mar 2009 17:45:36 +0100 Subject: Fixed some positioning issues Started with not being able to click NPCs properly, and I ended up correcting the draw positions of overhead text, targets and sprite ordering. It's now a bit more straight-forward. The position of a being is simply in the middle of the sprite at the bottom. When drawing the sprite, an offset remains because all the sprites are compensating for getting drawn half a tile to the left and one tile up. --- src/being.cpp | 59 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'src/being.cpp') 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 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) { -- cgit v1.2.3-70-g09d2