summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/enums/resources/notifytypes.h1
-rw-r--r--src/gui/widgets/itemcontainer.cpp24
-rw-r--r--src/net/eathena/mail2handler.cpp7
-rw-r--r--src/net/eathena/mail2handler.h2
-rw-r--r--src/net/eathena/mail2recv.cpp65
-rw-r--r--src/net/mail2handler.h2
-rw-r--r--src/net/tmwa/mail2handler.cpp2
-rw-r--r--src/net/tmwa/mail2handler.h2
-rw-r--r--src/resources/notifications.h4
9 files changed, 91 insertions, 18 deletions
diff --git a/src/enums/resources/notifytypes.h b/src/enums/resources/notifytypes.h
index 9131e979a..b38fe9d07 100644
--- a/src/enums/resources/notifytypes.h
+++ b/src/enums/resources/notifytypes.h
@@ -239,6 +239,7 @@ namespace NotifyTypes
MAIL_ATTACH_ITEM_NO_SPACE,
MAIL_ATTACH_ITEM_NOT_TRADEABLE,
MAIL_ATTACH_ITEM_UNKNOWN_ERROR,
+ MAIL_REMOVE_ITEM_ERROR,
TYPE_END
};
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index f701ab6af..fd998180a 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -1019,12 +1019,28 @@ void ItemContainer::mouseReleased(MouseEvent &event)
}
else if (src == DragDropSource::Mail)
{
- inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
+ if (settings.enableNewMailSystem)
{
+ if (mailEditWindow == nullptr)
+ return;
+ inventory = mailEditWindow->getInventory();
+ if (inventory == nullptr)
+ return;
const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item != nullptr)
- mInventory->removeItemAt(dragDrop.getTag());
+ if (item == nullptr)
+ return;
+ mail2Handler->removeItem(item->getTag(),
+ item->getQuantity());
+ }
+ else
+ {
+ inventory = PlayerInfo::getInventory();
+ if (inventory == nullptr)
+ return;
+ const Item *const item = inventory->getItem(dragDrop.getTag());
+ if (item == nullptr)
+ return;
+ mInventory->removeItemAt(dragDrop.getTag());
}
return;
}
diff --git a/src/net/eathena/mail2handler.cpp b/src/net/eathena/mail2handler.cpp
index 1b19e4823..bc749b0bf 100644
--- a/src/net/eathena/mail2handler.cpp
+++ b/src/net/eathena/mail2handler.cpp
@@ -85,11 +85,9 @@ void Mail2Handler::addItem(const Item *const item,
outMsg.writeInt16(CAST_S16(amount), "amount");
}
-void Mail2Handler::removeItem(const Item *const item,
+void Mail2Handler::removeItem(const int index,
const int amount) const
{
- if (item == nullptr)
- return;
if (packetVersion < 20140416 ||
(serverVersion < 19 && serverVersion != 0))
{
@@ -97,8 +95,7 @@ void Mail2Handler::removeItem(const Item *const item,
}
createOutPacket(CMSG_MAIL2_REMOVE_ITEM_MAIL);
- outMsg.writeInt16(CAST_S16(
- item->getInvIndex() + INVENTORY_OFFSET), "index");
+ outMsg.writeInt16(CAST_S16(index + INVENTORY_OFFSET), "index");
outMsg.writeInt16(CAST_S16(amount), "amount");
}
diff --git a/src/net/eathena/mail2handler.h b/src/net/eathena/mail2handler.h
index 0b7957375..f6f217579 100644
--- a/src/net/eathena/mail2handler.h
+++ b/src/net/eathena/mail2handler.h
@@ -40,7 +40,7 @@ class Mail2Handler final : public Net::Mail2Handler
void addItem(const Item *const item,
const int amount) const override final;
- void removeItem(const Item *const item,
+ void removeItem(const int index,
const int amount) const override final;
void sendMail(const std::string &to,
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp
index 521abb8dc..ee9c6b6da 100644
--- a/src/net/eathena/mail2recv.cpp
+++ b/src/net/eathena/mail2recv.cpp
@@ -28,6 +28,8 @@
#include "const/resources/item/cards.h"
+#include "being/playerinfo.h"
+
#include "enums/resources/notifytypes.h"
#include "gui/windows/maileditwindow.h"
@@ -47,6 +49,7 @@
#include "resources/item/itemoptionslist.h"
#include "utils/checkutils.h"
+#include "utils/gettext.h"
#include "debug.h"
@@ -116,8 +119,9 @@ void Mail2Recv::processAddItemResult(Net::MessageIn &msg)
if (res != 0)
{
+ Inventory *const inv = PlayerInfo::getInventory();
std::string itemName;
- const Item *const item = inventory->getItem(index);
+ const Item *const item = inv->getItem(index);
if (item == nullptr)
{
const ItemInfo &info = ItemDB::get(itemId);
@@ -177,16 +181,67 @@ void Mail2Recv::processAddItemResult(Net::MessageIn &msg)
}
inventory->setCards(slot, cards, 4);
inventory->setOptions(slot, options);
+ inventory->setTag(slot, index);
delete options;
}
void Mail2Recv::processRemoveItemResult(Net::MessageIn &msg)
{
- UNIMPLEMENTEDPACKET;
- msg.readUInt8("result");
- msg.readInt16("index");
- msg.readInt16("count");
+ const int result = msg.readUInt8("result");
+ const int index = msg.readInt16("index") - INVENTORY_OFFSET;
+ const int amount = msg.readInt16("count");
msg.readInt16("weight");
+
+ if (result == 0)
+ {
+ Inventory *const inv = PlayerInfo::getInventory();
+ if (inv == nullptr)
+ {
+ reportAlways("Player inventory not exists");
+ return;
+ }
+ std::string itemName;
+ const Item *const item = inv->getItem(index);
+ if (item != nullptr)
+ {
+ itemName = item->getName();
+ }
+ else
+ {
+ // TRANSLATORS: unknown item name
+ itemName = _("Unknown item");
+ }
+
+ NotifyManager::notify(
+ NotifyTypes::MAIL_REMOVE_ITEM_ERROR,
+ itemName);
+ return;
+ }
+ if (mailEditWindow == nullptr)
+ {
+ reportAlways("Mail edit window not created");
+ return;
+ }
+ Inventory *const inventory = mailEditWindow->getInventory();
+ if (inventory == nullptr)
+ {
+ reportAlways("Mail edit window inventory not exists");
+ return;
+ }
+ const int index2 = inventory->findIndexByTag(index);
+ if (index2 == -1)
+ {
+ reportAlways("Item not exists in mail edit window.");
+ return;
+ }
+ Item *const item = inventory->getItem(index2);
+ if (item == nullptr)
+ {
+ reportAlways("Item not exists.");
+ return;
+ }
+
+ item->increaseQuantity(-amount);
}
void Mail2Recv::processCheckNameResult(Net::MessageIn &msg)
diff --git a/src/net/mail2handler.h b/src/net/mail2handler.h
index 47b441f77..56ad516cd 100644
--- a/src/net/mail2handler.h
+++ b/src/net/mail2handler.h
@@ -50,7 +50,7 @@ class Mail2Handler notfinal
virtual void addItem(const Item *const item,
const int amount) const = 0;
- virtual void removeItem(const Item *const item,
+ virtual void removeItem(const int index,
const int amount) const = 0;
virtual void sendMail(const std::string &to,
diff --git a/src/net/tmwa/mail2handler.cpp b/src/net/tmwa/mail2handler.cpp
index d79e9585e..70a8cfda5 100644
--- a/src/net/tmwa/mail2handler.cpp
+++ b/src/net/tmwa/mail2handler.cpp
@@ -44,7 +44,7 @@ void Mail2Handler::addItem(const Item *const item A_UNUSED,
{
}
-void Mail2Handler::removeItem(const Item *const item A_UNUSED,
+void Mail2Handler::removeItem(const int index A_UNUSED,
const int amount A_UNUSED) const
{
}
diff --git a/src/net/tmwa/mail2handler.h b/src/net/tmwa/mail2handler.h
index e39e99347..221e714b5 100644
--- a/src/net/tmwa/mail2handler.h
+++ b/src/net/tmwa/mail2handler.h
@@ -40,7 +40,7 @@ class Mail2Handler final : public Net::Mail2Handler
void addItem(const Item *const item,
const int amount) const override final;
- void removeItem(const Item *const item,
+ void removeItem(const int index,
const int amount) const override final;
void sendMail(const std::string &to,
diff --git a/src/resources/notifications.h b/src/resources/notifications.h
index 490ea3191..1e25dbdb3 100644
--- a/src/resources/notifications.h
+++ b/src/resources/notifications.h
@@ -873,6 +873,10 @@ namespace NotifyManager
// TRANSLATORS: notification message
N_("Item %s attach failed. Unknown error."),
NotifyFlags::STRING},
+ {"mail remove item error",
+ // TRANSLATORS: notification message
+ N_("Item %s remove failed."),
+ NotifyFlags::STRING},
};
} // namespace NotifyManager
#endif // RESOURCES_NOTIFICATIONS_H