diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 69 | ||||
-rw-r--r-- | src/gui/windows/inventorywindow.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 77 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.h | 7 |
5 files changed, 154 insertions, 4 deletions
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index d891b19ec..f60377b19 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -1749,6 +1749,7 @@ void PopupMenu::showPopup(Window *const parent, case InventoryType::Cart: case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: default: diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index bc4ca9b1b..d96d89868 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -598,6 +598,9 @@ void ItemContainer::mousePressed(MouseEvent &event) case InventoryType::Mail: src = DragDropSource::Mail; break; + case InventoryType::Craft: + src = DragDropSource::Craft; + break; #endif default: #ifdef EATHENA_SUPPORT @@ -705,6 +708,9 @@ void ItemContainer::mouseReleased(MouseEvent &event) case InventoryType::Cart: dst = DragDropSource::Cart; break; + case InventoryType::Craft: + dst = DragDropSource::Craft; + break; #endif default: #ifdef EATHENA_SUPPORT @@ -848,6 +854,69 @@ void ItemContainer::mouseReleased(MouseEvent &event) } } #ifdef EATHENA_SUPPORT + else if (src == DragDropSource::Inventory && + dst == DragDropSource::Craft) + { + inventory = PlayerInfo::getInventory(); + if (inventory) + { + Item *const item = inventory->getItem(dragDrop.getTag()); + if (mInventory->addVirtualItem( + item, + getSlotByXY(event.getX(), event.getY()))) + { + inventory->virtualRemove(item, 1); + } + } + return; + } + else if (src == DragDropSource::Craft) + { + inventory = PlayerInfo::getInventory(); + if (dst == DragDropSource::Craft) + { + const Item *const item = mInventory->getItem( + dragDrop.getTag()); + const int index = getSlotByXY(event.getX(), event.getY()); + if (index == Inventory::NO_SLOT_INDEX) + { + if (inventory) + inventory->virtualRestore(item, 1); + mInventory->removeItemAt(dragDrop.getTag()); + return; + } + mInventory->removeItemAt(index); + mInventory->setItem(index, + item->getId(), + item->getType(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), + item->getFavorite(), + Equipm_false, + Equipped_false); + Item *const item2 = mInventory->getItem(index); + if (item2) + item2->setTag(item->getTag()); + mInventory->removeItemAt(dragDrop.getTag()); + } + else + { + if (inventory) + { + const Item *const item = inventory->getItem( + dragDrop.getTag()); + if (item) + { + inventory->virtualRestore(item, 1); + mInventory->removeItemAt(dragDrop.getTag()); + } + } + return; + } + } else if (src == DragDropSource::Mail) { inventory = PlayerInfo::getInventory(); diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index f1b76a2d1..eac1b692d 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -124,6 +124,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) : #ifdef EATHENA_SUPPORT case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: default: @@ -319,6 +320,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) : #ifdef EATHENA_SUPPORT case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: break; @@ -380,6 +382,7 @@ void InventoryWindow::storeSortOrder() const #ifdef EATHENA_SUPPORT case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: default: @@ -823,6 +826,7 @@ void InventoryWindow::close() #ifdef EATHENA_SUPPORT case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: break; diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index b589e5bb8..54ba7ca60 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -61,6 +61,8 @@ #include "resources/db/npcdb.h" #include "resources/db/npcdialogdb.h" +#include "resources/inventory/complexinventory.h" + #include "resources/item/item.h" #include "net/npchandler.h" @@ -126,7 +128,8 @@ NpcDialog::NpcDialog(const BeingId npcId) : mButton3(new Button(this, _("Add"), "add", this)), // TRANSLATORS: npc dialog button mResetButton(new Button(this, _("Reset"), "reset", this)), - mInventory(new Inventory(InventoryType::Npc, 1)), + mInventory(new Inventory(InventoryType::Craft, 1)), + mComplexInventory(new ComplexInventory(InventoryType::Npc, 1)), mItemContainer(new ItemContainer(this, mInventory, 10000, ShowEmptyRows_true)), mItemScrollArea(new ScrollArea(this, mItemContainer, @@ -258,6 +261,7 @@ NpcDialog::~NpcDialog() delete2(mItemLinkHandler); delete2(mItemContainer); delete2(mInventory); + delete2(mComplexInventory); delete2(mItemScrollArea); delete2(mListScrollArea); delete2(mSkinScrollArea); @@ -459,13 +463,64 @@ void NpcDialog::action(const ActionEvent &event) mInventory->clear(); break; } + case NPC_INPUT_ITEM_CRAFT: + { + restoreVirtuals(); + if (!PacketLimiter::limitPackets( + PacketType::PACKET_NPC_INPUT)) + { + return; + } + + std::string str; + const int sz = mInventory->getSize(); + if (sz == 0) + { + str = ""; + } + else + { + const Item *item = mInventory->getItem(0); + if (item) + { + str = strprintf("%d,%d", + item->getTag(), + item->getQuantity()); + } + else + { + str = ""; + } + for (int f = 1; f < sz; f ++) + { + str.append("|"); + item = mInventory->getItem(f); + if (item) + { + str.append(strprintf("%d,%d", + item->getTag(), + item->getQuantity())); + } + else + { + str.append(""); + } + } + } + + // need send selected item + npcHandler->stringInput(mNpcId, str); + mInventory->clear(); + break; + } case NPC_INPUT_NONE: default: break; } if (mInputState != NPC_INPUT_ITEM && - mInputState != NPC_INPUT_ITEM_INDEX) + mInputState != NPC_INPUT_ITEM_INDEX && + mInputState != NPC_INPUT_ITEM_CRAFT) { // addText will auto remove the input layout addText(strprintf("> \"%s\"", printText.c_str()), false); @@ -488,6 +543,7 @@ void NpcDialog::action(const ActionEvent &event) break; case NPC_INPUT_ITEM: case NPC_INPUT_ITEM_INDEX: + case NPC_INPUT_ITEM_CRAFT: mInventory->clear(); break; case NPC_INPUT_NONE: @@ -510,6 +566,7 @@ void NpcDialog::action(const ActionEvent &event) { case NPC_INPUT_ITEM: case NPC_INPUT_ITEM_INDEX: + case NPC_INPUT_ITEM_CRAFT: mInventory->clear(); break; case NPC_INPUT_STRING: @@ -534,6 +591,9 @@ void NpcDialog::action(const ActionEvent &event) case NPC_INPUT_ITEM_INDEX: npcHandler->stringInput(mNpcId, "-1"); break; + case NPC_INPUT_ITEM_CRAFT: + npcHandler->stringInput(mNpcId, ""); + break; case NPC_INPUT_STRING: case NPC_INPUT_INTEGER: case NPC_INPUT_NONE: @@ -568,7 +628,8 @@ void NpcDialog::action(const ActionEvent &event) printText = mItems[cnt]; if (mInputState != NPC_INPUT_ITEM && - mInputState != NPC_INPUT_ITEM_INDEX) + mInputState != NPC_INPUT_ITEM_INDEX && + mInputState != NPC_INPUT_ITEM_CRAFT) { // addText will auto remove the input layout addText(strprintf("> \"%s\"", printText.c_str()), false); @@ -727,6 +788,14 @@ void NpcDialog::itemIndexRequest(const int size) buildLayout(); } +void NpcDialog::itemCraftRequest(const int size) +{ + mActionState = NPC_ACTION_INPUT; + mInputState = NPC_INPUT_ITEM_CRAFT; + mInventory->resize(size); + buildLayout(); +} + void NpcDialog::move(const int amount) { if (mActionState != NPC_ACTION_INPUT) @@ -744,6 +813,7 @@ void NpcDialog::move(const int amount) case NPC_INPUT_STRING: case NPC_INPUT_ITEM: case NPC_INPUT_ITEM_INDEX: + case NPC_INPUT_ITEM_CRAFT: default: break; } @@ -995,6 +1065,7 @@ void NpcDialog::buildLayout() case NPC_INPUT_ITEM: case NPC_INPUT_ITEM_INDEX: + case NPC_INPUT_ITEM_CRAFT: placeItemInputControls(); break; diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h index 7a27e0100..7868fd7d1 100644 --- a/src/gui/windows/npcdialog.h +++ b/src/gui/windows/npcdialog.h @@ -35,6 +35,7 @@ class Being; class Button; class BrowserBox; +class ComplexInventory; class Container; class ExtendedListBox; class ItemLinkHandler; @@ -168,6 +169,8 @@ class NpcDialog final : public Window, void itemIndexRequest(const int size); + void itemCraftRequest(const int size); + void move(const int amount); void setVisible(Visible visible) override final; @@ -286,6 +289,7 @@ class NpcDialog final : public Window, Button *mResetButton A_NONNULLPOINTER; Inventory *mInventory A_NONNULLPOINTER; + ComplexInventory *mComplexInventory A_NONNULLPOINTER; ItemContainer *mItemContainer A_NONNULLPOINTER; ScrollArea *mItemScrollArea A_NONNULLPOINTER; @@ -296,7 +300,8 @@ class NpcDialog final : public Window, NPC_INPUT_STRING, NPC_INPUT_INTEGER, NPC_INPUT_ITEM, - NPC_INPUT_ITEM_INDEX + NPC_INPUT_ITEM_INDEX, + NPC_INPUT_ITEM_CRAFT }; enum NpcActionState |