From 70da45eca47e5d7c429b49f5c8ec02a5e2bfb47f Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 20 Mar 2007 21:53:25 +0000 Subject: Tweaked the target cursor and name drawing. --- src/gui/viewport.cpp | 115 ++++++++++++++++++++++++++++----------------------- src/gui/viewport.h | 13 ++++++ 2 files changed, 76 insertions(+), 52 deletions(-) (limited to 'src/gui') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a4a7873a..485f8d47 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -188,62 +188,12 @@ Viewport::draw(gcn::Graphics *gcnGraphics) if (mMap) { mMap->draw(graphics, (int) mViewX, (int) mViewY, 0); - // Draw target marker if needed - Being *target = player_node->getTarget(); - if (target) - { - graphics->setFont(speechFont); - graphics->setColor(gcn::Color(255, 32, 32)); - int dy = (target->getType() == Being::PLAYER) ? 80 : 42; - - std::string mobName = ""; - - if (target->mJob >= 1002) - { - int mobId = target->mJob - 1002; - mobName = MonsterDB::get(mobId).getName(); - - // Find whether target is in range - int rangex = target->mX - player_node->mX; - int rangey = target->mY - player_node->mY; - int attackRange = player_node->getAttackRange(); - - // If either is negative, convert to positive - if (rangex < 0) - { - rangex = -rangex; - } - if (rangey < 0) - { - rangey = -rangey; - } - - // Draw the target cursor, which one depends if the target is in range - if (rangex > attackRange || rangey > attackRange) - { - // Draw the out of range cursor - graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), - target->getPixelX() - (int) mViewX, - target->getPixelY() - (int) mViewY); - } - else - { - // Draw the in range cursor - graphics->drawImage(mTargetCursorInRange->getCurrentImage(), - target->getPixelX() - (int) mViewX, - target->getPixelY() - (int) mViewY); - } - - graphics->drawText(mobName, - target->getPixelX() - (int) mViewX + 15, - target->getPixelY() - (int) mViewY - dy, - gcn::Graphics::CENTER); - } - } + drawTargetCursor(graphics); mMap->draw(graphics, (int) mViewX, (int) mViewY, 1); mMap->draw(graphics, (int) mViewX, (int) mViewY, 2); mMap->drawOverlay(graphics, mViewX, mViewY, (int) config.getValue("OverlayDetail", 2)); + drawTargetName(graphics); } // Find a path from the player to the mouse, and draw it. This is for debug @@ -310,6 +260,67 @@ Viewport::logic() mTargetCursorOutRange->update(10); } +void +Viewport::drawTargetCursor(Graphics *graphics) +{ + // Draw target marker if needed + Being *target = player_node->getTarget(); + if (target) + { + if (target->mJob >= 1002) + { + // Find whether target is in range + int rangeX = target->mX - player_node->mX; + int rangeY = target->mY - player_node->mY; + int attackRange = player_node->getAttackRange(); + + // Make sure the ranges are positive + rangeX = abs(rangeX); + rangeY = abs(rangeY); + + // Draw the target cursor, which one depends if the target is in range + if (rangeX > attackRange || rangeY > attackRange) + { + // Draw the out of range cursor + graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), + target->getPixelX() - (int) mViewX, + target->getPixelY() - (int) mViewY); + } + else + { + // Draw the in range cursor + graphics->drawImage(mTargetCursorInRange->getCurrentImage(), + target->getPixelX() - (int) mViewX, + target->getPixelY() - (int) mViewY); + } + } + } +} + +void +Viewport::drawTargetName(Graphics *graphics) +{ + // Draw target marker if needed + Being *target = player_node->getTarget(); + if (target) + { + graphics->setFont(speechFont); + graphics->setColor(gcn::Color(255, 32, 32)); + int dy = (target->getType() == Being::PLAYER) ? 80 : 42; + + std::string mobName = ""; + if (target->mJob >= 1002) + { + int mobId = target->mJob - 1002; + mobName = MonsterDB::get(mobId).getName(); + graphics->drawText(mobName, + target->getPixelX() - (int) mViewX + 15, + target->getPixelY() - (int) mViewY - dy, + gcn::Graphics::CENTER); + } + } +} + void Viewport::mousePressed(gcn::MouseEvent &event) { diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 45863228..6bb82d7f 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -35,6 +35,7 @@ class Being; class FloorItem; class Item; class PopupMenu; +class Graphics; class SimpleAnimation; /** @@ -138,6 +139,18 @@ class Viewport : public WindowContainer, public gcn::MouseListener, * TODO Find some way to get rid of Being here */ void showPopup(int x, int y, Being *being); + + /** + * Draws range based target cursor + */ + void + drawTargetCursor(Graphics *graphics); + + /** + * Draws target name + */ + void + drawTargetName(Graphics *graphics); Map *mMap; /**< The current map. */ -- cgit v1.2.3-60-g2f50