diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-28 21:36:49 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-28 21:36:49 +0000 |
commit | d9b0d3ec1d3af85bfe35a7dd5d4d2ee2a9fb8331 (patch) | |
tree | 2322671cc5455a0b4ded770ba3291873e181413c /src/gui | |
parent | c6213e58858a1fbe3c28ca79ed5a5c32976fac1f (diff) | |
download | mana-d9b0d3ec1d3af85bfe35a7dd5d4d2ee2a9fb8331.tar.gz mana-d9b0d3ec1d3af85bfe35a7dd5d4d2ee2a9fb8331.tar.bz2 mana-d9b0d3ec1d3af85bfe35a7dd5d4d2ee2a9fb8331.tar.xz mana-d9b0d3ec1d3af85bfe35a7dd5d4d2ee2a9fb8331.zip |
Ported sell dialog to Guichan.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/buy.h | 4 | ||||
-rw-r--r-- | src/gui/sell.cpp | 145 | ||||
-rw-r--r-- | src/gui/sell.h | 93 | ||||
-rw-r--r-- | src/gui/shop.cpp | 19 | ||||
-rw-r--r-- | src/gui/shop.h | 1 | ||||
-rw-r--r-- | src/gui/stats.cpp | 2 |
6 files changed, 241 insertions, 23 deletions
diff --git a/src/gui/buy.h b/src/gui/buy.h index 0926c52e..c58f5248 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -40,14 +40,14 @@ class BuyDialog : public Window, public gcn::ActionListener, { public: /** - * Constructor + * Constructor. * * @see Window::Window */ BuyDialog(gcn::Container *parent); /** - * Destructor + * Destructor. */ ~BuyDialog(); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp new file mode 100644 index 00000000..f807d1c4 --- /dev/null +++ b/src/gui/sell.cpp @@ -0,0 +1,145 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "sell.h" +#include "button.h" +#include "slider.h" +#include "scrollarea.h" +#include "../graphic/graphic.h" + +#include <sstream> + +SellDialog::SellDialog(gcn::Container *parent): + Window(parent, "Sell") +{ + itemList = new gcn::ListBox(this); + scrollArea = new ScrollArea(itemList); + slider = new Slider(1.0); + quantityLabel = new gcn::Label("0"); + okButton = new Button("OK"); + cancelButton = new Button("Cancel"); + + setSize(260, 175); + scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); + slider->setDimension(gcn::Rectangle(5, 120, 200, 10)); + quantityLabel->setPosition(215, 120); + okButton->setPosition(180, 145); + cancelButton->setPosition(208, 145); + + itemList->setEventId("item"); + slider->setEventId("slider"); + okButton->setEventId("ok"); + cancelButton->setEventId("cancel"); + + itemList->addActionListener(this); + slider->addActionListener(this); + okButton->addActionListener(this); + cancelButton->addActionListener(this); + + add(scrollArea); + add(slider); + add(quantityLabel); + add(okButton); + add(cancelButton); + + setLocationRelativeTo(getParent()); +} + +SellDialog::~SellDialog() +{ + delete cancelButton; + delete okButton; + delete slider; + delete itemList; + delete scrollArea; +} + +void SellDialog::reset() +{ + shopInventory.clear(); +} + +void SellDialog::addItem(short index, int price) +{ + int id = inventoryWindow->items[index].id; + ITEM_SHOP item_shop; + + if (id >= 501 && id <= 511) { + sprintf(item_shop.name, "%s %i gp", item_db[id - 501], price); + } + else { + sprintf(item_shop.name, "Unknown item %i gp", price); + } + item_shop.price = price; + item_shop.index = index; + item_shop.id = id; + item_shop.quantity = inventoryWindow->items[index].quantity; + + shopInventory.push_back(item_shop); + itemList->adjustSize(); +} + +void SellDialog::action(const std::string& eventId) +{ + int selectedItem = itemList->getSelected(); + + if (eventId == "slider" || eventId == "item") { + if (selectedItem > -1) { + int maxItems = shopInventory[selectedItem].quantity; + std::stringstream ss; + + ss << (int)(slider->getValue() * maxItems); + quantityLabel->setCaption(ss.str()); + quantityLabel->adjustSize(); + } + } + else if (eventId == "ok") { + if (selectedItem > -1) { + // Attempt sell + int maxItems = shopInventory[selectedItem].quantity; + int amount = (int)(slider->getValue() * maxItems); + + if (amount > 0) { + WFIFOW(0) = net_w_value(0x00c9); + WFIFOW(2) = net_w_value(8); + WFIFOW(4) = net_w_value(shopInventory[selectedItem].index); + WFIFOW(6) = net_w_value(amount); + WFIFOSET(8); + } + } + setVisible(false); + } + else if (eventId == "cancel") { + setVisible(false); + } +} + +int SellDialog::getNumberOfElements() +{ + return shopInventory.size(); +} + +std::string SellDialog::getElementAt(int i) +{ + return shopInventory[i].name; +} diff --git a/src/gui/sell.h b/src/gui/sell.h new file mode 100644 index 00000000..610d1aca --- /dev/null +++ b/src/gui/sell.h @@ -0,0 +1,93 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_SELL_H +#define _TMW_SELL_H + +#include "gui.h" +#include "window.h" +#include "shop.h" + +#include <vector> + +/** + * The sell dialog. + * + * \ingroup GUI + */ +class SellDialog : public Window, public gcn::ActionListener, + public gcn::ListModel +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + SellDialog(gcn::Container *parent); + + /** + * Destructor. + */ + ~SellDialog(); + + /** + * Resets the dialog, clearing inventory. + */ + void reset(); + + /** + * Adds an item to the inventory. + */ + void addItem(short id, int price); + + /** + * Called when receiving actions from the widgets. + */ + void action(const std::string& eventId); + + /** + * Returns the number of items in the inventory. + */ + int getNumberOfElements(); + + /** + * Returns the name of item number i in the inventory. + */ + std::string getElementAt(int i); + + private: + gcn::Button *okButton; + gcn::Button *cancelButton; + gcn::ListBox *itemList; + gcn::ScrollArea *scrollArea; + gcn::Label *moneyLabel; + gcn::Label *quantityLabel; + gcn::Slider *slider; + + std::vector<ITEM_SHOP> shopInventory; + + int maxItems; +}; + +#endif diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index 4cdfd9f4..c7bf5967 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -48,25 +48,6 @@ char *shop_list(int index, int *list_size) { } } -void add_buy_item(short id, int price) { - ITEM_SHOP *item_shop = (ITEM_SHOP *)malloc(sizeof(ITEM_SHOP)); - if(id-501>=0 && id-501<=11) - sprintf(item_shop->name, "%s %i gp", item_db[id-501], price); - else - sprintf(item_shop->name, "Unknown item %i gp", price); - item_shop->price = price; - item_shop->id = id; - item_shop->next = NULL; - if(shop==NULL) - shop = item_shop; - else { - ITEM_SHOP *temp = shop; - while(temp->next) - temp = temp->next; - temp->next = item_shop; - } -} - void add_sell_item(short index, int price) { int id = inventoryWindow->items[index].id; ITEM_SHOP *item_shop = (ITEM_SHOP *)malloc(sizeof(ITEM_SHOP)); diff --git a/src/gui/shop.h b/src/gui/shop.h index 70b24b4e..2a1af602 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -45,7 +45,6 @@ extern char itemCurrenyQ[10]; extern char *item_db[]; char *shop_list(int index, int *list_size); -void add_buy_item(short id, int price); void add_sell_item(short index, int price); void changeQ(void *dp3, int d2); void close_shop(); diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp index e5d84821..eebfab70 100644 --- a/src/gui/stats.cpp +++ b/src/gui/stats.cpp @@ -82,7 +82,7 @@ void StatsWindow::update(){ } StatsWindow::~StatsWindow() { - for(int i = 0; i < 6; i++) { + for (int i = 0; i < 6; i++) { delete statsLabel[i]; delete statsButton[i]; } |