diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 29 | ||||
-rw-r--r-- | src/gui/windows/itemamountwindow.cpp | 60 | ||||
-rw-r--r-- | src/gui/windows/itemamountwindow.h | 10 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 21 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.h | 5 |
5 files changed, 107 insertions, 18 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index af614bcb1..f274dcd11 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -41,8 +41,15 @@ #include "gui/windows/inventorywindow.h" #include "gui/windows/shopwindow.h" #include "gui/windows/shortcutwindow.h" +#ifdef EATHENA_SUPPORT +#include "gui/windows/itemamountwindow.h" +#include "gui/windows/npcdialog.h" +#endif #include "net/inventoryhandler.h" +#ifdef EATHENA_SUPPORT +#include "net/npchandler.h" +#endif #include "net/tradehandler.h" #include "utils/delete2.h" @@ -862,12 +869,24 @@ void ItemContainer::mouseReleased(MouseEvent &event) if (inventory) { Item *const item = inventory->getItem(dragDrop.getTag()); - if (mInventory->addVirtualItem( - item, - getSlotByXY(event.getX(), event.getY()), - 1)) + const int slot = getSlotByXY(event.getX(), event.getY()); + if (item->getQuantity() > 1) { - inventory->virtualRemove(item, 1); + ItemAmountWindow::showWindow(ItemAmountWindow::CraftAdd, + npcHandler->getCurrentNpcDialog(), + item, + 0, + slot); + } + else + { + if (mInventory->addVirtualItem( + item, + slot, + 1)) + { + inventory->virtualRemove(item, 1); + } } } return; diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp index 35d7a629f..103fb619b 100644 --- a/src/gui/windows/itemamountwindow.cpp +++ b/src/gui/windows/itemamountwindow.cpp @@ -26,7 +26,6 @@ #include "input/keyboardconfig.h" -#include "net/inventoryhandler.h" #include "gui/viewport.h" #include "gui/models/itemsmodel.h" @@ -34,6 +33,9 @@ #include "gui/popups/itempopup.h" #include "gui/windows/maileditwindow.h" +#ifdef EATHENA_SUPPORT +#include "gui/windows/npcdialog.h" +#endif #include "gui/windows/shopwindow.h" #include "gui/windows/tradewindow.h" @@ -46,6 +48,11 @@ #include "gui/widgets/label.h" #include "gui/widgets/slider.h" +#include "net/inventoryhandler.h" +#ifdef EATHENA_SUPPORT +#include "net/npchandler.h" +#endif + #include "resources/item/item.h" #include "utils/gettext.h" @@ -54,7 +61,7 @@ #include "debug.h" -void ItemAmountWindow::finish(const Item *const item, +void ItemAmountWindow::finish(Item *const item, const int amount, const int price, const Usage usage) @@ -102,6 +109,12 @@ void ItemAmountWindow::finish(const Item *const item, if (mailEditWindow) mailEditWindow->addItem(item, amount); break; + case CraftAdd: + { + NpcDialog *const dialog = npcHandler->getCurrentNpcDialog(); + if (dialog) + dialog->addCraftItem(item, amount, price); // price as slot + } #endif default: break; @@ -336,13 +349,27 @@ void ItemAmountWindow::action(const ActionEvent &event) { if (mItemPriceTextField) { - finish(mItem, mItemAmountTextField->getValue(), - mItemPriceTextField->getValue(), mUsage); + finish(mItem, + mItemAmountTextField->getValue(), + mItemPriceTextField->getValue(), + mUsage); } else { - finish(mItem, mItemAmountTextField->getValue(), - 0, mUsage); + if (mUsage == CraftAdd) + { + finish(mItem, + mItemAmountTextField->getValue(), + mPrice, + mUsage); + } + else + { + finish(mItem, + mItemAmountTextField->getValue(), + 0, + mUsage); + } } close(); return; @@ -431,8 +458,11 @@ void ItemAmountWindow::keyReleased(KeyEvent &event A_UNUSED) mItemAmountSlide->setValue(mItemAmountTextField->getValue()); } -void ItemAmountWindow::showWindow(const Usage usage, Window *const parent, - Item *const item, int maxRange) +void ItemAmountWindow::showWindow(const Usage usage, + Window *const parent, + Item *const item, + int maxRange, + int tag) { if (!item) return; @@ -441,7 +471,17 @@ void ItemAmountWindow::showWindow(const Usage usage, Window *const parent, maxRange = item->getQuantity(); if (usage != ShopBuyAdd && usage != ShopSellAdd && maxRange <= 1) - finish(item, maxRange, 0, usage); + { + if (usage == CraftAdd) + finish(item, maxRange, tag, usage); + else + finish(item, maxRange, 0, usage); + } else - CREATEWIDGET(ItemAmountWindow, usage, parent, item, maxRange); + { + ItemAmountWindow *const window = CREATEWIDGETR(ItemAmountWindow, + usage, parent, item, maxRange); + if (usage == CraftAdd) + window->mPrice = tag; + } } diff --git a/src/gui/windows/itemamountwindow.h b/src/gui/windows/itemamountwindow.h index 30b205d95..a67c50174 100644 --- a/src/gui/windows/itemamountwindow.h +++ b/src/gui/windows/itemamountwindow.h @@ -58,6 +58,7 @@ class ItemAmountWindow final : public Window, ShopBuyAdd, ShopSellAdd, #ifdef EATHENA_SUPPORT + CraftAdd, MailAdd #endif }; @@ -91,13 +92,16 @@ class ItemAmountWindow final : public Window, /** * Creates the dialog, or bypass it if there aren't enough items. */ - static void showWindow(const Usage usage, Window *const parent, - Item *const item, int maxRange = 0); + static void showWindow(const Usage usage, + Window *const parent, + Item *const item, + int maxRange = 0, + const int tag = 0); ~ItemAmountWindow(); private: - static void finish(const Item *const item, + static void finish(Item *const item, const int amount, const int price, const Usage usage); diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 66cdc4bb3..2fcb53468 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -1370,3 +1370,24 @@ std::string NpcDialog::complexItemToStr(const ComplexItem *const item) } return str; } + +void NpcDialog::addCraftItem(Item *const item, + const int amount, + const int slot) +{ + if (mInputState != NPC_INPUT_ITEM_CRAFT) + return; + + Inventory *const inventory = PlayerInfo::getInventory(); + + if (!inventory) + return; + + if (mComplexInventory->addVirtualItem( + item, + slot, + amount)) + { + inventory->virtualRemove(item, amount); + } +} diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h index db9310f29..bc8cc284c 100644 --- a/src/gui/windows/npcdialog.h +++ b/src/gui/windows/npcdialog.h @@ -39,6 +39,7 @@ class ComplexInventory; class ComplexItem; class Container; class ExtendedListBox; +class Item; class ItemLinkHandler; class Inventory; class IntTextField; @@ -223,6 +224,10 @@ class NpcDialog final : public Window, void setSkin(const std::string &skin); + void addCraftItem(Item *const item, + const int amount, + const int slot); + static void copyToClipboard(const BeingId npcId, const int x, const int y); |