summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Langley <joshlangley[at]optusnet.com.au>2007-08-14 09:59:06 +0000
committerJoshua Langley <joshlangley[at]optusnet.com.au>2007-08-14 09:59:06 +0000
commit4eeecc48cbd801ea8038fc1c5325a00d7120d1d7 (patch)
tree9a6a1c43524ffcf59fb55f59f705614bcc2b0a22 /src
parent0601642d8b3aa2c7aa365e27aa3ef2459553c3fd (diff)
downloadmana-client-4eeecc48cbd801ea8038fc1c5325a00d7120d1d7.tar.gz
mana-client-4eeecc48cbd801ea8038fc1c5325a00d7120d1d7.tar.bz2
mana-client-4eeecc48cbd801ea8038fc1c5325a00d7120d1d7.tar.xz
mana-client-4eeecc48cbd801ea8038fc1c5325a00d7120d1d7.zip
inventory - split function fix
Diffstat (limited to 'src')
-rw-r--r--src/gui/inventorywindow.cpp56
-rw-r--r--src/gui/inventorywindow.h7
-rw-r--r--src/gui/item_amount.cpp11
-rw-r--r--src/gui/item_amount.h2
-rw-r--r--src/gui/itemcontainer.cpp6
5 files changed, 57 insertions, 25 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 32c18da6..085ab188 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -47,7 +47,8 @@
#include "../utils/strprintf.h"
InventoryWindow::InventoryWindow():
- Window(_("Inventory"))
+ Window(_("Inventory")),
+ mSplit(false)
{
setResizable(true);
setMinWidth(240);
@@ -58,8 +59,11 @@ InventoryWindow::InventoryWindow():
mUseButton = new Button(_("Use"), "use", this);
mDropButton = new Button(_("Drop"), "drop", this);
+ mSplitButton = new Button(_("Split"), "split", this);
- mSplitBox = new gcn::CheckBox(_("Split"));
+ mUseButton->adjustSize();
+ mDropButton->adjustSize();
+ mSplitButton->adjustSize();
mItems = new ItemContainer(player_node->mInventory.get(), 10, 5);
mItems->addSelectionListener(this);
@@ -79,15 +83,22 @@ InventoryWindow::InventoryWindow():
add(mUseButton);
add(mDropButton);
- add(mSplitBox);
+ add(mSplitButton);
add(mInvenScroll);
add(mItemNameLabel);
add(mItemDescriptionLabel);
add(mItemEffectLabel);
add(mWeightLabel);
- mUseButton->setWidth(48);
- mDropButton->setWidth(48);
+ if (mUseButton->getWidth() < 48) {
+ mUseButton->setWidth(48);
+ }
+ if (mDropButton->getWidth() < 48) {
+ mDropButton->setWidth(48);
+ }
+ if (mSplitButton->getWidth() < 48) {
+ mSplitButton->setWidth(48);
+ }
loadWindowState("Inventory");
updateContentSize();
@@ -97,7 +108,7 @@ InventoryWindow::~InventoryWindow()
{
delete mUseButton;
delete mDropButton;
- delete mSplitBox;
+ delete mSplitButton;
delete mItems;
delete mInvenScroll;
@@ -149,6 +160,13 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
}
mItems->selectNone();
}
+ else if (event.getId() == "split")
+ {
+ if (item && !item->isEquipment() && item->getQuantity() > 1) {
+ new ItemAmountWindow(AMOUNT_ITEM_SPLIT, this, item,
+ (item->getQuantity() - 1));
+ }
+ }
}
void InventoryWindow::selectionChanged(const SelectionEvent &event)
@@ -167,11 +185,12 @@ void InventoryWindow::selectionChanged(const SelectionEvent &event)
mItemEffectLabel->adjustSize();
mItemDescriptionLabel->adjustSize();
- if (mSplitBox->isMarked())
+ if (mSplit)
{
if (item && !item->isEquipment() && item->getQuantity() > 1) {
- mSplitBox->setMarked(false);
- new ItemAmountWindow(AMOUNT_ITEM_SPLIT, this, item);
+ mSplit = false;
+ new ItemAmountWindow(AMOUNT_ITEM_SPLIT, this, item,
+ (item->getQuantity() - 1));
}
}
}
@@ -187,7 +206,6 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if (!item) {
return;
}
-
/* Convert relative to the window coordinates to absolute screen
* coordinates.
*/
@@ -203,8 +221,10 @@ void InventoryWindow::updateContentSize()
// Resize widgets
mUseButton->setPosition(8, area.height - 24);
- mDropButton->setPosition(64, area.height - 24); // 8 + 48 + 8 = 64.
- mSplitBox->setPosition(128, area.height - 20);
+ mDropButton->setPosition(mUseButton->getWidth() + 16, area.height - 24);
+ mSplitButton->setPosition(
+ mUseButton->getWidth() + mDropButton->getWidth() + 24,
+ area.height - 24);
mInvenScroll->setSize(area.width - 16, area.height - 110);
mItemNameLabel->setPosition(8,
@@ -227,6 +247,12 @@ void InventoryWindow::updateButtons()
}
mUseButton->setEnabled(!!item);
mDropButton->setEnabled(!!item);
+ if (item && !item->isEquipment() && item->getQuantity() > 1) {
+ mSplitButton->setEnabled(true);
+ }
+ else {
+ mSplitButton->setEnabled(false);
+ }
}
Item* InventoryWindow::getItem()
@@ -241,8 +267,7 @@ InventoryWindow::keyPressed(gcn::KeyEvent &event)
{
case gcn::Key::LEFT_SHIFT:
case gcn::Key::RIGHT_SHIFT:
- mSplitBox->setMarked(true);
- break;
+ mSplit = true;
}
}
@@ -253,7 +278,6 @@ InventoryWindow::keyReleased(gcn::KeyEvent &event)
{
case gcn::Key::LEFT_SHIFT:
case gcn::Key::RIGHT_SHIFT:
- mSplitBox->setMarked(false);
- break;
+ mSplit = false;
}
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 450d6565..37ef0406 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -99,13 +99,16 @@ class InventoryWindow : public Window,
ItemContainer *mItems;
- gcn::Button *mUseButton, *mDropButton; /**< Use, Drop Item Buttons. */
- gcn::CheckBox *mSplitBox; /**< Split item checkbox. */
+ /**< Use, Drop, Split Item Buttons. */
+ gcn::Button *mUseButton, *mDropButton, *mSplitButton;
+
gcn::ScrollArea *mInvenScroll; /**< Inventory Scroll Area. */
gcn::Label *mItemNameLabel;
gcn::Label *mItemDescriptionLabel;
gcn::Label *mItemEffectLabel;
gcn::Label *mWeightLabel;
+
+ bool mSplit;
};
extern InventoryWindow *inventoryWindow;
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 22c219f2..33a45fe7 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -33,7 +33,8 @@
#include "../utils/gettext.h"
-ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
+ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item,
+ int maxRange):
Window("", true, parent),
mItem(item)
{
@@ -45,9 +46,12 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
Button *plusButton = new Button("+", "Plus", this);
Button *okButton = new Button(_("Ok"), "Drop", this);
Button *cancelButton = new Button(_("Cancel"), "Cancel", this);
- mItemAmountSlide = new Slider(1.0, mItem->getQuantity());
+ if (!maxRange) {
+ maxRange = mItem->getQuantity();
+ }
+ mItemAmountSlide = new Slider(1.0, maxRange);
- mItemAmountTextBox->setRange(1, mItem->getQuantity());
+ mItemAmountTextBox->setRange(1, maxRange);
mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10));
// Set button events Id
@@ -139,4 +143,3 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
mItemAmountTextBox->setInt(amount);
mItemAmountSlide->setValue(amount);
}
-
diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h
index 227f6a87..03303603 100644
--- a/src/gui/item_amount.h
+++ b/src/gui/item_amount.h
@@ -50,7 +50,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener
/**
* Constructor.
*/
- ItemAmountWindow(int usage, Window *parent, Item *item);
+ ItemAmountWindow(int usage, Window *parent, Item *item, int maxRange = 0);
/**
* Called when receiving actions from widget.
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 2f65d157..4ac2fba9 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -32,6 +32,8 @@
#include "../item.h"
#include "../localplayer.h"
+#include "../log.h"
+
#include "../resources/image.h"
#include "../resources/iteminfo.h"
#include "../resources/resourcemanager.h"
@@ -244,6 +246,7 @@ ItemContainer::mouseReleased(gcn::MouseEvent &event)
mDragged = false;
const int index = getSlotIndex(event.getX(), event.getY());
+ logger->log("index=%d", index);
if (index == Inventory::NO_SLOT_INDEX) {
return;
}
@@ -258,8 +261,7 @@ ItemContainer::mouseReleased(gcn::MouseEvent &event)
int
ItemContainer::getSlotIndex(const int posX, const int posY) const
{
- if(gcn::Rectangle(0, 0, (getWidth() - 1), (getHeight() - 1))
- .isPointInRect(posX, posY))
+ if (getDimension().isPointInRect(posX, posY))
{
// Takes into account, boxes are overlapping each other.
return (posY / (BOX_HEIGHT - 1)) * mGridColumns +