summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-03 22:02:16 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-03 22:02:16 +0300
commit66fa2d9c5cdb82808ed24fdd9f681679a7b99986 (patch)
tree34154dbb0aa5c8f571e092500d6a55661c5a545a
parentcb573ac24373a908ff549c35c3a80dd31b2fdea5 (diff)
downloadplus-66fa2d9c5cdb82808ed24fdd9f681679a7b99986.tar.gz
plus-66fa2d9c5cdb82808ed24fdd9f681679a7b99986.tar.bz2
plus-66fa2d9c5cdb82808ed24fdd9f681679a7b99986.tar.xz
plus-66fa2d9c5cdb82808ed24fdd9f681679a7b99986.zip
Add drag and drop between trade window and other windows.
-rw-r--r--src/gui/widgets/itemcontainer.cpp55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 11b9401ff..eccd21735 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -40,6 +40,7 @@
#include "net/net.h"
#include "net/inventoryhandler.h"
+#include "net/tradehandler.h"
#include "utils/gettext.h"
@@ -400,8 +401,21 @@ 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;
+ DragDropSource src = DRAGDROP_SOURCE_EMPTY;
+ switch (mInventory->getType())
+ {
+ case Inventory::INVENTORY:
+ src = DRAGDROP_SOURCE_INVENTORY;
+ break;
+ case Inventory::STORAGE:
+ src = DRAGDROP_SOURCE_STORAGE;
+ break;
+ case Inventory::TRADE:
+ src = DRAGDROP_SOURCE_TRADE;
+ break;
+ default:
+ break;
+ }
if (mSelectedIndex == index && mClicks != 2)
{
dragDrop.dragItem(item, src, index);
@@ -478,8 +492,21 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
else
{
const DragDropSource src = dragDrop.getSource();
- const DragDropSource dst = mInventory->isMainInventory()
- ? DRAGDROP_SOURCE_INVENTORY : DRAGDROP_SOURCE_STORAGE;
+ DragDropSource dst = DRAGDROP_SOURCE_EMPTY;
+ switch (mInventory->getType())
+ {
+ case Inventory::INVENTORY:
+ dst = DRAGDROP_SOURCE_INVENTORY;
+ break;
+ case Inventory::STORAGE:
+ dst = DRAGDROP_SOURCE_STORAGE;
+ break;
+ case Inventory::TRADE:
+ dst = DRAGDROP_SOURCE_TRADE;
+ break;
+ default:
+ break;
+ }
int srcContainer = -1;
int dstContainer = -1;
Inventory *inventory = nullptr;
@@ -497,13 +524,27 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
dstContainer = Inventory::INVENTORY;
inventory = PlayerInfo::getStorageInventory();
}
- if (srcContainer != -1 && inventory)
+ if (src == DRAGDROP_SOURCE_INVENTORY
+ && dst == DRAGDROP_SOURCE_TRADE)
+ {
+ inventory = PlayerInfo::getInventory();
+ }
+
+ if (inventory)
{
const Item *const item = inventory->getItem(dragDrop.getTag());
if (item)
{
- Net::getInventoryHandler()->moveItem2(srcContainer,
- item->getInvIndex(), item->getQuantity(), dstContainer);
+ if (srcContainer != -1)
+ { // inventory <--> storage
+ Net::getInventoryHandler()->moveItem2(srcContainer,
+ item->getInvIndex(), item->getQuantity(),
+ dstContainer);
+ }
+ else
+ { // inventory --> trade
+ Net::getTradeHandler()->addItem(item, item->getQuantity());
+ }
}
}
}