diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-10 16:13:40 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-10 16:13:40 +0200 |
commit | cab1abe41887d8b3ab426fbb56716ce99a3a1807 (patch) | |
tree | a9c3a2b08dbcbb7ca91879eb18b550e7b3b7daa2 /src | |
parent | 4a6cd2bb9168348a7f9521678bd71b72de755405 (diff) | |
download | mana-cab1abe41887d8b3ab426fbb56716ce99a3a1807.tar.gz mana-cab1abe41887d8b3ab426fbb56716ce99a3a1807.tar.bz2 mana-cab1abe41887d8b3ab426fbb56716ce99a3a1807.tar.xz mana-cab1abe41887d8b3ab426fbb56716ce99a3a1807.zip |
Make sure Unequip button is disabled when appropriate
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/equipmentwindow.cpp | 23 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 5 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 8934f7ce..aa81361d 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -84,13 +84,14 @@ EquipmentWindow::EquipmentWindow(): setDefaultSize(180, 300, ImageRect::CENTER); loadWindowState(); - gcn::Button *unequip = new Button(_("Unequip"), "unequip", this); - gcn::Rectangle const &area = getChildrenArea(); - unequip->setPosition(area.width - unequip->getWidth() - 5, - area.height - unequip->getHeight() - 5); + mUnequip = new Button(_("Unequip"), "unequip", this); + const gcn::Rectangle &area = getChildrenArea(); + mUnequip->setPosition(area.width - mUnequip->getWidth() - 5, + area.height - mUnequip->getHeight() - 5); + mUnequip->setEnabled(false); add(playerBox); - add(unequip); + add(mUnequip); for (int i = 0; i < EQUIP_VECTOREND; i++) { @@ -176,11 +177,11 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) mInventory->getItem(mEquipment->getArrows()); #endif player_node->unequipItem(item); - mSelected = -1; + setSelected(-1); } } -Item* EquipmentWindow::getItem(int x, int y) const +Item *EquipmentWindow::getItem(int x, int y) const { for (int i = 0; i < EQUIP_VECTOREND; i++) { @@ -224,7 +225,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) BOX_WIDTH, BOX_HEIGHT); if (tRect.isPointInRect(x, y) && item) - mSelected = i; + setSelected(i); } } else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) @@ -268,3 +269,9 @@ void EquipmentWindow::mouseExited(gcn::MouseEvent &event) { mItemPopup->setVisible(false); } + +void EquipmentWindow::setSelected(int index) +{ + mSelected = index; + mUnequip->setEnabled(mSelected != -1); +} diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index f6ba19f8..8bc350a4 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -24,6 +24,8 @@ #include "gui/widgets/window.h" +#include "guichanfwd.h" + #include <guichan/actionlistener.hpp> class Equipment; @@ -102,6 +104,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener Item *getItem(int x, int y) const; + void setSelected(int index); + Equipment *mEquipment; #ifdef EATHENA_SUPPORT Inventory *mInventory; @@ -119,6 +123,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener EquipBox mEquipBox[EQUIP_VECTOREND]; /**< Equipment Boxes. */ ItemPopup *mItemPopup; + gcn::Button *mUnequip; int mSelected; /**< Index of selected item. */ }; |