summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-08 18:40:48 -0600
committerIra Rice <irarice@gmail.com>2009-03-09 00:52:56 -0600
commit5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf (patch)
treea905c74e059311b5adf10a6eacbe53482d95c380 /src
parent6ea994477c58912785729e7922eb90862a1ab13c (diff)
downloadmana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.tar.gz
mana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.tar.bz2
mana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.tar.xz
mana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.zip
Add an interface for eAthena's storage system
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game.cpp5
-rw-r--r--src/gui/item_amount.cpp19
-rw-r--r--src/gui/item_amount.h2
-rw-r--r--src/gui/itemcontainer.cpp4
-rw-r--r--src/gui/itemshortcutcontainer.cpp16
-rw-r--r--src/gui/itemshortcutcontainer.h5
-rw-r--r--src/gui/shortcutcontainer.cpp5
-rw-r--r--src/gui/storagewindow.cpp213
-rw-r--r--src/gui/storagewindow.h105
-rw-r--r--src/gui/trade.cpp4
-rw-r--r--src/gui/window.h5
-rw-r--r--src/inventory.cpp11
-rw-r--r--src/inventory.h4
-rw-r--r--src/localplayer.cpp11
-rw-r--r--src/localplayer.h5
-rw-r--r--src/net/inventoryhandler.cpp84
-rw-r--r--src/net/playerhandler.cpp2
19 files changed, 435 insertions, 69 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 51d6b937..c7003946 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -191,6 +191,8 @@ SET(SRCS
gui/speechbubble.h
gui/status.cpp
gui/status.h
+ gui/storagewindow.cpp
+ gui/storagewindow.h
gui/table.cpp
gui/table.h
gui/table_model.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 6b5dda8b..963e41fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -141,6 +141,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
gui/speechbubble.h \
gui/status.cpp \
gui/status.h \
+ gui/storagewindow.cpp \
+ gui/storagewindow.h \
gui/table.cpp \
gui/table.h \
gui/table_model.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 110b75cc..ba035ecd 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -70,6 +70,7 @@
#include "gui/setup.h"
#include "gui/skill.h"
#include "gui/status.h"
+#include "gui/storagewindow.h"
#include "gui/trade.h"
#include "gui/viewport.h"
@@ -129,6 +130,7 @@ HelpWindow *helpWindow;
DebugWindow *debugWindow;
ShortcutWindow *itemShortcutWindow;
ShortcutWindow *emoteShortcutWindow;
+StorageWindow *storageWindow;
BeingManager *beingManager = NULL;
FloorItemManager *floorItemManager = NULL;
@@ -213,6 +215,7 @@ void createGuiWindows(Network *network)
new ItemShortcutContainer);
emoteShortcutWindow = new ShortcutWindow("emoteShortcut",
new EmoteShortcutContainer);
+ storageWindow = new StorageWindow(network);
// Set initial window visibility
chatWindow->setVisible((bool) config.getValue(
@@ -230,6 +233,7 @@ void createGuiWindows(Network *network)
emoteShortcutWindow->getWindowName() + "Visible", true));
minimap->setVisible((bool) config.getValue(
minimap->getWindowName() + "Visible", true));
+ storageWindow->setVisible(false);
}
/**
@@ -260,6 +264,7 @@ void destroyGuiWindows()
delete debugWindow;
delete itemShortcutWindow;
delete emoteShortcutWindow;
+ delete storageWindow;
}
Game::Game(Network *network):
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 8ab36df0..05dca472 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -24,6 +24,7 @@
#include "inttextfield.h"
#include "item_amount.h"
#include "slider.h"
+#include "storagewindow.h"
#include "trade.h"
#include "widgets/layout.h"
@@ -81,6 +82,14 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
setCaption(_("Select amount of items to drop."));
okButton->setActionEventId("Drop");
break;
+ case AMOUNT_STORE_ADD:
+ setCaption(_("Select amount of items to store."));
+ okButton->setActionEventId("AddStore");
+ break;
+ case AMOUNT_STORE_REMOVE:
+ setCaption(_("Select amount of items to remove from storage."));
+ okButton->setActionEventId("RemoveStore");
+ break;
default:
break;
}
@@ -124,6 +133,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue());
scheduleDelete();
}
+ else if (event.getId() == "AddStore")
+ {
+ storageWindow->addStore(mItem, mItemAmountTextField->getValue());
+ scheduleDelete();
+ }
+ else if (event.getId() == "RemoveStore")
+ {
+ storageWindow->removeStore(mItem, mItemAmountTextField->getValue());
+ scheduleDelete();
+ }
mItemAmountTextField->setValue(amount);
mItemAmountSlide->setValue(amount);
}
diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h
index 6bec86b3..279c239e 100644
--- a/src/gui/item_amount.h
+++ b/src/gui/item_amount.h
@@ -32,6 +32,8 @@ class Item;
#define AMOUNT_TRADE_ADD 1
#define AMOUNT_ITEM_DROP 2
+#define AMOUNT_STORE_ADD 3
+#define AMOUNT_STORE_REMOVE 4
/**
* Window used for selecting the amount of items to drop or trade.
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 02d6e66d..54f1f647 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -57,7 +57,7 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset):
mSelImg = resman->getImage("graphics/gui/selection.png");
if (!mSelImg) logger->error("Unable to load selection.png");
- mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
+ mMaxItems = mInventory->getLastUsedSlot() - (mOffset - 1); // Count from 0, usage from 2
addMouseListener(this);
addWidgetListener(this);
@@ -76,7 +76,7 @@ void ItemContainer::logic()
gcn::Widget::logic();
- int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
+ int i = mInventory->getLastUsedSlot() - (mOffset - 1); // Count from 0, usage from 2
if (i != mMaxItems)
{
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index e7a9afbe..abe81537 100644
--- a/src/gui/itemshortcutcontainer.cpp
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -64,22 +64,6 @@ ItemShortcutContainer::~ItemShortcutContainer()
delete mItemPopup;
}
-void ItemShortcutContainer::logic()
-{
- if (!isVisible())
- return;
-
- gcn::Widget::logic();
-
- int i = itemShortcut->getItemCount();
-
- if (i != mMaxItems)
- {
- mMaxItems = i;
- setWidth(getWidth());
- }
-}
-
void ItemShortcutContainer::draw(gcn::Graphics *graphics)
{
if (!isVisible())
diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h
index f6137af0..0149754e 100644
--- a/src/gui/itemshortcutcontainer.h
+++ b/src/gui/itemshortcutcontainer.h
@@ -50,11 +50,6 @@ class ItemShortcutContainer : public ShortcutContainer
virtual ~ItemShortcutContainer();
/**
- * Handles the logic of the ItemContainer
- */
- void logic();
-
- /**
* Draws the items.
*/
void draw(gcn::Graphics *graphics);
diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp
index 50ec9d06..fcb33279 100644
--- a/src/gui/shortcutcontainer.cpp
+++ b/src/gui/shortcutcontainer.cpp
@@ -43,13 +43,12 @@ void ShortcutContainer::widgetResized(const gcn::Event &event)
if (mGridWidth < 1)
mGridWidth = 1;
+ setHeight((mMaxItems / mGridWidth) * mBoxHeight);
+
mGridHeight = getHeight() / mBoxHeight;
if (mGridHeight < 1)
mGridHeight = 1;
-
- setHeight((mMaxItems / mGridWidth +
- (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight);
}
int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
new file mode 100644
index 00000000..856f9166
--- /dev/null
+++ b/src/gui/storagewindow.cpp
@@ -0,0 +1,213 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string>
+
+#include <guichan/font.hpp>
+#include <guichan/mouseinput.hpp>
+
+#include <guichan/widgets/label.hpp>
+
+#include "button.h"
+#include "inventorywindow.h"
+#include "item_amount.h"
+#include "itemcontainer.h"
+#include "progressbar.h"
+#include "scrollarea.h"
+#include "storagewindow.h"
+#include "viewport.h"
+
+#include "widgets/layout.h"
+
+#include "../inventory.h"
+#include "../item.h"
+#include "../localplayer.h"
+
+#include "../net/messageout.h"
+#include "../net/network.h"
+#include "../net/protocol.h"
+
+#include "../resources/iteminfo.h"
+
+#include "../utils/gettext.h"
+#include "../utils/strprintf.h"
+#include "../utils/stringutils.h"
+
+StorageWindow::StorageWindow(Network *network, int invSize):
+ Window(_("Storage")),
+ mNetwork(network),
+ mMaxSlots(invSize),
+ mItemDesc(false)
+{
+ setWindowName("Storage");
+ setResizable(true);
+
+ // If you adjust these defaults, don't forget to adjust the trade window's.
+ setDefaultSize(115, 25, 375, 300);
+
+ mCancelButton = new Button(_("Close"), "close", this);
+ mStoreButton = new Button(_("Store"), "store", this);
+ mRetrieveButton = new Button(_("Retrieve"), "retrieve", this);
+
+ mItems = new ItemContainer(player_node->getStorage(), 1);
+ mItems->addSelectionListener(this);
+
+ mInvenScroll = new ScrollArea(mItems);
+ mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+
+ mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed());
+
+ mSlotsLabel = new gcn::Label(_("Slots: "));
+
+ mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25);
+
+ setMinHeight(130);
+ setMinWidth(mSlotsLabel->getWidth());
+
+ place(0, 0, mSlotsLabel).setPadding(3);
+ place(1, 0, mSlotsBar, 3);
+ place(0, 1, mInvenScroll, 4, 4);
+ place(0, 5, mCancelButton);
+ place(2, 5, mStoreButton);
+ place(3, 5, mRetrieveButton);
+
+ Layout &layout = getLayout();
+ layout.setRowHeight(0, mStoreButton->getHeight());
+
+ loadWindowState();
+ setLocationRelativeTo(getParent());
+}
+
+StorageWindow::~StorageWindow()
+{
+ delete mItems;
+}
+
+void StorageWindow::logic()
+{
+ if (!isVisible())
+ return;
+
+ Window::logic();
+
+ if (mUsedSlots != toString(player_node->getStorage()->getNumberOfSlotsUsed()))
+ {
+ mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed());
+
+ mSlotsBar->setProgress((float)
+ player_node->getStorage()->getNumberOfSlotsUsed() / mMaxSlots);
+
+ mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots));
+ }
+}
+
+void StorageWindow::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "close")
+ {
+ close();
+ }
+ else if (event.getId() == "store")
+ {
+ Item *item = inventoryWindow->getSelectedItem();
+
+ if (!item)
+ return;
+
+ if (item->getQuantity() == 1)
+ {
+ addStore(item, 1);
+ }
+ else
+ {
+ // Choose amount of items to trade
+ new ItemAmountWindow(AMOUNT_STORE_ADD, this, item);
+ }
+ }
+ else if (event.getId() == "retrieve")
+ {
+ Item *item = mItems->getSelectedItem();
+
+ if (!item)
+ return;
+
+ if (item->getQuantity() == 1)
+ {
+ removeStore(item, 1);
+ }
+ else
+ {
+ // Choose amount of items to trade
+ new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item);
+ }
+ }
+}
+
+void StorageWindow::mouseClicked(gcn::MouseEvent &event)
+{
+ Window::mouseClicked(event);
+
+ if (event.getButton() == gcn::MouseEvent::RIGHT)
+ {
+ Item *item = mItems->getSelectedItem();
+
+ if (!item) {
+ mRetrieveButton->setEnabled(false);
+ return;
+ }
+
+ mRetrieveButton->setEnabled(true);
+
+ /* Convert relative to the window coordinates to absolute screen
+ * coordinates.
+ */
+ const int mx = event.getX() + getX();
+ const int my = event.getY() + getY();
+ viewport->showPopup(mx, my, item);
+ }
+}
+
+Item* StorageWindow::getSelectedItem() const
+{
+ return mItems->getSelectedItem();
+}
+
+void StorageWindow::addStore(Item* item, int ammount)
+{
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_MOVE_TO_STORAGE);
+ outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt32(ammount);
+}
+
+void StorageWindow::removeStore(Item* item, int ammount)
+{
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CSMG_MOVE_FROM_STORAGE);
+ outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt32(ammount);
+}
+
+void StorageWindow::close()
+{
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_CLOSE_STORAGE);
+}
diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h
new file mode 100644
index 00000000..23142ac1
--- /dev/null
+++ b/src/gui/storagewindow.h
@@ -0,0 +1,105 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef STORAGEWINDOW_H
+#define STORAGEWINDOW_H
+
+#include "window.h"
+
+#include "../inventory.h"
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/selectionlistener.hpp>
+
+class Item;
+class ItemContainer;
+class Network;
+class ProgressBar;
+class TextBox;
+
+/**
+ * Storage dialog.
+ *
+ * \ingroup Interface
+ */
+class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener
+{
+ public:
+ /**
+ * Constructor.
+ */
+ StorageWindow(Network *network, int invSize = (STORAGE_SIZE - 1));
+
+ /**
+ * Destructor.
+ */
+ ~StorageWindow();
+
+ /**
+ * Logic (updates buttons and weight information).
+ */
+ void logic();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Returns the selected item.
+ */
+ Item* getSelectedItem() const;
+
+ void mouseClicked(gcn::MouseEvent &event);
+
+ /**
+ * Add the specified ammount of the specified item to storage
+ */
+ void addStore(Item* item, int ammount);
+
+ /**
+ * Remove the specified ammount of the specified item from storage
+ */
+ void removeStore(Item* item, int ammount);
+
+ void close();
+
+ private:
+ Network *mNetwork;
+ ItemContainer *mItems;
+
+ std::string mSlots;
+ std::string mUsedSlots;
+ gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton;
+ gcn::ScrollArea *mInvenScroll;
+
+ gcn::Label *mSlotsLabel;
+
+ ProgressBar *mSlotsBar;
+
+ int mMaxSlots;
+
+ bool mItemDesc;
+};
+
+extern StorageWindow *storageWindow;
+
+#endif // STORAGEWINDOW_H
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index a12b94ed..76795688 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -49,8 +49,8 @@
TradeWindow::TradeWindow(Network *network):
Window(_("Trade: You")),
mNetwork(network),
- mMyInventory(new Inventory(INVENTORY_SIZE)),
- mPartnerInventory(new Inventory(INVENTORY_SIZE))
+ mMyInventory(new Inventory(INVENTORY_SIZE, 2)),
+ mPartnerInventory(new Inventory(INVENTORY_SIZE, 2))
{
setWindowName(_("Trade"));
setDefaultSize(115, 227, 342, 209);
diff --git a/src/gui/window.h b/src/gui/window.h
index 0a0f4be9..a4f56e05 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -63,7 +63,7 @@ class Window : public gcn::Window, gcn::WidgetListener
* @param skin The location where the window's skin XML can be found.
*/
Window(const std::string &caption = "Window", bool modal = false,
- Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml");
+ Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml");
/**
* Destructor. Deletes all the added widgets.
@@ -153,8 +153,7 @@ class Window : public gcn::Window, gcn::WidgetListener
/**
* Sets flag to show a title or not.
*/
- void setShowTitle(bool flag)
- { mShowTitle = flag; }
+ void setShowTitle(bool flag) { mShowTitle = flag; }
/**
* Sets whether the window is sticky. A sticky window will not have
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 4053bc96..d72e0e4a 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -34,8 +34,9 @@ struct SlotUsed : public std::unary_function<Item*, bool>
}
};
-Inventory::Inventory(int size):
- mSize(size)
+Inventory::Inventory(int size, int offset):
+ mSize(size),
+ mOffset(offset)
{
mItems = new Item*[mSize];
std::fill_n(mItems, mSize, (Item*) 0);
@@ -51,7 +52,7 @@ Inventory::~Inventory()
Item* Inventory::getItem(int index) const
{
- if (index < 0 || index >= INVENTORY_SIZE || !mItems[index] || mItems[index]->getQuantity() <= 0)
+ if (index < 0 || index >= mSize || !mItems[index] || mItems[index]->getQuantity() <= 0)
return 0;
return mItems[index];
@@ -127,7 +128,7 @@ bool Inventory::contains(Item *item) const
int Inventory::getFreeSlot() const
{
- Item **i = std::find_if(mItems + 2, mItems + mSize,
+ Item **i = std::find_if(mItems, mItems + mSize,
std::not1(SlotUsed()));
return (i == mItems + mSize) ? -1 : (i - mItems);
}
@@ -148,5 +149,5 @@ int Inventory::getLastUsedSlot() const
int Inventory::getInventorySize() const
{
- return INVENTORY_SIZE - 2;
+ return mSize - mOffset;
}
diff --git a/src/inventory.h b/src/inventory.h
index 3b3ec507..e23f7657 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -26,6 +26,7 @@
class Item;
#define INVENTORY_SIZE 102
+#define STORAGE_SIZE 301
class Inventory
{
@@ -33,7 +34,7 @@ class Inventory
/**
* Constructor.
*/
- Inventory(int size);
+ Inventory(int size, int offset);
/**
* Destructor.
@@ -111,6 +112,7 @@ class Inventory
protected:
Item **mItems; /**< The holder of items */
int mSize; /**< The max number of inventory items */
+ int mOffset; /**< Offset used by the inventory */
};
#endif
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 76d13a4b..d6acc48f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -37,6 +37,7 @@
#include "text.h"
#include "gui/gui.h"
+#include "gui/storagewindow.h"
#include "net/messageout.h"
#include "net/protocol.h"
@@ -74,8 +75,8 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
mTargetTime(-1), mLastAction(-1),
mLastTarget(-1), mWalkingDir(0),
mDestX(0), mDestY(0),
- mInventory(new Inventory(INVENTORY_SIZE)),
- mStorage(new Inventory(STORAGE_SIZE))
+ mInventory(new Inventory(INVENTORY_SIZE, 2)),
+ mStorage(new Inventory(STORAGE_SIZE, 1))
{
// Variable to keep the local player from doing certain actions before a map
// is initialized. e.g. drawing a player's name using the TextManager, since
@@ -694,3 +695,9 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height,
mTargetCursor[index][size] = currentCursor;
}
+void LocalPlayer::setInStorage(bool inStorage)
+{
+ mInStorage = inStorage;
+
+ storageWindow->setVisible(inStorage);
+}
diff --git a/src/localplayer.h b/src/localplayer.h
index 2fb8c615..85868750 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -30,9 +30,6 @@
// TODO move into some sane place...
#define MAX_SLOT 2
-#define INVENTORY_SIZE 102
-#define STORAGE_SIZE 301
-
class Equipment;
class FloorItem;
class ImageSet;
@@ -194,7 +191,7 @@ class LocalPlayer : public Player
* Accessors for mInStorage
*/
bool getInStorage() { return mInStorage; }
- void setInStorage(bool inStorage) { mInStorage = inStorage; }
+ void setInStorage(bool inStorage);
/**
* Sets the amount of XP. Shows XP gaining effect if the player is on
diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp
index b0511080..553ec8fd 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -34,6 +34,7 @@
#include "../log.h"
#include "../gui/chat.h"
+#include "../gui/storagewindow.h"
#include "../resources/iteminfo.h"
@@ -72,7 +73,6 @@ void InventoryHandler::handleMessage(MessageIn *msg)
{
case SMSG_PLAYER_INVENTORY:
case SMSG_PLAYER_STORAGE_ITEMS:
- case SMSG_PLAYER_STORAGE_EQUIP:
switch (msg->getId()) {
case SMSG_PLAYER_INVENTORY:
// Clear inventory - this will be a complete refresh
@@ -86,11 +86,10 @@ void InventoryHandler::handleMessage(MessageIn *msg)
* clear storage here
*/
storage->clear();
- logger->log("Received SMSG_PLAYER_STORAGE_ITEMS");
break;
default:
- logger->log("Received SMSG_PLAYER_STORAGE_EQUIP");
- break;
+ logger->log("HOW DID WE GET HERE?");
+ return;
}
msg->readInt16(); // length
number = (msg->getLength() - 4) / 18;
@@ -100,17 +99,8 @@ void InventoryHandler::handleMessage(MessageIn *msg)
itemId = msg->readInt16();
itemType = msg->readInt8();
identified = msg->readInt8();
- if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) {
- amount = 1;
- msg->readInt16(); // Equip Point?
- } else {
- amount = msg->readInt16();
- }
+ amount = msg->readInt16();
arrow = msg->readInt16();
- if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) {
- msg->readInt8(); // Attribute (broken)
- msg->readInt8(); // Refine level
- }
for (int i = 0; i < 4; i++)
cards[i] = msg->readInt16();
@@ -130,6 +120,29 @@ void InventoryHandler::handleMessage(MessageIn *msg)
}
break;
+ case SMSG_PLAYER_STORAGE_EQUIP:
+ msg->readInt16(); // length
+ number = (msg->getLength() - 4) / 20;
+
+ for (int loop = 0; loop < number; loop++) {
+ index = msg->readInt16();
+ itemId = msg->readInt16();
+ itemType = msg->readInt8();
+ identified = msg->readInt8();
+ amount = 1;
+ msg->readInt16(); // Equip Point?
+ msg->readInt16(); // Another Equip Point?
+ msg->readInt8(); // Attribute (broken)
+ msg->readInt8(); // Refine level
+ for (int i = 0; i < 4; i++)
+ cards[i] = msg->readInt16();
+
+ logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d",
+ index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]);
+ storage->setItem(index, itemId, amount, false);
+ }
+ break;
+
case SMSG_PLAYER_INVENTORY_ADD:
index = msg->readInt16();
amount = msg->readInt16();
@@ -203,35 +216,54 @@ void InventoryHandler::handleMessage(MessageIn *msg)
case SMSG_PLAYER_STORAGE_STATUS:
/*
- * Basic slots used vs total slots info
- * We don't really need this information, but this is
- * the closest we get to an "Open Storage" packet
- * from the server. It always comes after the two
- * SMSG_PLAYER_STORAGE_... packets that update
- * storage contents.
+ * This is the closest we get to an "Open Storage" packet from the
+ * server. It always comes after the two SMSG_PLAYER_STORAGE_...
+ * packets that update storage contents..
*/
- logger->log("Received SMSG_PLAYER_STORAGE_STATUS");
player_node->setInStorage(true);
+ msg->readInt16(); // Storage capacity
+ msg->readInt16(); // Used count
break;
case SMSG_PLAYER_STORAGE_ADD:
/*
* Move an item into storage
*/
+ index = msg->readInt16();
+ amount = msg->readInt32();
+ itemId = msg->readInt16();
+ identified = msg->readInt8();
+ msg->readInt8(); // attribute
+ msg->readInt8(); // refine
+ for (int i = 0; i < 4; i++)
+ cards[i] = msg->readInt16();
+
+ if (Item *item = storage->getItem(index)) {
+ item->setId(itemId);
+ item->increaseQuantity(amount);
+ } else {
+ storage->setItem(index, itemId, amount, false);
+ }
break;
case SMSG_PLAYER_STORAGE_REMOVE:
/*
- * Move an item out of storage
- */
+ * Move an item out of storage
+ */
+ index = msg->readInt16();
+ amount = msg->readInt16();
+ if (Item *item = storage->getItem(index)) {
+ item->increaseQuantity(-amount);
+ if (item->getQuantity() == 0)
+ storage->removeItemAt(index);
+ }
break;
case SMSG_PLAYER_STORAGE_CLOSE:
/*
- * Storage access has been closed
- */
+ * Storage access has been closed
+ */
player_node->setInStorage(false);
- logger->log("Received SMSG_PLAYER_STORAGE_CLOSE");
break;
}
}
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 232cf075..6533ac1e 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -39,6 +39,7 @@
#include "../gui/ok_dialog.h"
#include "../gui/sell.h"
#include "../gui/skill.h"
+#include "../gui/storagewindow.h"
#include "../gui/viewport.h"
#include "../utils/stringutils.h"
@@ -92,6 +93,7 @@ namespace {
buyDialog->setVisible(false);
sellDialog->setVisible(false);
buySellDialog->setVisible(false);
+ if (storageWindow->isVisible()) storageWindow->close();
current_npc = 0;
}
} deathListener;