summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoridiomatic <idio.castellani@gmail.com>2010-02-28 21:52:22 -0700
committerJared Adams <jaxad0127@gmail.com>2010-02-28 21:52:22 -0700
commitd32203d2e6539aa22953b9c04df000f79e85bf66 (patch)
tree3cc7e26cb6dd39e1a67d609b53d5a23bcf5269be
parente4a6c7106900bfec75bc9ee36ea2f37297100575 (diff)
downloadmana-d32203d2e6539aa22953b9c04df000f79e85bf66.tar.gz
mana-d32203d2e6539aa22953b9c04df000f79e85bf66.tar.bz2
mana-d32203d2e6539aa22953b9c04df000f79e85bf66.tar.xz
mana-d32203d2e6539aa22953b9c04df000f79e85bf66.zip
Add some new mousers and simplify related code
Signed-off-by: Jared Adams <jaxad0127@gmail.com>
-rw-r--r--data/graphics/gui/mouse.pngbin4508 -> 6193 bytes
-rw-r--r--src/gui/gui.h3
-rw-r--r--src/gui/viewport.cpp71
-rw-r--r--src/gui/viewport.h3
4 files changed, 51 insertions, 26 deletions
diff --git a/data/graphics/gui/mouse.png b/data/graphics/gui/mouse.png
index 84dc2ad1..df460e49 100644
--- a/data/graphics/gui/mouse.png
+++ b/data/graphics/gui/mouse.png
Binary files differ
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 7bd76c4a..112abcee 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -107,6 +107,9 @@ class Gui : public gcn::Gui
CURSOR_RESIZE_DOWN,
CURSOR_RESIZE_DOWN_LEFT,
CURSOR_RESIZE_DOWN_RIGHT,
+ CURSOR_FIGHT,
+ CURSOR_PICKUP,
+ CURSOR_TALK,
CURSOR_TOTAL
};
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 763d0c43..0ebf0cb9 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -312,25 +312,18 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
const int pixelX = event.getX() + (int) mPixelViewX;
const int pixelY = event.getY() + (int) mPixelViewY;
- const int tileX = pixelX / mMap->getTileWidth();
- const int tileY = pixelY / mMap->getTileHeight();
// Right click might open a popup
if (event.getButton() == gcn::MouseEvent::RIGHT)
{
- Being *being;
- FloorItem *floorItem;
-
- if ((being = beingManager->findBeingByPixel(pixelX, pixelY)) &&
- being != player_node)
+ if (mHoverBeing && mHoverBeing != player_node)
{
- mPopupMenu->showPopup(event.getX(), event.getY(), being);
+ mPopupMenu->showPopup(event.getX(), event.getY(), mHoverBeing);
return;
}
- else if ((floorItem = floorItemManager->findByCoordinates(tileX,
- tileY)))
+ else if (mHoverItem)
{
- mPopupMenu->showPopup(event.getX(), event.getY(), floorItem);
+ mPopupMenu->showPopup(event.getX(), event.getY(), mHoverItem);
return;
}
}
@@ -345,35 +338,32 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
// Left click can cause different actions
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- FloorItem *item;
- Being *being;
-
// Interact with some being
- if ((being = beingManager->findBeingByPixel(pixelX, pixelY)))
+ if (mHoverBeing)
{
- switch (being->getType())
+ switch (mHoverBeing->getType())
{
// Talk to NPCs
case Being::NPC:
- dynamic_cast<NPC*>(being)->talk();
+ static_cast<NPC*>(mHoverBeing)->talk();
break;
// Attack or walk to monsters or players
case Being::MONSTER:
case Being::PLAYER:
// Ignore it if its dead
- if (!being->isAlive())
+ if (!mHoverBeing->isAlive())
break;
- if (player_node->withinAttackRange(being) ||
+ if (player_node->withinAttackRange(mHoverBeing) ||
keyboard.isKeyActive(keyboard.KEY_ATTACK))
{
- player_node->attack(being,
+ player_node->attack(mHoverBeing,
!keyboard.isKeyActive(keyboard.KEY_TARGET));
}
else
{
- player_node->setGotoTarget(being);
+ player_node->setGotoTarget(mHoverBeing);
}
break;
default:
@@ -381,9 +371,9 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
}
// Picks up a item if we clicked on one
}
- else if ((item = floorItemManager->findByCoordinates(tileX, tileY)))
+ else if (mHoverItem)
{
- player_node->pickUp(item);
+ player_node->pickUp(mHoverItem);
}
else if (player_node->getCurrentAction() == Being::SIT)
{
@@ -478,11 +468,42 @@ void Viewport::mouseMoved(gcn::MouseEvent &event)
const int x = (event.getX() + (int) mPixelViewX);
const int y = (event.getY() + (int) mPixelViewY);
- mSelectedBeing = beingManager->findBeingByPixel(x, y);
- if (Player *p = dynamic_cast<Player*>(mSelectedBeing))
+ mHoverBeing = beingManager->findBeingByPixel(x, y);
+ if (Player *p = dynamic_cast<Player*>(mHoverBeing))
mBeingPopup->show(getMouseX(), getMouseY(), p);
else
mBeingPopup->setVisible(false);
+
+ mHoverItem = floorItemManager->findByCoordinates(x / mMap->getTileWidth(),
+ y / mMap->getTileHeight());
+
+ if (mHoverBeing)
+ {
+ switch (mHoverBeing->getType())
+ {
+ // NPCs
+ case Being::NPC:
+ gui->setCursorType(Gui::CURSOR_TALK);
+ break;
+
+ // Monsters
+ case Being::MONSTER:
+ gui->setCursorType(Gui::CURSOR_FIGHT);
+ break;
+ default:
+ gui->setCursorType(Gui::CURSOR_POINTER);
+ break;
+ }
+ // Item mouseover
+ }
+ else if (mHoverItem)
+ {
+ gui->setCursorType(Gui::CURSOR_PICKUP);
+ }
+ else
+ {
+ gui->setCursorType(Gui::CURSOR_POINTER);
+ }
}
void Viewport::toggleDebugPath()
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 5b92d950..c4fcece4 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -189,7 +189,8 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */
PopupMenu *mPopupMenu; /**< Popup menu. */
- Being *mSelectedBeing; /**< Current selected being. */
+ Being *mHoverBeing; /**< Being mouse is currently over. */
+ FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */
BeingPopup *mBeingPopup;
};