summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2007-03-20 21:53:25 +0000
committerDavid Athay <ko2fan@gmail.com>2007-03-20 21:53:25 +0000
commit70da45eca47e5d7c429b49f5c8ec02a5e2bfb47f (patch)
tree52abfd1c4653f01d455582cfae501f5002c3620d
parent8a49edf2371fddba894a8b0a4f05083f63475840 (diff)
downloadmana-70da45eca47e5d7c429b49f5c8ec02a5e2bfb47f.tar.gz
mana-70da45eca47e5d7c429b49f5c8ec02a5e2bfb47f.tar.bz2
mana-70da45eca47e5d7c429b49f5c8ec02a5e2bfb47f.tar.xz
mana-70da45eca47e5d7c429b49f5c8ec02a5e2bfb47f.zip
Tweaked the target cursor and name drawing.
-rw-r--r--ChangeLog9
-rw-r--r--src/gui/viewport.cpp115
-rw-r--r--src/gui/viewport.h13
3 files changed, 83 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index 937d1bdd..9d0f106c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
2007-03-20 David Athay <ko2fan@gmail.com>
- * src/gui/viewport.cpp: Fixed target cursor animation, and changed
- which layer it is drawn after.
+ * src/gui/viewport.cpp, src/gui/viewport.h: Split drawing the
+ target cursor and target name into functions.
+
+2007-03-20 David Athay <ko2fan@gmail.com>
+
+ * src/gui/viewport.cpp: Fixed target cursor animation, and changed
+ which layer it is drawn after.
2007-03-20 Philipp Sehmisch <tmw@crushnet.org>
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
@@ -311,6 +261,67 @@ Viewport::logic()
}
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)
{
// Check if we are alive and kickin'
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. */