diff options
-rw-r--r-- | The Mana World.dev | 22 | ||||
-rw-r--r-- | file.list | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/game.cpp | 21 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 61 | ||||
-rw-r--r-- | src/graphic/graphic.h | 2 | ||||
-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 |
12 files changed, 296 insertions, 76 deletions
diff --git a/The Mana World.dev b/The Mana World.dev index 797f3b93..837dc128 100644 --- a/The Mana World.dev +++ b/The Mana World.dev @@ -1,7 +1,7 @@ [Project] FileName=The Mana World.dev Name=tmw -UnitCount=74 +UnitCount=76 Type=0 Ver=1 ObjFiles= @@ -812,3 +812,23 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit77] +FileName=src\gui\buysell.cpp +CompileCpp=1 +Folder=gui +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit78] +FileName=src\gui\buysell.h +CompileCpp=1 +Folder=gui +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + @@ -18,6 +18,7 @@ MODULES = src/sound/sound.cpp \ src/gui/progressbar.cpp \ src/gui/radiobutton.cpp \ src/gui/scrollarea.cpp \ + src/gui/sell.cpp \ src/gui/setup.cpp \ src/gui/shop.cpp \ src/gui/skill.cpp \ diff --git a/src/Makefile.am b/src/Makefile.am index 052050fc..5a935d68 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ tmw_SOURCES = sound/sound.cpp \ gui/progressbar.cpp \ gui/radiobutton.cpp \ gui/scrollarea.cpp \ + gui/sell.cpp \ gui/setup.cpp \ gui/shop.cpp \ gui/skill.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 1ca1b35f..94abec3a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -759,13 +759,20 @@ void do_parse() { break; // Sell dialog case 0x00c7: - n_items = (len-4)/10; - if(n_items>0) { - show_npc_dialog = 4; - for(int k=0;k<n_items;k++) - add_sell_item(RFIFOW(4+10*k), RFIFOL(4+10*k+2)); - } else chatlog.chat_log("Nothing to sell", BY_SERVER, font); - break; + n_items = (len - 4) / 10; + if (n_items > 0) { + sellDialog->reset(); + sellDialog->setVisible(true); + for (int k = 0; k < n_items; k++) { + sellDialog->addItem( + RFIFOW(4 + 10 * k), RFIFOL(4 + 10 * k + 2)); + //add_sell_item(RFIFOW(4 + 10 * k), RFIFOL(4 + 10 * k + 2)); + } + } + else { + chatlog.chat_log("Nothing to sell", BY_SERVER, font); + } + break; // Answer to buy case 0x00ca: if(RFIFOB(2)==0) diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index 2635a194..cc450d33 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -43,6 +43,7 @@ gcn::TextField *chatInput; StatusWindow *statusWindow; BuyDialog *buyDialog; +SellDialog *sellDialog; BuySellDialog *buySellDialog; InventoryWindow *inventoryWindow; @@ -87,18 +88,6 @@ DIALOG npc_dialog[] = { { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; - -DIALOG sell_dialog[] = { - /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ - { tmw_dialog_proc, 300, 200, 260, 200, 0, 0, 0, 0, 0, 0, (char *)"Sell", NULL, NULL }, - { tmw_button_proc, 450, 376, 50, 20, 255, 0, 'o', D_EXIT, 0, 0, (char *)"&Ok", NULL, NULL }, - { tmw_button_proc, 508, 376, 50, 20, 255, 0, 'c', D_EXIT, 0, 0, (char *)"&Cancel", NULL, NULL }, - { tmw_slider_proc, 304, 326, 200, 20, 255, 0, 0, 0, 10, 0, NULL, (void *)changeQ, NULL }, - { tmw_list_proc, 304, 224, 252, 100, 0, 0, 0, 0, 0, 0, (char *)shop_list, NULL, NULL }, - { tmw_text_proc, 514, 326, 40, 20, 0, 0, 0, 0, 0, 0, (char *)itemCurrenyQ, NULL, NULL }, - { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } -}; - DIALOG skill_list_dialog[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ { tmw_dialog_proc, 300, 200, 260, 200, 0, 0, 0, 0, 0, 0, (char *)"Stats", NULL, NULL }, @@ -201,6 +190,9 @@ GraphicEngine::GraphicEngine() { buyDialog = new BuyDialog(guiTop); buyDialog->setVisible(false); + sellDialog = new SellDialog(guiTop); + sellDialog->setVisible(false); + buySellDialog = new BuySellDialog(guiTop, new BuySellListener()); buySellDialog->setVisible(false); @@ -211,7 +203,6 @@ GraphicEngine::GraphicEngine() { npc_player = init_dialog(npc_dialog, -1); position_dialog(npc_dialog, 300, 200); skill_player = init_dialog(skill_dialog, -1); - sell_player = init_dialog(sell_dialog, -1); skill_list_player = init_dialog(skill_list_dialog, -1); npc_list_player = init_dialog(npc_list_dialog, -1); @@ -235,6 +226,8 @@ GraphicEngine::GraphicEngine() { GraphicEngine::~GraphicEngine() { delete statusWindow; delete buyDialog; + delete sellDialog; + delete buySellDialog; //delete tileset; @@ -463,13 +456,6 @@ void GraphicEngine::refresh() { } node = node->next; } - - // Update character status display - statusWindow->update(); - - // Update GUI - guiGraphics->setTarget(buffer); - gui_update(NULL); set_trans_blender(0, 0, 0, 110); draw_trans_sprite(buffer, chat_background, 0, SCREEN_H - 125); @@ -486,27 +472,6 @@ void GraphicEngine::refresh() { WFIFOSET(6); } break; - case 4: - sell_dialog[3].d1 = get_item_quantity(sell_dialog[4].d1); - - dialog_message(sell_dialog, MSG_DRAW, 0, 0); - if (!gui_update(sell_player)) { - show_npc_dialog = shutdown_dialog(sell_player); - sell_dialog[3].d1 = 0; - if (show_npc_dialog == 1) { - WFIFOW(0) = net_w_value(0x00c9); - WFIFOW(2) = net_w_value(8); - WFIFOW(4) = net_w_value(get_item_index(sell_dialog[4].d1)); - WFIFOW(6) = net_w_value(sell_dialog[3].d2); - WFIFOSET(8); - } - show_npc_dialog = 0; - sell_dialog[3].d2 = 0; - sprintf((char *)sell_dialog[5].dp, "%i", 0); - sell_player = init_dialog(sell_dialog, -1); - close_shop(); - } - break; case 5: dialog_message(npc_list_dialog, MSG_DRAW, 0, 0); if (!gui_update(npc_list_player)) { @@ -548,10 +513,16 @@ void GraphicEngine::refresh() { } } - draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); - + // Update character status display + statusWindow->update(); + + // Update GUI + guiGraphics->setTarget(buffer); + gui_update(NULL); + textprintf_ex(buffer, font, 0, 0, makecol(255, 255, 255), -1, - "[%i fps] %i,%i", fps, mouse_x/32+camera_x, mouse_y/32+camera_y); - + "[%i fps] %i,%i", fps, + mouse_x / 32 + camera_x, mouse_y / 32 + camera_y); + blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index 3a4cfe07..40a6d107 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -26,6 +26,7 @@ #include "../map.h" #include "../being.h" #include "../gui/buy.h" +#include "../gui/sell.h" #include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/inventory.h" @@ -54,6 +55,7 @@ extern char npc_button[10]; extern StatusWindow *statusWindow; extern BuyDialog *buyDialog; +extern SellDialog *sellDialog; extern BuySellDialog *buySellDialog; extern InventoryWindow *inventoryWindow; 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]; } |