summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-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
10 files changed, 60 insertions, 37 deletions
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);
}
}