diff options
author | Ira Rice <irarice@gmail.com> | 2009-03-19 20:20:11 -0600 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-03-19 20:20:11 -0600 |
commit | abffda81e5bab1fbf4870238e803bb5bae9d0df0 (patch) | |
tree | 661e6d5de6bc258b5fc2366bc5f46b0d73a7bdf6 /src/gui/buy.cpp | |
parent | abeaa1184ae1f30adeeb6684748b3cf8e3f16b11 (diff) | |
download | mana-abffda81e5bab1fbf4870238e803bb5bae9d0df0.tar.gz mana-abffda81e5bab1fbf4870238e803bb5bae9d0df0.tar.bz2 mana-abffda81e5bab1fbf4870238e803bb5bae9d0df0.tar.xz mana-abffda81e5bab1fbf4870238e803bb5bae9d0df0.zip |
Reformatted the item amount window and the buy/sell windows so that
their guis are similarly laid out.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r-- | src/gui/buy.cpp | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index ea1df204..c2c8cfed 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -22,6 +22,7 @@ #include "button.h" #include "buy.h" +#include "gui.h" #include "label.h" #include "scrollarea.h" #include "shop.h" @@ -39,11 +40,12 @@ #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(260, 230, ImageRect::CENTER); @@ -52,20 +54,25 @@ BuyDialog::BuyDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mSlider = new Slider(1.0); - mQuantityLabel = new Label("0"); + + mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); + mQuantityLabel->setAlignment(gcn::Graphics::CENTER); mMoneyLabel = new Label(strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); + mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); mBuyButton = new Button(_("Buy"), "buy", this); mQuitButton = new Button(_("Quit"), "quit", this); + 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); + mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mBuyButton->setEnabled(false); @@ -75,16 +82,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); @@ -124,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()) @@ -157,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++? @@ -241,5 +258,12 @@ void BuyDialog::setVisible(bool visible) { Window::setVisible(visible); - if (visible) requestFocus(); + if (visible) + requestFocus(); +} + +void BuyDialog::close() +{ + setVisible(false); + current_npc = 0; } |