From e36c735ce6569cd9c0e668632e59bcbe3280d507 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 11 Jul 2013 20:49:20 +0300 Subject: Add chat command for gms for creating items. New command: /createitems It will open creation window. --- src/gui/buydialog.cpp | 30 +++++++++++++++++++++++++----- src/gui/buydialog.h | 9 +++++++++ src/gui/itemamountwindow.cpp | 2 +- src/gui/textcommandeditor.cpp | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp index a6d56e220..6c9cc0bd7 100644 --- a/src/gui/buydialog.cpp +++ b/src/gui/buydialog.cpp @@ -37,6 +37,7 @@ #include "gui/widgets/shoplistbox.h" #include "gui/widgets/slider.h" +#include "net/adminhandler.h" #include "net/buysellhandler.h" #include "net/net.h" #include "net/npchandler.h" @@ -188,6 +189,18 @@ class SortItemTypeFunctor final BuyDialog::DialogList BuyDialog::instances; +BuyDialog::BuyDialog() : + // TRANSLATORS: buy dialog name + Window(_("Create items"), false, nullptr, "buy.xml"), + gcn::ActionListener(), + gcn::SelectionListener(), + mNpcId(0), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(), + mSortModel(nullptr), + mSortDropDown(nullptr) +{ + init(); +} + BuyDialog::BuyDialog(const int npcId) : // TRANSLATORS: buy dialog name Window(_("Buy"), false, nullptr, "buy.xml"), @@ -210,7 +223,6 @@ BuyDialog::BuyDialog(std::string nick) : mSortDropDown(new DropDown(this, mSortModel, false, false, this, "sort")) { init(); - logger->log("BuyDialog::BuyDialog nick:" + mNick); } void BuyDialog::init() @@ -255,7 +267,8 @@ void BuyDialog::init() // You may change this symbol if your language uses another. mDecreaseButton = new Button(this, _("-"), "dec", this); // TRANSLATORS: buy dialog button - mBuyButton = new Button(this, _("Buy"), "buy", this); + mBuyButton = new Button(this, mNpcId == 0 + ? _("Create") :_("Buy"), "buy", this); // TRANSLATORS: buy dialog button mQuitButton = new Button(this, _("Quit"), "quit", this); // TRANSLATORS: buy dialog button @@ -420,7 +433,13 @@ void BuyDialog::action(const gcn::ActionEvent &event) } else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems) { - if (mNpcId != -1) + if (!mNpcId) + { + const ShopItem *const item = mShopItems->at(selectedItem); + Net::getAdminHandler()->createItems(item->getId(), + mAmountItems, item->getColor()); + } + else if (mNpcId != -1) { const ShopItem *const item = mShopItems->at(selectedItem); Net::getNpcHandler()->buyItem(mNpcId, item->getId(), @@ -444,7 +463,6 @@ void BuyDialog::action(const gcn::ActionEvent &event) { Net::getBuySellHandler()->sendBuyRequest(mNick, item, mAmountItems); -// logger->log("buy button mNick:" + mNick); if (tradeWindow) { tradeWindow->addAutoMoney(mNick, @@ -480,7 +498,9 @@ void BuyDialog::updateButtonsAndLabels() const int itemPrice = item->getPrice(); // Calculate how many the player can afford - if (itemPrice) + if (!mNpcId) + mMaxItems = 100; + else if (itemPrice) mMaxItems = mMoney / itemPrice; else mMaxItems = 1; diff --git a/src/gui/buydialog.h b/src/gui/buydialog.h index 35cc2d8db..875184851 100644 --- a/src/gui/buydialog.h +++ b/src/gui/buydialog.h @@ -49,6 +49,13 @@ class BuyDialog final : public Window, public gcn::SelectionListener { public: + /** + * Constructor. + * + * @see Window::Window + */ + BuyDialog(); + /** * Constructor. * @@ -58,6 +65,8 @@ class BuyDialog final : public Window, /** * Constructor. + * + * @see Window::Window */ explicit BuyDialog(std::string nick); diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp index 3df003bfb..61760f6d3 100644 --- a/src/gui/itemamountwindow.cpp +++ b/src/gui/itemamountwindow.cpp @@ -53,7 +53,7 @@ public: ItemsModal() : mStrings() { - std::map items = ItemDB::getItemInfos(); + const std::map &items = ItemDB::getItemInfos(); std::list tempStrings; for (std::map::const_iterator diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp index 449196ed8..029089704 100644 --- a/src/gui/textcommandeditor.cpp +++ b/src/gui/textcommandeditor.cpp @@ -57,7 +57,7 @@ public: IconsModal() : mStrings() { - std::map items = ItemDB::getItemInfos(); + const std::map &items = ItemDB::getItemInfos(); std::list tempStrings; for (std::map::const_iterator -- cgit v1.2.3-70-g09d2