From ec7d24a8f2d7d528bc200a62f7242e6817b9e1ed Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 15 Sep 2016 21:17:23 +0300 Subject: Add support for drag and drop into shops. --- src/enums/dragdropsource.h | 4 +++- src/gui/widgets/shoplistbox.cpp | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) 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()))); -- cgit v1.2.3-60-g2f50