From a9a1ed080289185cc5e71a127d7fdf35c920de8a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:03:30 -0600 Subject: Exposed a few more windows to the reset button on the setup window. These windows required an external declaration to reset. Signed-off-by: Ira Rice --- src/gui/buy.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gui/buy.h') diff --git a/src/gui/buy.h b/src/gui/buy.h index 9029fe9d..17ab6e19 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -117,4 +117,6 @@ class BuyDialog : public Window, public gcn::ActionListener, Uint32 mMaxItems; }; +extern BuyDialog *buyDialog; + #endif -- cgit v1.2.3-60-g2f50 From 6f0d88e781c8b1a75858c769b3641aa8cd477314 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 14:20:14 -0600 Subject: Fix up the NPC interraction widnows a bit --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 1 + src/gui/buysell.cpp | 16 +++++++++++++++- src/gui/buysell.h | 10 ++++++++++ src/gui/item_amount.cpp | 24 ++++++++++++------------ src/gui/npcstringdialog.cpp | 2 -- src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 1 + src/gui/storagewindow.h | 4 ++++ src/gui/trade.cpp | 27 ++++++++++++++------------- src/gui/trade.h | 13 ++++++------- src/gui/window.cpp | 2 +- src/net/buysellhandler.cpp | 7 ++----- src/net/playerhandler.cpp | 5 +---- 14 files changed, 81 insertions(+), 45 deletions(-) (limited to 'src/gui/buy.h') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 367a041e..ea1df204 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -236,3 +236,10 @@ void BuyDialog::updateButtonsAndLabels() mMoneyLabel->setCaption (strprintf(_("Price: %d GP / Total: %d GP"), price, mMoney - price)); } + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 17ab6e19..08697889 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,6 +96,7 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + void setVisible(bool visible); private: Network *mNetwork; gcn::Button *mBuyButton; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 64ffdc3f..df222797 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -54,8 +54,22 @@ BuySellDialog::BuySellDialog(Network *network): getTitleBarHeight()), ImageRect::CENTER); loadWindowState(); +} + +void BuySellDialog::logic() +{ + Window::logic(); + + if (isVisible() && !current_npc) + setVisible(false); +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); - requestFocus(); + if (visible) + requestFocus(); } void BuySellDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 0842c0e1..c6989709 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -46,6 +46,16 @@ class BuySellDialog : public Window, public gcn::ActionListener BuySellDialog(Network *network); /** +<<<<<<< HEAD:src/gui/buysell.h +======= + * Check for current NPC + */ + void logic(); + + void setVisible(bool visible); + + /** +>>>>>>> f64903f... Fix up the NPC interraction widnows a bit:src/gui/buysell.h * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8208d323..c5b27524 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,7 +36,9 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item), mUsage(usage), mMax(mItem->getQuantity()) + mItem(item), + mMax(item->getQuantity()), + mUsage(usage) { // Integer field mItemAmountTextField = new IntTextField(1); @@ -53,10 +55,8 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): // 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 *okButton = new Button(_("Ok"), "Ok", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); @@ -64,10 +64,10 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); - place(4, 0, addAllButton, 2); + place(5, 0, addAllButton); place(0, 1, mItemAmountSlide, 6); - place(4, 2, okButton); - place(5, 2, cancelButton); + place(4, 2, cancelButton); + place(5, 2, okButton); reflowLayout(250, 0); resetAmount(); @@ -101,17 +101,17 @@ void ItemAmountWindow::resetAmount() void ItemAmountWindow::action(const gcn::ActionEvent &event) { - int amount = mItemAmountTextField->getValue(); + int amount = mItemAmountSlide->getValue(); if (event.getId() == "Cancel") { scheduleDelete(); } - else if (event.getId() == "Plus") + else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus") + else if (event.getId() == "Minus" && amount > 0) { amount--; } @@ -121,9 +121,8 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "Ok" || event.getId() == "All") { - if (event.getId() == "All") { + if (event.getId() == "All") amount = mMax; - } switch (mUsage) { @@ -145,6 +144,7 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } scheduleDelete(); + return; } mItemAmountTextField->setValue(amount); diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f50136ba..43d0722f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,9 +64,7 @@ void NpcStringDialog::setValue(const std::string &value) void NpcStringDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "cancel") - { mValueField->setText(""); - } setVisible(false); NPC::mTalking = false; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b780b02b..ed023227 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -265,3 +265,10 @@ void SellDialog::updateButtonsAndLabels() (strprintf(_("Price: %d GP / Total: %d GP"), income, mPlayerMoney + income)); } + +void SellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index 5fb94c4e..c67a25b9 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,6 +82,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + void setVisible(bool visible); private: /** * Updates the state of buttons and labels. diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 86451bfe..8f02a618 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -80,6 +80,10 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void removeStore(Item* item, int ammount); + /** + * Closes the Storage Window, as well as telling the server that the + * window has been closed. + */ void close(); private: diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index bae0b651..18b86d4b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -54,6 +54,7 @@ TradeWindow::TradeWindow(Network *network): setWindowName(_("Trade")); setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); + setCloseButton(true); setMinWidth(342); setMinHeight(209); @@ -90,10 +91,10 @@ TradeWindow::TradeWindow(Network *network): place(0, 0, mMoneyLabel2); place(1, 0, mMoneyField); place = getPlacer(0, 2); - place(0, 0, mAddButton); - place(1, 0, mOkButton); - place(2, 0, mTradeButton); - place(3, 0, mCancelButton); + place(4, 0, mCancelButton); + place(5, 0, mTradeButton); + place(6, 0, mAddButton); + place(7, 0, mOkButton); Layout &layout = getLayout(); layout.extend(0, 2, 2, 1); layout.setRowHeight(1, Layout::AUTO_SET); @@ -108,14 +109,6 @@ TradeWindow::~TradeWindow() { } -void TradeWindow::widgetResized(const gcn::Event &event) -{ - mMyItemContainer->setWidth(mMyScroll->getWidth()); - mPartnerItemContainer->setWidth(mPartnerScroll->getWidth()); - - Window::widgetResized(event); -} - void TradeWindow::addMoney(int amount) { mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); @@ -212,6 +205,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { + addItem(item->getId(), true, quantity, item->isEquipment()); MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); @@ -249,7 +243,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (mMyInventory->contains(item)) { chatWindow->chatLog(_("Failed adding item. You can not " - "overlap one kind of item on the window."), BY_SERVER); + "overlap one kind of item on the window."), + BY_SERVER); return; } @@ -295,3 +290,9 @@ void TradeWindow::action(const gcn::ActionEvent &event) outMsg.writeInt16(CMSG_TRADE_OK); } } + +void TradeWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); +} diff --git a/src/gui/trade.h b/src/gui/trade.h index f4a6b5cd..c4d3076a 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -56,13 +56,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ ~TradeWindow(); - /** - * Called when resizing the window. - * - * @param event The calling event - */ - void widgetResized(const gcn::Event &event); - /** * Add money to the trade window. */ @@ -119,6 +112,12 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void action(const gcn::ActionEvent &event); + /** + * Closes the Trade Window, as well as telling the server that the + * window has been closed. + */ + void close(); + private: Network *mNetwork; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 404f5746..13c8f4ce 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -536,7 +536,7 @@ void Window::loadWindowState() void Window::saveWindowState() { // Saving X, Y and Width and Height for resizables in the config - if (!mWindowName.empty()) + if (!mWindowName.empty() && mWindowName != "window") { config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 5b8f0b68..287e5400 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -33,15 +33,12 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/sell.h" #include "../utils/gettext.h" -extern BuyDialog *buyDialog; -extern Window *buySellDialog; -extern SellDialog *sellDialog; - BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { @@ -65,8 +62,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) buyDialog->reset(); sellDialog->setVisible(false); sellDialog->reset(); - buySellDialog->setVisible(true); current_npc = msg->readInt32(); + buySellDialog->setVisible(true); break; case SMSG_NPC_BUY: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 6533ac1e..60d58a37 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -30,6 +30,7 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/gui.h" #include "../gui/npc_text.h" @@ -49,10 +50,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; -extern Window *buySellDialog; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -- cgit v1.2.3-60-g2f50 From abffda81e5bab1fbf4870238e803bb5bae9d0df0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:20:11 -0600 Subject: Reformatted the item amount window and the buy/sell windows so that their guis are similarly laid out. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 62 ++++++++++++++++++++++++++++------------- src/gui/buy.h | 9 ++++++ src/gui/gui.cpp | 5 ++++ src/gui/gui.h | 5 ++++ src/gui/inventorywindow.cpp | 2 +- src/gui/item_amount.cpp | 48 ++++++++++++++++++++------------ src/gui/item_amount.h | 7 ++++- src/gui/npcintegerdialog.cpp | 5 ++-- src/gui/sell.cpp | 66 +++++++++++++++++++++++++++++--------------- src/gui/sell.h | 9 ++++++ 10 files changed, 156 insertions(+), 62 deletions(-) (limited to 'src/gui/buy.h') 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; } diff --git a/src/gui/buy.h b/src/gui/buy.h index 08697889..ffd3f5c9 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,11 +96,20 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + /** + * Sets the visibility of this window. + */ void setVisible(bool visible); + + /** + * Closes the Buy Window, as well as resetting the current npc. + */ + void close(); private: Network *mNetwork; gcn::Button *mBuyButton; gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 434fc1e1..5bdab453 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -241,3 +241,8 @@ void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput) gcn::Gui::handleMouseMoved(mouseInput); mMouseInactivityTimer = 0; } + +const int Gui::getFontHeight() const +{ + return mGuiFont->getHeight(); +} diff --git a/src/gui/gui.h b/src/gui/gui.h index afa358be..609648fd 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -77,6 +77,11 @@ class Gui : public gcn::Gui gcn::Font* getFont() const { return mGuiFont; } + /** + * Return game font height. + */ + const int getFontHeight() const; + /** * Return the Font used for "Info Particles", i.e. ones showing, what * you picked up, etc. diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 98916c07..f6e81fc5 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -99,7 +99,7 @@ InventoryWindow::InventoryWindow(int invSize): place(6, 5, mUseButton); Layout &layout = getLayout(); - layout.setRowHeight(0, mDropButton->getHeight()); + layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); } diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index c5b27524..5a7cf18f 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -21,8 +21,9 @@ */ #include "button.h" -#include "inttextfield.h" +#include "gui.h" #include "item_amount.h" +#include "label.h" #include "slider.h" #include "storagewindow.h" #include "trade.h" @@ -33,6 +34,7 @@ #include "../localplayer.h" #include "../utils/gettext.h" +#include "../utils/strprintf.h" ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), @@ -40,12 +42,12 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): mMax(item->getQuantity()), mUsage(usage) { + setCloseButton(true); + // Integer field - mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, mMax); - mItemAmountTextField->setWidth(30); - mItemAmountTextField->setActionEventId("Dummy"); - mItemAmountTextField->addActionListener(this); + + mItemAmountLabel = new Label(strprintf("%d / %d", 1, mMax)); + mItemAmountLabel->setAlignment(gcn::Graphics::CENTER); // Slider mItemAmountSlide = new Slider(1.0, mMax); @@ -60,15 +62,22 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); + minusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + plusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + // Set positions + ContainerPlacer place; + place = getPlacer(0, 0); + place(0, 0, minusButton); - place(1, 0, mItemAmountTextField).setPadding(2); - place(2, 0, plusButton); - place(5, 0, addAllButton); - place(0, 1, mItemAmountSlide, 6); - place(4, 2, cancelButton); - place(5, 2, okButton); - reflowLayout(250, 0); + place(1, 0, mItemAmountSlide, 3); + place(4, 0, plusButton); + place(5, 0, mItemAmountLabel, 2); + place(7, 0, addAllButton); + place = getPlacer(0, 1); + place(4, 0, cancelButton); + place(5, 0, okButton); + reflowLayout(225, 0); resetAmount(); @@ -96,7 +105,7 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): void ItemAmountWindow::resetAmount() { - mItemAmountTextField->setValue(1); + mItemAmountLabel->setCaption(strprintf("%d / %d", 1, mMax)); } void ItemAmountWindow::action(const gcn::ActionEvent &event) @@ -105,13 +114,13 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) if (event.getId() == "Cancel") { - scheduleDelete(); + close(); } else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus" && amount > 0) + else if (event.getId() == "Minus" && amount > 1) { amount--; } @@ -147,6 +156,11 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) return; } - mItemAmountTextField->setValue(amount); + mItemAmountLabel->setCaption(strprintf("%d / %d", amount, mMax)); mItemAmountSlide->setValue(amount); } + +void ItemAmountWindow::close() +{ + scheduleDelete(); +} diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index b802f71c..34b33b37 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -58,8 +58,13 @@ class ItemAmountWindow : public Window, public gcn::ActionListener */ void resetAmount(); + /** + * Schedules the Item Amount window for deletion. + */ + void close(); + private: - IntTextField *mItemAmountTextField; /**< Item amount caption. */ + gcn::Label *mItemAmountLabel; /**< Item amount caption. */ Item *mItem; int mMax, mUsage; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 5b3e05aa..5332d196 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,6 +21,7 @@ */ #include "button.h" +#include "gui.h" #include "inttextfield.h" #include "npcintegerdialog.h" @@ -47,8 +48,8 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): cancelButton = new Button(_("Cancel"), "cancel", this); resetButton = new Button(_("Reset"), "reset", this); - mDecButton->setSize(20, 20); - mIncButton->setSize(20, 20); + mIncButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecButton->setSize(gui->getFontHeight(), gui->getFontHeight()); ContainerPlacer place; place = getPlacer(0, 0); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index ed023227..47e44ffe 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,6 +21,7 @@ */ #include "button.h" +#include "gui.h" #include "label.h" #include "scrollarea.h" #include "sell.h" @@ -39,12 +40,13 @@ #include "../utils/strprintf.h" SellDialog::SellDialog(Network *network): - Window(_("Sell")), + Window("Sell"), mNetwork(network), mMaxItems(0), mAmountItems(0) { - setWindowName("Sell"); + setWindowName(_("Sell")); setResizable(true); + setCloseButton(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); @@ -54,21 +56,26 @@ SellDialog::SellDialog(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); mSellButton = new Button(_("Sell"), "sell", 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); mSellButton->setEnabled(false); @@ -79,16 +86,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); @@ -114,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); @@ -126,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()) @@ -159,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) { @@ -270,5 +285,12 @@ void SellDialog::setVisible(bool visible) { Window::setVisible(visible); - if (visible) requestFocus(); + if (visible) + requestFocus(); +} + +void SellDialog::close() +{ + setVisible(false); + current_npc = 0; } diff --git a/src/gui/sell.h b/src/gui/sell.h index c67a25b9..930f8bc1 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,7 +82,15 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + /** + * Sets the visibility of this window. + */ void setVisible(bool visible); + + /** + * Closes the Buy Window, as well as resetting the current npc. + */ + void close(); private: /** * Updates the state of buttons and labels. @@ -92,6 +100,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener Network *mNetwork; gcn::Button *mSellButton; gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; -- cgit v1.2.3-60-g2f50