summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-09-15 21:17:23 +0300
committerAndrei Karas <akaras@inbox.ru>2016-09-15 21:17:23 +0300
commitec7d24a8f2d7d528bc200a62f7242e6817b9e1ed (patch)
tree78c1fb26ed2e198677a0ff75e07eec4765cee3fa /src
parent413637151f0eb471ff6b28feddc028c374f96401 (diff)
downloadmv-ec7d24a8f2d7d528bc200a62f7242e6817b9e1ed.tar.gz
mv-ec7d24a8f2d7d528bc200a62f7242e6817b9e1ed.tar.bz2
mv-ec7d24a8f2d7d528bc200a62f7242e6817b9e1ed.tar.xz
mv-ec7d24a8f2d7d528bc200a62f7242e6817b9e1ed.zip
Add support for drag and drop into shops.
Diffstat (limited to 'src')
-rw-r--r--src/enums/dragdropsource.h4
-rw-r--r--src/gui/widgets/shoplistbox.cpp49
2 files changed, 52 insertions, 1 deletions
diff --git a/src/enums/dragdropsource.h b/src/enums/dragdropsource.h
index e96de703b..619a66ed4 100644
--- a/src/enums/dragdropsource.h
+++ b/src/enums/dragdropsource.h
@@ -39,7 +39,9 @@ enumStart(DragDropSource)
Equipment,
Cart,
Mail,
- Craft
+ Craft,
+ ShopBuy,
+ ShopSell
}
enumEnd(DragDropSource);
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index 3ce06ba0d..ce8ce78e1 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -22,6 +22,7 @@
#include "gui/widgets/shoplistbox.h"
+#include "dragdrop.h"
#include "settings.h"
#include "being/playerinfo.h"
@@ -35,10 +36,16 @@
#include "gui/models/shopitems.h"
+#include "gui/windows/itemamountwindow.h"
+
+#include "net/serverfeatures.h"
+
#include "render/graphics.h"
#include "resources/image/image.h"
+#include "resources/inventory/inventory.h"
+
#include "resources/item/shopitem.h"
#include "debug.h"
@@ -239,6 +246,48 @@ void ShopListBox::mouseMoved(MouseEvent &event)
void ShopListBox::mouseReleased(MouseEvent& event)
{
ListBox::mouseReleased(event);
+ if (event.getType() == MouseEventType::RELEASED2)
+ {
+ if (dragDrop.isEmpty())
+ return;
+ const DragDropSourceT src = dragDrop.getSource();
+ if (mType != ShopListBoxType::SellShop &&
+ mType != ShopListBoxType::BuyShop)
+ {
+ return;
+ }
+ if (mType == ShopListBoxType::SellShop &&
+ serverFeatures->haveCart() &&
+ src != DragDropSource::Cart)
+ {
+ return;
+ }
+ Inventory *inventory;
+ if (src == DragDropSource::Inventory)
+ inventory = PlayerInfo::getInventory();
+ else if (src == DragDropSource::Cart)
+ inventory = PlayerInfo::getCartInventory();
+ else
+ return;
+ if (!inventory)
+ return;
+ Item *const item = inventory->getItem(dragDrop.getTag());
+ if (mType == ShopListBoxType::BuyShop)
+ {
+ ItemAmountWindow::showWindow(
+ ItemAmountWindowUsage::ShopBuyAdd,
+ nullptr,
+ item);
+ }
+ else
+ {
+ ItemAmountWindow::showWindow(
+ ItemAmountWindowUsage::ShopSellAdd,
+ nullptr,
+ item);
+ }
+ }
+
if (event.getButton() == MouseButton::RIGHT)
{
setSelected(std::max(0, getSelectionByMouse(event.getY())));