diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-19 15:09:27 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-19 15:09:27 +0000 |
commit | 3ddaec5f355ed1d231514cf0a863c4b9e35cf2a6 (patch) | |
tree | 5084eaa47d4874a3a573de226f19c4be072e4888 | |
parent | 19d5cc3a6bbbd911361b7e8b956840d0189d4c2b (diff) | |
download | mana-client-3ddaec5f355ed1d231514cf0a863c4b9e35cf2a6.tar.gz mana-client-3ddaec5f355ed1d231514cf0a863c4b9e35cf2a6.tar.bz2 mana-client-3ddaec5f355ed1d231514cf0a863c4b9e35cf2a6.tar.xz mana-client-3ddaec5f355ed1d231514cf0a863c4b9e35cf2a6.zip |
Reverted changeset r2269 (toString) as requested by ElvenProgrammer.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/being.cpp | 12 | ||||
-rw-r--r-- | src/configuration.cpp | 7 | ||||
-rw-r--r-- | src/engine.cpp | 17 | ||||
-rw-r--r-- | src/gui/buy.cpp | 18 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 24 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 9 | ||||
-rw-r--r-- | src/gui/debugwindow.cpp | 35 | ||||
-rw-r--r-- | src/gui/debugwindow.h | 7 | ||||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 7 | ||||
-rw-r--r-- | src/gui/inttextbox.cpp | 16 | ||||
-rw-r--r-- | src/gui/inventorywindow.cpp | 10 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 16 | ||||
-rw-r--r-- | src/gui/ministatus.cpp | 11 | ||||
-rw-r--r-- | src/gui/register.cpp | 2 | ||||
-rw-r--r-- | src/gui/sell.cpp | 18 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 11 | ||||
-rw-r--r-- | src/gui/status.cpp | 109 | ||||
-rw-r--r-- | src/gui/tabbedcontainer.cpp | 17 | ||||
-rw-r--r-- | src/gui/trade.cpp | 16 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 9 | ||||
-rw-r--r-- | src/log.cpp | 20 | ||||
-rw-r--r-- | src/main.cpp | 7 | ||||
-rw-r--r-- | src/monster.cpp | 12 | ||||
-rw-r--r-- | src/net/chathandler.cpp | 8 | ||||
-rw-r--r-- | src/utils/tostring.h | 37 |
27 files changed, 265 insertions, 202 deletions
@@ -1,5 +1,16 @@ 2006-03-19 Björn Steinbrink <B.Steinbrink@gmx.de> + * src/configuration.cpp, src/log.cpp, src/main.cpp, src/being.cpp, + src/monster.cpp, src/gui/equipmentwindow.cpp, src/gui/sell.cpp, + src/gui/trade.cpp, src/gui/char_server.cpp, src/gui/updatewindow.cpp, + src/gui/char_select.cpp, src/gui/setup_video.cpp, + src/gui/ministatus.cpp, src/gui/debugwindow.cpp, + src/gui/tabbedcontainer.cpp, src/gui/inventorywindow.cpp, + src/gui/buy.cpp, src/gui/itemcontainer.cpp, src/gui/inttextbox.cpp, + src/gui/debugwindow.h, src/gui/status.cpp, src/gui/register.cpp, + src/net/chathandler.cpp, src/engine.cpp, src/utils/tostring.h, + src/Makefile.am: Reverted changeset r2269 (toString) as requested by + ElvenProgrammer. * src/gui/login.cpp, src/gui/setup_audio.h, src/gui/setup.cpp, src/gui/setup_audio.cpp, src/gui/setup_video.cpp, src/gui/setup_video.h: Removed some duplicated initializations. diff --git a/src/Makefile.am b/src/Makefile.am index e4fef745..eaf3662d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -180,7 +180,6 @@ 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 a74efe5f..5ee8276c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -22,6 +22,8 @@ */ #include "being.h" +#include <sstream> + #include "game.h" #include "graphics.h" #include "log.h" @@ -31,8 +33,6 @@ #include "gui/gui.h" -#include "utils/tostring.h" - extern Spriteset *emotionset; PATH_NODE::PATH_NODE(Uint16 iX, Uint16 iY): @@ -120,7 +120,13 @@ Being::setSpeech(const std::string &text, Uint32 time) void Being::setDamage(Sint16 amount, Uint32 time) { - mDamage = amount ? toString(amount) : "miss"; + if (!amount) { + mDamage = "miss"; + } else { + std::stringstream damageString; + damageString << amount; + mDamage = damageString.str(); + } mDamageTime = tick_time; mShowDamage = true; } diff --git a/src/configuration.cpp b/src/configuration.cpp index 4085b20b..aa63f46c 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -24,13 +24,12 @@ #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; @@ -128,7 +127,9 @@ void Configuration::setValue(const std::string &key, std::string value) void Configuration::setValue(const std::string &key, float value) { - setValue(key, toString((value == (int)value) ? (int)value : value)); + std::stringstream ss; + ss << ((value == (int)value) ? (int)value : value); + setValue(key, ss.str()); } std::string Configuration::getValue(const std::string &key, std::string deflt) diff --git a/src/engine.cpp b/src/engine.cpp index 8d78a078..3be152bd 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -24,6 +24,7 @@ #include "engine.h" #include <list> +#include <sstream> #include "being.h" #include "beingmanager.h" @@ -50,7 +51,6 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" -#include "utils/tostring.h" extern Minimap *minimap; @@ -80,8 +80,10 @@ 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( - "graphics/sprites/weapon" + toString(i) + ".png", 64, 64); + filename.str(), 64, 64); if (!tmp) { logger->error("Unable to load weaponset"); } else { @@ -216,12 +218,15 @@ 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)); - graphics->drawText( - toString(mCurrentMap->getMetaTile(i->x, i->y)->Gcost), - squareX + 4, squareY + 12, gcn::Graphics::CENTER); + + 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); } } diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 86bd5413..18542385 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -23,6 +23,8 @@ #include "buy.h" +#include <sstream> + #include <guichan/widgets/label.hpp> #include "button.h" @@ -39,8 +41,6 @@ #include "../net/messageout.h" #include "../net/protocol.h" -#include "../utils/tostring.h" - BuyDialog::BuyDialog(Network *network): Window("Buy"), mNetwork(network), @@ -139,8 +139,10 @@ void BuyDialog::reset() void BuyDialog::addItem(short id, int price) { ITEM_SHOP item_shop; + std::stringstream ss; - item_shop.name = itemDb->getItemInfo(id)->getName() + " " + toString(price) + " GP"; + ss << itemDb->getItemInfo(id)->getName() << " " << price << " GP"; + item_shop.name = ss.str(); item_shop.price = price; item_shop.id = id; @@ -240,17 +242,21 @@ 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 - mQuantityLabel->setCaption(toString(mAmountItems)); + oss << mAmountItems; + mQuantityLabel->setCaption(oss.str()); mQuantityLabel->adjustSize(); - int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price : " + toString(price) + " GP"); + oss.str(""); + oss << "Price : " << mAmountItems * mShopItems->at(selectedItem).price << " GP"; + mMoneyLabel->setCaption(oss.str()); mMoneyLabel->adjustSize(); } } diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 40c1d145..b1d08951 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -23,6 +23,7 @@ #include "char_select.h" +#include <sstream> #include <string> #include <guichan/widgets/label.hpp> @@ -39,8 +40,6 @@ #include "../net/messageout.h" -#include "./utils/tostring.h" - /** * Listener for confirming character deletion. */ @@ -70,8 +69,7 @@ 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); @@ -173,10 +171,17 @@ void CharSelectDialog::updatePlayerInfo() LocalPlayer *pi = mCharInfo->getEntry(); if (pi) { - mNameLabel->setCaption(pi->getName()); - mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel)); - mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel)); - mMoneyLabel->setCaption("Gold: " + toString(pi->mGp)); + 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()); if (!mCharSelected) { mNewCharButton->setEnabled(false); @@ -186,7 +191,8 @@ 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 ad0df223..8a0a67ab 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -23,6 +23,8 @@ #include "char_server.h" +#include <sstream> + #include "button.h" #include "listbox.h" #include "scrollarea.h" @@ -33,8 +35,6 @@ #include "../net/network.h" // TODO this is just for iptostring, move that? -#include "../utils/tostring.h" - extern SERVER_INFO **server_info; /** @@ -120,6 +120,7 @@ ServerListModel::getNumberOfElements() std::string ServerListModel::getElementAt(int i) { - const SERVER_INFO *si = server_info[i]; - return si->name + " (" + toString(si->online_users) + ")"; + std::stringstream s; + s << server_info[i]->name << " (" << server_info[i]->online_users << ")"; + return s.str(); } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 66681a8b..cf30df93 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -23,9 +23,9 @@ #include "debugwindow.h" -#include <SDL_mouse.h> - #include <guichan/widgets/label.hpp> +#include <sstream> +#include <SDL_mouse.h> #include "button.h" @@ -33,8 +33,6 @@ #include "../engine.h" #include "../map.h" -#include "../utils/tostring.h" - DebugWindow::DebugWindow(): Window("Debug") { @@ -75,24 +73,29 @@ DebugWindow::logic() int mouseTileX = mouseX / 32 + camera_x; int mouseTileY = mouseY / 32 + camera_y; - mFPSLabel->setCaption("[" + toString(fps) + " FPS"); + std::stringstream updatedText; + updatedText << "[" << fps << " FPS]"; + mFPSLabel->setCaption(updatedText.str()); mFPSLabel->adjustSize(); - mTileMouseLabel->setCaption("[Mouse: " + - toString(mouseTileX) + ", " + toString(mouseTileY) + "]"); + updatedText.str(""); + updatedText << "[Mouse: " << mouseTileX << ", " << mouseTileY << "]"; + mTileMouseLabel->setCaption(updatedText.str()); mTileMouseLabel->adjustSize(); - Map *currentMap = engine->getCurrentMap(); - if (currentMap != NULL) + updatedText.str(""); + mCurrentMap = engine->getCurrentMap(); + + if (mCurrentMap != NULL) { - const std::string music = - " [Music File: " + currentMap->getProperty("music") + "]"; - mMusicFileLabel->setCaption(music); + updatedText << " [Music File: " + << mCurrentMap->getProperty("music") << "]"; + mMusicFileLabel->setCaption(updatedText.str()); mMusicFileLabel->adjustSize(); - - const std::string minimap = - " [MiniMap File: " + currentMap->getProperty("minimap") + "]"; - mMapFileLabel->setCaption(minimap); + updatedText.str(""); + updatedText << " [MiniMap File: " + << mCurrentMap->getProperty("minimap") << "]"; + mMapFileLabel->setCaption(updatedText.str()); mMapFileLabel->adjustSize(); } } diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 80524ffa..d318df16 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -24,14 +24,15 @@ #ifndef _TMW_DEBUGWINDOW_H #define _TMW_DEBUGWINDOW_H -#include <iosfwd> +#include <string> #include <guichan/actionlistener.hpp> #include "window.h" - #include "../guichanfwd.h" +class Map; + /** * The chat window. * @@ -58,6 +59,8 @@ 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 1b9cfc55..64c368bc 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -33,7 +33,7 @@ #include "../resources/iteminfo.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include <sstream> EquipmentWindow::EquipmentWindow(Equipment *equipment): Window("Equipment"), mEquipment(equipment) @@ -85,6 +85,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) image = mItemset->get(item->getInfo()->getImage() - 1); dynamic_cast<Graphics*>(graphics)->drawImage(image, 160, 25); - graphics->drawText(toString(item->getQuantity()), 170, 62, - gcn::Graphics::CENTER); + std::stringstream n; + n << item->getQuantity(); + graphics->drawText(n.str(), 170, 62, gcn::Graphics::CENTER); } diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp index 92f21e5f..560a6cec 100644 --- a/src/gui/inttextbox.cpp +++ b/src/gui/inttextbox.cpp @@ -23,9 +23,9 @@ #include "inttextbox.h" -#include <guichan/key.hpp> +#include <sstream> -#include "../utils/tostring.h" +#include <guichan/key.hpp> IntTextBox::IntTextBox(int i): mValue(i) @@ -40,8 +40,9 @@ void IntTextBox::keyPress(const gcn::Key &key) gcn::TextBox::keyPress(key); } - std::stringstream s(gcn::TextBox::getText()); + std::stringstream s; int i; + s << gcn::TextBox::getText(); s >> i; if (gcn::TextBox::getText() != "") setInt(i); @@ -62,10 +63,11 @@ int IntTextBox::getInt() void IntTextBox::setInt(int i) { + std::stringstream s; + if (i >= mMin && i <= mMax) mValue = i; - - const std::string valStr = toString(mValue); - setText(valStr); - setCaretPosition(valStr.length() + 1); + s << mValue; + setText(s.str()); + setCaretPosition(s.str().length() + 1); } diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 8f672bc9..422d92af 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -24,6 +24,7 @@ #include "inventorywindow.h" #include <string> +#include <sstream> #include <guichan/mouseinput.hpp> @@ -40,8 +41,6 @@ #include "../resources/iteminfo.h" -#include "../utils/tostring.h" - InventoryWindow::InventoryWindow(): Window("Inventory") { @@ -89,9 +88,10 @@ void InventoryWindow::logic() updateButtons(); // Update weight information - mWeightLabel->setCaption( - "Total Weight: " + toString(player_node->mTotalWeight) + " - " - "Maximum Weight: " + toString(player_node->mMaxWeight)); + std::stringstream tempstr; + tempstr << "Total Weight: " << player_node->mTotalWeight + << " - Maximum Weight: " << player_node->mMaxWeight; + mWeightLabel->setCaption(tempstr.str()); mWeightLabel->adjustSize(); } diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 9b8dc09b..e0730ced 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -23,6 +23,8 @@ #include "itemcontainer.h" +#include <sstream> + #include <guichan/mouseinput.hpp> #include "../graphics.h" @@ -36,8 +38,6 @@ #include "../resources/iteminfo.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" - ItemContainer::ItemContainer(Inventory *inventory): mInventory(inventory) { @@ -122,8 +122,16 @@ void ItemContainer::draw(gcn::Graphics* graphics) } // Draw item caption - graphics->drawText( - (item->isEquipped() ? "Eq." : toString(item->getQuantity())), + std::stringstream ss; + + if (!item->isEquipped()) { + ss << item->getQuantity(); + } + else { + ss << "Eq."; + } + + graphics->drawText(ss.str(), itemX + gridWidth / 2, itemY + gridHeight - 11, gcn::Graphics::CENTER); diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index be089b68..fc2f451b 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -24,14 +24,13 @@ #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("") { @@ -89,8 +88,12 @@ void MiniStatusWindow::update() // mpBar->setProgress((float)player_node->mp / (float)player_node->maxMp); // Update and center labels - mHpLabel->setCaption(toString(player_node->mHp)); - mMpLabel->setCaption(toString(player_node->mMp)); + std::stringstream updatedText; + updatedText << player_node->mHp; + mHpLabel->setCaption(updatedText.str()); + updatedText.str(""); + updatedText << player_node->mMp; + mMpLabel->setCaption(updatedText.str()); } void MiniStatusWindow::draw(gcn::Graphics *graphics) diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 39c918f7..a5e511b3 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.empty()) + if (user.length() == 0) { // No username errorMsg << "Enter your username first."; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index bde8906b..aa67adab 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -24,6 +24,7 @@ #include "sell.h" #include <cassert> +#include <sstream> #include <guichan/widgets/label.hpp> @@ -42,7 +43,6 @@ #include "../net/messageout.h" #include "../net/protocol.h" -#include "../utils/tostring.h" SellDialog::SellDialog(Network *network): Window("Sell"), @@ -141,8 +141,11 @@ void SellDialog::addItem(Item *item, int price) return; ITEM_SHOP item_shop; + std::stringstream ss; - item_shop.name = item->getInfo()->getName() + " " + toString(price) + " GP"; + ss << item->getInfo()->getName() << " " << price << " GP"; + + item_shop.name = ss.str(); item_shop.price = price; item_shop.index = item->getInvIndex(); item_shop.id = item->getId(); @@ -237,12 +240,15 @@ 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 - mQuantityLabel->setCaption(toString(mAmountItems)); + oss << mAmountItems; + mQuantityLabel->setCaption(oss.str()); mQuantityLabel->adjustSize(); - - int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price: " + toString(price)); + oss.str(""); + oss << "Price: " << mAmountItems * mShopItems->at(selectedItem).price; + mMoneyLabel->setCaption(oss.str()); mMoneyLabel->adjustSize(); // Update Buttons diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index a009d2d5..143f86ed 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -23,6 +23,7 @@ #include "setup_video.h" +#include <sstream> #include <string> #include <vector> #include <SDL.h> @@ -41,8 +42,6 @@ #include "../graphics.h" #include "../log.h" -#include "../utils/tostring.h" - extern Graphics *graphics; /** @@ -90,10 +89,10 @@ ModeListModel::ModeListModel() } else { //logger->log("Available Modes"); for (int i = 0; modes[i]; ++i) { - const std::string modeString = - toString((int)modes[i]->w) + "x" + toString((int)modes[i]->h); - //logger->log(modeString.c_str()); - mVideoModes.push_back(modeString); + std::stringstream ss; + ss << (int)modes[i]->w << "x" << (int)modes[i]->h; + //logger->log(ss.str().c_str()); + mVideoModes.push_back(ss.str()); } } } diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 7d6cabac..54412129 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -24,6 +24,7 @@ #include "status.h" #include <guichan/widgets/label.hpp> +#include <sstream> #include "button.h" #include "progressbar.h" @@ -31,8 +32,6 @@ #include "../localplayer.h" -#include "../utils/tostring.h" - StatusWindow::StatusWindow(LocalPlayer *player): Window(player->getName()), mPlayer(player) @@ -222,31 +221,43 @@ StatusWindow::StatusWindow(LocalPlayer *player): void StatusWindow::update() { + std::stringstream updateText; + // Status Part // ----------- - mLvlLabel->setCaption("Level: " + toString(mPlayer->mLevel)); + updateText.str(""); + updateText << "Level: " << mPlayer->mLevel; + mLvlLabel->setCaption(updateText.str()); mLvlLabel->adjustSize(); - mGpLabel->setCaption("Money: " + toString(mPlayer->mGp) + " GP"); + updateText.str(""); + updateText << "Money: " << mPlayer->mGp << " GP"; + mGpLabel->setCaption(updateText.str()); mGpLabel->adjustSize(); - mJobXpLabel->setCaption("Job: " + toString(mPlayer->mJobLevel)); + updateText.str(""); + updateText << "Job: " << mPlayer->mJobLevel; + mJobXpLabel->setCaption(updateText.str()); mJobXpLabel->adjustSize(); - mHpValueLabel->setCaption(toString(mPlayer->mHp) + - "/" + toString(mPlayer->mMaxHp)); + updateText.str(""); + updateText << mPlayer->mHp << "/" << mPlayer->mMaxHp; + mHpValueLabel->setCaption(updateText.str()); mHpValueLabel->adjustSize(); - mMpValueLabel->setCaption(toString(mPlayer->mMp) + - "/" + toString(mPlayer->mMaxMp)); + updateText.str(""); + updateText << mPlayer->mMp << "/" << mPlayer->mMaxMp; + mMpValueLabel->setCaption(updateText.str()); mMpValueLabel->adjustSize(); - mXpValueLabel->setCaption(toString(mPlayer->mXp) + - "/" + toString(mPlayer->mXpForNextLevel)); + updateText.str(""); + updateText << (int)mPlayer->mXp << "/" << (int)mPlayer->mXpForNextLevel; + mXpValueLabel->setCaption(updateText.str()); mXpValueLabel->adjustSize(); - mJobValueLabel->setCaption(toString(mPlayer->mJobXp) + - "/" + toString(mPlayer->mJobXpForNextLevel)); + updateText.str(""); + updateText << (int)mPlayer->mJobXp << "/" << (int)mPlayer->mJobXpForNextLevel; + mJobValueLabel->setCaption(updateText.str()); mJobValueLabel->adjustSize(); // HP Bar coloration @@ -281,76 +292,92 @@ 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++) { - mStatsLabel[i]->setCaption(attrNames[i]); - mStatsDisplayLabel[i]->setCaption(toString((int)mPlayer->mAttr[i])); - mPointsLabel[i]->setCaption(toString((int)mPlayer->mAttrUp[i])); + std::stringstream sstr; + mStatsLabel[i]->setCaption(attrNames[i]); mStatsLabel[i]->adjustSize(); + + sstr.str(""); + sstr << (int)mPlayer->mAttr[i]; + mStatsDisplayLabel[i]->setCaption(sstr.str()); 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("Remaining Status Points: " + - toString(statusPoints)); + mRemainingStatsPointsLabel->setCaption(updateText.str()); mRemainingStatsPointsLabel->adjustSize(); // Derived Stats Points // Attack TODO: Count equipped Weapons and items attack bonuses - mStatsAttackPoints->setCaption( - toString(mPlayer->ATK + mPlayer->ATK_BONUS)); + updateText.str(""); + updateText << int(mPlayer->ATK + mPlayer->ATK_BONUS); + mStatsAttackPoints->setCaption(updateText.str()); mStatsAttackPoints->adjustSize(); // Defense TODO: Count equipped Armors and items defense bonuses - mStatsDefensePoints->setCaption( - toString(mPlayer->DEF + mPlayer->DEF_BONUS)); + updateText.str(""); + updateText << int(mPlayer->DEF + mPlayer->DEF_BONUS); + mStatsDefensePoints->setCaption(updateText.str()); mStatsDefensePoints->adjustSize(); // Magic Attack TODO: Count equipped items M.Attack bonuses - mStatsMagicAttackPoints->setCaption( - toString(mPlayer->MATK + mPlayer->MATK_BONUS)); + updateText.str(""); + updateText << int(mPlayer->MATK + mPlayer->MATK_BONUS); + mStatsMagicAttackPoints->setCaption(updateText.str()); mStatsMagicAttackPoints->adjustSize(); // Magic Defense TODO: Count equipped items M.Defense bonuses - mStatsMagicDefensePoints->setCaption( - toString(mPlayer->MDEF + mPlayer->MDEF_BONUS)); + updateText.str(""); + updateText << int(mPlayer->MDEF + mPlayer->MDEF_BONUS); + mStatsMagicDefensePoints->setCaption(updateText.str()); mStatsMagicDefensePoints->adjustSize(); // Accuracy % - mStatsAccuracyPoints->setCaption(toString(mPlayer->HIT)); + updateText.str(""); + updateText << (int)mPlayer->HIT; + mStatsAccuracyPoints->setCaption(updateText.str()); mStatsAccuracyPoints->adjustSize(); // Evasion % - mStatsEvadePoints->setCaption(toString(mPlayer->FLEE)); + updateText.str(""); + updateText << (int)mPlayer->FLEE; + mStatsEvadePoints->setCaption(updateText.str()); mStatsEvadePoints->adjustSize(); // Reflex % - mStatsReflexPoints->setCaption(toString(mPlayer->DEX / 4)); // + counter + updateText.str(""); + updateText << ((int)mPlayer->DEX / 4); // + counter + mStatsReflexPoints->setCaption(updateText.str()); 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 f1927c6f..f19524e1 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -23,9 +23,9 @@ #include "tabbedcontainer.h" -#include "button.h" +#include <sstream> -#include "../utils/tostring.h" +#include "button.h" #define TABWIDTH 60 #define TABHEIGHT 20 @@ -48,9 +48,12 @@ TabbedContainer::~TabbedContainer() void TabbedContainer::addTab(gcn::Widget *widget, const std::string &caption) { + std::stringstream ss; int tabNumber = mTabs.size(); - Button *tab = new Button(caption, toString(tabNumber), this); + ss << tabNumber; + + Button *tab = new Button(caption, ss.str(), this); tab->setSize(TABWIDTH, TABHEIGHT); add(tab, TABWIDTH * tabNumber, 0); @@ -80,12 +83,14 @@ 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; - gcn::Widget *newContent = mContents[tabNo]; - if (newContent) { + if ((newContent = mContents[tabNo])) { if (mActiveContent) { remove(mActiveContent); } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 9b98fa09..ee7bca06 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -43,8 +43,6 @@ #include "../resources/iteminfo.h" -#include "../utils/tostring.h" - TradeWindow::TradeWindow(Network *network): Window("Trade: You"), mNetwork(network), @@ -132,7 +130,9 @@ TradeWindow::~TradeWindow() void TradeWindow::addMoney(int amount) { - mMoneyLabel->setCaption("You get: " + toString(amount) + "z"); + std::stringstream tempMoney; + tempMoney << "You get: " << amount << "z"; + mMoneyLabel->setCaption(tempMoney.str()); mMoneyLabel->adjustSize(); } @@ -292,12 +292,14 @@ void TradeWindow::action(const std::string &eventId) } else if (eventId == "ok") { - std::stringstream tempMoney(mMoneyField->getText()); + std::stringstream tempMoney[2]; + tempMoney[0] << mMoneyField->getText(); int tempInt; - if (tempMoney >> tempInt) + if (tempMoney[0] >> tempInt) { - mMoneyField->setText(toString(tempInt)); - + tempMoney[1] << tempInt; + mMoneyField->setText(tempMoney[1].str()); + 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 4f43d1fc..9db09f27 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -24,6 +24,7 @@ #include "updatewindow.h" #include <iostream> +#include <sstream> #include <SDL.h> #include <SDL_thread.h> @@ -40,8 +41,6 @@ #include "../log.h" #include "../main.h" -#include "../utils/tostring.h" - UpdaterWindow::UpdaterWindow(): Window("Updating..."), mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS), @@ -191,8 +190,10 @@ int UpdaterWindow::updateProgress(void *ptr, if (progress < 0) progress = 0.0f; if (progress > 1) progress = 1.0f; - uw->setLabel( - uw->mCurrentFile + " (" + toString((int)progress * 100) + "%)"); + std::stringstream progressString; + progressString << uw->mCurrentFile + << " (" << ((int)(progress * 100)) << "%)"; + uw->setLabel(progressString.str().c_str()); uw->setProgress(progress); if (state != UPDATE_STATE || uw->mDownloadStatus == UPDATE_ERROR) diff --git a/src/log.cpp b/src/log.cpp index d40927c5..d2f1e125 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 << "[" - << ((((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) - << "] "; + 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 << "] "; mLogFile << timeStr.str() << buf << std::endl; diff --git a/src/main.cpp b/src/main.cpp index d067d3c9..e3fbdca6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,7 @@ #include <getopt.h> #include <iostream> #include <physfs.h> +#include <sstream> #include <unistd.h> #include <vector> #include <SDL_image.h> @@ -77,7 +78,6 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" -#include "utils/tostring.h" // Account infos char n_server, n_character; @@ -266,9 +266,10 @@ 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( - "graphics/sprites/hairstyle" + toString(i + 1) + ".png", - 40, 40); + filename.str(), 40, 40); if (!tmp) { logger->error("Unable to load hairstyle"); } else { diff --git a/src/monster.cpp b/src/monster.cpp index af84b25e..6416c716 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,9 +39,13 @@ 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( - "graphics/sprites/monster" + toString(job - 1002) + ".png", - 60, 60); + filename.str(), 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 9095a4e1..97e8186d 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -25,6 +25,7 @@ #include <SDL_types.h> #include <string> +#include <sstream> #include "messagein.h" #include "protocol.h" @@ -35,8 +36,6 @@ #include "../gui/chat.h" -#include "../utils/tostring.h" - extern Being *player_node; ChatHandler::ChatHandler() @@ -56,6 +55,7 @@ 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: - chatWindow->chatLog("Online users: " + toString(msg->readInt32()), - BY_SERVER); + ss << "Online users: " << msg->readInt32(); + chatWindow->chatLog(ss.str(), BY_SERVER); break; case 0x010c: diff --git a/src/utils/tostring.h b/src/utils/tostring.h deleted file mode 100644 index 8fc6d105..00000000 --- a/src/utils/tostring.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 |