summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventorywindow.cpp146
-rw-r--r--src/gui/inventorywindow.h35
-rw-r--r--src/gui/itemamount.cpp9
-rw-r--r--src/gui/popupmenu.cpp3
-rw-r--r--src/gui/storagewindow.cpp216
-rw-r--r--src/gui/storagewindow.h113
6 files changed, 133 insertions, 389 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 6291d524..18705ada 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -53,10 +53,12 @@
#include <string>
-InventoryWindow::InventoryWindow():
- Window(_("Inventory")),
- mSplit(false),
- mItemDesc(false)
+InventoryWindow::WindowList InventoryWindow::instances;
+
+InventoryWindow::InventoryWindow(Inventory *inventory, bool isMainInventory):
+ Window(isMainInventory ? _("Inventory") : _("Storage")),
+ mInventory(inventory),
+ mSplit(false)
{
setWindowName("Inventory");
setupWindow->registerWindowForReset(this);
@@ -69,54 +71,79 @@ InventoryWindow::InventoryWindow():
setMinHeight(179);
addKeyListener(this);
- std::string longestUseString = getFont()->getWidth(_("Equip")) >
- getFont()->getWidth(_("Use")) ?
- _("Equip") : _("Use");
-
- if (getFont()->getWidth(longestUseString) <
- getFont()->getWidth(_("Unequip")))
- {
- longestUseString = _("Unequip");
- }
-
- mUseButton = new Button(longestUseString, "use", this);
- mDropButton = new Button(_("Drop..."), "drop", this);
- mSplitButton = new Button(_("Split"), "split", this);
- mOutfitButton = new Button(_("Outfits"), "outfit", this);
- mItems = new ItemContainer(player_node->getInventory());
+ mItems = new ItemContainer(mInventory);
mItems->addSelectionListener(this);
gcn::ScrollArea *invenScroll = new ScrollArea(mItems);
invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mSlotsLabel = new Label(_("Slots:"));
- mWeightLabel = new Label(_("Weight:"));
-
mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS);
- mWeightBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_WEIGHT);
-
- place(0, 0, mWeightLabel).setPadding(3);
- place(1, 0, mWeightBar, 3);
- place(4, 0, mSlotsLabel).setPadding(3);
- place(5, 0, mSlotsBar, 2);
- place(0, 1, invenScroll, 7).setPadding(3);
- place(0, 2, mUseButton);
- place(1, 2, mDropButton);
- place(2, 2, mSplitButton);
- place(6, 2, mOutfitButton);
+
+ if (isMainInventory)
+ {
+ std::string equip = _("Equip");
+ std::string use = _("Use");
+ std::string unequip = _("Unequip");
+
+ std::string longestUseString = getFont()->getWidth(equip) >
+ getFont()->getWidth(use) ? equip : use;
+
+ if (getFont()->getWidth(longestUseString) <
+ getFont()->getWidth(unequip))
+ {
+ longestUseString = unequip;
+ }
+
+ mUseButton = new Button(longestUseString, "use", this);
+ mDropButton = new Button(_("Drop..."), "drop", this);
+ mSplitButton = new Button(_("Split"), "split", this);
+ mOutfitButton = new Button(_("Outfits"), "outfit", this);
+
+ mWeightLabel = new Label(_("Weight:"));
+ mWeightBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_WEIGHT);
+
+ place(0, 0, mWeightLabel).setPadding(3);
+ place(1, 0, mWeightBar, 3);
+ place(4, 0, mSlotsLabel).setPadding(3);
+ place(5, 0, mSlotsBar, 2);
+ place(0, 1, invenScroll, 7).setPadding(3);
+ place(0, 2, mUseButton);
+ place(1, 2, mDropButton);
+ place(2, 2, mSplitButton);
+ place(6, 2, mOutfitButton);
+
+ updateWeight();
+ }
+ else
+ {
+ mStoreButton = new Button(_("Store"), "store", this);
+ mRetrieveButton = new Button(_("Retrieve"), "retrieve", this);
+
+ place(0, 0, mSlotsLabel).setPadding(3);
+ place(1, 0, mSlotsBar, 3);
+ place(0, 1, invenScroll, 4, 4);
+ place(0, 5, mStoreButton);
+ place(1, 5, mRetrieveButton);
+ }
Layout &layout = getLayout();
layout.setRowHeight(1, Layout::AUTO_SET);
- player_node->getInventory()->addInventoyListener(this);
+ mInventory->addInventoyListener(this);
+
+ instances.push_back(this);
loadWindowState();
- updateWeight();
- slotsChanged(player_node->getInventory());
+ slotsChanged(mInventory);
+
+ if (!isMainInventory)
+ setVisible(true);
}
InventoryWindow::~InventoryWindow()
{
+ mInventory->removeInventoyListener(this);
}
void InventoryWindow::action(const gcn::ActionEvent &event)
@@ -157,6 +184,27 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
(item->getQuantity() - 1));
}
+ else if (event.getId() == "store")
+ {
+ if (!inventoryWindow->isVisible()) return;
+
+ Item *item = inventoryWindow->getSelectedItem();
+
+ if (!item)
+ return;
+
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item);
+ }
+ else if (event.getId() == "retrieve")
+ {
+ Item *item = mItems->getSelectedItem();
+
+ if (!item)
+ return;
+
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, this,
+ item);
+ }
}
Item *InventoryWindow::getSelectedItem() const
@@ -185,15 +233,16 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (StorageWindow::isActive() &&
- keyboard.isKeyActive(keyboard.KEY_EMOTE))
+ if (isStorageActive() && keyboard.isKeyActive(keyboard.KEY_EMOTE))
{
Item *item = mItems->getSelectedItem();
if(!item)
return;
- StorageWindow::addStore(item, item->getQuantity());
+ Net::getInventoryHandler()->moveItem(Net::InventoryHandler::INVENTORY,
+ item->getInvIndex(), item->getQuantity(),
+ Net::InventoryHandler::STORAGE);
}
}
}
@@ -271,6 +320,16 @@ void InventoryWindow::setSplitAllowed(bool allowed)
mSplitButton->setVisible(allowed);
}
+void InventoryWindow::close()
+{
+ if (this == inventoryWindow)
+ return;
+
+ Net::getInventoryHandler()->closeStorage(Net::InventoryHandler::STORAGE);
+
+ scheduleDelete();
+}
+
void InventoryWindow::updateWeight()
{
int total = player_node->getTotalWeight();
@@ -284,10 +343,13 @@ void InventoryWindow::updateWeight()
void InventoryWindow::slotsChanged(Inventory* inventory)
{
- const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
- const int maxSlots = player_node->getInventory()->getSize();
+ if (inventory == mInventory)
+ {
+ const int usedSlots = mInventory->getNumberOfSlotsUsed();
+ const int maxSlots = mInventory->getSize();
- mSlotsBar->setProgress((float) usedSlots / maxSlots);
+ mSlotsBar->setProgress((float) usedSlots / maxSlots);
- mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
+ mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
+ }
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index cfea130f..406c24bf 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -24,7 +24,6 @@
#include "inventory.h"
-#include "gui/storagewindow.h"
#include "gui/widgets/window.h"
#include "net/inventoryhandler.h"
@@ -54,7 +53,7 @@ class InventoryWindow : public Window,
/**
* Constructor.
*/
- InventoryWindow();
+ InventoryWindow(Inventory *inventory, bool isMainInventory = false);
/**
* Destructor.
@@ -95,6 +94,12 @@ class InventoryWindow : public Window,
* Sets whether the split button should be shown.
*/
void setSplitAllowed(bool allowed);
+
+ /**
+ * Closes the Storage Window, as well as telling the server that the
+ * window has been closed.
+ */
+ void close();
/**
* Updates the weight bar.
@@ -103,24 +108,28 @@ class InventoryWindow : public Window,
void slotsChanged(Inventory* inventory);
+ /**
+ * Returns true if any instances exist.
+ */
+ static bool isStorageActive() { return instances.size() > 1; }
+
private:
+ typedef std::list<InventoryWindow*> WindowList;
+ static WindowList instances;
+
+ Inventory *mInventory;
ItemContainer *mItems;
- std::string mWeight;
- std::string mSlots;
+ std::string mWeight, mSlots;
+
+ gcn::Button *mUseButton, *mDropButton, *mSplitButton, *mOutfitButton,
+ *mStoreButton, *mRetrieveButton;
- gcn::Button *mUseButton;
- gcn::Button *mDropButton;
- gcn::Button *mSplitButton;
- gcn::Button *mOutfitButton;
- gcn::Label *mWeightLabel;
- gcn::Label *mSlotsLabel;
+ gcn::Label *mWeightLabel, *mSlotsLabel;
- ProgressBar *mWeightBar;
- ProgressBar *mSlotsBar;
+ ProgressBar *mWeightBar, *mSlotsBar;
bool mSplit;
- bool mItemDesc;
};
extern InventoryWindow *inventoryWindow;
diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp
index 1dc5425f..f28bbed7 100644
--- a/src/gui/itemamount.cpp
+++ b/src/gui/itemamount.cpp
@@ -24,7 +24,6 @@
#include "item.h"
#include "keyboardconfig.h"
-#include "gui/storagewindow.h"
#include "gui/trade.h"
#include "gui/itempopup.h"
#include "gui/viewport.h"
@@ -54,10 +53,14 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage)
Net::getInventoryHandler()->splitItem(item, amount);
break;
case StoreAdd:
- StorageWindow::addStore(item, amount);
+ Net::getInventoryHandler()->moveItem(Net::InventoryHandler::INVENTORY,
+ item->getInvIndex(), amount,
+ Net::InventoryHandler::STORAGE);
break;
case StoreRemove:
- StorageWindow::removeStore(item, amount);
+ Net::getInventoryHandler()->moveItem(Net::InventoryHandler::STORAGE,
+ item->getInvIndex(), amount,
+ Net::InventoryHandler::INVENTORY);
break;
default:
break;
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 9052e9d2..8404fad1 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -33,7 +33,6 @@
#include "gui/chat.h"
#include "gui/inventorywindow.h"
-#include "gui/storagewindow.h"
#include "gui/itemamount.h"
#include "gui/widgets/browserbox.h"
@@ -386,7 +385,7 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
mBrowserBox->addRow(strprintf("@@split|%s@@", _("Split")));
}
- if (StorageWindow::isActive())
+ if (InventoryWindow::isStorageActive())
{
mBrowserBox->addRow(strprintf("@@store|%s@@", _("Store")));
}
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
deleted file mode 100644
index c07653b1..00000000
--- a/src/gui/storagewindow.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * The Mana Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- *
- * This file is part of The Mana Client.
- *
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/storagewindow.h"
-
-#include "inventory.h"
-#include "item.h"
-#include "localplayer.h"
-#include "units.h"
-#include "keyboardconfig.h"
-
-#include "gui/inventorywindow.h"
-#include "gui/itemamount.h"
-#include "gui/setup.h"
-#include "gui/theme.h"
-#include "gui/viewport.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/itemcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/progressbar.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "net/inventoryhandler.h"
-#include "net/net.h"
-
-#include "resources/iteminfo.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include <guichan/font.hpp>
-#include <guichan/mouseinput.hpp>
-
-#include <string>
-
-StorageWindow::WindowList StorageWindow::instances;
-
-StorageWindow::StorageWindow(Inventory *inventory):
- Window(_("Storage")),
- mInventory(inventory),
- mItemDesc(false)
-{
- setWindowName("Storage");
- setResizable(true);
- setCloseButton(true);
- setupWindow->registerWindowForReset(this);
-
- // If you adjust these defaults, don't forget to adjust the trade window's.
- setDefaultSize(375, 300, ImageRect::CENTER);
-
- mStoreButton = new Button(_("Store"), "store", this);
- mRetrieveButton = new Button(_("Retrieve"), "retrieve", this);
-
- mCloseButton = new Button(_("Close"), "close", this);
-
- mItems = new ItemContainer(mInventory, true);
- mItems->addSelectionListener(this);
-
- gcn::ScrollArea *invenScroll = new ScrollArea(mItems);
- invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
-
- mUsedSlots = mInventory->getNumberOfSlotsUsed();
-
- mSlotsLabel = new Label(_("Slots:"));
-
- mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS);
- mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mInventory->getSize()));
- mSlotsBar->setProgress((float) mUsedSlots / mInventory->getSize());
-
- setMinHeight(130);
- setMinWidth(200);
-
- place(0, 0, mSlotsLabel).setPadding(3);
- place(1, 0, mSlotsBar, 3);
- place(0, 1, invenScroll, 4, 4);
- place(0, 5, mStoreButton);
- place(1, 5, mRetrieveButton);
- place(3, 5, mCloseButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, mStoreButton->getHeight());
-
- loadWindowState();
-
- instances.push_back(this);
- setVisible(true);
-
- mInventory->addInventoyListener(this);
- slotsChanged(mInventory);
-}
-
-StorageWindow::~StorageWindow()
-{
- instances.remove(this);
-}
-
-void StorageWindow::action(const gcn::ActionEvent &event)
-{
- if (event.getId() == "store")
- {
- if (!inventoryWindow->isVisible()) return;
-
- Item *item = inventoryWindow->getSelectedItem();
-
- if (!item)
- return;
-
- ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item);
- }
- else if (event.getId() == "retrieve")
- {
- Item *item = mItems->getSelectedItem();
-
- if (!item)
- return;
-
- ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, this,
- item);
- }
- else if (event.getId() == "close")
- {
- close();
- }
-}
-
-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(this, mx, my, item, false);
- }
- if (event.getButton() == gcn::MouseEvent::LEFT)
- {
- if (keyboard.isKeyActive(keyboard.KEY_EMOTE))
- {
- Item *item = mItems->getSelectedItem();
-
- if(!item)
- return;
-
- removeStore(item, item->getQuantity());
- }
- }
-}
-
-Item *StorageWindow::getSelectedItem() const
-{
- return mItems->getSelectedItem();
-}
-
-void StorageWindow::slotsChanged(Inventory* inventory)
-{
- const int usedSlots = mInventory->getNumberOfSlotsUsed();
-
- mSlotsBar->setProgress((float) usedSlots / mInventory->getSize());
-
- mSlotsBar->setText(strprintf("%d/%d", usedSlots, mInventory->getSize()));
-}
-
-void StorageWindow::addStore(Item *item, int amount)
-{
- Net::getInventoryHandler()->moveItem(Net::InventoryHandler::INVENTORY,
- item->getInvIndex(), amount,
- Net::InventoryHandler::STORAGE);
-}
-
-void StorageWindow::removeStore(Item *item, int amount)
-{
- Net::getInventoryHandler()->moveItem(Net::InventoryHandler::STORAGE,
- item->getInvIndex(), amount,
- Net::InventoryHandler::INVENTORY);
-}
-
-void StorageWindow::close()
-{
- Net::getInventoryHandler()->closeStorage(Net::InventoryHandler::STORAGE);
-
- scheduleDelete();
-}
diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h
deleted file mode 100644
index 8e09768d..00000000
--- a/src/gui/storagewindow.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The Mana Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- *
- * This file is part of The Mana Client.
- *
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef STORAGEWINDOW_H
-#define STORAGEWINDOW_H
-
-#include "inventory.h"
-
-#include "gui/widgets/window.h"
-
-#include "net/inventoryhandler.h"
-#include "net/net.h"
-
-#include <guichan/actionlistener.hpp>
-#include <guichan/selectionlistener.hpp>
-
-class Item;
-class ItemContainer;
-class ProgressBar;
-class TextBox;
-
-/**
- * Storage dialog.
- *
- * \ingroup Interface
- */
-class StorageWindow : public Window, gcn::ActionListener,
- gcn::SelectionListener,
- public InventoryListener
-{
- public:
- /**
- * Constructor.
- */
- StorageWindow(Inventory *inventory);
-
- /**
- * Destructor.
- */
- ~StorageWindow();
-
- /**
- * 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);
-
- /**
- * Closes the Storage Window, as well as telling the server that the
- * window has been closed.
- */
- void close();
-
- void slotsChanged(Inventory* inventory);
-
- /**
- * Add the specified ammount of the specified item to storage
- */
- static void addStore(Item* item, int amount);
-
- /**
- * Remove the specified ammount of the specified item from storage
- */
- static void removeStore(Item* item, int amount);
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() { return instances.size() > 0; }
-
- private:
- typedef std::list<StorageWindow*> WindowList;
- static WindowList instances;
-
- Inventory *mInventory;
- ItemContainer *mItems;
-
- int mSlots;
- int mUsedSlots;
- gcn::Button *mStoreButton, *mRetrieveButton, *mCloseButton;
-
- gcn::Label *mSlotsLabel;
-
- ProgressBar *mSlotsBar;
-
- bool mItemDesc;
-};
-
-#endif // STORAGEWINDOW_H