diff options
author | Ira Rice <irarice@gmail.com> | 2009-02-04 14:43:01 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-02-04 14:43:01 -0700 |
commit | 35c4cb970f14989445828aefa4cf17f3260f9281 (patch) | |
tree | dfb79ca9626955cf0411b5053ef7fff97c205b3c /src/gui | |
parent | 15d15965978d5ce73252e840c3da8ac15b48d858 (diff) | |
download | mana-client-35c4cb970f14989445828aefa4cf17f3260f9281.tar.gz mana-client-35c4cb970f14989445828aefa4cf17f3260f9281.tar.bz2 mana-client-35c4cb970f14989445828aefa4cf17f3260f9281.tar.xz mana-client-35c4cb970f14989445828aefa4cf17f3260f9281.zip |
Added a right click popup menu, and item popups to the equipment window.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/equipmentwindow.cpp | 79 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 9 |
2 files changed, 79 insertions, 9 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 1fb2b601..f5ab604e 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -26,7 +26,10 @@ #include "button.h" #include "equipmentwindow.h" +#include "gui.h" +#include "itempopup.h" #include "playerbox.h" +#include "viewport.h" #include "../equipment.h" #include "../graphics.h" @@ -59,8 +62,9 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): Window(_("Equipment")), mEquipment(equipment), mSelected(-1) - { + mItemPopup = new ItemPopup(); + // Control that shows the Player mPlayerBox = new PlayerBox; mPlayerBox->setDimension(gcn::Rectangle(50, 80, 74, 123)); @@ -153,6 +157,23 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) } } +Item* EquipmentWindow::getItem(const int &x, const int &y) +{ + for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) + { + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); + + if (tRect.isPointInRect(x, y)) + { + return (i != EQUIP_AMMO_SLOT) ? + mInventory->getItem(mEquipment->getEquipment(i)) : + mInventory->getItem(mEquipment->getArrows()); + } + } + return NULL; +} + void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) { Window::mousePressed(mouseEvent); @@ -162,21 +183,61 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) Item* item; - // Checks if any of the presses were in the equip boxes. - for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) + if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { - item = (i != EQUIP_AMMO_SLOT) ? - mInventory->getItem(mEquipment->getEquipment(i)) : - mInventory->getItem(mEquipment->getArrows()); - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); - if (tRect.isPointInRect(x, y)) + // Checks if any of the presses were in the equip boxes. + for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) { + item = getItem(x, y); + if (item) { mSelected = i; + break; } } } + else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) + { + item = getItem(x, y); + + if (!item) + return; + + /* Convert relative to the window coordinates to absolute screen + * coordinates. + */ + const int mx = x + getX(); + const int my = y + getY(); + viewport->showPopup(mx, my, item); + } } +// Show ItemTooltip +void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) +{ + const int x = event.getX(); + const int y = event.getY(); + + Item* item = getItem(x, y); + + if (item) + { + int mouseX, mouseY; + SDL_GetMouseState(&mouseX, &mouseY); + + mItemPopup->setItem(item->getInfo()); + mItemPopup->setOpaque(false); + mItemPopup->view(x + getX(), y + getY()); + } + else + { + mItemPopup->setVisible(false); + } +} + +// Hide ItemTooltip +void EquipmentWindow::mouseExited(gcn::MouseEvent &event) +{ + mItemPopup->setVisible(false); +} diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 8e9b22eb..b64c768b 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -28,6 +28,8 @@ class Equipment; class Inventory; +class Item; +class ItemPopup; class PlayerBox; /** @@ -66,6 +68,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener void mousePressed(gcn::MouseEvent& mouseEvent); + Item* getItem(const int &x, const int &y); + enum { // Equipment rules: EQUIP_LEGS_SLOT = 0, @@ -84,11 +88,16 @@ class EquipmentWindow : public Window, public gcn::ActionListener private: + void mouseExited(gcn::MouseEvent &event); + void mouseMoved(gcn::MouseEvent &event); + Equipment *mEquipment; Inventory *mInventory; gcn::Button *mUnequip; /**< Button for unequipping. */ EquipBox mEquipBox[EQUIP_VECTOREND]; /**< Equipment Boxes. */ + ItemPopup *mItemPopup; + PlayerBox *mPlayerBox; int mSelected; /**< Index of selected item. */ |