From 323b0e57c673035ad8065c7daf399124f15c24d4 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Mon, 6 Feb 2006 04:18:16 +0000 Subject: Use virtual methods instead of getType() checks. --- src/being.cpp | 13 ------------- src/being.h | 4 ++-- src/localplayer.h | 6 ++++++ src/player.cpp | 10 ++++++++++ src/player.h | 2 ++ 5 files changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index b417fc34..3570fe30 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -217,19 +217,6 @@ Being::logic() } } -void -Being::drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) -{ - int px = mPx + offsetX; - int py = mPy + offsetY; - - // Draw player name - if (getType() != LOCALPLAYER) { - graphics->setFont(speechFont); - graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER); - } -} - void Being::drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) { diff --git a/src/being.h b/src/being.h index d87f06ab..edc25c09 100644 --- a/src/being.h +++ b/src/being.h @@ -197,8 +197,8 @@ class Being : public Sprite /** * Draws the name text below the being. */ - void - drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); + virtual void + drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) {}; /** * Returns the type of the being. diff --git a/src/localplayer.h b/src/localplayer.h index fe87fbab..7867e13d 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -51,6 +51,12 @@ class LocalPlayer : public Player virtual void logic(); virtual void nextStep(); + /** + * Draws the name text below the being. + */ + virtual void + drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) {}; + virtual Type getType() const; void clearInventory(); diff --git a/src/player.cpp b/src/player.cpp index 5720f0a6..71bb6ca5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -123,3 +123,13 @@ void Player::draw(Graphics *graphics, int offsetX, int offsetY) py - 50 + 2 * hairtable[frame][dir][1]); } } + +void +Player::drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) +{ + int px = mPx + offsetX; + int py = mPy + offsetY; + + graphics->setFont(speechFont); + graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER); +} diff --git a/src/player.h b/src/player.h index 5d75a1db..3c68116e 100644 --- a/src/player.h +++ b/src/player.h @@ -39,6 +39,8 @@ class Player : public Being virtual Type getType() const; virtual void draw(Graphics *graphics, int offsetX, int offsetY); + + virtual void drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); }; #endif -- cgit v1.2.3-70-g09d2