summaryrefslogtreecommitdiff
path: root/src/gui/windows/maileditwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/windows/maileditwindow.cpp')
-rw-r--r--src/gui/windows/maileditwindow.cpp77
1 files changed, 48 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());
+ }
+}