From 3c7ec1268f2699884a5d96aa1df20742457caabd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 24 Aug 2017 04:46:47 +0300 Subject: Add attach items to new mail. --- src/enums/resources/notifytypes.h | 5 ++ src/gui/windows/maileditwindow.cpp | 5 ++ src/gui/windows/maileditwindow.h | 2 + src/net/eathena/mail2recv.cpp | 120 +++++++++++++++++++++++++++++++++---- src/resources/notifications.h | 20 +++++++ 5 files changed, 139 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/enums/resources/notifytypes.h b/src/enums/resources/notifytypes.h index ec39b70b9..9131e979a 100644 --- a/src/enums/resources/notifytypes.h +++ b/src/enums/resources/notifytypes.h @@ -234,6 +234,11 @@ namespace NotifyTypes BUY_FAILED_SYSTEM_ERROR, BUY_FAILED_WRONG_ITEM, MAIL_NAME_VALIDATION_ERROR, + MAIL_ATTACH_ITEM_WEIGHT_ERROR, + MAIL_ATTACH_ITEM_FATAL_ERROR, + MAIL_ATTACH_ITEM_NO_SPACE, + MAIL_ATTACH_ITEM_NOT_TRADEABLE, + MAIL_ATTACH_ITEM_UNKNOWN_ERROR, TYPE_END }; diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp index 5f7426a76..fb805e105 100644 --- a/src/gui/windows/maileditwindow.cpp +++ b/src/gui/windows/maileditwindow.cpp @@ -212,3 +212,8 @@ void MailEditWindow::close() { scheduleDelete(); } + +Inventory *MailEditWindow::getInventory() const +{ + return mInventory; +} diff --git a/src/gui/windows/maileditwindow.h b/src/gui/windows/maileditwindow.h index e25fb8f4f..a7d921f8d 100644 --- a/src/gui/windows/maileditwindow.h +++ b/src/gui/windows/maileditwindow.h @@ -56,6 +56,8 @@ class MailEditWindow final : public Window, void close() override final; + Inventory *getInventory() const A_WARN_UNUSED; + private: Button *mSendButton; Button *mCloseButton; diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp index a28455a83..521abb8dc 100644 --- a/src/net/eathena/mail2recv.cpp +++ b/src/net/eathena/mail2recv.cpp @@ -20,20 +20,32 @@ #include "net/eathena/mail2recv.h" +#include "itemcolormanager.h" #include "logger.h" - #include "notifymanager.h" +#include "const/net/inventory.h" + #include "const/resources/item/cards.h" #include "enums/resources/notifytypes.h" +#include "gui/windows/maileditwindow.h" #include "gui/windows/mailwindow.h" #include "net/messagein.h" #include "net/eathena/mail2handler.h" +#include "resources/iteminfo.h" + +#include "resources/db/itemdb.h" + +#include "resources/inventory/inventory.h" + +#include "resources/item/item.h" +#include "resources/item/itemoptionslist.h" + #include "utils/checkutils.h" #include "debug.h" @@ -61,22 +73,25 @@ void Mail2Recv::processOpenNewMailWindow(Net::MessageIn &msg) void Mail2Recv::processAddItemResult(Net::MessageIn &msg) { - UNIMPLEMENTEDPACKET; - msg.readUInt8("result"); - msg.readInt16("index"); - msg.readInt16("count"); - msg.readInt16("itid"); - msg.readUInt8("type"); - msg.readUInt8("identify"); - msg.readUInt8("damaged"); - msg.readUInt8("refine"); + const int res = msg.readUInt8("result"); + const int index = msg.readInt16("index") - INVENTORY_OFFSET; + const int amount = msg.readInt16("amount"); + const int itemId = msg.readInt16("item id"); + const ItemTypeT itemType = static_cast( + msg.readUInt8("item type")); + const uint8_t identify = msg.readUInt8("identify"); + const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged); + const uint8_t refine = msg.readUInt8("refine"); + int cards[maxCards]; for (int f = 0; f < maxCards; f++) - msg.readUInt16("card"); + cards[f] = msg.readUInt16("card"); + ItemOptionsList *options = new ItemOptionsList(5); for (int f = 0; f < 5; f ++) { - msg.readInt16("option index"); - msg.readInt16("option value"); + const uint16_t idx = msg.readInt16("option index"); + const uint16_t val = msg.readInt16("option value"); msg.readUInt8("option param"); + options->add(idx, val); } msg.readInt16("weight"); msg.readUInt8("unknown 1"); @@ -84,6 +99,85 @@ void Mail2Recv::processAddItemResult(Net::MessageIn &msg) msg.readUInt8("unknown 3"); msg.readUInt8("unknown 4"); msg.readUInt8("unknown 5"); + + if (mailEditWindow == nullptr) + { + reportAlways("Mail edit window not created"); + delete options; + return; + } + Inventory *const inventory = mailEditWindow->getInventory(); + if (inventory == nullptr) + { + reportAlways("Mail edit window inventory not exists"); + delete options; + return; + } + + if (res != 0) + { + std::string itemName; + const Item *const item = inventory->getItem(index); + if (item == nullptr) + { + const ItemInfo &info = ItemDB::get(itemId); + itemName = info.getName(); + } + else + { + itemName = item->getName(); + } + + switch (res) + { + case 1: + NotifyManager::notify( + NotifyTypes::MAIL_ATTACH_ITEM_WEIGHT_ERROR, + itemName); + break; + case 2: + NotifyManager::notify( + NotifyTypes::MAIL_ATTACH_ITEM_FATAL_ERROR, + itemName); + break; + case 3: + NotifyManager::notify( + NotifyTypes::MAIL_ATTACH_ITEM_NO_SPACE, + itemName); + break; + case 4: + NotifyManager::notify( + NotifyTypes::MAIL_ATTACH_ITEM_NOT_TRADEABLE, + itemName); + break; + default: + NotifyManager::notify( + NotifyTypes::MAIL_ATTACH_ITEM_UNKNOWN_ERROR, + itemName); + UNIMPLEMENTEDPACKETFIELD(res); + break; + } + delete options; + return; + } + const int slot = inventory->addItem(itemId, + itemType, + amount, + refine, + ItemColorManager::getColorFromCards(&cards[0]), + fromBool(identify, Identified), + damaged, + Favorite_false, + Equipm_false, + Equipped_false); + if (slot == -1) + { + delete options; + return; + } + inventory->setCards(slot, cards, 4); + inventory->setOptions(slot, options); + delete options; } void Mail2Recv::processRemoveItemResult(Net::MessageIn &msg) diff --git a/src/resources/notifications.h b/src/resources/notifications.h index cdfee9e3d..490ea3191 100644 --- a/src/resources/notifications.h +++ b/src/resources/notifications.h @@ -853,6 +853,26 @@ namespace NotifyManager // TRANSLATORS: notification message N_("Mail destination name %s is wrong."), NotifyFlags::STRING}, + {"mail attach item weight error", + // TRANSLATORS: notification message + N_("Item %s attach failed. Weight too big."), + NotifyFlags::STRING}, + {"mail attach item fatal error", + // TRANSLATORS: notification message + N_("Item %s attach failed. Fatal error."), + NotifyFlags::STRING}, + {"mail attach item no space", + // TRANSLATORS: notification message + N_("Item %s attach failed. No more space."), + NotifyFlags::STRING}, + {"mail attach item non tradeable", + // TRANSLATORS: notification message + N_("Item %s attach failed. Item on tradeable."), + NotifyFlags::STRING}, + {"mail attach item unknown error", + // TRANSLATORS: notification message + N_("Item %s attach failed. Unknown error."), + NotifyFlags::STRING}, }; } // namespace NotifyManager #endif // RESOURCES_NOTIFICATIONS_H -- cgit v1.2.3-60-g2f50