summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.cpp3
-rw-r--r--src/gui/equipmentwindow.cpp2
-rw-r--r--src/gui/inventorywindow.cpp7
-rw-r--r--src/gui/itemamount.cpp4
-rw-r--r--src/gui/popupmenu.cpp10
-rw-r--r--src/gui/popupmenu.h6
-rw-r--r--src/gui/storagewindow.cpp29
-rw-r--r--src/gui/storagewindow.h26
-rw-r--r--src/gui/viewport.cpp5
-rw-r--r--src/gui/viewport.h6
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp2
-rw-r--r--src/localplayer.cpp11
-rw-r--r--src/localplayer.h15
-rw-r--r--src/net/ea/inventoryhandler.cpp78
-rw-r--r--src/net/ea/inventoryhandler.h31
-rw-r--r--src/net/ea/playerhandler.cpp2
-rw-r--r--src/net/inventoryhandler.h1
17 files changed, 147 insertions, 91 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 40450fee..7ebf6f8e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -106,7 +106,6 @@ StatusWindow *statusWindow;
MiniStatusWindow *miniStatusWindow;
InventoryWindow *inventoryWindow;
SkillDialog *skillDialog;
-StorageWindow *storageWindow;
Minimap *minimap;
EquipmentWindow *equipmentWindow;
TradeWindow *tradeWindow;
@@ -154,7 +153,6 @@ static void createGuiWindows()
chatWindow = new ChatWindow;
tradeWindow = new TradeWindow;
equipmentWindow = new EquipmentWindow(player_node->mEquipment.get());
- storageWindow = new StorageWindow;
statusWindow = new StatusWindow;
miniStatusWindow = new MiniStatusWindow;
inventoryWindow = new InventoryWindow;
@@ -202,7 +200,6 @@ static void destroyGuiWindows()
del_0(debugWindow)
del_0(itemShortcutWindow)
del_0(emoteShortcutWindow)
- del_0(storageWindow)
del_0(outfitWindow)
del_0(specialsWindow)
del_0(socialWindow)
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 4400c9f5..581fd818 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -207,7 +207,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
*/
const int mx = x + getX();
const int my = y + getY();
- viewport->showPopup(mx, my, item, true);
+ viewport->showPopup(this, mx, my, item, true);
}
}
}
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 9c5f138e..ed008e63 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -220,19 +220,20 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
*/
const int mx = event.getX() + getX();
const int my = event.getY() + getY();
- viewport->showPopup(mx, my, item);
+ viewport->showPopup(this, mx, my, item);
}
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (storageWindow && keyboard.isKeyActive(keyboard.KEY_EMOTE))
+ if (StorageWindow::isActive() &&
+ keyboard.isKeyActive(keyboard.KEY_EMOTE))
{
Item *item = mItems->getSelectedItem();
if(!item)
return;
- storageWindow->addStore(item, item->getQuantity());
+ StorageWindow::addStore(item, item->getQuantity());
}
}
}
diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp
index c4c38a9d..1dc5425f 100644
--- a/src/gui/itemamount.cpp
+++ b/src/gui/itemamount.cpp
@@ -54,10 +54,10 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage)
Net::getInventoryHandler()->splitItem(item, amount);
break;
case StoreAdd:
- storageWindow->addStore(item, amount);
+ StorageWindow::addStore(item, amount);
break;
case StoreRemove:
- storageWindow->removeStore(item, amount);
+ StorageWindow::removeStore(item, amount);
break;
default:
break;
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index e9c71496..7e4bfd65 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -320,8 +320,8 @@ void PopupMenu::handleLink(const std::string &link)
else if (link == "retrieve")
{
- ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove,
- storageWindow, mItem);
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, mWindow,
+ mItem);
}
else if (link == "party" && being && being->getType() == Being::PLAYER)
@@ -356,10 +356,12 @@ void PopupMenu::handleLink(const std::string &link)
mItem = NULL;
}
-void PopupMenu::showPopup(int x, int y, Item *item, bool isInventory)
+void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
+ bool isInventory)
{
assert(item);
mItem = item;
+ mWindow = parent;
mBrowserBox->clearRows();
if (isInventory)
@@ -384,7 +386,7 @@ void PopupMenu::showPopup(int x, int y, Item *item, bool isInventory)
mBrowserBox->addRow(strprintf("@@split|%s@@", _("Split")));
}
- if (player_node->getInStorage())
+ if (StorageWindow::isActive())
{
mBrowserBox->addRow(strprintf("@@store|%s@@", _("Store")));
}
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 3299694f..3bb49967 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -29,6 +29,7 @@ class Being;
class BrowserBox;
class FloorItem;
class Item;
+class Window;
/**
* Window showing popup menu.
@@ -56,7 +57,8 @@ class PopupMenu : public Popup, public LinkHandler
* Shows the related popup menu when right click on the inventory
* at the specified mouse coordinates.
*/
- void showPopup(int x, int y, Item *item, bool isInventory);
+ void showPopup(Window *parent, int x, int y, Item *item,
+ bool isInventory);
/**
* Handles link action.
@@ -70,6 +72,8 @@ class PopupMenu : public Popup, public LinkHandler
FloorItem* mFloorItem;
Item *mItem;
+ Window *mWindow;
+
/**
* Shared code for the various showPopup functions.
*/
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index ff0ba162..bf54afb9 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -52,9 +52,11 @@
#include <string>
-StorageWindow::StorageWindow(int invSize):
+StorageWindow::WindowList StorageWindow::instances;
+
+StorageWindow::StorageWindow(Inventory *inventory):
Window(_("Storage")),
- mMaxSlots(invSize),
+ mInventory(inventory),
mItemDesc(false)
{
setWindowName("Storage");
@@ -70,19 +72,19 @@ StorageWindow::StorageWindow(int invSize):
mCloseButton = new Button(_("Close"), "close", this);
- mItems = new ItemContainer(player_node->getStorage(), true);
+ mItems = new ItemContainer(mInventory, true);
mItems->addSelectionListener(this);
gcn::ScrollArea *invenScroll = new ScrollArea(mItems);
invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mUsedSlots = player_node->getStorage()->getNumberOfSlotsUsed();
+ mUsedSlots = mInventory->getNumberOfSlotsUsed();
mSlotsLabel = new Label(_("Slots:"));
mSlotsBar = new ProgressBar(0.0f, 100, 20, gcn::Color(225, 200, 25));
- mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots));
- mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
+ mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mInventory->getSize()));
+ mSlotsBar->setProgress((float) mUsedSlots / mInventory->getSize());
setMinHeight(130);
setMinWidth(200);
@@ -98,10 +100,14 @@ StorageWindow::StorageWindow(int invSize):
layout.setRowHeight(0, mStoreButton->getHeight());
loadWindowState();
+
+ instances.push_back(this);
+ setVisible(true);
}
StorageWindow::~StorageWindow()
{
+ instances.remove(this);
}
void StorageWindow::logic()
@@ -111,15 +117,16 @@ void StorageWindow::logic()
Window::logic();
- const int usedSlots = player_node->getStorage()->getNumberOfSlotsUsed();
+ const int usedSlots = mInventory->getNumberOfSlotsUsed();
if (mUsedSlots != usedSlots)
{
mUsedSlots = usedSlots;
- mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
+ mSlotsBar->setProgress((float) mUsedSlots / mInventory->getSize());
- mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots));
+ mSlotsBar->setText(strprintf("%d/%d", mUsedSlots,
+ mInventory->getSize()));
}
}
@@ -173,7 +180,7 @@ void StorageWindow::mouseClicked(gcn::MouseEvent &event)
*/
const int mx = event.getX() + getX();
const int my = event.getY() + getY();
- viewport->showPopup(mx, my, item, false);
+ viewport->showPopup(this, mx, my, item, false);
}
if (event.getButton() == gcn::MouseEvent::LEFT)
{
@@ -211,4 +218,6 @@ void StorageWindow::removeStore(Item *item, int amount)
void StorageWindow::close()
{
Net::getInventoryHandler()->closeStorage(Net::InventoryHandler::STORAGE);
+
+ scheduleDelete();
}
diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h
index 766f2b1a..046b7613 100644
--- a/src/gui/storagewindow.h
+++ b/src/gui/storagewindow.h
@@ -49,8 +49,7 @@ class StorageWindow : public Window, gcn::ActionListener,
/**
* Constructor.
*/
- StorageWindow(int invSize = Net::getInventoryHandler()
- ->getSize(Net::InventoryHandler::STORAGE));
+ StorageWindow(Inventory *inventory);
/**
* Destructor.
@@ -75,22 +74,31 @@ class StorageWindow : public Window, gcn::ActionListener,
void mouseClicked(gcn::MouseEvent &event);
/**
+ * Closes the Storage Window, as well as telling the server that the
+ * window has been closed.
+ */
+ void close();
+
+ /**
* Add the specified ammount of the specified item to storage
*/
- void addStore(Item* item, int amount);
+ static void addStore(Item* item, int amount);
/**
* Remove the specified ammount of the specified item from storage
*/
- void removeStore(Item* item, int amount);
+ static void removeStore(Item* item, int amount);
/**
- * Closes the Storage Window, as well as telling the server that the
- * window has been closed.
+ * Returns true if any instances exist.
*/
- void close();
+ static bool isActive() { return instances.size() > 0; }
private:
+ typedef std::list<StorageWindow*> WindowList;
+ static WindowList instances;
+
+ Inventory *mInventory;
ItemContainer *mItems;
int mSlots;
@@ -101,11 +109,7 @@ class StorageWindow : public Window, gcn::ActionListener,
ProgressBar *mSlotsBar;
- int mMaxSlots;
-
bool mItemDesc;
};
-extern StorageWindow *storageWindow;
-
#endif // STORAGEWINDOW_H
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 48f19b9a..763d0c43 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -449,9 +449,10 @@ void Viewport::mouseReleased(gcn::MouseEvent &event)
mLocalWalkTime = -1;
}
-void Viewport::showPopup(int x, int y, Item *item, bool isInventory)
+void Viewport::showPopup(Window *parent, int x, int y, Item *item,
+ bool isInventory)
{
- mPopupMenu->showPopup(x, y, item, isInventory);
+ mPopupMenu->showPopup(parent, x, y, item, isInventory);
}
void Viewport::closePopupMenu()
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 9a64ff78..5b92d950 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -30,13 +30,14 @@
#include <guichan/mouselistener.hpp>
class Being;
+class BeingPopup;
class FloorItem;
class Graphics;
class ImageSet;
class Item;
class Map;
class PopupMenu;
-class BeingPopup;
+class Window;
/** Delay between two mouse calls when dragging mouse and move the player */
const int walkingMouseDelay = 500;
@@ -107,7 +108,8 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
* Shows a popup for an item.
* TODO Find some way to get rid of Item here
*/
- void showPopup(int x, int y, Item *item, bool isInventory = true);
+ void showPopup(Window *parent, int x, int y, Item *item,
+ bool isInventory = true);
/**
* Closes the popup menu. Needed for when the player dies or switching
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index b2ddcf0c..66e053d8 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -193,7 +193,7 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
// Convert relative to the window coordinates to absolute screen
// coordinates.
- viewport->showPopup(viewport->getMouseX(), viewport->getMouseY(), item);
+ viewport->showPopup(NULL, viewport->getMouseX(), viewport->getMouseY(), item);
}
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index d7f64113..8ce03bba 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -77,7 +77,6 @@ LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(int id, int job):
Player(id, job, 0),
mEquipment(new Equipment),
- mInStorage(false),
mAttackRange(0),
mTargetTime(-1),
mLastTarget(-1),
@@ -101,8 +100,6 @@ LocalPlayer::LocalPlayer(int id, int job):
mInventory(new Inventory(Net::getInventoryHandler()
->getSize(Net::InventoryHandler::INVENTORY))),
mLocalWalkTime(-1),
- mStorage(new Inventory(Net::getInventoryHandler()
- ->getSize(Net::InventoryHandler::STORAGE))),
mMessageTime(0)
{
// Variable to keep the local player from doing certain actions before a map
@@ -124,7 +121,6 @@ LocalPlayer::LocalPlayer(int id, int job):
LocalPlayer::~LocalPlayer()
{
delete mInventory;
- delete mStorage;
config.removeListener("showownname", this);
@@ -1095,13 +1091,6 @@ void LocalPlayer::loadTargetCursor(const std::string &filename,
mTargetCursor[index][size] = currentCursor;
}
-void LocalPlayer::setInStorage(bool inStorage)
-{
- mInStorage = inStorage;
-
- storageWindow->setVisible(inStorage);
-}
-
void LocalPlayer::addMessageToQueue(const std::string &message,
Palette::ColorType color)
{
diff --git a/src/localplayer.h b/src/localplayer.h
index 6279d546..919b5540 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -133,11 +133,6 @@ class LocalPlayer : public Player
Inventory *getInventory() const { return mInventory; }
/**
- * Returns the player's storage
- */
- Inventory *getStorage() const { return mStorage; }
-
- /**
* Check the player has permission to invite users to specific guild
*/
bool checkInviteRights(const std::string &guildName);
@@ -264,12 +259,6 @@ class LocalPlayer : public Player
*/
void pickedUp(const ItemInfo &itemInfo, int amount);
- /**
- * Accessors for mInStorage
- */
- bool getInStorage() { return mInStorage; }
- void setInStorage(bool inStorage);
-
int getHp() const
{ return mHp; }
@@ -430,8 +419,6 @@ class LocalPlayer : public Player
void startWalking(unsigned char dir);
- bool mInStorage; /**< Whether storage is currently accessible */
-
int mAttackRange;
int mTargetTime; /** How long the being has been targeted **/
@@ -482,8 +469,6 @@ class LocalPlayer : public Player
int mLocalWalkTime; /**< Timestamp used to control keyboard walk
messages flooding */
- Inventory *mStorage;
-
/** Load the target cursors into memory */
void initTargetCursor();
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index decd4c2a..4e8aa725 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -107,6 +107,20 @@ InventoryHandler::InventoryHandler()
};
handledMessages = _messages;
inventoryHandler = this;
+
+ mStorage = 0;
+ mStorageWindow = 0;
+}
+
+InventoryHandler::~InventoryHandler()
+{
+ if (mStorageWindow)
+ {
+ mStorageWindow->close();
+ mStorageWindow = 0;
+ }
+
+ delete mStorage;
}
void InventoryHandler::handleMessage(Net::MessageIn &msg)
@@ -115,7 +129,6 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
int index, amount, itemId, equipType, arrow;
int identified, cards[4], itemType;
Inventory *inventory = player_node->getInventory();
- Inventory *storage = player_node->getStorage();
switch (msg.getId())
{
@@ -129,6 +142,10 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
inventory->clear();
}
+ else
+ {
+ mInventoryItems.clear();
+ }
msg.readInt16(); // length
number = (msg.getLength() - 4) / 18;
@@ -170,7 +187,8 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
}
else
{
- storage->setItem(index, itemId, amount, false);
+ mInventoryItems.push_back(InventoryItem(index, itemId,
+ amount, false));
}
}
break;
@@ -201,7 +219,8 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
cards[0], cards[1], cards[2], cards[3]);
}
- storage->setItem(index, itemId, amount, false);
+ mInventoryItems.push_back(InventoryItem(index, itemId, amount,
+ false));
}
break;
@@ -280,15 +299,27 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
* server. It always comes after the two SMSG_PLAYER_STORAGE_...
* packets that update storage contents.
*/
- player_node->setInStorage(true);
- msg.readInt16(); // Used count
- msg.readInt16(); // Storage capacity
+ {
+ msg.readInt16(); // Used count
+ int size = msg.readInt16(); // Max size
+
+ if (!mStorage)
+ mStorage = new Inventory(size);
+
+ InventoryItems::iterator it = mInventoryItems.begin();
+ InventoryItems::iterator it_end = mInventoryItems.end();
+ for (; it != it_end; it++)
+ mStorage->setItem((*it).slot, (*it).id, (*it).quantity,
+ (*it).equip);
+ mInventoryItems.clear();
+
+ if (!mStorageWindow)
+ mStorageWindow = new StorageWindow(mStorage);
+ }
break;
case SMSG_PLAYER_STORAGE_ADD:
- /*
- * Move an item into storage
- */
+ // Move an item into storage
index = msg.readInt16() - STORAGE_OFFSET;
amount = msg.readInt32();
itemId = msg.readInt16();
@@ -298,37 +329,38 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
- if (Item *item = storage->getItem(index))
+ if (Item *item = mStorage->getItem(index))
{
item->setId(itemId);
item->increaseQuantity(amount);
}
else
{
- storage->setItem(index, itemId, amount, false);
+ mStorage->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() - STORAGE_OFFSET;
amount = msg.readInt16();
- if (Item *item = storage->getItem(index))
+ if (Item *item = mStorage->getItem(index))
{
item->increaseQuantity(-amount);
if (item->getQuantity() == 0)
- storage->removeItemAt(index);
+ mStorage->removeItemAt(index);
}
break;
case SMSG_PLAYER_STORAGE_CLOSE:
- /*
- * Storage access has been closed
- */
- storage->clear();
- player_node->setInStorage(false);
+ // Storage access has been closed
+
+ // Storage window deletes itself
+ mStorageWindow = 0;
+
+ mStorage->clear();
+ delete mStorage;
+ mStorage = 0;
break;
case SMSG_PLAYER_EQUIPMENT:
@@ -482,9 +514,9 @@ size_t InventoryHandler::getSize(StorageType type) const
case INVENTORY:
return 100;
case STORAGE:
- return 300;
+ return 0;
case GUILD_STORAGE:
- return 1000;
+ return 0;
default:
return 0;
}
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index a2d0d388..2699e584 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -26,11 +26,15 @@
#include "inventory.h"
#include "localplayer.h"
+#include "gui/storagewindow.h"
+
#include "net/inventoryhandler.h"
#include "net/net.h"
#include "net/ea/messagehandler.h"
+#include <list>
+
namespace EAthena {
class EquipBackend : public Equipment::Backend {
@@ -89,11 +93,35 @@ class EquipBackend : public Equipment::Backend {
int mEquipment[EQUIPMENT_SIZE];
};
+/**
+ * Used to cache storage data until we get size data for it.
+ */
+class InventoryItem
+{
+ public:
+ int slot;
+ int id;
+ int quantity;
+ bool equip;
+
+ InventoryItem(int slot, int id, int quantity, bool equip)
+ {
+ this->slot = slot;
+ this->id = id;
+ this->quantity = quantity;
+ this->equip = equip;
+ }
+};
+
+typedef std::list<InventoryItem> InventoryItems;
+
class InventoryHandler : public MessageHandler, public Net::InventoryHandler
{
public:
InventoryHandler();
+ ~InventoryHandler();
+
void handleMessage(Net::MessageIn &msg);
void equipItem(const Item *item);
@@ -121,6 +149,9 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
private:
EquipBackend mEquips;
+ InventoryItems mInventoryItems;
+ Inventory *mStorage;
+ StorageWindow *mStorageWindow;
};
} // namespace EAthena
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index 46919488..89e55f92 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -86,8 +86,6 @@ namespace {
NpcDialog::closeAll();
SellDialog::closeAll();
- if (storageWindow->isVisible())
- storageWindow->close();
viewport->closePopupMenu();
}
} deathListener;
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index e3d0064d..9d0a5bc8 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -61,6 +61,7 @@ class InventoryHandler
virtual void moveItem(StorageType source, int slot, int amount,
StorageType destination) = 0;
+ // TODO: fix/remove me
virtual size_t getSize(StorageType type) const = 0;
virtual ~InventoryHandler() {}