summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-08-19 20:42:46 +0300
committerAndrei Karas <akaras@inbox.ru>2011-08-19 20:42:46 +0300
commit7191eefef8c7a02c7cf56f598ea76fe791328434 (patch)
treed45d89df864f4ea4906e764c0a825a7daf63e3e3 /src/gui
parent05d7793aa71a600d76d169ca80744768b277c17b (diff)
downloadplus-7191eefef8c7a02c7cf56f598ea76fe791328434.tar.gz
plus-7191eefef8c7a02c7cf56f598ea76fe791328434.tar.bz2
plus-7191eefef8c7a02c7cf56f598ea76fe791328434.tar.xz
plus-7191eefef8c7a02c7cf56f598ea76fe791328434.zip
Fix adding items to trade.
Now possible add same items from all ways. Also added protection from adding same stackable items.
Diffstat (limited to 'src/gui')
-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
4 files changed, 31 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
{