summaryrefslogtreecommitdiff
path: root/src/gui/sell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/sell.cpp')
-rw-r--r--src/gui/sell.cpp74
1 files changed, 47 insertions, 27 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index e1b15bac..fe391636 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -19,9 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <guichan/widgets/label.hpp>
-
#include "button.h"
+#include "label.h"
#include "scrollarea.h"
#include "sell.h"
#include "shop.h"
@@ -46,30 +45,36 @@ SellDialog::SellDialog(Network *network):
{
setWindowName("Sell");
setResizable(true);
+ setCloseButton(true);
setMinWidth(260);
setMinHeight(230);
- setDefaultSize(0, 0, 260, 230);
+ setDefaultSize(260, 230, ImageRect::CENTER);
// Create a ShopItems instance, that is aware of duplicate entries.
mShopItems = new ShopItems(true);
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");
- mMoneyLabel = new gcn::Label(strprintf(_("Price: %s / Total: %s"),
- "", ""));
+
+ mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems));
+ mQuantityLabel->setAlignment(gcn::Graphics::CENTER);
+ mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"),
+ "", ""));
+
mIncreaseButton = new Button("+", "+", this);
mDecreaseButton = new Button("-", "-", this);
mSellButton = new Button(_("Sell"), "sell", 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);
mSellButton->setEnabled(false);
@@ -80,16 +85,21 @@ SellDialog::SellDialog(Network *network):
mSlider->setActionEventId("slider");
mSlider->addActionListener(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, mSellButton);
- 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, mSellButton);
+ place(7, 9, mQuitButton);
+
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
@@ -116,9 +126,7 @@ void SellDialog::reset()
void SellDialog::addItem(const Item *item, int price)
{
if (!item)
- {
return;
- }
mShopItems->addItem(item->getInvIndex(), item->getId(),
item->getQuantity(), price);
@@ -128,15 +136,14 @@ void SellDialog::addItem(const Item *item, int price)
void SellDialog::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 item selection
if (selectedItem == -1 ||
selectedItem >= (int) mShopItems->getNumberOfElements())
@@ -161,6 +168,12 @@ void SellDialog::action(const gcn::ActionEvent &event)
mSlider->setValue(mAmountItems);
updateButtonsAndLabels();
}
+ else if (event.getId() == "max")
+ {
+ mAmountItems = mMaxItems;
+ mSlider->setValue(mAmountItems);
+ updateButtonsAndLabels();
+ }
else if (event.getId() == "sell" && mAmountItems > 0
&& mAmountItems <= mMaxItems)
{
@@ -279,5 +292,12 @@ void SellDialog::setVisible(bool visible)
{
Window::setVisible(visible);
- if (visible) requestFocus();
+ if (visible)
+ requestFocus();
+}
+
+void SellDialog::close()
+{
+ setVisible(false);
+ current_npc = 0;
}