diff options
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r-- | src/gui/buy.cpp | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index cc2262ec..15a558a3 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -1,29 +1,28 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright (C) 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 + * 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 * 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, + * This program 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 + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "buy.h" - #include <guichan/widgets/label.hpp> #include "button.h" +#include "buy.h" #include "scrollarea.h" #include "shop.h" #include "shoplistbox.h" @@ -32,12 +31,27 @@ #include "widgets/layout.h" #include "../npc.h" +#include "../units.h" + +#ifdef TMWSERV_SUPPORT #include "../net/gameserver/player.h" +#else +#include "../net/messageout.h" +#include "../net/ea/protocol.h" +#endif + #include "../utils/gettext.h" #include "../utils/strprintf.h" +#ifdef TMWSERV_SUPPORT BuyDialog::BuyDialog(): +#else +BuyDialog::BuyDialog(Network *network): +#endif Window(_("Buy")), +#ifndef TMWSERV_SUPPORT + mNetwork(network), +#endif mMoney(0), mAmountItems(0), mMaxItems(0) { setWindowName("Buy"); @@ -52,7 +66,8 @@ BuyDialog::BuyDialog(): mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label(strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); + mMoneyLabel = new gcn::Label(strprintf(_("Price: %s / Total: %s"), + "", "")); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); mBuyButton = new Button(_("Buy"), "buy", this); @@ -128,7 +143,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - current_npc = 0; + if (current_npc) current_npc->handleDeath(); return; } @@ -162,8 +177,16 @@ void BuyDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems) { +#ifdef TMWSERV_SUPPORT Net::GameServer::Player::tradeWithNPC (mShopItems->at(selectedItem)->getId(), mAmountItems); +#else + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_REQUEST); + outMsg.writeInt16(8); + outMsg.writeInt16(mAmountItems); + outMsg.writeInt16(mShopItems->at(selectedItem)->getId()); +#endif // Update money and adjust the max number of items that can be bought mMaxItems -= mAmountItems; @@ -230,5 +253,7 @@ void BuyDialog::updateButtonsAndLabels() // Update quantity and money labels mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); mMoneyLabel->setCaption - (strprintf(_("Price: %d GP / Total: %d GP"), price, mMoney - price)); + (strprintf(_("Price: %s / Total: %s"), + Units::formatCurrency(price).c_str(), + Units::formatCurrency(mMoney - price).c_str())); } |