summaryrefslogtreecommitdiff
path: root/src/gui/widgets/itemcontainer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-03 21:20:31 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-03 21:20:31 +0300
commitcb573ac24373a908ff549c35c3a80dd31b2fdea5 (patch)
treee63d24c33a760fc6d408a09900fc1e02dc603c00 /src/gui/widgets/itemcontainer.cpp
parenta1bd0179b28fa93c771bc5602f64746878f0ffad (diff)
downloadmv-cb573ac24373a908ff549c35c3a80dd31b2fdea5.tar.gz
mv-cb573ac24373a908ff549c35c3a80dd31b2fdea5.tar.bz2
mv-cb573ac24373a908ff549c35c3a80dd31b2fdea5.tar.xz
mv-cb573ac24373a908ff549c35c3a80dd31b2fdea5.zip
add drag and drop support between inventory and storage.
Diffstat (limited to 'src/gui/widgets/itemcontainer.cpp')
-rw-r--r--src/gui/widgets/itemcontainer.cpp69
1 files changed, 51 insertions, 18 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 972c066ac..11b9401ff 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -23,10 +23,11 @@
#include "gui/widgets/itemcontainer.h"
#include "dragdrop.h"
+#include "dropshortcut.h"
#include "inventory.h"
#include "item.h"
#include "itemshortcut.h"
-#include "dropshortcut.h"
+#include "playerinfo.h"
#include "gui/chatwindow.h"
#include "gui/gui.h"
@@ -172,8 +173,6 @@ ItemContainer::ItemContainer(const Widget2 *const widget,
mForceQuantity(forceQuantity),
mSwapItems(false),
mDescItems(false),
- mDragPosX(0),
- mDragPosY(0),
mTag(0),
mSortType(0),
mName(),
@@ -401,9 +400,11 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (item && mDescItems && chatWindow)
chatWindow->addItemText(item->getInfo().getName());
+ const DragDropSource src = mInventory->isMainInventory()
+ ? DRAGDROP_SOURCE_INVENTORY : DRAGDROP_SOURCE_STORAGE;
if (mSelectedIndex == index && mClicks != 2)
{
- dragDrop.dragItem(item, DRAGDROP_SOURCE_INVENTORY);
+ dragDrop.dragItem(item, src, index);
dragDrop.select(item);
mSelectionStatus = SEL_DESELECTING;
}
@@ -411,7 +412,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
{
if (index >= 0)
{
- dragDrop.dragItem(item, DRAGDROP_SOURCE_INVENTORY);
+ dragDrop.dragItem(item, src, index);
dragDrop.select(item);
setSelectedIndex(index);
mSelectionStatus = SEL_SELECTING;
@@ -440,11 +441,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
void ItemContainer::mouseDragged(gcn::MouseEvent &event)
{
if (mSelectionStatus != SEL_NONE)
- {
mSelectionStatus = SEL_DRAGGING;
- mDragPosX = event.getX();
- mDragPosY = event.getY();
- }
}
void ItemContainer::mouseReleased(gcn::MouseEvent &event)
@@ -456,25 +453,61 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
{
case SEL_SELECTING:
mSelectionStatus = SEL_SELECTED;
- return;
+ break;
case SEL_DESELECTING:
selectNone();
- return;
+ break;
case SEL_DRAGGING:
mSelectionStatus = SEL_SELECTED;
break;
case SEL_NONE:
case SEL_SELECTED:
default:
- return;
+ break;
};
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
- if (index == mSelectedIndex || mSelectedIndex == -1)
- return;
- Net::getInventoryHandler()->moveItem(mSelectedIndex, index);
+ if (dragDrop.isEmpty())
+ {
+ const int index = getSlotIndex(event.getX(), event.getY());
+ if (index == Inventory::NO_SLOT_INDEX)
+ return;
+ if (index == mSelectedIndex || mSelectedIndex == -1)
+ return;
+ Net::getInventoryHandler()->moveItem(mSelectedIndex, index);
+ }
+ else
+ {
+ const DragDropSource src = dragDrop.getSource();
+ const DragDropSource dst = mInventory->isMainInventory()
+ ? DRAGDROP_SOURCE_INVENTORY : DRAGDROP_SOURCE_STORAGE;
+ int srcContainer = -1;
+ int dstContainer = -1;
+ Inventory *inventory = nullptr;
+ if (src == DRAGDROP_SOURCE_INVENTORY
+ && dst == DRAGDROP_SOURCE_STORAGE)
+ {
+ srcContainer = Inventory::INVENTORY;
+ dstContainer = Inventory::STORAGE;
+ inventory = PlayerInfo::getInventory();
+ }
+ else if (src == DRAGDROP_SOURCE_STORAGE
+ && dst == DRAGDROP_SOURCE_INVENTORY)
+ {
+ srcContainer = Inventory::STORAGE;
+ dstContainer = Inventory::INVENTORY;
+ inventory = PlayerInfo::getStorageInventory();
+ }
+ if (srcContainer != -1 && inventory)
+ {
+ const Item *const item = inventory->getItem(dragDrop.getTag());
+ if (item)
+ {
+ Net::getInventoryHandler()->moveItem2(srcContainer,
+ item->getInvIndex(), item->getQuantity(), dstContainer);
+ }
+ }
+ }
+
selectNone();
}