summaryrefslogtreecommitdiff
path: root/src/gui/buy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r--src/gui/buy.cpp69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 7e03c591..c5c37601 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -19,10 +19,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <guichan/widgets/label.hpp>
-
#include "button.h"
#include "buy.h"
+#include "label.h"
#include "scrollarea.h"
#include "shop.h"
#include "shoplistbox.h"
@@ -40,34 +39,39 @@
#include "../utils/strprintf.h"
BuyDialog::BuyDialog(Network *network):
- Window(_("Buy")), mNetwork(network),
+ Window("Buy"), mNetwork(network),
mMoney(0), mAmountItems(0), mMaxItems(0)
{
setWindowName("Buy");
setResizable(true);
+ setCloseButton(true);
setMinWidth(260);
setMinHeight(230);
- setDefaultSize(0, 0, 260, 230);
+ setDefaultSize(260, 230, ImageRect::CENTER);
mShopItems = new ShopItems;
mShopItemList = new ShopListBox(mShopItems, mShopItems);
mScrollArea = new ScrollArea(mShopItemList);
+ mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+
mSlider = new Slider(1.0);
- mQuantityLabel = new gcn::Label("0");
+ mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems));
+ mQuantityLabel->setAlignment(gcn::Graphics::CENTER);
mMoneyLabel = new gcn::Label(strprintf(_("Price: %s / Total: %s"),
"", ""));
+
mIncreaseButton = new Button("+", "+", this);
mDecreaseButton = new Button("-", "-", this);
mBuyButton = new Button(_("Buy"), "buy", this);
mQuitButton = new Button(_("Quit"), "quit", this);
- mItemDescLabel = new gcn::Label(strprintf(_("Description: %s"), ""));
- mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), ""));
+ mAddMaxButton = new Button(_("Max"), "max", this);
+ mItemDescLabel = new Label(strprintf(_("Description: %s"), ""));
+ mItemEffectLabel = new Label(strprintf(_("Effect: %s"), ""));
- mIncreaseButton->setSize(20, 20);
- mDecreaseButton->setSize(20, 20);
+ mDecreaseButton->adjustSize();
+ mDecreaseButton->setWidth(mIncreaseButton->getWidth());
- mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mIncreaseButton->setEnabled(false);
mDecreaseButton->setEnabled(false);
mBuyButton->setEnabled(false);
@@ -77,16 +81,21 @@ BuyDialog::BuyDialog(Network *network):
mSlider->addActionListener(this);
mShopItemList->addSelectionListener(this);
- 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);
+ ContainerPlacer place;
+ place = getPlacer(0, 0);
+
+ place(0, 0, mScrollArea, 8, 5).setPadding(3);
place(0, 5, mDecreaseButton);
- place(1, 5, mIncreaseButton);
- place(3, 5, mBuyButton);
- place(4, 5, mQuitButton);
+ place(1, 5, mSlider, 3);
+ place(4, 5, mIncreaseButton);
+ place(5, 5, mQuantityLabel, 2);
+ place(7, 5, mAddMaxButton);
+ place(0, 6, mMoneyLabel, 8);
+ place(0, 7, mItemEffectLabel, 8);
+ place(0, 8, mItemDescLabel, 8);
+ place(6, 9, mBuyButton);
+ place(7, 9, mQuitButton);
+
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
@@ -127,15 +136,14 @@ void BuyDialog::addItem(int id, int price)
void BuyDialog::action(const gcn::ActionEvent &event)
{
- int selectedItem = mShopItemList->getSelected();
-
if (event.getId() == "quit")
{
- setVisible(false);
- current_npc = 0;
+ close();
return;
}
+ int selectedItem = mShopItemList->getSelected();
+
// The following actions require a valid selection
if (selectedItem < 0 ||
selectedItem >= (int) mShopItems->getNumberOfElements())
@@ -160,6 +168,12 @@ void BuyDialog::action(const gcn::ActionEvent &event)
mSlider->setValue(mAmountItems);
updateButtonsAndLabels();
}
+ else if (event.getId() == "max")
+ {
+ mAmountItems = mMaxItems;
+ mSlider->setValue(mAmountItems);
+ updateButtonsAndLabels();
+ }
// TODO: Actually we'd have a bug elsewhere if this check for the number
// of items to be bought ever fails, Bertram removed the assertions, is
// there a better way to ensure this fails in an _obvious_ way in C++?
@@ -253,5 +267,12 @@ void BuyDialog::setVisible(bool visible)
{
Window::setVisible(visible);
- if (visible) requestFocus();
+ if (visible)
+ requestFocus();
+}
+
+void BuyDialog::close()
+{
+ setVisible(false);
+ current_npc = 0;
}