diff options
Diffstat (limited to 'src/gui/inventorywindow.cpp')
-rw-r--r-- | src/gui/inventorywindow.cpp | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 591ebd2f..5df1d4ba 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -23,14 +23,13 @@ #include "inventory.h" #include "item.h" -#include "localplayer.h" #include "units.h" #include "keyboardconfig.h" +#include "playerinfo.h" #include "gui/itemamount.h" #include "gui/setup.h" #include "gui/sdlinput.h" -#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/button.h" @@ -44,6 +43,7 @@ #include "net/net.h" #include "resources/iteminfo.h" +#include "resources/theme.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -60,6 +60,8 @@ InventoryWindow::InventoryWindow(Inventory *inventory): mInventory(inventory), mSplit(false) { + listen("Attributes"); + setWindowName(isMainInventory() ? "Inventory" : "Storage"); setupWindow->registerWindowForReset(this); setResizable(true); @@ -138,13 +140,19 @@ InventoryWindow::InventoryWindow(Inventory *inventory): slotsChanged(mInventory); if (!isMainInventory()) + { setVisible(true); + PlayerInfo::setStorageCount(PlayerInfo::getStorageCount() + 1); + } } InventoryWindow::~InventoryWindow() { instances.remove(this); mInventory->removeInventoyListener(this); + + if (!isMainInventory()) + PlayerInfo::setStorageCount(PlayerInfo::getStorageCount() - 1); } void InventoryWindow::action(const gcn::ActionEvent &event) @@ -180,12 +188,12 @@ void InventoryWindow::action(const gcn::ActionEvent &event) if (item->isEquipment()) { if (item->isEquipped()) - Net::getInventoryHandler()->unequipItem(item); + item->doEvent("doUnequip"); else - Net::getInventoryHandler()->equipItem(item); + item->doEvent("doEquip"); } else - Net::getInventoryHandler()->useItem(item); + item->doEvent("doUse"); } else if (event.getId() == "drop") { @@ -234,20 +242,30 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { - if (isStorageActive() && keyboard.isKeyActive(keyboard.KEY_EMOTE)) + if (instances.size() > 1 && keyboard.isKeyActive(keyboard.KEY_EMOTE)) { Item *item = mItems->getSelectedItem(); if(!item) return; if (mInventory->isMainInventory()) - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, - item->getInvIndex(), item->getQuantity(), - Inventory::STORAGE); + { + Mana::Event event("doMove"); + event.setItem("item", item); + event.setInt("amount", item->getQuantity()); + event.setInt("source", Inventory::INVENTORY); + event.setInt("destination", Inventory::STORAGE); + event.trigger("Item"); + } else - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, - item->getInvIndex(), item->getQuantity(), - Inventory::INVENTORY); + { + Mana::Event event("doMove"); + event.setItem("item", item); + event.setInt("amount", item->getQuantity()); + event.setInt("source", Inventory::STORAGE); + event.setInt("destination", Inventory::INVENTORY); + event.trigger("Item"); + } } } } @@ -336,15 +354,36 @@ void InventoryWindow::close() } else { - Net::getInventoryHandler()->closeStorage(Inventory::STORAGE); + Mana::Event event("doCloseInventory"); + event.setInt("type", mInventory->getType()); + event.trigger("Item"); scheduleDelete(); } } +void InventoryWindow::event(const std::string &channel, const Mana::Event &event) +{ + if (event.getName() == "UpdateAttribute") + { + int id = event.getInt("id"); + if (id == TOTAL_WEIGHT || + id == MAX_WEIGHT) + { + updateWeight(); + } + } +} + void InventoryWindow::updateWeight() { - int total = player_node->getTotalWeight(); - int max = player_node->getMaxWeight(); + if (!isMainInventory()) + return; + + int total = PlayerInfo::getAttribute(TOTAL_WEIGHT); + int max = PlayerInfo::getAttribute(MAX_WEIGHT); + + if (max <= 0) + return; // Adjust progress bar mWeightBar->setProgress((float) total / max); |