summaryrefslogtreecommitdiff
path: root/src/gui/inventorywindow.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-03-24 23:10:51 -0600
committerJared Adams <jaxad0127@gmail.com>2010-03-25 11:31:55 -0600
commitbf6cb46d9b06b06470efd5ad3ebae7e274f6906f (patch)
tree281cdf6d017477f07e02e73acef175f937c18eed /src/gui/inventorywindow.cpp
parent83077364f8b67fb9fc57e8b04a1feff0e243848d (diff)
downloadmana-client-bf6cb46d9b06b06470efd5ad3ebae7e274f6906f.tar.gz
mana-client-bf6cb46d9b06b06470efd5ad3ebae7e274f6906f.tar.bz2
mana-client-bf6cb46d9b06b06470efd5ad3ebae7e274f6906f.tar.xz
mana-client-bf6cb46d9b06b06470efd5ad3ebae7e274f6906f.zip
Eliminate the logic methods from InventoryWindow and StorageWindow
Diffstat (limited to 'src/gui/inventorywindow.cpp')
-rw-r--r--src/gui/inventorywindow.cpp104
1 files changed, 44 insertions, 60 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 701558a9..6291d524 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -53,9 +53,8 @@
#include <string>
-InventoryWindow::InventoryWindow(int invSize):
+InventoryWindow::InventoryWindow():
Window(_("Inventory")),
- mMaxSlots(invSize),
mSplit(false),
mItemDesc(false)
{
@@ -90,10 +89,6 @@ InventoryWindow::InventoryWindow(int invSize):
gcn::ScrollArea *invenScroll = new ScrollArea(mItems);
invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mTotalWeight = -1;
- mMaxWeight = -1;
- mUsedSlots = -1;
-
mSlotsLabel = new Label(_("Slots:"));
mWeightLabel = new Label(_("Weight:"));
@@ -113,45 +108,17 @@ InventoryWindow::InventoryWindow(int invSize):
Layout &layout = getLayout();
layout.setRowHeight(1, Layout::AUTO_SET);
+ player_node->getInventory()->addInventoyListener(this);
+
loadWindowState();
+ updateWeight();
+ slotsChanged(player_node->getInventory());
}
InventoryWindow::~InventoryWindow()
{
}
-void InventoryWindow::logic()
-{
- if (!isVisible())
- return;
-
- Window::logic();
-
- // It would be nicer if this update could be event based, needs some
- // redesign of InventoryWindow and ItemContainer probably.
- updateButtons();
-
- const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
-
- if (mMaxWeight != player_node->getMaxWeight() ||
- mTotalWeight != player_node->getTotalWeight() ||
- mUsedSlots != usedSlots)
- {
- mTotalWeight = player_node->getTotalWeight();
- mMaxWeight = player_node->getMaxWeight();
- mUsedSlots = usedSlots;
-
- // Adjust progress bars
- mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
- mWeightBar->setProgress((float) mTotalWeight / mMaxWeight);
-
- mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots));
- mWeightBar->setText(strprintf("%s/%s",
- Units::formatWeight(mTotalWeight).c_str(),
- Units::formatWeight(mMaxWeight).c_str()));
- }
-}
-
void InventoryWindow::action(const gcn::ActionEvent &event)
{
if (event.getId() == "outfit")
@@ -255,39 +222,29 @@ void InventoryWindow::keyReleased(gcn::KeyEvent &event)
void InventoryWindow::valueChanged(const gcn::SelectionEvent &event)
{
- if (mSplit && Net::getInventoryHandler()->canSplit(mItems->getSelectedItem()))
- {
- Item *item = mItems->getSelectedItem();
+ Item *item = mItems->getSelectedItem();
- if (item)
- ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
- (item->getQuantity() - 1));
+ if (mSplit && Net::getInventoryHandler()->
+ canSplit(mItems->getSelectedItem()) && item)
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
+ (item->getQuantity() - 1));
}
-}
-
-void InventoryWindow::setSplitAllowed(bool allowed)
-{
- mSplitButton->setVisible(allowed);
-}
-
-void InventoryWindow::updateButtons()
-{
- const Item *selectedItem = mItems->getSelectedItem();
-
- if (!selectedItem || selectedItem->getQuantity() == 0)
+ if (!item || item->getQuantity() == 0)
{
mUseButton->setEnabled(false);
mDropButton->setEnabled(false);
+
return;
}
mUseButton->setEnabled(true);
mDropButton->setEnabled(true);
- if (selectedItem->isEquipment())
+ if (item->isEquipment())
{
- if (selectedItem->isEquipped())
+ if (item->isEquipped())
mUseButton->setCaption(_("Unequip"));
else
mUseButton->setCaption(_("Equip"));
@@ -297,13 +254,40 @@ void InventoryWindow::updateButtons()
mUseButton->setCaption(_("Use"));
}
- if (selectedItem->getQuantity() > 1)
+ if (item->getQuantity() > 1)
mDropButton->setCaption(_("Drop..."));
else
mDropButton->setCaption(_("Drop"));
- if (Net::getInventoryHandler()->canSplit(selectedItem))
+ if (Net::getInventoryHandler()->canSplit(item))
mSplitButton->setEnabled(true);
else
mSplitButton->setEnabled(false);
}
+
+
+void InventoryWindow::setSplitAllowed(bool allowed)
+{
+ mSplitButton->setVisible(allowed);
+}
+
+void InventoryWindow::updateWeight()
+{
+ int total = player_node->getTotalWeight();
+ int max = player_node->getMaxWeight();
+
+ // Adjust progress bar
+ mWeightBar->setProgress((float) total / max);
+ mWeightBar->setText(strprintf("%s/%s", Units::formatWeight(total).c_str(),
+ Units::formatWeight(max).c_str()));
+}
+
+void InventoryWindow::slotsChanged(Inventory* inventory)
+{
+ const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
+ const int maxSlots = player_node->getInventory()->getSize();
+
+ mSlotsBar->setProgress((float) usedSlots / maxSlots);
+
+ mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
+}