summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-15 02:37:23 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-15 02:37:23 +0300
commit5fc61f321cbe6c8f4a4e6529c27603302f3d5eba (patch)
tree7b5561a239e10bb6437b94a681f66c524c4d8d91
parent4761556e5e4cf8471ab65c65c2b3fd4003ac5ba0 (diff)
downloadplus-5fc61f321cbe6c8f4a4e6529c27603302f3d5eba.tar.gz
plus-5fc61f321cbe6c8f4a4e6529c27603302f3d5eba.tar.bz2
plus-5fc61f321cbe6c8f4a4e6529c27603302f3d5eba.tar.xz
plus-5fc61f321cbe6c8f4a4e6529c27603302f3d5eba.zip
Update existing item after inserting card.
-rw-r--r--src/gui/popups/itempopup.cpp5
-rw-r--r--src/gui/popups/itempopup.h2
-rw-r--r--src/item.cpp12
-rw-r--r--src/item.h2
-rw-r--r--src/net/eathena/inventoryhandler.cpp25
5 files changed, 39 insertions, 7 deletions
diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp
index 2374f693b..33b2eba91 100644
--- a/src/gui/popups/itempopup.cpp
+++ b/src/gui/popups/itempopup.cpp
@@ -330,6 +330,11 @@ void ItemPopup::mouseMoved(MouseEvent &event)
// When the mouse moved on top of the popup, hide it
setVisible(Visible_false);
+ resetPopup();
+}
+
+void ItemPopup::resetPopup()
+{
mLastName.clear();
mLastColor = 1;
mLastId = 0;
diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h
index 6072bc90c..fb3feefa2 100644
--- a/src/gui/popups/itempopup.h
+++ b/src/gui/popups/itempopup.h
@@ -68,6 +68,8 @@ class ItemPopup final : public Popup
void mouseMoved(MouseEvent &event) override final;
+ void resetPopup();
+
private:
std::string getCardsString(const int *const cards);
diff --git a/src/item.cpp b/src/item.cpp
index d42a11859..7fa816c86 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -160,3 +160,15 @@ void Item::setCards(const int *const cards, const int size)
for (int f = 0; f < sz; f ++)
mCards[f] = cards[f];
}
+
+void Item::addCard(const int card)
+{
+ for (int f = 0; f < maxCards; f ++)
+ {
+ if (!mCards[f])
+ {
+ mCards[f] = card;
+ return;
+ }
+ }
+}
diff --git a/src/item.h b/src/item.h
index f14258321..815160c32 100644
--- a/src/item.h
+++ b/src/item.h
@@ -211,6 +211,8 @@ class Item notfinal
int getType() const A_WARN_UNUSED
{ return mType; }
+ void addCard(const int card);
+
int mId; /**< Item type id. */
unsigned char mColor;
int mQuantity; /**< Number of items. */
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp
index c73425874..015ff3c2c 100644
--- a/src/net/eathena/inventoryhandler.cpp
+++ b/src/net/eathena/inventoryhandler.cpp
@@ -30,6 +30,8 @@
#include "enums/resources/notifytypes.h"
+#include "gui/popups/itempopup.h"
+
#include "gui/widgets/createwidget.h"
#include "gui/windows/insertcarddialog.h"
@@ -810,7 +812,7 @@ void InventoryHandler::processPlayerUseCard(Net::MessageIn &msg)
void InventoryHandler::processPlayerInsertCard(Net::MessageIn &msg)
{
- msg.readInt16("item index");
+ const int itemIndex = msg.readInt16("item index") - INVENTORY_OFFSET;
const int cardIndex = msg.readInt16("card index") - INVENTORY_OFFSET;
if (msg.readUInt8("flag"))
{
@@ -820,12 +822,21 @@ void InventoryHandler::processPlayerInsertCard(Net::MessageIn &msg)
{
NotifyManager::notify(NotifyTypes::CARD_INSERT_SUCCESS);
Inventory *const inv = PlayerInfo::getInventory();
- Item *const item = inv->getItem(cardIndex);
- if (!item)
- return;
- item->increaseQuantity(-1);
- if (item->getQuantity() == 0)
- inv->removeItemAt(cardIndex);
+ Item *const card = inv->getItem(cardIndex);
+ int cardId = 0;
+ if (card)
+ {
+ cardId = card->getId();
+ card->increaseQuantity(-1);
+ if (card->getQuantity() == 0)
+ inv->removeItemAt(cardIndex);
+ }
+ Item *const item = inv->getItem(itemIndex);
+ if (item)
+ {
+ item->addCard(cardId);
+ itemPopup->resetPopup();
+ }
}
}