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