summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-09-03 16:47:48 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-09-03 16:47:48 +0000
commitfe3ecae6936b41045b405fb5055a9ad754ddec3b (patch)
treeadfcc1071e96fb26b08bb9d5d06fda70c03aeff9 /src
parent77efbb50066a030d1f44f8de8d06ace9f284e3a2 (diff)
downloadmana-client-fe3ecae6936b41045b405fb5055a9ad754ddec3b.tar.gz
mana-client-fe3ecae6936b41045b405fb5055a9ad754ddec3b.tar.bz2
mana-client-fe3ecae6936b41045b405fb5055a9ad754ddec3b.tar.xz
mana-client-fe3ecae6936b41045b405fb5055a9ad754ddec3b.zip
Fixed updating of labels in trade window.
Diffstat (limited to 'src')
-rw-r--r--src/gui/selectionlistener.h2
-rw-r--r--src/gui/trade.cpp63
-rw-r--r--src/gui/trade.h10
3 files changed, 40 insertions, 35 deletions
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;