diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-02-09 23:47:02 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-02-09 23:47:02 +0100 |
commit | fa2f3ac593a792c32095c2e885665ec91bb4019d (patch) | |
tree | f44aee845f0229dfcc6b2ad3c74613e0352f36c2 /src/gui/equipmentwindow.cpp | |
parent | 07f7d52f661a74e6d0c780ca53e724651e3dcc48 (diff) | |
parent | 40edf4e91558cffd83d9015a2cf4a16360e27855 (diff) | |
download | mana-fa2f3ac593a792c32095c2e885665ec91bb4019d.tar.gz mana-fa2f3ac593a792c32095c2e885665ec91bb4019d.tar.bz2 mana-fa2f3ac593a792c32095c2e885665ec91bb4019d.tar.xz mana-fa2f3ac593a792c32095c2e885665ec91bb4019d.zip |
Merged with Aethyra master as of 2009-02-09
Conflicts:
A lot of files...
Diffstat (limited to 'src/gui/equipmentwindow.cpp')
-rw-r--r-- | src/gui/equipmentwindow.cpp | 94 |
1 files changed, 81 insertions, 13 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 40496381..a2be6b00 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -26,7 +26,9 @@ #include "button.h" #include "equipmentwindow.h" +#include "itempopup.h" #include "playerbox.h" +#include "viewport.h" #include "../equipment.h" #include "../graphics.h" @@ -55,12 +57,12 @@ static const int boxPosition[][2] = { {129, 78} // EQUIP_AMMO_SLOT }; -EquipmentWindow::EquipmentWindow(Equipment *equipment): +EquipmentWindow::EquipmentWindow(): 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)); @@ -85,12 +87,15 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); } + mEquipment = player_node->mEquipment.get(); mInventory = player_node->getInventory(); } EquipmentWindow::~EquipmentWindow() { delete mUnequip; + delete mItemPopup; + delete mPlayerBox; } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -153,6 +158,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 +184,67 @@ 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++) { - if (item) + 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)) { - mSelected = i; + if (item) + { + mSelected = i; + } } } } + 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); +} |