summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/inventorywindow.cpp16
-rw-r--r--src/gui/inventorywindow.h2
-rw-r--r--src/gui/itemamount.cpp8
-rw-r--r--src/gui/trade.cpp6
-rw-r--r--src/inventory.cpp8
-rw-r--r--src/inventory.h17
-rw-r--r--src/localplayer.cpp3
-rw-r--r--src/net/ea/inventoryhandler.cpp26
-rw-r--r--src/net/ea/inventoryhandler.h15
-rw-r--r--src/net/inventoryhandler.h18
-rw-r--r--src/net/manaserv/inventoryhandler.cpp18
-rw-r--r--src/net/manaserv/inventoryhandler.h10
13 files changed, 83 insertions, 66 deletions
diff --git a/src/game.cpp b/src/game.cpp
index f2ad6109..185fcb03 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -155,7 +155,7 @@ static void createGuiWindows()
equipmentWindow = new EquipmentWindow(player_node->mEquipment.get());
statusWindow = new StatusWindow;
miniStatusWindow = new MiniStatusWindow;
- inventoryWindow = new InventoryWindow(player_node->getInventory(), true);
+ inventoryWindow = new InventoryWindow(player_node->getInventory());
skillDialog = new SkillDialog;
minimap = new Minimap;
helpWindow = new HelpWindow;
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 41d0246c..26f12285 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -55,12 +55,12 @@
InventoryWindow::WindowList InventoryWindow::instances;
-InventoryWindow::InventoryWindow(Inventory *inventory, bool isMainInventory):
- Window(isMainInventory ? _("Inventory") : _("Storage")),
+InventoryWindow::InventoryWindow(Inventory *inventory):
+ Window(inventory->isMainInventory() ? _("Inventory") : _("Storage")),
mInventory(inventory),
mSplit(false)
{
- setWindowName(isMainInventory ? "Inventory" : "Storage");
+ setWindowName(inventory->isMainInventory() ? "Inventory" : "Storage");
setupWindow->registerWindowForReset(this);
setResizable(true);
setCloseButton(true);
@@ -80,7 +80,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory, bool isMainInventory):
mSlotsLabel = new Label(_("Slots:"));
mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS);
- if (isMainInventory)
+ if (inventory->isMainInventory())
{
std::string equip = _("Equip");
std::string use = _("Use");
@@ -137,7 +137,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory, bool isMainInventory):
loadWindowState();
slotsChanged(mInventory);
- if (!isMainInventory)
+ if (!inventory->isMainInventory())
setVisible(true);
}
@@ -241,9 +241,9 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if(!item)
return;
- Net::getInventoryHandler()->moveItem(Net::InventoryHandler::INVENTORY,
+ Net::getInventoryHandler()->moveItem(Inventory::INVENTORY,
item->getInvIndex(), item->getQuantity(),
- Net::InventoryHandler::STORAGE);
+ Inventory::STORAGE);
}
}
}
@@ -326,7 +326,7 @@ void InventoryWindow::close()
if (this == inventoryWindow)
return;
- Net::getInventoryHandler()->closeStorage(Net::InventoryHandler::STORAGE);
+ Net::getInventoryHandler()->closeStorage(Inventory::STORAGE);
scheduleDelete();
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 406c24bf..948482f5 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -53,7 +53,7 @@ class InventoryWindow : public Window,
/**
* Constructor.
*/
- InventoryWindow(Inventory *inventory, bool isMainInventory = false);
+ InventoryWindow(Inventory *inventory);
/**
* Destructor.
diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp
index f28bbed7..a98a67ab 100644
--- a/src/gui/itemamount.cpp
+++ b/src/gui/itemamount.cpp
@@ -53,14 +53,14 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage)
Net::getInventoryHandler()->splitItem(item, amount);
break;
case StoreAdd:
- Net::getInventoryHandler()->moveItem(Net::InventoryHandler::INVENTORY,
+ Net::getInventoryHandler()->moveItem(Inventory::INVENTORY,
item->getInvIndex(), amount,
- Net::InventoryHandler::STORAGE);
+ Inventory::STORAGE);
break;
case StoreRemove:
- Net::getInventoryHandler()->moveItem(Net::InventoryHandler::STORAGE,
+ Net::getInventoryHandler()->moveItem(Inventory::STORAGE,
item->getInvIndex(), amount,
- Net::InventoryHandler::INVENTORY);
+ Inventory::INVENTORY);
break;
default:
break;
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 0f86913a..dcb38e8e 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -56,10 +56,8 @@
TradeWindow::TradeWindow():
Window(_("Trade: You")),
- mMyInventory(new Inventory(Net::getInventoryHandler()
- ->getSize(Net::InventoryHandler::INVENTORY))),
- mPartnerInventory(new Inventory(Net::getInventoryHandler()
- ->getSize(Net::InventoryHandler::INVENTORY))),
+ mMyInventory(new Inventory(Inventory::TRADE)),
+ mPartnerInventory(new Inventory(Inventory::TRADE)),
mStatus(PROPOSING)
{
setWindowName("Trade");
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 8a6e79bb..a6038c85 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -23,6 +23,9 @@
#include "item.h"
#include "log.h"
+#include "net/inventoryhandler.h"
+#include "net/net.h"
+
#include <algorithm>
struct SlotUsed : public std::unary_function<Item*, bool>
@@ -33,8 +36,9 @@ struct SlotUsed : public std::unary_function<Item*, bool>
}
};
-Inventory::Inventory(int size):
- mSize(size),
+Inventory::Inventory(int type, int size):
+ mType(type),
+ mSize(size == -1 ? Net::getInventoryHandler()->getSize(type) : size),
mUsed(0)
{
mItems = new Item*[mSize];
diff --git a/src/inventory.h b/src/inventory.h
index 0529d504..0ee516d6 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -43,12 +43,20 @@ class Inventory
public:
static const int NO_SLOT_INDEX = -1; /**< Slot has no index. */
+ enum {
+ INVENTORY,
+ STORAGE,
+ TRADE,
+ TYPE_END
+ };
+
+
/**
* Constructor.
*
* @param size the number of items that fit in the inventory
*/
- Inventory(int size);
+ Inventory(int type, int size = -1);
/**
* Destructor.
@@ -123,12 +131,19 @@ class Inventory
void removeInventoyListener(InventoryListener* listener);
+ int getType() const
+ { return mType; }
+
+ bool isMainInventory() const
+ { return mType == INVENTORY; }
+
protected:
typedef std::list<InventoryListener*> InventoryListenerList;
InventoryListenerList mInventoryListeners;
void distributeSlotsChangedEvent();
+ int mType;
Item **mItems; /**< The holder of items */
int mSize; /**< The max number of inventory items */
int mUsed; /**< THe number of slots in use */
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 6c5f257d..1a110810 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -98,8 +98,7 @@ LocalPlayer::LocalPlayer(int id, int job):
mLastAction(-1),
mWalkingDir(0),
mPathSetByMouse(false),
- mInventory(new Inventory(Net::getInventoryHandler()
- ->getSize(Net::InventoryHandler::INVENTORY))),
+ mInventory(new Inventory(Inventory::INVENTORY)),
mLocalWalkTime(-1),
mMessageTime(0)
{
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 1b191354..36d024f6 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -296,7 +296,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
int size = msg.readInt16(); // Max size
if (!mStorage)
- mStorage = new Inventory(size);
+ mStorage = new Inventory(Inventory::STORAGE, size);
InventoryItems::iterator it = mInventoryItems.begin();
InventoryItems::iterator it_end = mInventoryItems.end();
@@ -472,26 +472,26 @@ void InventoryHandler::moveItem(int oldIndex, int newIndex)
// Not implemented for eAthena (possible?)
}
-void InventoryHandler::openStorage(StorageType type)
+void InventoryHandler::openStorage(int type)
{
// Doesn't apply to eAthena, since opening happens through NPCs?
}
-void InventoryHandler::closeStorage(StorageType type)
+void InventoryHandler::closeStorage(int type)
{
MessageOut outMsg(CMSG_CLOSE_STORAGE);
}
-void InventoryHandler::moveItem(StorageType source, int slot, int amount,
- StorageType destination)
+void InventoryHandler::moveItem(int source, int slot, int amount,
+ int destination)
{
- if (source == INVENTORY && destination == STORAGE)
+ if (source == Inventory::INVENTORY && destination == Inventory::STORAGE)
{
MessageOut outMsg(CMSG_MOVE_TO_STORAGE);
outMsg.writeInt16(slot + INVENTORY_OFFSET);
outMsg.writeInt32(amount);
}
- else if (source == STORAGE && destination == INVENTORY)
+ else if (source == Inventory::STORAGE && destination == Inventory::INVENTORY)
{
MessageOut outMsg(CSMG_MOVE_FROM_STORAGE);
outMsg.writeInt16(slot + STORAGE_OFFSET);
@@ -499,16 +499,18 @@ void InventoryHandler::moveItem(StorageType source, int slot, int amount,
}
}
-size_t InventoryHandler::getSize(StorageType type) const
+size_t InventoryHandler::getSize(int type) const
{
switch (type)
{
- case INVENTORY:
+ case Inventory::INVENTORY:
return 100;
- case STORAGE:
- return 0;
+ case Inventory::STORAGE:
+ return 0; // Comes from server after items
+ case Inventory::TRADE:
+ return 12;
case GUILD_STORAGE:
- return 0;
+ return 0; // Comes from server after items
default:
return 0;
}
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index d08e4772..cb127af9 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -118,6 +118,11 @@ typedef std::list<InventoryItem> InventoryItems;
class InventoryHandler : public MessageHandler, public Net::InventoryHandler
{
public:
+ enum {
+ GUILD_STORAGE = Inventory::TYPE_END,
+ CART
+ };
+
InventoryHandler();
~InventoryHandler();
@@ -138,14 +143,14 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
void moveItem(int oldIndex, int newIndex);
- void openStorage(StorageType type);
+ void openStorage(int type);
- void closeStorage(StorageType type);
+ void closeStorage(int type);
- void moveItem(StorageType source, int slot, int amount,
- StorageType destination);
+ void moveItem(int source, int slot, int amount,
+ int destination);
- size_t getSize(StorageType type) const;
+ size_t getSize(int type) const;
private:
EquipBackend mEquips;
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index 9d0a5bc8..e48043a7 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -22,6 +22,7 @@
#ifndef INVENTORYHANDLER_H
#define INVENTORYHANDLER_H
+#include "inventory.h"
#include "item.h"
#include <iosfwd>
@@ -45,24 +46,17 @@ class InventoryHandler
virtual void moveItem(int oldIndex, int newIndex) = 0;
- enum StorageType {
- INVENTORY,
- STORAGE,
- GUILD_STORAGE,
- CART
- };
+ virtual void openStorage(int type) = 0;
- virtual void openStorage(StorageType type) = 0;
-
- virtual void closeStorage(StorageType type) = 0;
+ virtual void closeStorage(int type) = 0;
//void changeCart() = 0;
- virtual void moveItem(StorageType source, int slot, int amount,
- StorageType destination) = 0;
+ virtual void moveItem(int source, int slot, int amount,
+ int destination) = 0;
// TODO: fix/remove me
- virtual size_t getSize(StorageType type) const = 0;
+ virtual size_t getSize(int type) const = 0;
virtual ~InventoryHandler() {}
};
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index 66f4a2ba..76fca7ae 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -79,7 +79,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
mEquips.setEquipment(slot, id);
}
- else if (slot >= 32 && slot < 32 + getSize(INVENTORY))
+ else if (slot >= 32 && slot < 32 + getSize(Inventory::INVENTORY))
{
int amount = id ? msg.readInt8() : 0;
player_node->setInvItem(slot - 32, id, amount);
@@ -154,30 +154,30 @@ void InventoryHandler::moveItem(int oldIndex, int newIndex)
gameServerConnection->send(msg);
}
-void InventoryHandler::openStorage(StorageType type)
+void InventoryHandler::openStorage(int type)
{
// TODO
}
-void InventoryHandler::closeStorage(StorageType type)
+void InventoryHandler::closeStorage(int type)
{
// TODO
}
-void InventoryHandler::moveItem(StorageType source, int slot, int amount,
- StorageType destination)
+void InventoryHandler::moveItem(int source, int slot, int amount,
+ int destination)
{
// TODO
}
-size_t InventoryHandler::getSize(StorageType type) const
+size_t InventoryHandler::getSize(int type) const
{
switch (type)
{
- case INVENTORY:
+ case Inventory::INVENTORY:
+ case Inventory::TRADE:
return 50;
- case STORAGE:
- case GUILD_STORAGE:
+ case Inventory::STORAGE:
return 300;
default:
return 0;
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index 49f013cf..fd08b95e 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -88,14 +88,14 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler
void moveItem(int oldIndex, int newIndex);
- void openStorage(StorageType type);
+ void openStorage(int type);
- void closeStorage(StorageType type);
+ void closeStorage(int type);
- void moveItem(StorageType source, int slot, int amount,
- StorageType destination);
+ void moveItem(int source, int slot, int amount,
+ int destination);
- size_t getSize(StorageType type) const;
+ size_t getSize(int type) const;
private:
EquipBackend mEquips;