summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/inventorywindow.cpp2
-rw-r--r--src/gui/popupmenu.cpp6
-rw-r--r--src/gui/tradewindow.cpp33
-rw-r--r--src/gui/tradewindow.h4
-rw-r--r--src/inventory.cpp3
5 files changed, 34 insertions, 14 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 27fbf7760..3b7b7b273 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -427,7 +427,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
else
{
if (tradeWindow)
- tradeWindow->tradeItem(item, item->getQuantity());
+ tradeWindow->tradeItem(item, item->getQuantity(), true);
}
}
}
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index a7c008684..eefa83500 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -1066,18 +1066,18 @@ void PopupMenu::handleLink(const std::string &link,
int cnt = 10;
if (cnt > mItem->getQuantity())
cnt = mItem->getQuantity();
- tradeWindow->tradeItem(mItem, cnt);
+ tradeWindow->tradeItem(mItem, cnt, true);
}
}
else if (link == "addtrade half" && mItem)
{
if (tradeWindow)
- tradeWindow->tradeItem(mItem, mItem->getQuantity() / 2);
+ tradeWindow->tradeItem(mItem, mItem->getQuantity() / 2, true);
}
else if (link == "addtrade all" && mItem)
{
if (tradeWindow)
- tradeWindow->tradeItem(mItem, mItem->getQuantity());
+ tradeWindow->tradeItem(mItem, mItem->getQuantity(), true);
}
else if (link == "retrieve" && mItem)
{
diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp
index c607636d9..d00fb61f4 100644
--- a/src/gui/tradewindow.cpp
+++ b/src/gui/tradewindow.cpp
@@ -246,8 +246,11 @@ void TradeWindow::receivedOk(bool own)
}
}
-void TradeWindow::tradeItem(Item *item, int quantity)
+void TradeWindow::tradeItem(Item *item, int quantity, bool check)
{
+ if (check && !checkItem(item))
+ return;
+
Net::getTradeHandler()->addItem(item, quantity);
}
@@ -325,15 +328,9 @@ void TradeWindow::action(const gcn::ActionEvent &event)
if (mMyInventory->getFreeSlot() == -1)
return;
- if (mMyInventory->contains(item))
- {
- if (localChatTab)
- {
- localChatTab->chatLog(_("Failed adding item. You can not "
- "overlap one kind of item on the window."), BY_SERVER);
- }
+
+ if (!checkItem(item))
return;
- }
// Choose amount of items to trade
ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, this, item);
@@ -442,3 +439,21 @@ void TradeWindow::initTrade(std::string nick)
if (!player_relations.isGoodName(nick))
setCaptionFont(gui->getSecureFont());
}
+
+bool TradeWindow::checkItem(Item *item)
+{
+ Item *tradeItem = mMyInventory->findItem(
+ item->getId(), item->getColor());
+
+ if (tradeItem && (tradeItem->getQuantity() > 1
+ || item->getQuantity() > 1))
+ {
+ if (localChatTab)
+ {
+ localChatTab->chatLog(_("Failed adding item. You can not "
+ "overlap one kind of item on the window."), BY_SERVER);
+ }
+ return false;
+ }
+ return true;
+}
diff --git a/src/gui/tradewindow.h b/src/gui/tradewindow.h
index 3c5ed56b0..16b3d9d6f 100644
--- a/src/gui/tradewindow.h
+++ b/src/gui/tradewindow.h
@@ -95,7 +95,7 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener
/**
* Send trade packet.
*/
- void tradeItem(Item *item, int quantity);
+ void tradeItem(Item *item, int quantity, bool check = false);
/**
* Updates the labels and makes sure only one item is selected in
@@ -131,6 +131,8 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener
std::string getAutoTradeNick()
{ return mAutoAddToNick; }
+ bool checkItem(Item *item);
+
private:
enum Status
{
diff --git a/src/inventory.cpp b/src/inventory.cpp
index acd35efdd..f907b2cc2 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -155,6 +155,9 @@ void Inventory::removeItemAt(int index)
bool Inventory::contains(Item *item) const
{
+ if (!item)
+ return false;
+
for (unsigned i = 0; i < mSize; i++)
{
if (mItems[i] && mItems[i]->getId() == item->getId())