From 7191eefef8c7a02c7cf56f598ea76fe791328434 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 19 Aug 2011 20:42:46 +0300 Subject: Fix adding items to trade. Now possible add same items from all ways. Also added protection from adding same stackable items. --- src/gui/inventorywindow.cpp | 2 +- src/gui/popupmenu.cpp | 6 +++--- src/gui/tradewindow.cpp | 33 ++++++++++++++++++++++++--------- src/gui/tradewindow.h | 4 +++- 4 files changed, 31 insertions(+), 14 deletions(-) (limited to 'src/gui') 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 { -- cgit v1.2.3-60-g2f50