summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-06 21:35:19 +0100
committerIra Rice <irarice@gmail.com>2009-01-06 15:03:22 -0700
commitea50de0b56063f3e7c6436422d275ac6e71d0072 (patch)
tree8b6a862e90a313d655e42f543e2a57bc7500a57e /src
parent6ee1046233bfa2218eff1ffa45e31821b3559ea0 (diff)
downloadmana-ea50de0b56063f3e7c6436422d275ac6e71d0072.tar.gz
mana-ea50de0b56063f3e7c6436422d275ac6e71d0072.tar.bz2
mana-ea50de0b56063f3e7c6436422d275ac6e71d0072.tar.xz
mana-ea50de0b56063f3e7c6436422d275ac6e71d0072.zip
Used layout for buy, sell and item amount dialogs
(changes by Guillaume Melquiond, merged from the mainline client)
Diffstat (limited to 'src')
-rw-r--r--src/gui/buy.cpp77
-rw-r--r--src/gui/buy.h8
-rw-r--r--src/gui/item_amount.cpp59
-rw-r--r--src/gui/sell.cpp75
-rw-r--r--src/gui/sell.h5
5 files changed, 61 insertions, 163 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index a3424ab6..0717efa6 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -28,6 +28,8 @@
#include "shoplistbox.h"
#include "slider.h"
+#include "widgets/layout.h"
+
#include "../npc.h"
#include "../net/messageout.h"
@@ -62,7 +64,6 @@ BuyDialog::BuyDialog(Network *network):
mIncreaseButton->setSize(20, 20);
mDecreaseButton->setSize(20, 20);
- mQuantityLabel->setWidth(60);
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mIncreaseButton->setEnabled(false);
@@ -70,22 +71,22 @@ BuyDialog::BuyDialog(Network *network):
mBuyButton->setEnabled(false);
mSlider->setEnabled(false);
- mShopItemList->setActionEventId("item");
mSlider->setActionEventId("slider");
-
- mShopItemList->addSelectionListener(this);
mSlider->addActionListener(this);
+ mShopItemList->addSelectionListener(this);
- add(mScrollArea);
- add(mSlider);
- add(mQuantityLabel);
- add(mBuyButton);
- add(mQuitButton);
- add(mIncreaseButton);
- add(mDecreaseButton);
- add(mMoneyLabel);
- add(mItemDescLabel);
- add(mItemEffectLabel);
+ place(0, 0, mScrollArea, 5).setPadding(3);
+ place(0, 1, mQuantityLabel, 2);
+ place(2, 1, mSlider, 3);
+ place(0, 2, mMoneyLabel, 5);
+ place(0, 3, mItemEffectLabel, 5);
+ place(0, 4, mItemDescLabel, 5);
+ place(0, 5, mDecreaseButton);
+ place(1, 5, mIncreaseButton);
+ place(3, 5, mBuyButton);
+ place(4, 5, mQuitButton);
+ Layout &layout = getLayout();
+ layout.setRowHeight(0, Layout::AUTO_SET);
loadWindowState();
setLocationRelativeTo(getParent());
@@ -191,53 +192,7 @@ void BuyDialog::valueChanged(const gcn::SelectionEvent &event)
mSlider->gcn::Slider::setScale(1, mMaxItems);
}
-void BuyDialog::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
-
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
- const int height = area.height;
-
- mDecreaseButton->setPosition(8, height - 8 - mDecreaseButton->getHeight());
- mIncreaseButton->setPosition(
- mDecreaseButton->getX() + mDecreaseButton->getWidth() + 5,
- mDecreaseButton->getY());
-
- mQuitButton->setPosition(
- width - 8 - mQuitButton->getWidth(),
- height - 8 - mQuitButton->getHeight());
- mBuyButton->setPosition(
- mQuitButton->getX() - 5 - mBuyButton->getWidth(),
- mQuitButton->getY());
-
- mItemDescLabel->setDimension(gcn::Rectangle(8,
- mBuyButton->getY() - 5 - mItemDescLabel->getHeight(),
- width - 16,
- mItemDescLabel->getHeight()));
- mItemEffectLabel->setDimension(gcn::Rectangle(8,
- mItemDescLabel->getY() - 5 - mItemEffectLabel->getHeight(),
- width - 16,
- mItemEffectLabel->getHeight()));
- mMoneyLabel->setDimension(gcn::Rectangle(8,
- mItemEffectLabel->getY() - 5 - mMoneyLabel->getHeight(),
- width - 16,
- mMoneyLabel->getHeight()));
-
- mQuantityLabel->setPosition(
- width - mQuantityLabel->getWidth() - 8,
- mMoneyLabel->getY() - 5 - mQuantityLabel->getHeight());
- mSlider->setDimension(gcn::Rectangle(8,
- mQuantityLabel->getY(),
- mQuantityLabel->getX() - 8 - 8,
- 10));
-
- mScrollArea->setDimension(gcn::Rectangle(8, 8, width - 16,
- mSlider->getY() - 5 - 8));
-}
-
-void
-BuyDialog::updateButtonsAndLabels()
+void BuyDialog::updateButtonsAndLabels()
{
const int selectedItem = mShopItemList->getSelected();
int price = 0;
diff --git a/src/gui/buy.h b/src/gui/buy.h
index 3b94bbaa..7f0f04ac 100644
--- a/src/gui/buy.h
+++ b/src/gui/buy.h
@@ -93,13 +93,7 @@ class BuyDialog : public Window, public gcn::ActionListener,
/**
* Updates the state of buttons and labels.
*/
- void
- updateButtonsAndLabels();
-
- /**
- * Called whenever the widget changes size.
- */
- void widgetResized(const gcn::Event &event);
+ void updateButtonsAndLabels();
private:
Network *mNetwork;
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 191c7b8b..48b0e601 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -25,6 +25,8 @@
#include "slider.h"
#include "trade.h"
+#include "widgets/layout.h"
+
#include "../item.h"
#include "../localplayer.h"
@@ -34,38 +36,37 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
Window("", true, parent),
mItem(item)
{
+ const int maxRange = mItem->getQuantity();
+
// Integer field
mItemAmountTextBox = new IntTextBox(1);
- mItemAmountTextBox->setRange(1, mItem->getQuantity());
+ mItemAmountTextBox->setRange(1, maxRange);
+ mItemAmountTextBox->setWidth(30);
+ mItemAmountTextBox->setActionEventId("Dummy");
+ mItemAmountTextBox->addActionListener(this);
// Slider
- mItemAmountSlide = new Slider(1.0, mItem->getQuantity());
+ mItemAmountSlide = new Slider(1.0, maxRange);
+ mItemAmountSlide->setHeight(10);
mItemAmountSlide->setActionEventId("Slide");
mItemAmountSlide->addActionListener(this);
// Buttons
Button *minusButton = new Button("-", "Minus", this);
+ minusButton->setSize(20, 20);
Button *plusButton = new Button("+", "Plus", this);
+ plusButton->setSize(20, 20);
Button *okButton = new Button(_("Ok"), "Drop", this);
Button *cancelButton = new Button(_("Cancel"), "Cancel", this);
// Set positions
- mItemAmountTextBox->setPosition(35, 10);
- mItemAmountTextBox->setSize(24, 16);
- plusButton->setPosition(60, 5);
- minusButton->setPosition(10, 5);
- mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10));
- mItemAmountSlide->setPosition(10, 35);
- okButton->setPosition(10, 50);
- cancelButton->setPosition(60, 50);
-
- // Assemble
- add(mItemAmountTextBox);
- add(plusButton);
- add(minusButton);
- add(mItemAmountSlide);
- add(okButton);
- add(cancelButton);
+ place(0, 0, minusButton);
+ place(1, 0, mItemAmountTextBox).setPadding(2);
+ place(2, 0, plusButton);
+ place(0, 1, mItemAmountSlide, 6);
+ place(4, 2, okButton);
+ place(5, 2, cancelButton);
+ reflowLayout(250, 0);
resetAmount();
@@ -82,7 +83,6 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
break;
}
- setContentSize(200, 80);
setLocationRelativeTo(getParentWindow());
setVisible(true);
}
@@ -100,16 +100,6 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
{
scheduleDelete();
}
- else if (event.getId() == "Drop")
- {
- player_node->dropItem(mItem, mItemAmountTextBox->getInt());
- scheduleDelete();
- }
- else if (event.getId() == "AddTrade")
- {
- tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt());
- scheduleDelete();
- }
else if (event.getId() == "Plus")
{
amount++;
@@ -122,7 +112,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
{
amount = static_cast<int>(mItemAmountSlide->getValue());
}
+ else if (event.getId() == "Drop")
+ {
+ player_node->dropItem(mItem, mItemAmountTextBox->getInt());
+ scheduleDelete();
+ }
+ else if (event.getId() == "AddTrade")
+ {
+ tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt());
+ scheduleDelete();
+ }
mItemAmountTextBox->setInt(amount);
mItemAmountSlide->setValue(amount);
}
-
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 567fa59c..fac0a0b8 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -30,6 +30,8 @@
#include "shop.h"
#include "slider.h"
+#include "widgets/layout.h"
+
#include "../item.h"
#include "../npc.h"
@@ -70,7 +72,6 @@ SellDialog::SellDialog(Network *network):
mIncreaseButton->setSize(20, 20);
mDecreaseButton->setSize(20, 20);
- mQuantityLabel->setWidth(60);
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mIncreaseButton->setEnabled(false);
@@ -79,23 +80,22 @@ SellDialog::SellDialog(Network *network):
mSlider->setEnabled(false);
mShopItemList->setPriceCheck(false);
- mShopItemList->setActionEventId("item");
- mSlider->setActionEventId("slider");
-
- mShopItemList->addActionListener(this);
mShopItemList->addSelectionListener(this);
+ mSlider->setActionEventId("slider");
mSlider->addActionListener(this);
- add(mScrollArea);
- add(mSlider);
- add(mQuantityLabel);
- add(mMoneyLabel);
- add(mItemEffectLabel);
- add(mItemDescLabel);
- add(mIncreaseButton);
- add(mDecreaseButton);
- add(mSellButton);
- add(mQuitButton);
+ place(0, 0, mScrollArea, 5).setPadding(3);
+ place(0, 1, mQuantityLabel, 2);
+ place(2, 1, mSlider, 3);
+ place(0, 2, mMoneyLabel, 5);
+ place(0, 3, mItemEffectLabel, 5);
+ place(0, 4, mItemDescLabel, 5);
+ place(0, 5, mDecreaseButton);
+ place(1, 5, mIncreaseButton);
+ place(3, 5, mSellButton);
+ place(4, 5, mQuitButton);
+ Layout &layout = getLayout();
+ layout.setRowHeight(0, Layout::AUTO_SET);
loadWindowState();
setLocationRelativeTo(getParent());
@@ -212,51 +212,6 @@ void SellDialog::valueChanged(const gcn::SelectionEvent &event)
mSlider->gcn::Slider::setScale(1, mMaxItems);
}
-void SellDialog::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
-
- gcn::Rectangle area = getChildrenArea();
- int width = area.width;
- int height = area.height;
-
- mDecreaseButton->setPosition(8, height - 8 - mDecreaseButton->getHeight());
- mIncreaseButton->setPosition(
- mDecreaseButton->getX() + mDecreaseButton->getWidth() + 5,
- mDecreaseButton->getY());
-
- mQuitButton->setPosition(
- width - 8 - mQuitButton->getWidth(),
- height - 8 - mQuitButton->getHeight());
- mSellButton->setPosition(
- mQuitButton->getX() - 5 - mSellButton->getWidth(),
- mQuitButton->getY());
-
- mItemDescLabel->setDimension(gcn::Rectangle(8,
- mSellButton->getY() - 5 - mItemDescLabel->getHeight(),
- width - 16,
- mItemDescLabel->getHeight()));
- mItemEffectLabel->setDimension(gcn::Rectangle(8,
- mItemDescLabel->getY() - 5 - mItemEffectLabel->getHeight(),
- width - 16,
- mItemEffectLabel->getHeight()));
- mMoneyLabel->setDimension(gcn::Rectangle(8,
- mItemEffectLabel->getY() - 5 - mMoneyLabel->getHeight(),
- width - 16,
- mMoneyLabel->getHeight()));
-
- mQuantityLabel->setPosition(
- width - mQuantityLabel->getWidth() - 8,
- mMoneyLabel->getY() - 5 - mQuantityLabel->getHeight());
- mSlider->setDimension(gcn::Rectangle(8,
- mQuantityLabel->getY(),
- mQuantityLabel->getX() - 8 - 8,
- 10));
-
- mScrollArea->setDimension(gcn::Rectangle(8, 8, width - 16,
- mSlider->getY() - 5 - 8));
-}
-
void SellDialog::setMoney(int amount)
{
mPlayerMoney = amount;
diff --git a/src/gui/sell.h b/src/gui/sell.h
index 48961efc..0bf8b5a6 100644
--- a/src/gui/sell.h
+++ b/src/gui/sell.h
@@ -77,11 +77,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener
void valueChanged(const gcn::SelectionEvent &event);
/**
- * Called whenever the widget changes size.
- */
- void widgetResized(const gcn::Event &event);
-
- /**
* Gives Player's Money amount
*/
void setMoney(int amount);