summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-04-29 01:36:13 +0300
committerAndrei Karas <akaras@inbox.ru>2015-04-29 14:10:28 +0300
commit4b0f30b1e1879cee6d65394d826bba21eca6c40b (patch)
tree14d16cadd1b8fe20bc0bfa2ea8974ff46b00b496 /src/gui
parent13920702c8a5e5b093d9a3ef5a5e8b254931915b (diff)
downloadmv-4b0f30b1e1879cee6d65394d826bba21eca6c40b.tar.gz
mv-4b0f30b1e1879cee6d65394d826bba21eca6c40b.tar.bz2
mv-4b0f30b1e1879cee6d65394d826bba21eca6c40b.tar.xz
mv-4b0f30b1e1879cee6d65394d826bba21eca6c40b.zip
Allos send items by mail.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/popups/popupmenu.cpp1
-rw-r--r--src/gui/widgets/itemcontainer.cpp15
-rw-r--r--src/gui/windows/inventorywindow.cpp4
-rw-r--r--src/gui/windows/itemamountwindow.cpp9
-rw-r--r--src/gui/windows/itemamountwindow.h3
-rw-r--r--src/gui/windows/mailedit.cpp82
-rw-r--r--src/gui/windows/mailedit.h13
-rw-r--r--src/gui/windows/mailwindow.cpp4
8 files changed, 118 insertions, 13 deletions
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index a2d8b1ef5..f01a57a4e 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -1716,6 +1716,7 @@ void PopupMenu::showPopup(Window *const parent,
case InventoryType::NPC:
#ifdef EATHENA_SUPPORT
case InventoryType::VENDING:
+ case InventoryType::MAIL:
#endif
case InventoryType::TYPE_END:
default:
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 6d2c72c5c..723f043d7 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -421,6 +421,11 @@ void ItemContainer::mousePressed(MouseEvent &event)
case InventoryType::CART:
src = DRAGDROP_SOURCE_CART;
break;
+#ifdef EATHENA_SUPPORT
+ case InventoryType::MAIL:
+ src = DRAGDROP_SOURCE_MAIL;
+ break;
+#endif
default:
#ifdef EATHENA_SUPPORT
case InventoryType::VENDING:
@@ -520,6 +525,11 @@ void ItemContainer::mouseReleased(MouseEvent &event)
case InventoryType::NPC:
dst = DRAGDROP_SOURCE_NPC;
break;
+#ifdef EATHENA_SUPPORT
+ case InventoryType::MAIL:
+ dst = DRAGDROP_SOURCE_MAIL;
+ break;
+#endif
case InventoryType::CART:
dst = DRAGDROP_SOURCE_CART;
break;
@@ -585,7 +595,8 @@ void ItemContainer::mouseReleased(MouseEvent &event)
inventory = PlayerInfo::getInventory();
}
else if (src == DRAGDROP_SOURCE_INVENTORY
- && dst == DRAGDROP_SOURCE_NPC)
+ && (dst == DRAGDROP_SOURCE_NPC
+ || dst == DRAGDROP_SOURCE_MAIL))
{
inventory = PlayerInfo::getInventory();
const Item *const item = inventory->getItem(dragDrop.getTag());
@@ -603,7 +614,7 @@ void ItemContainer::mouseReleased(MouseEvent &event)
}
return;
}
- else if (src == DRAGDROP_SOURCE_NPC)
+ else if (src == DRAGDROP_SOURCE_NPC || src == DRAGDROP_SOURCE_MAIL)
{
inventory = PlayerInfo::getInventory();
const Item *const item = inventory->getItem(dragDrop.getTag());
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index 28367d2c0..5712bb436 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -120,6 +120,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) :
case InventoryType::NPC:
#ifdef EATHENA_SUPPORT
case InventoryType::VENDING:
+ case InventoryType::MAIL:
#endif
case InventoryType::TYPE_END:
default:
@@ -303,6 +304,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) :
case InventoryType::NPC:
#ifdef EATHENA_SUPPORT
case InventoryType::VENDING:
+ case InventoryType::MAIL:
#endif
case InventoryType::TYPE_END:
break;
@@ -362,6 +364,7 @@ void InventoryWindow::storeSortOrder() const
case InventoryType::NPC:
#ifdef EATHENA_SUPPORT
case InventoryType::VENDING:
+ case InventoryType::MAIL:
#endif
case InventoryType::TYPE_END:
default:
@@ -808,6 +811,7 @@ void InventoryWindow::close()
case InventoryType::NPC:
#ifdef EATHENA_SUPPORT
case InventoryType::VENDING:
+ case InventoryType::MAIL:
#endif
case InventoryType::TYPE_END:
break;
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
index 7198d087a..d1cf9138c 100644
--- a/src/gui/windows/itemamountwindow.cpp
+++ b/src/gui/windows/itemamountwindow.cpp
@@ -35,6 +35,7 @@
#include "gui/popups/itempopup.h"
+#include "gui/windows/mailedit.h"
#include "gui/windows/shopwindow.h"
#include "gui/windows/tradewindow.h"
@@ -93,6 +94,10 @@ void ItemAmountWindow::finish(const Item *const item,
if (shopWindow)
shopWindow->addSellItem(item, amount, price);
break;
+ case MailAdd:
+ if (mailEditWindow)
+ mailEditWindow->addItem(item, amount);
+ break;
default:
break;
}
@@ -234,6 +239,10 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
// TRANSLATORS: amount window message
setCaption(_("Select amount of items to store."));
break;
+ case MailAdd:
+ // TRANSLATORS: amount window message
+ setCaption(_("Select amount of items to send."));
+ break;
case CartAdd:
// TRANSLATORS: amount window message
setCaption(_("Select amount of items to store to cart."));
diff --git a/src/gui/windows/itemamountwindow.h b/src/gui/windows/itemamountwindow.h
index 8ce4f13c6..92d0341e0 100644
--- a/src/gui/windows/itemamountwindow.h
+++ b/src/gui/windows/itemamountwindow.h
@@ -56,7 +56,8 @@ class ItemAmountWindow final : public Window,
CartRemove,
ItemSplit,
ShopBuyAdd,
- ShopSellAdd
+ ShopSellAdd,
+ MailAdd
};
A_DELETE_COPY(ItemAmountWindow)
diff --git a/src/gui/windows/mailedit.cpp b/src/gui/windows/mailedit.cpp
index 14e36063c..ba3972992 100644
--- a/src/gui/windows/mailedit.cpp
+++ b/src/gui/windows/mailedit.cpp
@@ -20,16 +20,24 @@
#include "gui/windows/mailedit.h"
+#include "inventory.h"
+#include "item.h"
+
+#include "being/playerinfo.h"
#include "net/mailhandler.h"
+#include "gui/windows/inventorywindow.h"
+#include "gui/windows/itemamountwindow.h"
#include "gui/windows/setupwindow.h"
#include "gui/widgets/button.h"
#include "gui/widgets/containerplacer.h"
#include "gui/widgets/inttextfield.h"
+#include "gui/widgets/itemcontainer.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/layouttype.h"
+#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textfield.h"
#include "utils/gettext.h"
@@ -37,14 +45,18 @@
#include "debug.h"
+MailEdit *mailEditWindow = nullptr;
+
MailEdit::MailEdit() :
// TRANSLATORS: mail edit window name
- Window(_("Edit mail"), true, nullptr, "mailedit.xml"),
+ Window(_("Edit mail"), false, nullptr, "mailedit.xml"),
ActionListener(),
// TRANSLATORS: mail edit window button
mSendButton(new Button(this, _("Send"), "send", this)),
// TRANSLATORS: mail edit window button
mCloseButton(new Button(this, _("Close"), "close", this)),
+ // TRANSLATORS: mail edit window button
+ mAddButton(new Button(this, _("Add"), "add", this)),
// TRANSLATORS: mail edit window label
mToLabel(new Label(this, _("To:"))),
// TRANSLATORS: mail edit window label
@@ -52,11 +64,17 @@ MailEdit::MailEdit() :
// TRANSLATORS: mail edit window label
mMoneyLabel(new Label(this, _("Money:"))),
// TRANSLATORS: mail edit window label
+ mItemLabel(new Label(this, _("Item:"))),
+ // TRANSLATORS: mail edit window label
mMessageLabel(new Label(this, _("Message:"))),
mToField(new TextField(this)),
mSubjectField(new TextField(this)),
mMoneyField(new IntTextField(this, 0, 0, 10000000)),
- mMessageField(new TextField(this))
+ mMessageField(new TextField(this)),
+ mInventory(new Inventory(InventoryType::MAIL, 1)),
+ mItemContainer(new ItemContainer(this, mInventory)),
+ mItemScrollArea(new ScrollArea(this, mItemContainer,
+ getOptionBool("showitemsbackground"), "mailedit_listbackground.xml"))
{
setWindowName("MailEdit");
setCloseButton(true);
@@ -77,17 +95,26 @@ MailEdit::MailEdit() :
mToField->setWidth(100);
mSubjectField->setWidth(100);
mMessageField->setWidth(100);
+ mItemScrollArea->setHeight(70);
+
+ mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
+ mItemScrollArea->setVerticalScrollPolicy(ScrollArea::SHOW_NEVER);
placer(0, 0, mToLabel);
- placer(1, 0, mToField, 2);
+ placer(1, 0, mToField, 3);
placer(0, 1, mSubjectLabel);
- placer(1, 1, mSubjectField, 2);
+ placer(1, 1, mSubjectField, 3);
placer(0, 2, mMoneyLabel);
- placer(1, 2, mMoneyField, 2);
- placer(0, 3, mMessageLabel);
- placer(1, 3, mMessageField, 2);
- placer(0, 4, mSendButton);
- placer(2, 4, mCloseButton);
+ placer(1, 2, mMoneyField, 3);
+// placer(0, 3, mItemScrollArea, 3);
+ placer(0, 3, mItemLabel);
+ placer(1, 3, mItemScrollArea, 2, 2);
+ placer(3, 4, mAddButton, 1);
+
+ placer(0, 5, mMessageLabel);
+ placer(1, 5, mMessageField, 3);
+ placer(0, 6, mSendButton);
+ placer(3, 6, mCloseButton);
loadWindowState();
enableVisibleSound(true);
@@ -95,6 +122,7 @@ MailEdit::MailEdit() :
MailEdit::~MailEdit()
{
+ mailEditWindow = nullptr;
}
void MailEdit::action(const ActionEvent &event)
@@ -109,8 +137,44 @@ void MailEdit::action(const ActionEvent &event)
const int money = mMoneyField->getValue();
if (money)
mailHandler->setAttachMoney(money);
+ const Item *const tempItem = mInventory->getItem(0);
+ if (tempItem)
+ {
+ const Inventory *const inv = PlayerInfo::getInventory();
+ const Item *const item = inv->findItem(tempItem->getId(), 1);
+ if (item)
+ {
+ mailHandler->setAttach(item->getInvIndex(),
+ tempItem->getQuantity());
+ }
+ }
+
mailHandler->send(mToField->getText(),
mSubjectField->getText(),
mMessageField->getText());
}
+ else if (eventId == "add")
+ {
+ Item *const item = inventoryWindow->getSelectedItem();
+
+ if (!item)
+ return;
+
+ ItemAmountWindow::showWindow(ItemAmountWindow::MailAdd,
+ this, item);
+ }
+}
+
+void MailEdit::addItem(const Item *const item, const int amount)
+{
+ mInventory->addItem(item->getId(),
+ item->getType(),
+ amount,
+ item->getRefine(),
+ item->getColor(),
+ item->getIdentified(),
+ item->getDamaged(),
+ item->getFavorite(),
+ Equipm_false,
+ Equipped_false);
}
diff --git a/src/gui/windows/mailedit.h b/src/gui/windows/mailedit.h
index 5cd482a53..57ae40828 100644
--- a/src/gui/windows/mailedit.h
+++ b/src/gui/windows/mailedit.h
@@ -29,7 +29,11 @@
class Button;
class IntTextField;
+class Inventory;
+class Item;
+class ItemContainer;
class Label;
+class ScrollArea;
class TextField;
class MailEdit final : public Window,
@@ -44,18 +48,27 @@ class MailEdit final : public Window,
void action(const ActionEvent &event) override final;
+ void addItem(const Item *const item, const int amount);
+
private:
Button *mSendButton;
Button *mCloseButton;
+ Button *mAddButton;
Label *mToLabel;
Label *mSubjectLabel;
Label *mMoneyLabel;
+ Label *mItemLabel;
Label *mMessageLabel;
TextField *mToField;
TextField *mSubjectField;
IntTextField *mMoneyField;
TextField *mMessageField;
+ Inventory *mInventory;
+ ItemContainer *mItemContainer;
+ ScrollArea *mItemScrollArea;
};
+extern MailEdit *mailEditWindow;
+
#endif // EATHENA_SUPPORT
#endif // GUI_WINDOWS_MAILEDIT_H
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
index e9933b307..ef6444405 100644
--- a/src/gui/windows/mailwindow.cpp
+++ b/src/gui/windows/mailwindow.cpp
@@ -109,7 +109,8 @@ void MailWindow::action(const ActionEvent &event)
}
else if (eventId == "new")
{
- new MailEdit();
+ if (!mailEditWindow)
+ mailEditWindow = new MailEdit();
}
else if (eventId == "open")
{
@@ -124,6 +125,7 @@ void MailWindow::action(const ActionEvent &event)
void MailWindow::clear()
{
delete_all(mMessages);
+ mMessages.clear();
mMailModel->clear();
mListBox->setSelected(-1);
}