diff options
author | idiomatic <idio.castellani@gmail.com> | 2010-02-28 21:52:22 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-02-28 21:52:22 -0700 |
commit | d32203d2e6539aa22953b9c04df000f79e85bf66 (patch) | |
tree | 3cc7e26cb6dd39e1a67d609b53d5a23bcf5269be /src/gui/viewport.cpp | |
parent | e4a6c7106900bfec75bc9ee36ea2f37297100575 (diff) | |
download | mana-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>
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r-- | src/gui/viewport.cpp | 71 |
1 files changed, 46 insertions, 25 deletions
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() |