summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/engine.cpp44
-rw-r--r--src/engine.h2
-rw-r--r--src/gui/chat.cpp12
-rw-r--r--src/gui/chat.h2
-rw-r--r--src/gui/checkbox.cpp3
-rw-r--r--src/gui/equipmentwindow.cpp8
-rw-r--r--src/gui/help.cpp3
-rw-r--r--src/gui/itemcontainer.cpp6
-rw-r--r--src/gui/listbox.cpp5
-rw-r--r--src/gui/listbox.h12
-rw-r--r--src/gui/login.cpp8
-rw-r--r--src/gui/ministatus.cpp32
-rw-r--r--src/gui/window.cpp25
-rw-r--r--src/main.cpp14
-rw-r--r--src/resources/image.cpp12
16 files changed, 74 insertions, 120 deletions
diff --git a/ChangeLog b/ChangeLog
index bfe50df2..62d861a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2006-03-15 Björn Steinbrink <B.Steinbrink@gmx.de>
+ * src/engine.h, src/main.cpp, src/gui/equipmentwindow.cpp,
+ src/gui/window.cpp, src/gui/login.cpp, src/gui/listbox.h,
+ src/gui/chat.h, src/gui/ministatus.cpp, src/gui/chat.cpp,
+ src/gui/help.cpp, src/gui/itemcontainer.cpp, src/gui/listbox.cpp,
+ src/gui/checkbox.cpp, src/engine.cpp, src/resources/image.cpp: A bunch
+ of cosmetic changes.
* src/net/network.cpp: Fixed connection not being shut down completely
in case of an error.
diff --git a/src/engine.cpp b/src/engine.cpp
index 43d4d0e5..3be152bd 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -82,7 +82,6 @@ Engine::Engine(Network *network):
{
std::stringstream filename;
filename << "graphics/sprites/weapon" << i << ".png";
- printf("hairstyle: %s\n", filename.str().c_str());
Spriteset *tmp = ResourceManager::getInstance()->createSpriteset(
filename.str(), 64, 64);
if (!tmp) {
@@ -117,53 +116,44 @@ Engine::~Engine()
delete itemDb;
}
-void Engine::changeMap(std::string mapPath)
+void Engine::changeMap(const std::string &mapPath)
{
- // Clean up floor items
+ // Clear floor items and beings
floorItemManager->clear();
-
beingManager->clear();
- // Generate full map path
- mapPath = "maps/" + mapPath;
- mapPath = mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz";
+ std::string oldMusic;
+ // Remove old map
+ if (mCurrentMap) {
+ oldMusic = mCurrentMap->getProperty("music");
+ delete mCurrentMap;
+ }
- // Store in global var
- map_path = mapPath;
+ // Generate full map path
+ map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz";
// Attempt to load the new map
- Map *newMap = MapReader::readMap(mapPath);
-
- if (!newMap) {
+ if (!(mCurrentMap = MapReader::readMap(map_path))) {
logger->error("Could not find map file");
}
// Notify the minimap and beingManager about the map change
Image *mapImage = NULL;
- if (newMap->hasProperty("minimap")) {
+ if (mCurrentMap->hasProperty("minimap")) {
ResourceManager *resman = ResourceManager::getInstance();
- mapImage = resman->getImage(newMap->getProperty("minimap"));
+ mapImage = resman->getImage(mCurrentMap->getProperty("minimap"));
}
minimap->setMapImage(mapImage);
- beingManager->setMap(newMap);
+ beingManager->setMap(mCurrentMap);
- // Start playing new music file when necessary
- std::string oldMusic = "";
-
- if (mCurrentMap) {
- oldMusic = mCurrentMap->getProperty("music");
- delete mCurrentMap;
- }
-
- std::string newMusic = newMap->getProperty("music");
+ // Change the music, if necessary
+ std::string newMusic = mCurrentMap->getProperty("music");
if (newMusic != oldMusic) {
- newMusic = std::string(TMW_DATADIR) + "data/music/" + newMusic;
+ newMusic = std::string(TMW_DATADIR "data/music/") + newMusic;
sound.playMusic(newMusic.c_str(), -1);
}
- mCurrentMap = newMap;
-
// Send "map loaded"
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_MAP_LOADED);
diff --git a/src/engine.h b/src/engine.h
index fd508857..ff39cfba 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -56,7 +56,7 @@ class Engine
/**
* Sets the currently active map.
*/
- void changeMap(std::string mapName);
+ void changeMap(const std::string &mapName);
/**
* Performs engine logic.
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 558c5558..7e0e4849 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -197,9 +197,9 @@ ChatWindow::action(const std::string& eventId)
{
std::string message = mChatInput->getText();
- if (message.length() > 0) {
+ if (!message.empty()) {
// If message different from previous, put it in the history
- if (mHistory.size() == 0 || message != mHistory.back()) {
+ if (mHistory.empty() || message != mHistory.back()) {
mHistory.push_back(message);
}
@@ -207,7 +207,7 @@ ChatWindow::action(const std::string& eventId)
mCurHist = mHistory.end();
// Send the message to the server
- chatSend(player_node->getName().c_str(), message.c_str());
+ chatSend(player_node->getName(), message);
// Clear the text from the chat input
mChatInput->setText("");
@@ -252,7 +252,7 @@ ChatWindow::isFocused()
}
void
-ChatWindow::chatSend(std::string nick, std::string msg)
+ChatWindow::chatSend(const std::string &nick, std::string msg)
{
// Prepare command
if (msg.substr(0, 1) == "/")
@@ -292,9 +292,7 @@ ChatWindow::chatSend(std::string nick, std::string msg)
}
// Prepare ordinary message
else {
- nick += " : ";
- nick += msg;
- msg = nick;
+ msg = nick + " : " + msg;
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_CHAT_MESSAGE);
diff --git a/src/gui/chat.h b/src/gui/chat.h
index f1c48569..80e57a84 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -182,7 +182,7 @@ class ChatWindow : public Window, public gcn::ActionListener,
* chatlog.chat_send("Zaeiru", "Hello to all users on the screen!");
*/
void
- chatSend(std::string nick, std::string msg);
+ chatSend(const std::string &nick, std::string msg);
/** Called when key is pressed */
void keyPress(const gcn::Key& key);
diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp
index 7506d3c0..ec7eb578 100644
--- a/src/gui/checkbox.cpp
+++ b/src/gui/checkbox.cpp
@@ -37,10 +37,9 @@ Image *CheckBox::checkBoxDisabledChecked;
CheckBox::CheckBox(const std::string& caption, bool marked):
gcn::CheckBox(caption, marked)
{
- ResourceManager *resman = ResourceManager::getInstance();
-
if (instances == 0)
{
+ ResourceManager *resman = ResourceManager::getInstance();
Image *checkBox = resman->getImage("graphics/gui/checkbox.png");
checkBoxNormal = checkBox->getSubImage(0, 0, 9, 10);
checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10);
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 61a9ad55..64c368bc 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -60,8 +60,10 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
Item *item;
Image *image;
+ // Rectangles around items are black
+ graphics->setColor(gcn::Color(0, 0, 0));
+
for (int i = 0; i < 8; i++) {
- graphics->setColor(gcn::Color(0, 0, 0));
graphics->drawRectangle(gcn::Rectangle(10 + 36 * (i % 4),
36 * (i / 4) + 25, 32, 32));
@@ -74,7 +76,6 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
image, 36 * (i % 4) + 10, 36 * (i / 4) + 25);
}
- graphics->setColor(gcn::Color(0, 0, 0));
graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32));
if (!(item = mEquipment->getArrows())) {
@@ -86,6 +87,5 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
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(n.str(), 170, 62, gcn::Graphics::CENTER);
}
diff --git a/src/gui/help.cpp b/src/gui/help.cpp
index 6b2eca6b..dfb814db 100644
--- a/src/gui/help.cpp
+++ b/src/gui/help.cpp
@@ -26,9 +26,6 @@
#include "button.h"
#include "browserbox.h"
#include "scrollarea.h"
-#include "textbox.h"
-
-#include "../log.h"
#include "../resources/resourcemanager.h"
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 874c0b63..e0730ced 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -76,8 +76,7 @@ void ItemContainer::draw(gcn::Graphics* graphics)
{
int gridWidth = mItemset->get(0)->getWidth() + 4;
int gridHeight = mItemset->get(0)->getHeight() + 10;
- int w = getWidth();
- int columns = w / gridWidth;
+ int columns = getWidth() / gridWidth;
// Have at least 1 column
if (columns < 1)
@@ -170,8 +169,7 @@ void ItemContainer::mousePress(int mx, int my, int button)
{
int gridWidth = mItemset->get(0)->getWidth() + 4;
int gridHeight = mItemset->get(0)->getHeight() + 10;
- int w = getWidth();
- int columns = w / gridWidth;
+ int columns = getWidth() / gridWidth;
if (button == gcn::MouseInput::LEFT || gcn::MouseInput::RIGHT)
{
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 5b20bb55..df03b81b 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -27,11 +27,6 @@
#include <guichan/graphics.hpp>
#include <guichan/listmodel.hpp>
-ListBox::ListBox():
- gcn::ListBox()
-{
-}
-
ListBox::ListBox(gcn::ListModel *listModel):
gcn::ListBox(listModel)
{
diff --git a/src/gui/listbox.h b/src/gui/listbox.h
index 23b81a57..5999f7a7 100644
--- a/src/gui/listbox.h
+++ b/src/gui/listbox.h
@@ -21,8 +21,8 @@
* $Id$
*/
-#ifndef __TMW_LISTBOX_H__
-#define __TMW_LISTBOX_H__
+#ifndef _TMW_LISTBOX_H
+#define _TMW_LISTBOX_H
#include <guichan/widgets/listbox.hpp>
@@ -33,16 +33,12 @@
*
* \ingroup GUI
*/
-class ListBox : public gcn::ListBox {
+class ListBox : public gcn::ListBox
+{
public:
/**
* Constructor.
*/
- ListBox();
-
- /**
- * Constructor.
- */
ListBox(gcn::ListModel *listModel);
/**
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index d6c8bfea..ee648669 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -39,7 +39,7 @@
void
WrongDataNoticeListener::setTarget(gcn::TextField *textField)
{
- this->mTarget = textField;
+ mTarget = textField;
}
void
@@ -114,7 +114,7 @@ LoginDialog::LoginDialog(LoginData *loginData):
setLocationRelativeTo(getParent());
- if (!mUserField->getText().length()) {
+ if (mUserField->getText().empty()) {
mUserField->requestFocus();
} else {
mPassField->requestFocus();
@@ -134,9 +134,9 @@ LoginDialog::action(const std::string& eventId)
if (eventId == "ok")
{
// Check login
- if (mUserField->getText().length() == 0)
+ if (mUserField->getText().empty())
{
- mWrongDataNoticeListener->setTarget(this->mPassField);
+ mWrongDataNoticeListener->setTarget(mPassField);
OkDialog *dlg = new OkDialog("Error", "Enter your username first");
dlg->addActionListener(mWrongDataNoticeListener);
}
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index e4cfc6a6..fc2f451b 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -23,7 +23,6 @@
#include "ministatus.h"
-#include <guichan/imagefont.hpp>
#include <guichan/widgets/label.hpp>
#include <sstream>
@@ -48,12 +47,18 @@ MiniStatusWindow::MiniStatusWindow():
mHpBar->setPosition(0, 3);
mMpBar->setPosition(mHpBar->getWidth() + 3, 3);
+ mHpLabel->setDimension(mHpBar->getDimension());
+ mMpLabel->setDimension(mMpBar->getDimension());
+
mHpLabel->setForegroundColor(gcn::Color(255, 255, 255));
mMpLabel->setForegroundColor(gcn::Color(255, 255, 255));
mHpLabel->setFont(speechFont);
mMpLabel->setFont(speechFont);
+ mHpLabel->setAlignment(gcn::Graphics::CENTER);
+ mMpLabel->setAlignment(gcn::Graphics::CENTER);
+
add(mHpBar);
add(mMpBar);
add(mHpLabel);
@@ -70,16 +75,13 @@ void MiniStatusWindow::update()
{
mHpBar->setColor(223, 32, 32); // Red
}
+ else if (player_node->mHp < int((player_node->mMaxHp / 3) * 2))
+ {
+ mHpBar->setColor(230, 171, 34); // Orange
+ }
else
{
- if (player_node->mHp < int((player_node->mMaxHp / 3) * 2))
- {
- mHpBar->setColor(230, 171, 34); // Orange
- }
- else
- {
- mHpBar->setColor(0, 171, 34); // Green
- }
+ mHpBar->setColor(0, 171, 34); // Green
}
mHpBar->setProgress((float)player_node->mHp / (float)player_node->mMaxHp);
@@ -89,21 +91,9 @@ void MiniStatusWindow::update()
std::stringstream updatedText;
updatedText << player_node->mHp;
mHpLabel->setCaption(updatedText.str());
- mHpLabel->adjustSize();
updatedText.str("");
updatedText << player_node->mMp;
mMpLabel->setCaption(updatedText.str());
- mMpLabel->adjustSize();
- mHpLabel->setPosition(
- mHpBar->getX() +
- int((mHpBar->getWidth() / 2) - (mHpLabel->getWidth() / 2)),
- mHpBar->getY() +
- int((mHpBar->getHeight() / 2) - (mHpLabel->getHeight() / 2)));
- mMpLabel->setPosition(
- mMpBar->getX() +
- int((mMpBar->getWidth() / 2) - (mMpLabel->getWidth() / 2)),
- mMpBar->getY() +
- int((mMpBar->getHeight() / 2) - (mMpLabel->getHeight() / 2)));
}
void MiniStatusWindow::draw(gcn::Graphics *graphics)
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 3b577116..492fe292 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -46,25 +46,12 @@ Image *Window::resizeGrip;
class WindowConfigListener : public ConfigListener
{
- public:
- /**
- * Called when an config option changes.
- */
- void optionChanged(const std::string &name)
- {
- if (name == "guialpha")
- {
- float guiAlpha = config.getValue("guialpha", 0.8);
-
- for (int i = 0; i < 9; i++)
- {
- if (Window::border.grid[i]->getAlpha() != guiAlpha)
- {
- Window::border.grid[i]->setAlpha(guiAlpha);
- }
- }
- }
- }
+ void optionChanged(const std::string &)
+ {
+ for_each(Window::border.grid, Window::border.grid + 9,
+ std::bind2nd(std::mem_fun(&Image::setAlpha),
+ config.getValue("guialpha", 0.8)));
+ }
};
Window::Window(const std::string& caption, bool modal, Window *parent):
diff --git a/src/main.cpp b/src/main.cpp
index de41bb14..e3fbdca6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -210,15 +210,11 @@ void init_engine()
if (tmwFile == NULL) {
// We reopen the file in write mode and we create it
tmwFile = fopen(configPath.c_str(), "wt");
- if (tmwFile == NULL) {
- std::cout << "Can't create " << configPath << ". Using Defaults." << std::endl;
- }
- else {
- fclose(tmwFile);
- config.init(configPath);
- }
}
- else {
+ if (tmwFile == NULL) {
+ std::cout << "Can't create " << configPath << ". "
+ "Using Defaults." << std::endl;
+ } else {
fclose(tmwFile);
config.init(configPath);
}
@@ -267,7 +263,7 @@ void init_engine()
playerset = resman->createSpriteset(
"graphics/sprites/player_male_base.png", 64, 64);
if (!playerset) logger->error("Couldn't load player spriteset!");
-
+
for (int i=0; i < NR_HAIR_STYLES; i++)
{
std::stringstream filename;
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index ee2736d4..51899d3f 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -282,14 +282,16 @@ Image *Image::getSubImage(int x, int y, int width, int height)
void Image::setAlpha(float a)
{
- mAlpha = a;
-
- if (!mImage) {
+ if (mAlpha == a) {
return;
}
- // Set the alpha value this image is drawn at
- SDL_SetAlpha(mImage, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * mAlpha));
+ mAlpha = a;
+
+ if (mImage) {
+ // Set the alpha value this image is drawn at
+ SDL_SetAlpha(mImage, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * mAlpha));
+ }
}
float Image::getAlpha()