summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/being.cpp12
-rw-r--r--src/configuration.cpp7
-rw-r--r--src/engine.cpp17
-rw-r--r--src/gui/buy.cpp18
-rw-r--r--src/gui/char_select.cpp24
-rw-r--r--src/gui/char_server.cpp9
-rw-r--r--src/gui/debugwindow.cpp35
-rw-r--r--src/gui/debugwindow.h7
-rw-r--r--src/gui/equipmentwindow.cpp7
-rw-r--r--src/gui/inttextbox.cpp16
-rw-r--r--src/gui/inventorywindow.cpp10
-rw-r--r--src/gui/itemcontainer.cpp16
-rw-r--r--src/gui/ministatus.cpp11
-rw-r--r--src/gui/register.cpp2
-rw-r--r--src/gui/sell.cpp18
-rw-r--r--src/gui/setup_video.cpp11
-rw-r--r--src/gui/status.cpp109
-rw-r--r--src/gui/tabbedcontainer.cpp17
-rw-r--r--src/gui/trade.cpp16
-rw-r--r--src/gui/updatewindow.cpp9
-rw-r--r--src/log.cpp20
-rw-r--r--src/main.cpp7
-rw-r--r--src/monster.cpp12
-rw-r--r--src/net/chathandler.cpp8
-rw-r--r--src/utils/tostring.h37
26 files changed, 202 insertions, 254 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index eaf3662d..e4fef745 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -180,6 +180,7 @@ tmw_SOURCES = graphic/spriteset.cpp \
resources/buddylist.h \
resources/buddylist.cpp \
utils/dtor.h \
+ utils/tostring.h \
base64.cpp \
base64.h \
being.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index 5ee8276c..a74efe5f 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -22,8 +22,6 @@
*/
#include "being.h"
-#include <sstream>
-
#include "game.h"
#include "graphics.h"
#include "log.h"
@@ -33,6 +31,8 @@
#include "gui/gui.h"
+#include "utils/tostring.h"
+
extern Spriteset *emotionset;
PATH_NODE::PATH_NODE(Uint16 iX, Uint16 iY):
@@ -120,13 +120,7 @@ Being::setSpeech(const std::string &text, Uint32 time)
void
Being::setDamage(Sint16 amount, Uint32 time)
{
- if (!amount) {
- mDamage = "miss";
- } else {
- std::stringstream damageString;
- damageString << amount;
- mDamage = damageString.str();
- }
+ mDamage = amount ? toString(amount) : "miss";
mDamageTime = tick_time;
mShowDamage = true;
}
diff --git a/src/configuration.cpp b/src/configuration.cpp
index aa63f46c..4085b20b 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -24,12 +24,13 @@
#include "configuration.h"
-#include <sstream>
#include <libxml/xmlwriter.h>
#include "configlistener.h"
#include "log.h"
+#include "utils/tostring.h"
+
void Configuration::init(const std::string &filename)
{
mConfigPath = filename;
@@ -127,9 +128,7 @@ void Configuration::setValue(const std::string &key, std::string value)
void Configuration::setValue(const std::string &key, float value)
{
- std::stringstream ss;
- ss << ((value == (int)value) ? (int)value : value);
- setValue(key, ss.str());
+ setValue(key, toString((value == (int)value) ? (int)value : value));
}
std::string Configuration::getValue(const std::string &key, std::string deflt)
diff --git a/src/engine.cpp b/src/engine.cpp
index 3be152bd..8d78a078 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -24,7 +24,6 @@
#include "engine.h"
#include <list>
-#include <sstream>
#include "being.h"
#include "beingmanager.h"
@@ -51,6 +50,7 @@
#include "resources/resourcemanager.h"
#include "utils/dtor.h"
+#include "utils/tostring.h"
extern Minimap *minimap;
@@ -80,10 +80,8 @@ Engine::Engine(Network *network):
30, 32);
for (int i = 0; i < 2; i++)
{
- std::stringstream filename;
- filename << "graphics/sprites/weapon" << i << ".png";
Spriteset *tmp = ResourceManager::getInstance()->createSpriteset(
- filename.str(), 64, 64);
+ "graphics/sprites/weapon" + toString(i) + ".png", 64, 64);
if (!tmp) {
logger->error("Unable to load weaponset");
} else {
@@ -218,15 +216,12 @@ void Engine::draw(Graphics *graphics)
{
int squareX = i->x * 32 - map_x + 12;
int squareY = i->y * 32 - map_y + 12;
+
graphics->setColor(gcn::Color(255, 0, 0));
graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8));
-
- MetaTile *tile = mCurrentMap->getMetaTile(i->x, i->y);
-
- std::stringstream cost;
- cost << tile->Gcost;
- graphics->drawText(cost.str(), squareX + 4, squareY + 12,
- gcn::Graphics::CENTER);
+ graphics->drawText(
+ toString(mCurrentMap->getMetaTile(i->x, i->y)->Gcost),
+ squareX + 4, squareY + 12, gcn::Graphics::CENTER);
}
}
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 18542385..86bd5413 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -23,8 +23,6 @@
#include "buy.h"
-#include <sstream>
-
#include <guichan/widgets/label.hpp>
#include "button.h"
@@ -41,6 +39,8 @@
#include "../net/messageout.h"
#include "../net/protocol.h"
+#include "../utils/tostring.h"
+
BuyDialog::BuyDialog(Network *network):
Window("Buy"), mNetwork(network),
@@ -139,10 +139,8 @@ void BuyDialog::reset()
void BuyDialog::addItem(short id, int price)
{
ITEM_SHOP item_shop;
- std::stringstream ss;
- ss << itemDb->getItemInfo(id)->getName() << " " << price << " GP";
- item_shop.name = ss.str();
+ item_shop.name = itemDb->getItemInfo(id)->getName() + " " + toString(price) + " GP";
item_shop.price = price;
item_shop.id = id;
@@ -242,21 +240,17 @@ void BuyDialog::action(const std::string& eventId)
// If anything has changed, we have to update the buttons and labels
if (updateButtonsAndLabels) {
- std::stringstream oss;
-
// Update buttons
mIncreaseButton->setEnabled(mAmountItems < mMaxItems);
mDecreaseButton->setEnabled(mAmountItems > 0);
mBuyButton->setEnabled(mAmountItems > 0);
// Update labels
- oss << mAmountItems;
- mQuantityLabel->setCaption(oss.str());
+ mQuantityLabel->setCaption(toString(mAmountItems));
mQuantityLabel->adjustSize();
- oss.str("");
- oss << "Price : " << mAmountItems * mShopItems->at(selectedItem).price << " GP";
- mMoneyLabel->setCaption(oss.str());
+ int price = mAmountItems * mShopItems->at(selectedItem).price;
+ mMoneyLabel->setCaption("Price : " + toString(price) + " GP");
mMoneyLabel->adjustSize();
}
}
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index b1d08951..40c1d145 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -23,7 +23,6 @@
#include "char_select.h"
-#include <sstream>
#include <string>
#include <guichan/widgets/label.hpp>
@@ -40,6 +39,8 @@
#include "../net/messageout.h"
+#include "./utils/tostring.h"
+
/**
* Listener for confirming character deletion.
*/
@@ -69,7 +70,8 @@ void CharDeleteConfirm::action(const std::string &eventId)
}
CharSelectDialog::CharSelectDialog(Network *network, LockedArray<LocalPlayer*> *charInfo):
- Window("Select Character"), mNetwork(network), mCharInfo(charInfo), mCharSelected(false)
+ Window("Select Character"), mNetwork(network),
+ mCharInfo(charInfo), mCharSelected(false)
{
mSelectButton = new Button("Ok", "ok", this);
mCancelButton = new Button("Cancel", "cancel", this);
@@ -171,17 +173,10 @@ void CharSelectDialog::updatePlayerInfo()
LocalPlayer *pi = mCharInfo->getEntry();
if (pi) {
- std::stringstream nameCaption, levelCaption, jobCaption, moneyCaption;
-
- nameCaption << pi->getName();
- levelCaption << "Lvl: " << pi->mLevel;
- jobCaption << "Job Lvl: " << pi->mJobLevel;
- moneyCaption << "Gold: " << pi->mGp;
-
- mNameLabel->setCaption(nameCaption.str());
- mLevelLabel->setCaption(levelCaption.str());
- mJobLevelLabel->setCaption(jobCaption.str());
- mMoneyLabel->setCaption(moneyCaption.str());
+ mNameLabel->setCaption(pi->getName());
+ mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel));
+ mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel));
+ mMoneyLabel->setCaption("Gold: " + toString(pi->mGp));
if (!mCharSelected)
{
mNewCharButton->setEnabled(false);
@@ -191,8 +186,7 @@ void CharSelectDialog::updatePlayerInfo()
mPlayerBox->mHairStyle = pi->getHairStyle() - 1;
mPlayerBox->mHairColor = pi->getHairColor() - 1;
mPlayerBox->mShowPlayer = true;
- }
- else {
+ } else {
mNameLabel->setCaption("Name");
mLevelLabel->setCaption("Level");
mJobLevelLabel->setCaption("Job Level");
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 8a0a67ab..ad0df223 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -23,8 +23,6 @@
#include "char_server.h"
-#include <sstream>
-
#include "button.h"
#include "listbox.h"
#include "scrollarea.h"
@@ -35,6 +33,8 @@
#include "../net/network.h" // TODO this is just for iptostring, move that?
+#include "../utils/tostring.h"
+
extern SERVER_INFO **server_info;
/**
@@ -120,7 +120,6 @@ ServerListModel::getNumberOfElements()
std::string
ServerListModel::getElementAt(int i)
{
- std::stringstream s;
- s << server_info[i]->name << " (" << server_info[i]->online_users << ")";
- return s.str();
+ const SERVER_INFO *si = server_info[i];
+ return si->name + " (" + toString(si->online_users) + ")";
}
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index cf30df93..66681a8b 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -23,16 +23,18 @@
#include "debugwindow.h"
-#include <guichan/widgets/label.hpp>
-#include <sstream>
#include <SDL_mouse.h>
+#include <guichan/widgets/label.hpp>
+
#include "button.h"
#include "../game.h"
#include "../engine.h"
#include "../map.h"
+#include "../utils/tostring.h"
+
DebugWindow::DebugWindow():
Window("Debug")
{
@@ -73,29 +75,24 @@ DebugWindow::logic()
int mouseTileX = mouseX / 32 + camera_x;
int mouseTileY = mouseY / 32 + camera_y;
- std::stringstream updatedText;
- updatedText << "[" << fps << " FPS]";
- mFPSLabel->setCaption(updatedText.str());
+ mFPSLabel->setCaption("[" + toString(fps) + " FPS");
mFPSLabel->adjustSize();
- updatedText.str("");
- updatedText << "[Mouse: " << mouseTileX << ", " << mouseTileY << "]";
- mTileMouseLabel->setCaption(updatedText.str());
+ mTileMouseLabel->setCaption("[Mouse: " +
+ toString(mouseTileX) + ", " + toString(mouseTileY) + "]");
mTileMouseLabel->adjustSize();
- updatedText.str("");
- mCurrentMap = engine->getCurrentMap();
-
- if (mCurrentMap != NULL)
+ Map *currentMap = engine->getCurrentMap();
+ if (currentMap != NULL)
{
- updatedText << " [Music File: "
- << mCurrentMap->getProperty("music") << "]";
- mMusicFileLabel->setCaption(updatedText.str());
+ const std::string music =
+ " [Music File: " + currentMap->getProperty("music") + "]";
+ mMusicFileLabel->setCaption(music);
mMusicFileLabel->adjustSize();
- updatedText.str("");
- updatedText << " [MiniMap File: "
- << mCurrentMap->getProperty("minimap") << "]";
- mMapFileLabel->setCaption(updatedText.str());
+
+ const std::string minimap =
+ " [MiniMap File: " + currentMap->getProperty("minimap") + "]";
+ mMapFileLabel->setCaption(minimap);
mMapFileLabel->adjustSize();
}
}
diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h
index d318df16..80524ffa 100644
--- a/src/gui/debugwindow.h
+++ b/src/gui/debugwindow.h
@@ -24,14 +24,13 @@
#ifndef _TMW_DEBUGWINDOW_H
#define _TMW_DEBUGWINDOW_H
-#include <string>
+#include <iosfwd>
#include <guichan/actionlistener.hpp>
#include "window.h"
-#include "../guichanfwd.h"
-class Map;
+#include "../guichanfwd.h"
/**
* The chat window.
@@ -59,8 +58,6 @@ class DebugWindow : public Window, public gcn::ActionListener
private:
gcn::Label *mMusicFileLabel, *mMapFileLabel;
gcn::Label *mTileMouseLabel, *mFPSLabel;
- Map *mCurrentMap;
-
};
#endif
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 64c368bc..1b9cfc55 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -33,7 +33,7 @@
#include "../resources/iteminfo.h"
#include "../resources/resourcemanager.h"
-#include <sstream>
+#include "../utils/tostring.h"
EquipmentWindow::EquipmentWindow(Equipment *equipment):
Window("Equipment"), mEquipment(equipment)
@@ -85,7 +85,6 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
image = mItemset->get(item->getInfo()->getImage() - 1);
dynamic_cast<Graphics*>(graphics)->drawImage(image, 160, 25);
- std::stringstream n;
- n << item->getQuantity();
- graphics->drawText(n.str(), 170, 62, gcn::Graphics::CENTER);
+ graphics->drawText(toString(item->getQuantity()), 170, 62,
+ gcn::Graphics::CENTER);
}
diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp
index 560a6cec..92f21e5f 100644
--- a/src/gui/inttextbox.cpp
+++ b/src/gui/inttextbox.cpp
@@ -23,10 +23,10 @@
#include "inttextbox.h"
-#include <sstream>
-
#include <guichan/key.hpp>
+#include "../utils/tostring.h"
+
IntTextBox::IntTextBox(int i):
mValue(i)
{
@@ -40,9 +40,8 @@ void IntTextBox::keyPress(const gcn::Key &key)
gcn::TextBox::keyPress(key);
}
- std::stringstream s;
+ std::stringstream s(gcn::TextBox::getText());
int i;
- s << gcn::TextBox::getText();
s >> i;
if (gcn::TextBox::getText() != "")
setInt(i);
@@ -63,11 +62,10 @@ int IntTextBox::getInt()
void IntTextBox::setInt(int i)
{
- std::stringstream s;
-
if (i >= mMin && i <= mMax)
mValue = i;
- s << mValue;
- setText(s.str());
- setCaretPosition(s.str().length() + 1);
+
+ const std::string valStr = toString(mValue);
+ setText(valStr);
+ setCaretPosition(valStr.length() + 1);
}
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 422d92af..8f672bc9 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -24,7 +24,6 @@
#include "inventorywindow.h"
#include <string>
-#include <sstream>
#include <guichan/mouseinput.hpp>
@@ -41,6 +40,8 @@
#include "../resources/iteminfo.h"
+#include "../utils/tostring.h"
+
InventoryWindow::InventoryWindow():
Window("Inventory")
{
@@ -88,10 +89,9 @@ void InventoryWindow::logic()
updateButtons();
// Update weight information
- std::stringstream tempstr;
- tempstr << "Total Weight: " << player_node->mTotalWeight
- << " - Maximum Weight: " << player_node->mMaxWeight;
- mWeightLabel->setCaption(tempstr.str());
+ mWeightLabel->setCaption(
+ "Total Weight: " + toString(player_node->mTotalWeight) + " - "
+ "Maximum Weight: " + toString(player_node->mMaxWeight));
mWeightLabel->adjustSize();
}
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index e0730ced..9b8dc09b 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -23,8 +23,6 @@
#include "itemcontainer.h"
-#include <sstream>
-
#include <guichan/mouseinput.hpp>
#include "../graphics.h"
@@ -38,6 +36,8 @@
#include "../resources/iteminfo.h"
#include "../resources/resourcemanager.h"
+#include "../utils/tostring.h"
+
ItemContainer::ItemContainer(Inventory *inventory):
mInventory(inventory)
{
@@ -122,16 +122,8 @@ void ItemContainer::draw(gcn::Graphics* graphics)
}
// Draw item caption
- std::stringstream ss;
-
- if (!item->isEquipped()) {
- ss << item->getQuantity();
- }
- else {
- ss << "Eq.";
- }
-
- graphics->drawText(ss.str(),
+ graphics->drawText(
+ (item->isEquipped() ? "Eq." : toString(item->getQuantity())),
itemX + gridWidth / 2,
itemY + gridHeight - 11,
gcn::Graphics::CENTER);
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index fc2f451b..be089b68 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -24,13 +24,14 @@
#include "ministatus.h"
#include <guichan/widgets/label.hpp>
-#include <sstream>
#include "gui.h"
#include "progressbar.h"
#include "../localplayer.h"
+#include "../utils/tostring.h"
+
MiniStatusWindow::MiniStatusWindow():
Window("")
{
@@ -88,12 +89,8 @@ void MiniStatusWindow::update()
// mpBar->setProgress((float)player_node->mp / (float)player_node->maxMp);
// Update and center labels
- std::stringstream updatedText;
- updatedText << player_node->mHp;
- mHpLabel->setCaption(updatedText.str());
- updatedText.str("");
- updatedText << player_node->mMp;
- mMpLabel->setCaption(updatedText.str());
+ mHpLabel->setCaption(toString(player_node->mHp));
+ mMpLabel->setCaption(toString(player_node->mMp));
}
void MiniStatusWindow::draw(gcn::Graphics *graphics)
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index a5e511b3..39c918f7 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -139,7 +139,7 @@ RegisterDialog::action(const std::string& eventId)
int error = 0;
// Check login
- if (user.length() == 0)
+ if (user.empty())
{
// No username
errorMsg << "Enter your username first.";
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index aa67adab..bde8906b 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -24,7 +24,6 @@
#include "sell.h"
#include <cassert>
-#include <sstream>
#include <guichan/widgets/label.hpp>
@@ -43,6 +42,7 @@
#include "../net/messageout.h"
#include "../net/protocol.h"
+#include "../utils/tostring.h"
SellDialog::SellDialog(Network *network):
Window("Sell"),
@@ -141,11 +141,8 @@ void SellDialog::addItem(Item *item, int price)
return;
ITEM_SHOP item_shop;
- std::stringstream ss;
- ss << item->getInfo()->getName() << " " << price << " GP";
-
- item_shop.name = ss.str();
+ item_shop.name = item->getInfo()->getName() + " " + toString(price) + " GP";
item_shop.price = price;
item_shop.index = item->getInvIndex();
item_shop.id = item->getId();
@@ -240,15 +237,12 @@ void SellDialog::action(const std::string& eventId)
// If anything changed, we need to update the buttons and labels
if (updateButtonsAndLabels) {
- std::stringstream oss;
-
// Update labels
- oss << mAmountItems;
- mQuantityLabel->setCaption(oss.str());
+ mQuantityLabel->setCaption(toString(mAmountItems));
mQuantityLabel->adjustSize();
- oss.str("");
- oss << "Price: " << mAmountItems * mShopItems->at(selectedItem).price;
- mMoneyLabel->setCaption(oss.str());
+
+ int price = mAmountItems * mShopItems->at(selectedItem).price;
+ mMoneyLabel->setCaption("Price: " + toString(price));
mMoneyLabel->adjustSize();
// Update Buttons
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 143f86ed..a009d2d5 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -23,7 +23,6 @@
#include "setup_video.h"
-#include <sstream>
#include <string>
#include <vector>
#include <SDL.h>
@@ -42,6 +41,8 @@
#include "../graphics.h"
#include "../log.h"
+#include "../utils/tostring.h"
+
extern Graphics *graphics;
/**
@@ -89,10 +90,10 @@ ModeListModel::ModeListModel()
} else {
//logger->log("Available Modes");
for (int i = 0; modes[i]; ++i) {
- std::stringstream ss;
- ss << (int)modes[i]->w << "x" << (int)modes[i]->h;
- //logger->log(ss.str().c_str());
- mVideoModes.push_back(ss.str());
+ const std::string modeString =
+ toString((int)modes[i]->w) + "x" + toString((int)modes[i]->h);
+ //logger->log(modeString.c_str());
+ mVideoModes.push_back(modeString);
}
}
}
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 54412129..7d6cabac 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -24,7 +24,6 @@
#include "status.h"
#include <guichan/widgets/label.hpp>
-#include <sstream>
#include "button.h"
#include "progressbar.h"
@@ -32,6 +31,8 @@
#include "../localplayer.h"
+#include "../utils/tostring.h"
+
StatusWindow::StatusWindow(LocalPlayer *player):
Window(player->getName()),
mPlayer(player)
@@ -221,43 +222,31 @@ StatusWindow::StatusWindow(LocalPlayer *player):
void StatusWindow::update()
{
- std::stringstream updateText;
-
// Status Part
// -----------
- updateText.str("");
- updateText << "Level: " << mPlayer->mLevel;
- mLvlLabel->setCaption(updateText.str());
+ mLvlLabel->setCaption("Level: " + toString(mPlayer->mLevel));
mLvlLabel->adjustSize();
- updateText.str("");
- updateText << "Money: " << mPlayer->mGp << " GP";
- mGpLabel->setCaption(updateText.str());
+ mGpLabel->setCaption("Money: " + toString(mPlayer->mGp) + " GP");
mGpLabel->adjustSize();
- updateText.str("");
- updateText << "Job: " << mPlayer->mJobLevel;
- mJobXpLabel->setCaption(updateText.str());
+ mJobXpLabel->setCaption("Job: " + toString(mPlayer->mJobLevel));
mJobXpLabel->adjustSize();
- updateText.str("");
- updateText << mPlayer->mHp << "/" << mPlayer->mMaxHp;
- mHpValueLabel->setCaption(updateText.str());
+ mHpValueLabel->setCaption(toString(mPlayer->mHp) +
+ "/" + toString(mPlayer->mMaxHp));
mHpValueLabel->adjustSize();
- updateText.str("");
- updateText << mPlayer->mMp << "/" << mPlayer->mMaxMp;
- mMpValueLabel->setCaption(updateText.str());
+ mMpValueLabel->setCaption(toString(mPlayer->mMp) +
+ "/" + toString(mPlayer->mMaxMp));
mMpValueLabel->adjustSize();
- updateText.str("");
- updateText << (int)mPlayer->mXp << "/" << (int)mPlayer->mXpForNextLevel;
- mXpValueLabel->setCaption(updateText.str());
+ mXpValueLabel->setCaption(toString(mPlayer->mXp) +
+ "/" + toString(mPlayer->mXpForNextLevel));
mXpValueLabel->adjustSize();
- updateText.str("");
- updateText << (int)mPlayer->mJobXp << "/" << (int)mPlayer->mJobXpForNextLevel;
- mJobValueLabel->setCaption(updateText.str());
+ mJobValueLabel->setCaption(toString(mPlayer->mJobXp) +
+ "/" + toString(mPlayer->mJobXpForNextLevel));
mJobValueLabel->adjustSize();
// HP Bar coloration
@@ -292,92 +281,76 @@ void StatusWindow::update()
"Dexterity",
"Luck"
};
-
int statusPoints = mPlayer->mStatsPointsToAttribute;
- updateText.str("");
- updateText << "Remaining Status Points: " << statusPoints;
-
// Update labels
for (int i = 0; i < 6; i++) {
- std::stringstream sstr;
-
mStatsLabel[i]->setCaption(attrNames[i]);
- mStatsLabel[i]->adjustSize();
+ mStatsDisplayLabel[i]->setCaption(toString((int)mPlayer->mAttr[i]));
+ mPointsLabel[i]->setCaption(toString((int)mPlayer->mAttrUp[i]));
- sstr.str("");
- sstr << (int)mPlayer->mAttr[i];
- mStatsDisplayLabel[i]->setCaption(sstr.str());
+ mStatsLabel[i]->adjustSize();
mStatsDisplayLabel[i]->adjustSize();
-
- sstr.str("");
- sstr << (int)mPlayer->mAttrUp[i];
- mPointsLabel[i]->setCaption(sstr.str());
mPointsLabel[i]->adjustSize();
mStatsButton[i]->setEnabled(mPlayer->mAttrUp[i] <= statusPoints);
}
- mRemainingStatsPointsLabel->setCaption(updateText.str());
+ mRemainingStatsPointsLabel->setCaption("Remaining Status Points: " +
+ toString(statusPoints));
mRemainingStatsPointsLabel->adjustSize();
// Derived Stats Points
// Attack TODO: Count equipped Weapons and items attack bonuses
- updateText.str("");
- updateText << int(mPlayer->ATK + mPlayer->ATK_BONUS);
- mStatsAttackPoints->setCaption(updateText.str());
+ mStatsAttackPoints->setCaption(
+ toString(mPlayer->ATK + mPlayer->ATK_BONUS));
mStatsAttackPoints->adjustSize();
// Defense TODO: Count equipped Armors and items defense bonuses
- updateText.str("");
- updateText << int(mPlayer->DEF + mPlayer->DEF_BONUS);
- mStatsDefensePoints->setCaption(updateText.str());
+ mStatsDefensePoints->setCaption(
+ toString(mPlayer->DEF + mPlayer->DEF_BONUS));
mStatsDefensePoints->adjustSize();
// Magic Attack TODO: Count equipped items M.Attack bonuses
- updateText.str("");
- updateText << int(mPlayer->MATK + mPlayer->MATK_BONUS);
- mStatsMagicAttackPoints->setCaption(updateText.str());
+ mStatsMagicAttackPoints->setCaption(
+ toString(mPlayer->MATK + mPlayer->MATK_BONUS));
mStatsMagicAttackPoints->adjustSize();
// Magic Defense TODO: Count equipped items M.Defense bonuses
- updateText.str("");
- updateText << int(mPlayer->MDEF + mPlayer->MDEF_BONUS);
- mStatsMagicDefensePoints->setCaption(updateText.str());
+ mStatsMagicDefensePoints->setCaption(
+ toString(mPlayer->MDEF + mPlayer->MDEF_BONUS));
mStatsMagicDefensePoints->adjustSize();
// Accuracy %
- updateText.str("");
- updateText << (int)mPlayer->HIT;
- mStatsAccuracyPoints->setCaption(updateText.str());
+ mStatsAccuracyPoints->setCaption(toString(mPlayer->HIT));
mStatsAccuracyPoints->adjustSize();
// Evasion %
- updateText.str("");
- updateText << (int)mPlayer->FLEE;
- mStatsEvadePoints->setCaption(updateText.str());
+ mStatsEvadePoints->setCaption(toString(mPlayer->FLEE));
mStatsEvadePoints->adjustSize();
// Reflex %
- updateText.str("");
- updateText << ((int)mPlayer->DEX / 4); // + counter
- mStatsReflexPoints->setCaption(updateText.str());
+ mStatsReflexPoints->setCaption(toString(mPlayer->DEX / 4)); // + counter
mStatsReflexPoints->adjustSize();
// Update Second column widgets position
mGpLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20,
mLvlLabel->getY());
- mXpLabel->setPosition(mHpValueLabel->getX() + mHpValueLabel->getWidth() + 10,
- mHpLabel->getY());
- mXpBar->setPosition(mXpLabel->getX() + mXpLabel->getWidth() + 5,
- mXpLabel->getY());
- mXpValueLabel->setPosition(mXpBar->getX() + mXpBar->getWidth() + 5,
- mXpLabel->getY());
+ mXpLabel->setPosition(
+ mHpValueLabel->getX() + mHpValueLabel->getWidth() + 10,
+ mHpLabel->getY());
+ mXpBar->setPosition(
+ mXpLabel->getX() + mXpLabel->getWidth() + 5,
+ mXpLabel->getY());
+ mXpValueLabel->setPosition(
+ mXpBar->getX() + mXpBar->getWidth() + 5,
+ mXpLabel->getY());
mJobXpLabel->setPosition(mXpLabel->getX(), mMpLabel->getY());
- mJobXpBar->setPosition(mXpBar->getX() + mXpBar->getWidth() -
- mJobXpBar->getWidth(), mJobXpLabel->getY());
+ mJobXpBar->setPosition(
+ mXpBar->getX() + mXpBar->getWidth() - mJobXpBar->getWidth(),
+ mJobXpLabel->getY());
mJobValueLabel->setPosition(290, mJobXpLabel->getY());
}
diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp
index f19524e1..f1927c6f 100644
--- a/src/gui/tabbedcontainer.cpp
+++ b/src/gui/tabbedcontainer.cpp
@@ -23,10 +23,10 @@
#include "tabbedcontainer.h"
-#include <sstream>
-
#include "button.h"
+#include "../utils/tostring.h"
+
#define TABWIDTH 60
#define TABHEIGHT 20
@@ -48,12 +48,9 @@ TabbedContainer::~TabbedContainer()
void TabbedContainer::addTab(gcn::Widget *widget, const std::string &caption)
{
- std::stringstream ss;
int tabNumber = mTabs.size();
- ss << tabNumber;
-
- Button *tab = new Button(caption, ss.str(), this);
+ Button *tab = new Button(caption, toString(tabNumber), this);
tab->setSize(TABWIDTH, TABHEIGHT);
add(tab, TABWIDTH * tabNumber, 0);
@@ -83,14 +80,12 @@ void TabbedContainer::logic()
void TabbedContainer::action(const std::string &event)
{
+ std::stringstream ss(event);
int tabNo;
- std::stringstream ss;
- gcn::Widget *newContent;
-
- ss << event;
ss >> tabNo;
- if ((newContent = mContents[tabNo])) {
+ gcn::Widget *newContent = mContents[tabNo];
+ if (newContent) {
if (mActiveContent) {
remove(mActiveContent);
}
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index ee7bca06..9b98fa09 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -43,6 +43,8 @@
#include "../resources/iteminfo.h"
+#include "../utils/tostring.h"
+
TradeWindow::TradeWindow(Network *network):
Window("Trade: You"),
mNetwork(network),
@@ -130,9 +132,7 @@ TradeWindow::~TradeWindow()
void TradeWindow::addMoney(int amount)
{
- std::stringstream tempMoney;
- tempMoney << "You get: " << amount << "z";
- mMoneyLabel->setCaption(tempMoney.str());
+ mMoneyLabel->setCaption("You get: " + toString(amount) + "z");
mMoneyLabel->adjustSize();
}
@@ -292,14 +292,12 @@ void TradeWindow::action(const std::string &eventId)
}
else if (eventId == "ok")
{
- std::stringstream tempMoney[2];
- tempMoney[0] << mMoneyField->getText();
+ std::stringstream tempMoney(mMoneyField->getText());
int tempInt;
- if (tempMoney[0] >> tempInt)
+ if (tempMoney >> tempInt)
{
- tempMoney[1] << tempInt;
- mMoneyField->setText(tempMoney[1].str());
-
+ mMoneyField->setText(toString(tempInt));
+
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST);
outMsg.writeInt16(0);
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 9db09f27..4f43d1fc 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -24,7 +24,6 @@
#include "updatewindow.h"
#include <iostream>
-#include <sstream>
#include <SDL.h>
#include <SDL_thread.h>
@@ -41,6 +40,8 @@
#include "../log.h"
#include "../main.h"
+#include "../utils/tostring.h"
+
UpdaterWindow::UpdaterWindow():
Window("Updating..."),
mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS),
@@ -190,10 +191,8 @@ int UpdaterWindow::updateProgress(void *ptr,
if (progress < 0) progress = 0.0f;
if (progress > 1) progress = 1.0f;
- std::stringstream progressString;
- progressString << uw->mCurrentFile
- << " (" << ((int)(progress * 100)) << "%)";
- uw->setLabel(progressString.str().c_str());
+ uw->setLabel(
+ uw->mCurrentFile + " (" + toString((int)progress * 100) + "%)");
uw->setProgress(progress);
if (state != UPDATE_STATE || uw->mDownloadStatus == UPDATE_ERROR)
diff --git a/src/log.cpp b/src/log.cpp
index d2f1e125..d40927c5 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -71,16 +71,16 @@ void Logger::log(const char *log_text, ...)
// Print the log entry
std::stringstream timeStr;
- timeStr << "[";
- timeStr << ((((t / 60) / 60) % 24 < 10) ? "0" : "");
- timeStr << (int)(((t / 60) / 60) % 24);
- timeStr << ":";
- timeStr << (((t / 60) % 60 < 10) ? "0" : "");
- timeStr << (int)((t / 60) % 60);
- timeStr << ":";
- timeStr << ((t % 60 < 10) ? "0" : "");
- timeStr << (int)(t % 60);
- timeStr << "] ";
+ timeStr << "["
+ << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
+ << (int)(((t / 60) / 60) % 24)
+ << ":"
+ << (((t / 60) % 60 < 10) ? "0" : "")
+ << (int)((t / 60) % 60)
+ << ":"
+ << ((t % 60 < 10) ? "0" : "")
+ << (int)(t % 60)
+ << "] ";
mLogFile << timeStr.str() << buf << std::endl;
diff --git a/src/main.cpp b/src/main.cpp
index e3fbdca6..d067d3c9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,7 +26,6 @@
#include <getopt.h>
#include <iostream>
#include <physfs.h>
-#include <sstream>
#include <unistd.h>
#include <vector>
#include <SDL_image.h>
@@ -78,6 +77,7 @@
#include "resources/resourcemanager.h"
#include "utils/dtor.h"
+#include "utils/tostring.h"
// Account infos
char n_server, n_character;
@@ -266,10 +266,9 @@ void init_engine()
for (int i=0; i < NR_HAIR_STYLES; i++)
{
- std::stringstream filename;
- filename << "graphics/sprites/hairstyle" << (i + 1) << ".png";
Spriteset *tmp = ResourceManager::getInstance()->createSpriteset(
- filename.str(), 40, 40);
+ "graphics/sprites/hairstyle" + toString(i + 1) + ".png",
+ 40, 40);
if (!tmp) {
logger->error("Unable to load hairstyle");
} else {
diff --git a/src/monster.cpp b/src/monster.cpp
index 6416c716..af84b25e 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -23,13 +23,13 @@
#include "monster.h"
-#include <sstream>
-
#include "game.h"
#include "log.h"
#include "resources/resourcemanager.h"
+#include "utils/tostring.h"
+
class Spriteset;
extern std::map<int, Spriteset*> monsterset;
@@ -39,13 +39,9 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map):
// Load monster spriteset, if necessary
if (monsterset.find(job - 1002) == monsterset.end())
{
- std::stringstream filename;
-
- filename << "graphics/sprites/monster" << (job - 1002) << ".png";
- logger->log("%s",filename.str().c_str());
-
Spriteset *tmp = ResourceManager::getInstance()->createSpriteset(
- filename.str(), 60, 60);
+ "graphics/sprites/monster" + toString(job - 1002) + ".png",
+ 60, 60);
if (!tmp) {
logger->error("Unable to load monster spriteset!");
} else {
diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp
index 97e8186d..9095a4e1 100644
--- a/src/net/chathandler.cpp
+++ b/src/net/chathandler.cpp
@@ -25,7 +25,6 @@
#include <SDL_types.h>
#include <string>
-#include <sstream>
#include "messagein.h"
#include "protocol.h"
@@ -36,6 +35,8 @@
#include "../gui/chat.h"
+#include "../utils/tostring.h"
+
extern Being *player_node;
ChatHandler::ChatHandler()
@@ -55,7 +56,6 @@ void ChatHandler::handleMessage(MessageIn *msg)
{
Being *being;
std::string chatMsg;
- std::stringstream ss;
Sint16 chatMsgLength;
switch (msg->getId())
@@ -105,8 +105,8 @@ void ChatHandler::handleMessage(MessageIn *msg)
break;
case SMSG_WHO_ANSWER:
- ss << "Online users: " << msg->readInt32();
- chatWindow->chatLog(ss.str(), BY_SERVER);
+ chatWindow->chatLog("Online users: " + toString(msg->readInt32()),
+ BY_SERVER);
break;
case 0x010c:
diff --git a/src/utils/tostring.h b/src/utils/tostring.h
new file mode 100644
index 00000000..8fc6d105
--- /dev/null
+++ b/src/utils/tostring.h
@@ -0,0 +1,37 @@
+/*
+ * 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_UTILS_TOSTRING_H
+#define _TMW_UTISL_TOSTRING_H
+
+#include <sstream>
+
+template<typename T>
+std::string toString(const T &arg)
+{
+ std::stringstream ss;
+ ss << arg;
+ return ss.str();
+}
+
+#endif