summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--src/gui/selectionlistener.h2
-rw-r--r--src/gui/trade.cpp63
-rw-r--r--src/gui/trade.h10
4 files changed, 42 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 703e1f47..d8ab42fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@
also be used to fix similar problem in trade, buy and sell dialogs).
Made the ItemInfo be passed around as a reference instead of a pointer,
since it is never NULL.
+ * src/gui/trade.cpp, src/gui/trade.h: Fixed updating of labels in
+ trade window.
2006-09-02 Bernard Lidicky <bernard@matfyz.cz>
diff --git a/src/gui/selectionlistener.h b/src/gui/selectionlistener.h
index e01b0c2f..b39672b5 100644
--- a/src/gui/selectionlistener.h
+++ b/src/gui/selectionlistener.h
@@ -18,7 +18,7 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: itemcontainer.h 2545 2006-08-17 19:11:28Z crush_tmw $
+ * $Id$
*/
#ifndef _TMW_SELECTIONLISTENER_H__
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index babb5a87..cb839157 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -59,12 +59,14 @@ TradeWindow::TradeWindow(Network *network):
mTradeButton = new Button("Trade", "trade", this);
mMyItemContainer = new ItemContainer(mMyInventory.get());
+ mMyItemContainer->addSelectionListener(this);
mMyItemContainer->setPosition(2, 2);
mMyScroll = new ScrollArea(mMyItemContainer);
mMyScroll->setPosition(8, 8);
mPartnerItemContainer = new ItemContainer(mPartnerInventory.get());
+ mPartnerItemContainer->addSelectionListener(this);
mPartnerItemContainer->setPosition(2, 58);
mPartnerScroll = new ScrollArea(mPartnerItemContainer);
@@ -221,53 +223,54 @@ void TradeWindow::tradeItem(Item *item, int quantity)
outMsg.writeInt32(quantity);
}
-void TradeWindow::mouseClick(int x, int y, int button, int count)
+void TradeWindow::selectionChanged(const SelectionEvent &event)
{
- Window::mouseClick(x, y, button, count);
-
Item *item;
- // mMyItems selected
- if (x >= mMyScroll->getX() + 3
- && x <= mMyScroll->getX() + mMyScroll->getWidth() - 10
- && y >= mMyScroll->getY() + 16
- && y <= mMyScroll->getY() + mMyScroll->getHeight() + 15
- && (item = mMyItemContainer->getItem()))
+ /* If an item is selected in one container, make sure no item is selected
+ * in the other container.
+ */
+ if (event.getSource() == mMyItemContainer &&
+ (item = mMyItemContainer->getItem()))
{
- mPartnerItemContainer->selectNone();
- // mPartnerItems selected
+ mPartnerItemContainer->selectNone();
}
- else if (x >= mPartnerScroll->getX() + 3
- && x <= mPartnerScroll->getX() + mPartnerScroll->getWidth() - 20
- && y >= mPartnerScroll->getY() + 16
- && y <= mPartnerScroll->getY() + mPartnerScroll->getHeight() + 15
- && (item = mPartnerItemContainer->getItem()))
+ else if ((item = mPartnerItemContainer->getItem()))
{
- mMyItemContainer->selectNone();
- } else {
- return;
+ mMyItemContainer->selectNone();
}
- // Show Name and Description
- std::string SomeText;
- SomeText = "Name: " + item->getInfo().getName();
- mItemNameLabel->setCaption(SomeText);
- mItemNameLabel->adjustSize();
- SomeText = "Description: " + item->getInfo().getDescription();
- mItemDescriptionLabel->setCaption(SomeText);
- mItemDescriptionLabel->adjustSize();
+ // Update name and description
+ if (!item)
+ {
+ mItemNameLabel->setCaption("Name:");
+ mItemDescriptionLabel->setCaption("Description:");
+ }
+ else
+ {
+ std::string SomeText;
+ SomeText = "Name: " + item->getInfo().getName();
+ mItemNameLabel->setCaption(SomeText);
+ mItemNameLabel->adjustSize();
+ SomeText = "Description: " + item->getInfo().getDescription();
+ mItemDescriptionLabel->setCaption(SomeText);
+ mItemDescriptionLabel->adjustSize();
+ }
}
void TradeWindow::action(const std::string& eventId, gcn::Widget* widget)
{
Item *item = inventoryWindow->getItem();
- if (eventId == "add") {
- if (!item) {
+ if (eventId == "add")
+ {
+ if (!item)
+ {
return;
}
- if (mMyInventory->getFreeSlot() < 1) {
+ if (mMyInventory->getFreeSlot() < 1)
+ {
return;
}
diff --git a/src/gui/trade.h b/src/gui/trade.h
index eb3c0f97..339fc4e3 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -29,6 +29,7 @@
#include <guichan/actionlistener.hpp>
#include "window.h"
+#include "selectionlistener.h"
#include "../guichanfwd.h"
@@ -43,7 +44,7 @@ class ScrollArea;
*
* \ingroup Interface
*/
-class TradeWindow : public Window, gcn::ActionListener
+class TradeWindow : public Window, gcn::ActionListener, SelectionListener
{
public:
/**
@@ -103,14 +104,15 @@ class TradeWindow : public Window, gcn::ActionListener
tradeItem(Item *item, int quantity);
/**
- * Called on mouse click.
+ * Updates the labels and makes sure only one item is selected in
+ * either my inventory or partner inventory.
*/
- void mouseClick(int x, int y, int button, int count);
+ void selectionChanged(const SelectionEvent &event);
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId, gcn::Widget* widget);
+ void action(const std::string &eventId, gcn::Widget *widget);
private:
Network *mNetwork;