summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/maileditwindow.cpp77
-rw-r--r--src/gui/windows/maileditwindow.h2
2 files changed, 50 insertions, 29 deletions
diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp
index fb805e105..45e61a948 100644
--- a/src/gui/windows/maileditwindow.cpp
+++ b/src/gui/windows/maileditwindow.cpp
@@ -36,11 +36,14 @@
#include "resources/item/item.h"
+#include "net/mail2handler.h"
#include "net/mailhandler.h"
#include "utils/delete2.h"
#include "utils/gettext.h"
+#include <climits>
+
#include "debug.h"
MailEditWindow *mailEditWindow = nullptr;
@@ -67,7 +70,8 @@ MailEditWindow::MailEditWindow() :
mMessageLabel(new Label(this, _("Message:"))),
mToField(new TextField(this)),
mSubjectField(new TextField(this)),
- mMoneyField(new IntTextField(this, 0, 0, 10000000)),
+ mMoneyField(new IntTextField(this, 0, 0,
+ settings.enableNewMailSystem ? INT_MAX : 10000000)),
mMessageField(new TextField(this)),
mInventory(new Inventory(InventoryType::Mail,
settings.enableNewMailSystem ? -1 : 1)),
@@ -135,34 +139,7 @@ void MailEditWindow::action(const ActionEvent &event)
}
else if (eventId == "send")
{
- const int money = mMoneyField->getValue();
- if (money != 0)
- mailHandler->setAttachMoney(money);
- const Item *const tempItem = mInventory->getItem(0);
- if (tempItem != nullptr)
- {
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- const Item *const item = inv->findItem(
- tempItem->getId(), ItemColor_one);
- if (item != nullptr)
- {
- mailHandler->setAttach(item->getInvIndex(),
- tempItem->getQuantity());
- }
- }
- }
-
- std::string subject = mSubjectField->getText();
- if (subject.empty())
- {
- // TRANSLATORS: empty mail message subject
- subject.append(_("empty subject"));
- }
- mailHandler->send(mToField->getText(),
- subject,
- mMessageField->getText());
+ sendMail();
}
else if (eventId == "add")
{
@@ -217,3 +194,45 @@ Inventory *MailEditWindow::getInventory() const
{
return mInventory;
}
+
+void MailEditWindow::sendMail()
+{
+ const int money = mMoneyField->getValue();
+ std::string subject = mSubjectField->getText();
+ if (subject.empty())
+ {
+ // TRANSLATORS: empty mail message subject
+ subject.append(_("empty subject"));
+ }
+ if (mUseMail2)
+ {
+ mail2Handler->sendMail(mToField->getText(),
+ subject,
+ mMessageField->getText(),
+ money);
+ }
+ else
+ {
+ if (money != 0)
+ mailHandler->setAttachMoney(money);
+ const Item *const tempItem = mInventory->getItem(0);
+ if (tempItem != nullptr)
+ {
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (inv != nullptr)
+ {
+ const Item *const item = inv->findItem(
+ tempItem->getId(), ItemColor_one);
+ if (item != nullptr)
+ {
+ mailHandler->setAttach(item->getInvIndex(),
+ tempItem->getQuantity());
+ }
+ }
+ }
+
+ mailHandler->send(mToField->getText(),
+ subject,
+ mMessageField->getText());
+ }
+}
diff --git a/src/gui/windows/maileditwindow.h b/src/gui/windows/maileditwindow.h
index a7d921f8d..031a1545d 100644
--- a/src/gui/windows/maileditwindow.h
+++ b/src/gui/windows/maileditwindow.h
@@ -59,6 +59,8 @@ class MailEditWindow final : public Window,
Inventory *getInventory() const A_WARN_UNUSED;
private:
+ void sendMail();
+
Button *mSendButton;
Button *mCloseButton;
Button *mAddButton;