diff options
Diffstat (limited to 'src/gui/sell.cpp')
-rw-r--r-- | src/gui/sell.cpp | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 591cf97b..e7671110 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -1,9 +1,8 @@ /* - * Aethyra + * The Mana World * Copyright (C) 2004 The Mana World Development Team * - * This file is part of Aethyra based on original code - * from The Mana World. + * This file is part of The Mana World. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,30 +19,44 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "button.h" -#include "label.h" -#include "scrollarea.h" -#include "sell.h" -#include "shop.h" -#include "shoplistbox.h" -#include "slider.h" +#include "gui/sell.h" -#include "widgets/layout.h" +#include "gui/button.h" +#include "gui/label.h" +#include "gui/scrollarea.h" +#include "gui/shop.h" +#include "gui/shoplistbox.h" +#include "gui/slider.h" -#include "../npc.h" +#include "gui/widgets/layout.h" -#include "../net/messageout.h" -#include "../net/protocol.h" +#include "npc.h" +#include "shopitem.h" +#include "units.h" -#include "../utils/gettext.h" -#include "../utils/strprintf.h" +#include "net/messageout.h" +#ifdef TMWSERV_SUPPORT +#include "net/tmwserv/gameserver/player.h" +#else +#include "net/ea/protocol.h" +#endif +#include "resources/iteminfo.h" + +#include "utils/gettext.h" +#include "utils/strprintf.h" + +#ifdef TMWSERV_SUPPORT +SellDialog::SellDialog(): + Window(_("Sell")), +#else SellDialog::SellDialog(Network *network): - Window("Sell"), + Window(_("Sell")), mNetwork(network), +#endif mMaxItems(0), mAmountItems(0) { - setWindowName(_("Sell")); + setWindowName("Sell"); setResizable(true); setCloseButton(true); setMinWidth(260); @@ -61,8 +74,8 @@ SellDialog::SellDialog(Network *network): 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)); + mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"), + "", "")); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); @@ -103,6 +116,7 @@ SellDialog::SellDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } @@ -122,6 +136,16 @@ void SellDialog::reset() updateButtonsAndLabels(); } +#ifdef TMWSERV_SUPPORT + +void SellDialog::addItem(int item, int amount, int price) +{ + mShopItems->addItem(item, amount, price); + mShopItemList->adjustSize(); +} + +#else + void SellDialog::addItem(const Item *item, int price) { if (!item) @@ -133,6 +157,8 @@ void SellDialog::addItem(const Item *item, int price) mShopItemList->adjustSize(); } +#endif + void SellDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "quit") @@ -176,10 +202,14 @@ void SellDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "sell" && mAmountItems > 0 && mAmountItems <= mMaxItems) { +#ifdef TMWSERV_SUPPORT + Net::GameServer::Player::tradeWithNPC + (mShopItems->at(selectedItem)->getId(), mAmountItems); +#else // Attempt sell MessageOut outMsg(mNetwork); - ShopItem* item = mShopItems->at(selectedItem); + ShopItem *item = mShopItems->at(selectedItem); int sellCount; mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); @@ -194,6 +224,7 @@ void SellDialog::action(const gcn::ActionEvent &event) mAmountItems -= sellCount; outMsg.writeInt16(sellCount); } +#endif mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); @@ -275,9 +306,16 @@ void SellDialog::updateButtonsAndLabels() // Update the quantity and money labels mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); - mMoneyLabel->setCaption - (strprintf(_("Price: %d GP / Total: %d GP"), - income, mPlayerMoney + income)); + mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), + Units::formatCurrency(income).c_str(), + Units::formatCurrency(mPlayerMoney + income).c_str())); +} + +void SellDialog::logic() +{ + Window::logic(); + + if (!current_npc) setVisible(false); } void SellDialog::setVisible(bool visible) |