summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-08 20:27:29 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-08 20:27:29 +0300
commit5d0b4c09a67f279847337aa06bc3066c07f63114 (patch)
treeb2f8bbdb3252222c9bc50efa04a5689faa3b1760 /src/gui
parent4b014aa3f403ae02587f6a3d89180f75161d4b78 (diff)
downloadmanaverse-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.gz
manaverse-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.bz2
manaverse-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.xz
manaverse-5d0b4c09a67f279847337aa06bc3066c07f63114.zip
Impliment craft inventory for moving items one by one.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/itemcontainer.cpp33
-rw-r--r--src/gui/widgets/itemcontainer.h3
-rw-r--r--src/gui/windows/npcdialog.cpp96
-rw-r--r--src/gui/windows/npcdialog.h3
4 files changed, 84 insertions, 51 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index d96d89868..af614bcb1 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -799,7 +799,8 @@ void ItemContainer::mouseReleased(MouseEvent &event)
Item *const item = inventory->getItem(dragDrop.getTag());
if (mInventory->addVirtualItem(
item,
- getSlotByXY(event.getX(), event.getY())))
+ getSlotByXY(event.getX(), event.getY()),
+ 1))
{
inventory->virtualRemove(item, 1);
}
@@ -863,7 +864,8 @@ void ItemContainer::mouseReleased(MouseEvent &event)
Item *const item = inventory->getItem(dragDrop.getTag());
if (mInventory->addVirtualItem(
item,
- getSlotByXY(event.getX(), event.getY())))
+ getSlotByXY(event.getX(), event.getY()),
+ 1))
{
inventory->virtualRemove(item, 1);
}
@@ -881,26 +883,14 @@ void ItemContainer::mouseReleased(MouseEvent &event)
if (index == Inventory::NO_SLOT_INDEX)
{
if (inventory)
- inventory->virtualRestore(item, 1);
- mInventory->removeItemAt(dragDrop.getTag());
+ {
+ inventory->virtualRestore(item,
+ item->getQuantity());
+ 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());
+ mInventory->moveItem(index, dragDrop.getTag());
}
else
{
@@ -910,7 +900,8 @@ void ItemContainer::mouseReleased(MouseEvent &event)
dragDrop.getTag());
if (item)
{
- inventory->virtualRestore(item, 1);
+ inventory->virtualRestore(item,
+ item->getQuantity());
mInventory->removeItemAt(dragDrop.getTag());
}
}
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
index a7b62bbd6..e40ad4f17 100644
--- a/src/gui/widgets/itemcontainer.h
+++ b/src/gui/widgets/itemcontainer.h
@@ -138,6 +138,9 @@ class ItemContainer final : public Widget,
void unsetInventory()
{ mInventory = nullptr; }
+ void setInventory(Inventory *const inventory)
+ { mInventory = inventory; }
+
void setCellBackgroundImage(const std::string &xmlName);
void setMaxColumns(const int maxColumns);
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 54ba7ca60..66cdc4bb3 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -63,7 +63,7 @@
#include "resources/inventory/complexinventory.h"
-#include "resources/item/item.h"
+#include "resources/item/complexitem.h"
#include "net/npchandler.h"
#include "net/packetlimiter.h"
@@ -129,7 +129,7 @@ NpcDialog::NpcDialog(const BeingId npcId) :
// TRANSLATORS: npc dialog button
mResetButton(new Button(this, _("Reset"), "reset", this)),
mInventory(new Inventory(InventoryType::Craft, 1)),
- mComplexInventory(new ComplexInventory(InventoryType::Npc, 1)),
+ mComplexInventory(new ComplexInventory(InventoryType::Craft, 1)),
mItemContainer(new ItemContainer(this, mInventory,
10000, ShowEmptyRows_true)),
mItemScrollArea(new ScrollArea(this, mItemContainer,
@@ -473,38 +473,22 @@ void NpcDialog::action(const ActionEvent &event)
}
std::string str;
- const int sz = mInventory->getSize();
+ const int sz = mComplexInventory->getSize();
if (sz == 0)
{
str = "";
}
else
{
- const Item *item = mInventory->getItem(0);
- if (item)
- {
- str = strprintf("%d,%d",
- item->getTag(),
- item->getQuantity());
- }
- else
- {
- str = "";
- }
+ const ComplexItem *item = dynamic_cast<ComplexItem*>(
+ mComplexInventory->getItem(0));
+ str = complexItemToStr(item);
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("");
- }
+ item = dynamic_cast<ComplexItem*>(
+ mComplexInventory->getItem(f));
+ str.append(complexItemToStr(item));
}
}
@@ -543,9 +527,11 @@ 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_ITEM_CRAFT:
+ mComplexInventory->clear();
+ break;
case NPC_INPUT_NONE:
case NPC_INPUT_LIST:
default:
@@ -566,9 +552,11 @@ 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_ITEM_CRAFT:
+ mComplexInventory->clear();
+ break;
case NPC_INPUT_STRING:
case NPC_INPUT_INTEGER:
case NPC_INPUT_LIST:
@@ -611,8 +599,19 @@ void NpcDialog::action(const ActionEvent &event)
{
Item *const item = inventoryWindow->getSelectedItem();
Inventory *const inventory = PlayerInfo::getInventory();
- if (mInventory->addVirtualItem(item, 0) && inventory)
- inventory->virtualRemove(item, 1);
+ if (inventory)
+ {
+ if (mInputState == NPC_INPUT_ITEM_CRAFT)
+ {
+ if (mComplexInventory->addVirtualItem(item, 0, 1))
+ inventory->virtualRemove(item, 1);
+ }
+ else
+ {
+ if (mInventory->addVirtualItem(item, 0, 1))
+ inventory->virtualRemove(item, 1);
+ }
+ }
}
}
else if (eventId.find("skin_") == 0)
@@ -792,7 +791,7 @@ void NpcDialog::itemCraftRequest(const int size)
{
mActionState = NPC_ACTION_INPUT;
mInputState = NPC_INPUT_ITEM_CRAFT;
- mInventory->resize(size);
+ mComplexInventory->resize(size);
buildLayout();
}
@@ -988,6 +987,11 @@ void NpcDialog::placeItemInputControls()
mItemContainer->setMaxColumns(10000);
}
+ if (mInputState == NPC_INPUT_ITEM_CRAFT)
+ mItemContainer->setInventory(mComplexInventory);
+ else
+ mItemContainer->setInventory(mInventory);
+
if (mDialogInfo && mDialogInfo->hideText)
{
if (mShowAvatar)
@@ -1334,3 +1338,35 @@ void NpcDialog::restoreVirtuals()
if (inventory)
inventory->restoreVirtuals();
}
+
+std::string NpcDialog::complexItemToStr(const ComplexItem *const item)
+{
+ std::string str;
+ if (item)
+ {
+ const std::vector<Item*> &items = item->getChilds();
+ const int sz = items.size();
+ logger->log("complexItemToStr size=%d", sz);
+ if (!sz)
+ return str;
+
+ const Item *item2 = items[0];
+
+ str = strprintf("%d,%d",
+ item2->getInvIndex(),
+ item2->getQuantity());
+ for (int f = 1; f < sz; f ++)
+ {
+ str.append(";");
+ item2 = items[f];
+ str.append(strprintf("%d,%d",
+ item2->getInvIndex(),
+ item2->getQuantity()));
+ }
+ }
+ else
+ {
+ str = "";
+ }
+ return str;
+}
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
index 7868fd7d1..db9310f29 100644
--- a/src/gui/windows/npcdialog.h
+++ b/src/gui/windows/npcdialog.h
@@ -36,6 +36,7 @@ class Being;
class Button;
class BrowserBox;
class ComplexInventory;
+class ComplexItem;
class Container;
class ExtendedListBox;
class ItemLinkHandler;
@@ -253,6 +254,8 @@ class NpcDialog final : public Window,
void restoreVirtuals();
+ std::string complexItemToStr(const ComplexItem *const item);
+
BeingId mNpcId;
int mDefaultInt;