diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-30 20:51:36 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-30 20:51:36 +0200 |
commit | ebe29a9410458abac19c4ba10d5dce476e7ca34b (patch) | |
tree | bd8d2e2d3fb57822562d5b253a1cfd2057061e39 | |
parent | 005a76ce5d539666022c80eb5b0c1dd760db19e7 (diff) | |
download | mana-ebe29a9410458abac19c4ba10d5dce476e7ca34b.tar.gz mana-ebe29a9410458abac19c4ba10d5dce476e7ca34b.tar.bz2 mana-ebe29a9410458abac19c4ba10d5dce476e7ca34b.tar.xz mana-ebe29a9410458abac19c4ba10d5dce476e7ca34b.zip |
Made the popup-menu work again for equip/unequip processes.
I disabled the drop from equipment window since it was more
simple to implement, and because it seemed useless or even bad
for the user experience to me.
-rw-r--r-- | src/gui/equipmentwindow.cpp | 26 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 6 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 25 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 4 | ||||
-rw-r--r-- | src/gui/viewport.h | 2 |
6 files changed, 41 insertions, 24 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 212dcd2b..4b269325 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -211,30 +211,32 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) const int x = mouseEvent.getX(); const int y = mouseEvent.getY(); + Item *item = 0; - if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) + // Checks if any of the presses were in the equip boxes. + for (int i = 0; i < mBoxesNumber; ++i) { - // Checks if any of the presses were in the equip boxes. - for (int i = 0; i < mBoxesNumber; ++i) - { - Item *item = mEquipment->getEquipment(i); - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); + item = mEquipment->getEquipment(i); + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); - if (tRect.isPointInRect(x, y) && item) - setSelected(i); + if (tRect.isPointInRect(x, y) && item) + { + setSelected(i); + break; } } - else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) + + if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) { - if (Item *item = getItem(x, y)) + if (item) { /* Convert relative to the window coordinates to absolute screen * coordinates. */ const int mx = x + getX(); const int my = y + getY(); - viewport->showPopup(this, mx, my, item, true); + viewport->showPopup(this, mx, my, item, true, false); } } } diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index b8e63efc..57a13d40 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -58,6 +58,12 @@ class EquipmentWindow : public Window, public gcn::ActionListener */ void loadEquipBoxes(); + /** + * Returns the current selected slot or -1 if none. + */ + int getSelected() + { return mSelected; } + protected: /** * Equipment box. diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 1c2f3b60..fbe3c739 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -32,6 +32,7 @@ #include "playerrelations.h" #include "gui/chat.h" +#include "gui/equipmentwindow.h" #include "gui/inventorywindow.h" #include "gui/itemamount.h" @@ -266,15 +267,20 @@ void PopupMenu::handleLink(const std::string &link) { } - else if (link == "activate") + else if (link == "activate" || link == "equip" || link == "unequip") { assert(mItem); if (mItem->isEquippable()) { if (mItem->isEquipped()) - mItem->doEvent(Event::DoUnequip); + { + PlayerInfo::getEquipment()->triggerUnequip( + equipmentWindow->getSelected()); + } else + { mItem->doEvent(Event::DoEquip); + } } else { @@ -347,7 +353,7 @@ void PopupMenu::handleLink(const std::string &link) } void PopupMenu::showPopup(Window *parent, int x, int y, Item *item, - bool isInventory) + bool isInventory, bool canDrop) { assert(item); mItem = item; @@ -364,17 +370,20 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item, if (item->getInfo().getEquippable()) { if (item->isEquipped()) - mBrowserBox->addRow(strprintf("@@equip|%s@@", _("Unequip"))); + mBrowserBox->addRow(strprintf("@@unequip|%s@@", _("Unequip"))); else mBrowserBox->addRow(strprintf("@@equip|%s@@", _("Equip"))); } if (item->getInfo().getActivatable()) mBrowserBox->addRow(strprintf("@@activate|%s@@", _("Activate"))); - if (item->getQuantity() > 1) - mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop..."))); - else - mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop"))); + if (canDrop) + { + if (item->getQuantity() > 1) + mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop..."))); + else + mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop"))); + } if (Net::getInventoryHandler()->canSplit(item)) { diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 969c5c20..111f94ed 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -55,7 +55,7 @@ class PopupMenu : public Popup, public LinkHandler * at the specified mouse coordinates. */ void showPopup(Window *parent, int x, int y, Item *item, - bool isInventory); + bool isInventory, bool canDrop = true); /** * Handles link action. diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 0353fd44..945be7de 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -530,9 +530,9 @@ void Viewport::mouseReleased(gcn::MouseEvent &event) } void Viewport::showPopup(Window *parent, int x, int y, Item *item, - bool isInventory) + bool isInventory, bool canDrop) { - mPopupMenu->showPopup(parent, x, y, item, isInventory); + mPopupMenu->showPopup(parent, x, y, item, isInventory, canDrop); } void Viewport::closePopupMenu() diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 5814f08e..e5fb92b0 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -106,7 +106,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, * TODO Find some way to get rid of Item here */ void showPopup(Window *parent, int x, int y, Item *item, - bool isInventory = true); + bool isInventory = true, bool canDrop = true); /** * Closes the popup menu. Needed for when the player dies or switching |