summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-21 18:16:33 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-21 23:18:46 +0300
commitb1e41be0a3f87f42f8bab2416a8f1ce432f95fe2 (patch)
tree000809beac3bd1602c9b3aefc1f0c36b407b5eac
parentecff5b8d9e74a7e8549d59596e62e4ff2807c796 (diff)
downloadmv-b1e41be0a3f87f42f8bab2416a8f1ce432f95fe2.tar.gz
mv-b1e41be0a3f87f42f8bab2416a8f1ce432f95fe2.tar.bz2
mv-b1e41be0a3f87f42f8bab2416a8f1ce432f95fe2.tar.xz
mv-b1e41be0a3f87f42f8bab2416a8f1ce432f95fe2.zip
Improve shopwindow class.
-rw-r--r--src/gui/shopwindow.cpp21
-rw-r--r--src/gui/shopwindow.h12
2 files changed, 16 insertions, 17 deletions
diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp
index 5b131fd55..d7fcc2a60 100644
--- a/src/gui/shopwindow.cpp
+++ b/src/gui/shopwindow.cpp
@@ -207,8 +207,7 @@ void ShopWindow::action(const gcn::ActionEvent &event)
close();
return;
}
-
- if (eventId == "yes")
+ else if (eventId == "yes")
{
startTrade();
}
@@ -285,7 +284,7 @@ void ShopWindow::startTrade()
if (!actorSpriteManager || !tradeWindow)
return;
- Being *const being = actorSpriteManager->findBeingByName(
+ const Being *const being = actorSpriteManager->findBeingByName(
mTradeNick, Being::PLAYER);
tradeWindow->clear();
if (mTradeMoney)
@@ -363,7 +362,7 @@ void ShopWindow::loadList()
mBuyShopItems->clear();
mSellShopItems->clear();
- std::string shopListName = Client::getServerConfigDirectory()
+ const std::string shopListName = Client::getServerConfigDirectory()
+ "/shoplist.txt";
if (!stat(shopListName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
@@ -378,11 +377,10 @@ void ShopWindow::loadList()
while (shopFile.getline(line, 100))
{
std::string buf;
- std::string str = line;
+ const std::string str = line;
if (!str.empty())
{
std::vector<int> tokens;
-
std::stringstream ss(str);
while (ss >> buf)
@@ -408,13 +406,13 @@ void ShopWindow::loadList()
}
}
-void ShopWindow::saveList()
+void ShopWindow::saveList() const
{
if (!mBuyShopItems || !mSellShopItems)
return;
std::ofstream shopFile;
- std::string shopListName = Client::getServerConfigDirectory()
+ const std::string shopListName = Client::getServerConfigDirectory()
+ "/shoplist.txt";
std::map<int, ShopItem*> mapItems;
@@ -684,7 +682,7 @@ void ShopWindow::showList(const std::string &nick, std::string data) const
}
}
-void ShopWindow::processRequest(std::string nick, std::string data,
+void ShopWindow::processRequest(const std::string &nick, std::string data,
const int mode)
{
if (!player_node || !mTradeNick.empty() || PlayerInfo::isTrading()
@@ -793,7 +791,7 @@ void ShopWindow::updateTimes()
BLOCK_END("ShopWindow::updateTimes")
}
-bool ShopWindow::checkFloodCounter(int &counterTime) const
+bool ShopWindow::checkFloodCounter(int &counterTime)
{
if (!counterTime || counterTime > cur_time)
counterTime = cur_time;
@@ -804,7 +802,8 @@ bool ShopWindow::checkFloodCounter(int &counterTime) const
return true;
}
-bool ShopWindow::findShopItem(const ShopItem *const shopItem, const int mode)
+bool ShopWindow::findShopItem(const ShopItem *const shopItem,
+ const int mode) const
{
if (!shopItem)
return false;
diff --git a/src/gui/shopwindow.h b/src/gui/shopwindow.h
index 9b7e64572..e35a6cc90 100644
--- a/src/gui/shopwindow.h
+++ b/src/gui/shopwindow.h
@@ -85,7 +85,7 @@ class ShopWindow final : public Window, public gcn::ActionListener,
/**
* Sets the visibility of this window.
*/
- void setVisible(bool visible);
+ void setVisible(bool visible) override;
/**
* Returns true if any instances exist.
@@ -104,13 +104,13 @@ class ShopWindow final : public Window, public gcn::ActionListener,
void loadList();
- void saveList();
+ void saveList() const;
void announce(ShopItems *const list, const int mode);
void giveList(const std::string &nick, const int mode);
- void setAcceptPlayer(std::string name)
+ void setAcceptPlayer(const std::string &name)
{ mAcceptPlayer = name; }
const std::string &getAcceptPlayer() const A_WARN_UNUSED
@@ -121,17 +121,17 @@ class ShopWindow final : public Window, public gcn::ActionListener,
void showList(const std::string &nick, std::string data) const;
- void processRequest(std::string nick, std::string data,
+ void processRequest(const std::string &nick, std::string data,
const int mode);
bool findShopItem(const ShopItem *const shopItem,
- const int mode) A_WARN_UNUSED;
+ const int mode) const A_WARN_UNUSED;
static int sumAmount(const Item *const shopItem) A_WARN_UNUSED;
void updateTimes();
- bool checkFloodCounter(int &counterTime) const A_WARN_UNUSED;
+ static bool checkFloodCounter(int &counterTime) A_WARN_UNUSED;
bool isShopEmpty() const A_WARN_UNUSED;