diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-07 16:59:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-07 16:59:33 +0300 |
commit | 62c5097904bfc6c6e44e776730ea1d01aaf891c2 (patch) | |
tree | 57216dc3193690c95152405ba50ab222d431a089 /src | |
parent | 8eb2e7d993ad9759da2fbeccea1a924b1b7f64dd (diff) | |
download | plus-62c5097904bfc6c6e44e776730ea1d01aaf891c2.tar.gz plus-62c5097904bfc6c6e44e776730ea1d01aaf891c2.tar.bz2 plus-62c5097904bfc6c6e44e776730ea1d01aaf891c2.tar.xz plus-62c5097904bfc6c6e44e776730ea1d01aaf891c2.zip |
Add partial implimentation for craft inventory. For now almost same with npc inventory.
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/actions.cpp | 1 | ||||
-rw-r--r-- | src/enums/dragdropsource.h | 4 | ||||
-rw-r--r-- | src/enums/inventorytype.h | 1 | ||||
-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 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 1 | ||||
-rw-r--r-- | src/net/ea/npcrecv.cpp | 9 | ||||
-rw-r--r-- | src/resources/inventory/inventory.cpp | 5 | ||||
-rw-r--r-- | src/resources/inventory/inventory.h | 2 |
12 files changed, 174 insertions, 7 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index d8fa1c165..df4f23779 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -261,6 +261,7 @@ static Item *getItemByInvIndex(const InputEvent &event, case InventoryType::Cart: case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: default: diff --git a/src/enums/dragdropsource.h b/src/enums/dragdropsource.h index 2f61ca686..9a65b9dcb 100644 --- a/src/enums/dragdropsource.h +++ b/src/enums/dragdropsource.h @@ -35,12 +35,12 @@ enumStart(DragDropSource) Ground, Drop, Shortcuts, - Craft, Npc, #ifdef EATHENA_SUPPORT Equipment, Cart, - Mail + Mail, + Craft #else Equipment #endif diff --git a/src/enums/inventorytype.h b/src/enums/inventorytype.h index 9bcc0a60e..b15676c2a 100644 --- a/src/enums/inventorytype.h +++ b/src/enums/inventorytype.h @@ -35,6 +35,7 @@ enumStart(InventoryType) Cart, Vending, Mail, + Craft, #endif TypeEnd } 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 diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 179d23845..81fc0103a 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -91,6 +91,7 @@ size_t InventoryHandler::getSize(const InventoryTypeT type) const case InventoryType::Cart: case InventoryType::Vending: case InventoryType::Mail: + case InventoryType::Craft: #endif case InventoryType::TypeEnd: default: diff --git a/src/net/ea/npcrecv.cpp b/src/net/ea/npcrecv.cpp index d4c6b3d6b..c447fd5c5 100644 --- a/src/net/ea/npcrecv.cpp +++ b/src/net/ea/npcrecv.cpp @@ -202,6 +202,15 @@ void NpcRecv::processNpcCommand(Net::MessageIn &msg) mDialog->itemIndexRequest(invSize); break; } + case 12: // send complex items + { + int invSize = toInt(id, int); + if (!invSize) + invSize = 1; + if (mDialog) + mDialog->itemCraftRequest(invSize); + break; + } default: UNIMPLIMENTEDPACKET; break; diff --git a/src/resources/inventory/inventory.cpp b/src/resources/inventory/inventory.cpp index ad44245a1..180a1b4f3 100644 --- a/src/resources/inventory/inventory.cpp +++ b/src/resources/inventory/inventory.cpp @@ -330,6 +330,11 @@ std::string Inventory::getName() const // TRANSLATORS: inventory type name return N_("Mail"); } + case InventoryType::Craft: + { + // TRANSLATORS: inventory type name + return N_("Craft"); + } #endif case InventoryType::Trade: { diff --git a/src/resources/inventory/inventory.h b/src/resources/inventory/inventory.h index 501141ed8..1e1a97dd4 100644 --- a/src/resources/inventory/inventory.h +++ b/src/resources/inventory/inventory.h @@ -45,7 +45,7 @@ class InventoryListener; class Item; -class Inventory final +class Inventory notfinal { public: A_DELETE_COPY(Inventory) |