summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-25 20:45:38 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-25 20:45:38 +0300
commitf7d3792df9fd01ea7baabaf9b612031b1f28d7ab (patch)
treea38b12795443c2c364059cf418d6171171d4434b /src
parent6adafcc07e2101ab085bd9f2182c965ef70d0519 (diff)
downloadmanaverse-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.gz
manaverse-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.bz2
manaverse-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.xz
manaverse-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.zip
Add basic support for view mail message.
Diffstat (limited to 'src')
-rw-r--r--src/gui/windows/mailviewwindow.cpp81
-rw-r--r--src/gui/windows/mailviewwindow.h16
-rw-r--r--src/gui/windows/mailwindow.cpp19
-rw-r--r--src/gui/windows/mailwindow.h8
-rw-r--r--src/net/eathena/mail2recv.cpp91
-rw-r--r--src/net/eathena/mailrecv.cpp2
6 files changed, 154 insertions, 63 deletions
diff --git a/src/gui/windows/mailviewwindow.cpp b/src/gui/windows/mailviewwindow.cpp
index 19d1211bb..d99fd602f 100644
--- a/src/gui/windows/mailviewwindow.cpp
+++ b/src/gui/windows/mailviewwindow.cpp
@@ -21,6 +21,7 @@
#include "gui/windows/mailviewwindow.h"
#include "configuration.h"
+#include "settings.h"
#include "net/mailhandler.h"
@@ -32,8 +33,9 @@
#include "gui/widgets/button.h"
#include "gui/widgets/containerplacer.h"
#include "gui/widgets/createwidget.h"
-#include "gui/widgets/icon.h"
+#include "gui/widgets/itemcontainer.h"
#include "gui/widgets/label.h"
+#include "gui/widgets/scrollarea.h"
#include "utils/delete2.h"
#include "utils/gettext.h"
@@ -42,6 +44,8 @@
#include "resources/image/image.h"
+#include "resources/inventory/inventory.h"
+
#include "resources/loaders/imageloader.h"
#include "resources/db/itemdb.h"
@@ -50,7 +54,8 @@
MailViewWindow *mailViewWindow = nullptr;
-MailViewWindow::MailViewWindow(const MailMessage *const message) :
+MailViewWindow::MailViewWindow(const MailMessage *const message,
+ const int itemsCount) :
// TRANSLATORS: mail view window name
Window(_("View mail"), Modal_false, nullptr, "mailview.xml"),
ActionListener(),
@@ -76,9 +81,12 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
// TRANSLATORS: mail view window label
mMessageLabel(new Label(this, strprintf("%s %s", _("Message:"),
message->text.c_str()))),
- // TRANSLATORS: mail view window label
- mItemLabel(nullptr),
- mIcon(nullptr)
+ mInventory(new Inventory(InventoryType::Mail, itemsCount)),
+ mItemContainer(new ItemContainer(this, mInventory)),
+ mItemScrollArea(new ScrollArea(this, mItemContainer,
+ fromBool(getOptionBool("showitemsbackground"), Opaque),
+ "mailedit_listbackground.xml")),
+ mUseMail2(settings.enableNewMailSystem)
{
setWindowName("MailView");
setCloseButton(true);
@@ -91,6 +99,10 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
setMinWidth(200);
setMinHeight(100);
center();
+ mItemScrollArea->setHeight(100);
+ mItemScrollArea->setWidth(100);
+
+ mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
ContainerPlacer placer;
placer = getPlacer(0, 0);
@@ -107,35 +119,14 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
placer(0, n++, mMoneyLabel);
}
placer(0, n++, mMessageLabel);
- if (message->itemId != 0)
- {
- const ItemInfo &item = ItemDB::get(message->itemId);
- // +++ need use message->cards and ItemColorManager for colors
- Image *const image = Loader::getImage(combineDye2(
- pathJoin(paths.getStringValue("itemIcons"),
- item.getDisplay().image),
- item.getDyeIconColorsString(ItemColor_one)));
-
- mIcon = new Icon(this, image);
- if (message->itemAmount != 1)
- {
- mItemLabel = new Label(this, std::string(
- // TRANSLATORS: mail view item label
- _("Item:")).append(
- " (").append(
- toString(message->itemAmount)).append(
- ") "));
- }
- else
- {
- mItemLabel = new Label(this,
- // TRANSLATORS: mail view item label
- std::string(_("Item:")).append(" "));
- }
- placer(0, n, mItemLabel);
- placer(1, n++, mIcon);
- }
- if ((message->money != 0) || (message->itemId != 0))
+ placer(0, n++, mItemScrollArea);
+
+ logger->log("sizes: %d, %d",
+ mItemContainer->getWidth(),
+ mItemContainer->getHeight());
+
+ if (message->money != 0 ||
+ message->itemId != 0)
{
mGetAttachButton = new Button(this,
// TRANSLATORS: mail view attach button
@@ -158,13 +149,11 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
MailViewWindow::~MailViewWindow()
{
- if (mIcon != nullptr)
- {
- Image *const image = mIcon->getImage();
- if (image != nullptr)
- image->decRef();
- }
- delete2(mMessage);
+ if (mUseMail2)
+ mMessage = nullptr;
+ else
+ delete2(mMessage);
+ delete2(mInventory);
mailViewWindow = nullptr;
}
@@ -203,3 +192,13 @@ void MailViewWindow::action(const ActionEvent &event)
scheduleDelete();
}
}
+
+Inventory *MailViewWindow::getInventory() const
+{
+ return mInventory;
+}
+
+void MailViewWindow::updateItems()
+{
+ mItemContainer->updateMatrix();
+}
diff --git a/src/gui/windows/mailviewwindow.h b/src/gui/windows/mailviewwindow.h
index 97cd8e84e..a9d19e57e 100644
--- a/src/gui/windows/mailviewwindow.h
+++ b/src/gui/windows/mailviewwindow.h
@@ -27,7 +27,10 @@
class Button;
class Icon;
+class Inventory;
+class ItemContainer;
class Label;
+class ScrollArea;
struct MailMessage;
@@ -35,7 +38,8 @@ class MailViewWindow final : public Window,
public ActionListener
{
public:
- explicit MailViewWindow(const MailMessage *const message) A_NONNULL(2);
+ MailViewWindow(const MailMessage *const message,
+ const int itemsCount) A_NONNULL(2);
A_DELETE_COPY(MailViewWindow)
@@ -43,6 +47,10 @@ class MailViewWindow final : public Window,
void action(const ActionEvent &event) override final;
+ Inventory *getInventory() const A_WARN_UNUSED;
+
+ void updateItems();
+
private:
const MailMessage *mMessage;
Button *mGetAttachButton;
@@ -55,8 +63,10 @@ class MailViewWindow final : public Window,
Label *mFromLabel;
Label *mSubjectLabel;
Label *mMessageLabel;
- Label *mItemLabel;
- Icon *mIcon;
+ Inventory *mInventory;
+ ItemContainer *mItemContainer;
+ ScrollArea *mItemScrollArea;
+ bool mUseMail2;
};
extern MailViewWindow *mailViewWindow;
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
index c12b719fc..8dc54cf94 100644
--- a/src/gui/windows/mailwindow.cpp
+++ b/src/gui/windows/mailwindow.cpp
@@ -140,7 +140,10 @@ void MailWindow::action(const ActionEvent &event)
if (sel < 0)
return;
const MailMessage *const mail = mMessages[sel];
- mailHandler->readMessage(mail->id);
+ if (mUseMail2)
+ mail2Handler->readMail(mOpenType, mail->id);
+ else
+ mailHandler->readMessage(mail->id);
}
else if (eventId == "delete")
{
@@ -234,7 +237,8 @@ void MailWindow::removeMail(const int64_t id)
}
}
-void MailWindow::showMessage(MailMessage *const mail)
+void MailWindow::showMessage(MailMessage *const mail,
+ const int itemsCount)
{
if (mail == nullptr)
return;
@@ -247,7 +251,8 @@ void MailWindow::showMessage(MailMessage *const mail)
mail->strTime = mail2->strTime;
}
delete mailViewWindow;
- CREATEWIDGETV(mailViewWindow, MailViewWindow, mail);
+ CREATEWIDGETV(mailViewWindow, MailViewWindow, mail,
+ itemsCount);
}
void MailWindow::viewNext(const int64_t id)
@@ -337,3 +342,11 @@ void MailWindow::createMail(const std::string &to)
CREATEWIDGETV0(mailEditWindow, MailEditWindow);
mailEditWindow->setTo(to);
}
+
+MailMessage *MailWindow::findMail(const int64_t id)
+{
+ std::map<int64_t, MailMessage*>::iterator it = mMessagesMap.find(id);
+ if (it != mMessagesMap.end())
+ return (*it).second;
+ return nullptr;
+}
diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h
index 8a6bc6695..3c38e0329 100644
--- a/src/gui/windows/mailwindow.h
+++ b/src/gui/windows/mailwindow.h
@@ -55,7 +55,8 @@ class MailWindow final : public Window,
void clear() override final;
- void showMessage(MailMessage *const mail);
+ void showMessage(MailMessage *const mail,
+ const int itemsCount);
void removeMail(const int64_t id);
@@ -69,9 +70,14 @@ class MailWindow final : public Window,
void createMail(const std::string &to);
+ MailMessage *findMail(const int64_t id) A_WARN_UNUSED;
+
void setOpenType(const MailOpenTypeT &type)
{ mOpenType = type; }
+ MailOpenTypeT getOpenType() const A_WARN_UNUSED
+ { return mOpenType; }
+
private:
void refreshMails();
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp
index b3ffae6c0..3da4ae4c5 100644
--- a/src/net/eathena/mail2recv.cpp
+++ b/src/net/eathena/mail2recv.cpp
@@ -35,6 +35,7 @@
#include "gui/mailmessage.h"
#include "gui/windows/maileditwindow.h"
+#include "gui/windows/mailviewwindow.h"
#include "gui/windows/mailwindow.h"
#include "net/messagein.h"
@@ -310,32 +311,94 @@ void Mail2Recv::processMailListPage(Net::MessageIn &msg)
void Mail2Recv::processReadMail(Net::MessageIn &msg)
{
- UNIMPLEMENTEDPACKET;
msg.readInt16("len");
- msg.readUInt8("open type");
- msg.readInt64("mail id");
+ const MailOpenTypeT openType = static_cast<MailOpenTypeT>(
+ msg.readUInt8("open type"));
+ const int64_t mailId = msg.readInt64("mail id");
const int textLen = msg.readInt16("text len");
- msg.readInt64("money");
+ const int64_t money = msg.readInt64("money");
const int itemsCount = msg.readUInt8("item count");
- msg.readString(textLen, "text message");
+ const std::string text = msg.readString(textLen, "text message");
+ MailMessage *mail = nullptr;
+
+ if (mailWindow != nullptr &&
+ openType == mailWindow->getOpenType())
+ {
+ mail = mailWindow->findMail(mailId);
+ }
+
+ if (mail == nullptr)
+ {
+ reportAlways("Mail message not found");
+ for (int f = 0; f < itemsCount; f ++)
+ {
+ msg.readInt16("amount");
+ msg.readInt16("item id");
+ msg.readUInt8("identify");
+ msg.readUInt8("damaged");
+ msg.readUInt8("refine");
+ for (int d = 0; d < maxCards; d ++)
+ msg.readUInt16("card");
+ msg.readInt32("unknown");
+ msg.readUInt8("type");
+ msg.readInt32("unknown");
+ for (int d = 0; d < 5; d ++)
+ {
+ msg.readInt16("option index");
+ msg.readInt16("option value");
+ msg.readUInt8("option param");
+ }
+ }
+ return;
+ }
+
+ mail->money = money;
+ mail->text = text;
+ mailWindow->showMessage(mail, itemsCount);
+
+ Inventory *const inventory = mailViewWindow->getInventory();
+
for (int f = 0; f < itemsCount; f ++)
{
- msg.readInt16("amount");
- msg.readInt16("item id");
- msg.readUInt8("identify");
- msg.readUInt8("damaged");
- msg.readUInt8("refine");
+ const int amount = msg.readInt16("amount");
+ const int itemId = msg.readInt16("item id");
+ 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 d = 0; d < maxCards; d ++)
- msg.readUInt16("card");
+ cards[d] = msg.readUInt16("card");
msg.readInt32("unknown");
- msg.readUInt8("type");
+ const ItemTypeT itemType = static_cast<ItemTypeT>(
+ msg.readUInt8("item type"));
msg.readInt32("unknown");
+ ItemOptionsList *options = new ItemOptionsList(5);
for (int d = 0; d < 5; d ++)
{
- 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);
}
+
+ 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;
+ continue;
+ }
+ inventory->setCards(slot, cards, 4);
+ inventory->setOptions(slot, options);
+ delete options;
}
}
diff --git a/src/net/eathena/mailrecv.cpp b/src/net/eathena/mailrecv.cpp
index 93a548c69..ac638b300 100644
--- a/src/net/eathena/mailrecv.cpp
+++ b/src/net/eathena/mailrecv.cpp
@@ -110,7 +110,7 @@ void MailRecv::processReadMail(Net::MessageIn &msg)
mail->text = msg.readString(sz, "message");
msg.readUInt8("zero");
mail->strTime = timeToStr(mail->time);
- mailWindow->showMessage(mail);
+ mailWindow->showMessage(mail, mail->itemId != 0 ? 1 : 0);
}
void MailRecv::processGetAttachment(Net::MessageIn &msg)