From 2257406db0fd374e929def04525671c2826306c2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 18 Feb 2012 02:06:44 +0300 Subject: Fix code style. --- src/localplayer.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0576c8ddb..4675f80cf 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -3168,15 +3168,11 @@ void LocalPlayer::specialMove(unsigned char direction) && getInvertDirection() <= 4) && !mIsServerBuggy) { - int max; - if (getInvertDirection() == 2) - max = 10; - else - max = 30; - if (mAction == MOVE) return; + int max; + if (getInvertDirection() == 2) max = 5; else if (getInvertDirection() == 4) -- cgit v1.2.3-70-g09d2 From 87539666b11b2e61c4259404bf01ec8a5695052c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 19 Feb 2012 16:58:38 +0300 Subject: Fix display combined xp+job particle if used client data translations. --- src/localplayer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 4675f80cf..03199f7be 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1677,7 +1677,7 @@ void LocalPlayer::processEvent(Channels channel, - event.getInt("oldValue"); if (change != 0) - addMessageToQueue(toString(change) + " xp"); + addMessageToQueue(strprintf("%d %s", change, _("xp"))); break; } case LEVEL: @@ -1711,7 +1711,8 @@ void LocalPlayer::processEvent(Channels channel, MessagePair pair = mMessages.back(); // TRANSLATORS: this is normal experience if (pair.first.find(strprintf(" %s", - _("xp"))) == pair.first.size() - 3) + _("xp"))) == pair.first.size() + - strlen(_("xp")) - 1) { mMessages.pop_back(); // TRANSLATORS: this is job experience -- cgit v1.2.3-70-g09d2 From a8d90b8a84b5a21c53fb5d279dc983ae1e2c3217 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 22 Feb 2012 19:50:00 +0300 Subject: Fix code style. --- build/bmake | 1 - src/configuration.cpp | 2 +- src/effectmanager.h | 1 + src/gui/setup_joystick.cpp | 2 +- src/guichan/color.cpp | 18 +++++++++--------- src/guichan/defaultfont.cpp | 2 +- src/guichan/focushandler.cpp | 20 ++++++++++---------- src/guichan/include/guichan/sdl/sdlpixel.hpp | 23 +++++++++++++---------- src/guichan/sdl/sdlimage.cpp | 4 ++-- src/localplayer.cpp | 2 +- src/opengl1graphics.h | 4 ++-- src/openglgraphics.h | 6 +++--- src/particleemitterprop.h | 1 + src/utils/mathutils.h | 2 ++ src/utils/translation/poparser.cpp | 2 +- 15 files changed, 48 insertions(+), 42 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/build/bmake b/build/bmake index d99766ea7..33df5d180 100755 --- a/build/bmake +++ b/build/bmake @@ -8,7 +8,6 @@ cd .. #for feature #-Wstrict-overflow=4 -Wfloat-equal #-Wunsafe-loop-optimizations -#-Wnon-virtual-dtor #-Woverloaded-virtual #-Wformat=2 #-Wswitch-enum diff --git a/src/configuration.cpp b/src/configuration.cpp index 1ff205195..694f94e78 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -334,7 +334,7 @@ float Configuration::getFloatValue(const std::string &key) const (static_cast(itdef->second))->getData()); } else if (itdef->second->getType() - == VariableData::DATA_STRING) + == VariableData::DATA_STRING) { defaultValue = atof((static_cast( itdef->second))->getData().c_str()); diff --git a/src/effectmanager.h b/src/effectmanager.h index df19a0040..f8babd2f5 100644 --- a/src/effectmanager.h +++ b/src/effectmanager.h @@ -24,6 +24,7 @@ #include #include +#include class Being; diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 290607be4..a3240282a 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -146,7 +146,7 @@ void Setup_Joystick::action(const gcn::ActionEvent &event) { mCalibrateButton->setCaption(_("Stop")); mCalibrateLabel->setCaption( - _("Rotate the stick and dont press buttons")); + _("Rotate the stick and don't press buttons")); joystick->startCalibration(); } } diff --git a/src/guichan/color.cpp b/src/guichan/color.cpp index d3dc7a738..f58e7b58e 100644 --- a/src/guichan/color.cpp +++ b/src/guichan/color.cpp @@ -97,23 +97,23 @@ namespace gcn b - color.b, 255); - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); + result.r = (result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r)); + result.g = (result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g)); + result.b = (result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b)); return result; } Color Color::operator*(float value) const { - Color result((int)(r * value), - (int)(g * value), - (int)(b * value), + Color result(static_cast(r * value), + static_cast(g * value), + static_cast(b * value), a); - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); + result.r = (result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r)); + result.g = (result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g)); + result.b = (result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b)); return result; } diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp index 8871d51de..70901bc8e 100644 --- a/src/guichan/defaultfont.cpp +++ b/src/guichan/defaultfont.cpp @@ -89,7 +89,7 @@ namespace gcn int DefaultFont::getStringIndexAt(const std::string& text, int x) const { - if (x > (int)text.size() * 8) + if (x > static_cast(text.size() * 8)) return text.size(); return x / 8; diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp index 832a201ad..e3610fb1e 100644 --- a/src/guichan/focushandler.cpp +++ b/src/guichan/focushandler.cpp @@ -158,7 +158,7 @@ namespace gcn { int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) + for (i = 0; i < static_cast(mWidgets.size()); ++i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -167,7 +167,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { ++ focusedWidget; @@ -180,7 +180,7 @@ namespace gcn -- i; - if (focusedWidget >= (int)mWidgets.size()) + if (focusedWidget >= static_cast(mWidgets.size())) focusedWidget = 0; if (focusedWidget == focused) @@ -213,7 +213,7 @@ namespace gcn int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++ i) + for (i = 0; i < static_cast(mWidgets.size()); ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -222,7 +222,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { -- focusedWidget; @@ -342,7 +342,7 @@ namespace gcn int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) + for (i = 0; i < static_cast(mWidgets.size()); ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -352,7 +352,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { ++ focusedWidget; @@ -365,7 +365,7 @@ namespace gcn -- i; - if (focusedWidget >= (int)mWidgets.size()) + if (focusedWidget >= static_cast(mWidgets.size())) focusedWidget = 0; if (focusedWidget == focused) @@ -411,7 +411,7 @@ namespace gcn int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) + for (i = 0; i < static_cast(mWidgets.size()); ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -421,7 +421,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { -- focusedWidget; diff --git a/src/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp index a0221ca7c..bfd08341b 100644 --- a/src/guichan/include/guichan/sdl/sdlpixel.hpp +++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp @@ -68,7 +68,8 @@ namespace gcn SDL_LockSurface(surface); - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint8 *p = static_cast(surface->pixels) + + y * surface->pitch + x * bpp; unsigned int color = 0; @@ -79,7 +80,7 @@ namespace gcn break; case 2: - color = *(Uint16 *)p; + color = *reinterpret_cast(p); break; case 3: @@ -90,7 +91,7 @@ namespace gcn break; case 4: - color = *(Uint32 *)p; + color = *reinterpret_cast(p); break; default: @@ -123,7 +124,7 @@ namespace gcn SDL_LockSurface(surface); - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint8 *p = static_cast(surface->pixels) + y * surface->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); @@ -134,7 +135,7 @@ namespace gcn break; case 2: - *(Uint16 *)p = pixel; + *reinterpret_cast(p) = pixel; break; case 3: @@ -153,7 +154,7 @@ namespace gcn break; case 4: - *(Uint32 *)p = pixel; + *reinterpret_cast(p) = pixel; break; default: @@ -199,7 +200,7 @@ namespace gcn unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask) * (255 - a)) >> 8; - return (unsigned short)((b & f->Rmask) + return static_cast((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask)); } @@ -230,7 +231,8 @@ namespace gcn SDL_LockSurface(surface); - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint8 *p = static_cast(surface->pixels) + + y * surface->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); @@ -241,7 +243,7 @@ namespace gcn break; case 2: - *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, + *reinterpret_cast(p) = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format); break; @@ -275,7 +277,8 @@ namespace gcn break; case 4: - *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a); + *reinterpret_cast(p) = SDLAlpha32(pixel, + *reinterpret_cast(p), color.a); break; default: break; diff --git a/src/guichan/sdl/sdlimage.cpp b/src/guichan/sdl/sdlimage.cpp index e4aadc465..4f9b9565c 100644 --- a/src/guichan/sdl/sdlimage.cpp +++ b/src/guichan/sdl/sdlimage.cpp @@ -130,8 +130,8 @@ namespace gcn for (i = 0; i < mSurface->w * mSurface->h; ++i) { - if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB( - mSurface->format, 255, 0, 255)) + if ((static_cast(mSurface->pixels))[i] + == SDL_MapRGB(mSurface->format, 255, 0, 255)) { hasPink = true; break; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 03199f7be..b07511196 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2153,7 +2153,7 @@ static const char *pvpAttackStrings[] = N_("(a) attack all players"), N_("(f) attack all except friends"), N_("(b) attack bad relations"), - N_("(d) dont attack players"), + N_("(d) don't attack players"), N_("(?) pvp attack") }; diff --git a/src/opengl1graphics.h b/src/opengl1graphics.h index 76dc3ef00..8cc3c89a7 100644 --- a/src/opengl1graphics.h +++ b/src/opengl1graphics.h @@ -23,15 +23,14 @@ #ifndef OPENGL1GRAPHICS_H #define OPENGL1GRAPHICS_H +#ifdef USE_OPENGL #include "main.h" #include "graphics.h" -#ifdef USE_OPENGL #define NO_SDL_GLEXT #include -#endif class OpenGL1Graphics : public Graphics { @@ -140,5 +139,6 @@ class OpenGL1Graphics : public Graphics bool mColorAlpha; bool mSync; }; +#endif #endif diff --git a/src/openglgraphics.h b/src/openglgraphics.h index f3bdc4470..9eeb530ac 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -23,15 +23,14 @@ #ifndef OPENGLGRAPHICS_H #define OPENGLGRAPHICS_H -#include "main.h" +#ifdef USE_OPENGL +#include "main.h" #include "graphics.h" -#ifdef USE_OPENGL #define NO_SDL_GLEXT #include -#endif class OpenGLGraphics : public Graphics { @@ -154,5 +153,6 @@ class OpenGLGraphics : public Graphics bool mColorAlpha; bool mSync; }; +#endif #endif diff --git a/src/particleemitterprop.h b/src/particleemitterprop.h index cadfa0f3a..2b6b7ba1a 100644 --- a/src/particleemitterprop.h +++ b/src/particleemitterprop.h @@ -21,6 +21,7 @@ */ #include +#include /** * Returns a random numeric value that is larger than or equal min and smaller diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h index 8ccd71e79..6d5a8339d 100644 --- a/src/utils/mathutils.h +++ b/src/utils/mathutils.h @@ -23,7 +23,9 @@ #ifndef UTILS_MATHUTILS_H #define UTILS_MATHUTILS_H +#include #include +#include static uint16_t crc_table[256] = { diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp index 24d2ee4d4..521774592 100644 --- a/src/utils/translation/poparser.cpp +++ b/src/utils/translation/poparser.cpp @@ -144,7 +144,7 @@ bool PoParser::readMsgId() mLine = ""; return true; } - // stop reading if we dont read msgid before + // stop reading if we don't read msgid before return mMsgId.empty(); } } -- cgit v1.2.3-70-g09d2 From 81db0022e50e25d922ac7d67d9ec6017b8856f13 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 25 Feb 2012 21:28:51 +0300 Subject: Fix old casts. --- src/being.cpp | 2 +- src/configuration.cpp | 3 ++- src/graphics.cpp | 23 +++++++++++++-------- src/gui/charcreatedialog.cpp | 10 +++++++-- src/gui/debugwindow.cpp | 2 +- src/gui/editserverdialog.cpp | 3 ++- src/gui/equipmentwindow.cpp | 10 +++++++-- src/gui/itempopup.cpp | 2 +- src/gui/outfitwindow.cpp | 2 +- src/gui/popupmenu.cpp | 2 +- src/gui/serverdialog.cpp | 4 ++-- src/gui/setup_relations.cpp | 2 +- src/gui/updaterwindow.cpp | 4 ++-- src/gui/viewport.cpp | 3 ++- src/gui/widgets/browserbox.cpp | 22 ++++++++++---------- src/gui/widgets/guitable.cpp | 9 ++++---- src/gui/widgets/setupitem.cpp | 4 ++-- src/gui/widgets/textfield.cpp | 2 +- src/guichan/include/guichan/sdl/sdlpixel.hpp | 4 ++-- src/guichan/sdl/sdlgraphics.cpp | 23 ++++++++++++++------- src/guichan/sdl/sdlimage.cpp | 4 ++-- src/guichan/widgets/scrollarea.cpp | 8 +++---- src/guichan/widgets/slider.cpp | 4 ++-- src/guichan/widgets/tabbedarea.cpp | 2 +- src/guichan/widgets/textbox.cpp | 31 ++++++++++++++-------------- src/guichan/widgets/window.cpp | 2 +- src/guildmanager.cpp | 6 +++--- src/localplayer.cpp | 2 +- src/net/messagein.cpp | 2 +- src/net/tmwa/playerhandler.cpp | 4 ++-- src/opengl1graphics.cpp | 6 ++++-- src/openglgraphics.cpp | 10 +++++---- src/utils/copynpaste.cpp | 10 +++++++-- src/utils/langs.cpp | 8 +++---- src/utils/physfsrwops.cpp | 22 ++++++++++---------- src/utils/process.cpp | 6 +++--- src/utils/stringutils.cpp | 6 +++--- 37 files changed, 153 insertions(+), 116 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/being.cpp b/src/being.cpp index e1cb9b0ae..b5f55592f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2320,7 +2320,7 @@ void Being::recalcSpritesOrder() int val = slotRemap.at(slot); int id = 0; - if ((int)mSpriteIDs.size() > val) + if (static_cast(mSpriteIDs.size()) > val) id = mSpriteIDs[val]; int idx = -1; diff --git a/src/configuration.cpp b/src/configuration.cpp index 694f94e78..97540c385 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -572,7 +572,8 @@ void ConfigurationObject::writeToXML(XmlTextWriterPtr writer) elt_it != it->second.end(); ++elt_it) { xmlTextWriterStartElement(writer, BAD_CAST name); - (*elt_it)->writeToXML(writer); + if (*elt_it) + (*elt_it)->writeToXML(writer); xmlTextWriterEndElement(writer); } diff --git a/src/graphics.cpp b/src/graphics.cpp index 5241bbcc6..e6841fa5c 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -845,7 +845,8 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) case 1: for (y = y1; y < y2; y++) { - Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) *(p + x) = pixel; } @@ -853,12 +854,14 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) case 2: for (y = y1; y < y2; y++) { - Uint8 *p0 = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p0 = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) { Uint8 *p = p0 + x * 2; - *(Uint16 *)p = gcn::SDLAlpha16( - pixel, *(Uint32 *)p, mColor.a, mTarget->format); + *reinterpret_cast(p) = gcn::SDLAlpha16( + pixel, *reinterpret_cast(p), + mColor.a, mTarget->format); } } break; @@ -871,7 +874,8 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) for (y = y1; y < y2; y++) { - Uint8 *p0 = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p0 = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) { Uint8 *p = p0 + x * 3; @@ -896,18 +900,19 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) const unsigned a1 = (255 - mColor.a); for (y = y1; y < y2; y++) { - Uint8 *p0 = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p0 = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) { Uint8 *p = p0 + x * 4; - Uint32 dst = *(Uint32 *)p; + Uint32 dst = *reinterpret_cast(p); const unsigned int b = (pb + (dst & 0xff) * a1) >> 8; const unsigned int g = (pg + (dst & 0xff00) * a1) >> 8; const unsigned int r = (pr + (dst & 0xff0000) * a1) >> 8; - *(Uint32 *)p = ((b & 0xff) | (g & 0xff00) - | (r & 0xff0000)); + *reinterpret_cast(p) = ((b & 0xff) + | (g & 0xff00) | (r & 0xff0000)); } } break; diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 8d4767a15..9f7436ad8 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -474,8 +474,11 @@ void CharCreateDialog::updateHair() mHairStyle %= Being::getNumOfHairstyles(); if (mHairStyle < 0) mHairStyle += Being::getNumOfHairstyles(); - if (mHairStyle < (signed)minHairStyle || mHairStyle > (signed)maxHairStyle) + if (mHairStyle < static_cast(minHairStyle) + || mHairStyle > static_cast(maxHairStyle)) + { mHairStyle = minHairStyle; + } const ItemInfo &item = ItemDB::get(-mHairStyle); mHairStyleNameLabel->setCaption(item.getName()); mHairStyleNameLabel->adjustSize(); @@ -483,8 +486,11 @@ void CharCreateDialog::updateHair() mHairColor %= ColorDB::getHairSize(); if (mHairColor < 0) mHairColor += ColorDB::getHairSize(); - if (mHairColor < (signed)minHairColor || mHairColor > (signed)maxHairColor) + if (mHairColor < static_cast(minHairColor) + || mHairColor > static_cast(maxHairColor)) + { mHairColor = minHairColor; + } mHairColorNameLabel->setCaption(ColorDB::getHairColorName(mHairColor)); mHairColorNameLabel->adjustSize(); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index b65068dc5..fa01b5aa8 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -390,7 +390,7 @@ void NetDebugTab::logic() if (player_node && player_node->getPingTime() != 0) { mPingLabel->setCaption(strprintf(_("Ping: %s ms"), - toString((int)player_node->getPingTime()).c_str())); + toString(static_cast(player_node->getPingTime())).c_str())); } else { diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 8a4a9579d..53e31c3c8 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -184,7 +184,8 @@ void EditServerDialog::action(const gcn::ActionEvent &event) mServer.name = mNameField->getText(); mServer.description = mDescriptionField->getText(); mServer.hostname = mServerAddressField->getText(); - mServer.port = (short) atoi(mPortField->getText().c_str()); + mServer.port = static_cast(atoi( + mPortField->getText().c_str())); if (mTypeField) { diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 275bf19bb..89063c3dc 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -407,8 +407,11 @@ void EquipmentWindow::loadSlot(XmlNodePtr slotNode, ImageSet *imageset) const int imageIndex = XML::getProperty(slotNode, "image", -1); Image *image = nullptr; - if (imageset && imageIndex >= 0 && imageIndex < (signed)imageset->size()) + if (imageset && imageIndex >= 0 && imageIndex + < static_cast(imageset->size())) + { image = imageset->get(imageIndex); + } if (mBoxes[slot]) { @@ -510,8 +513,11 @@ void EquipmentWindow::addBox(int idx, int x, int y, int imageIndex) { Image *image = nullptr; - if (mImageSet && imageIndex >= 0 && imageIndex < (signed)mImageSet->size()) + if (mImageSet && imageIndex >= 0 && imageIndex + < static_cast(mImageSet->size())) + { image = mImageSet->get(imageIndex); + } mBoxes[idx] = new EquipmentBox(x + getPadding(), y + getTitleBarHeight(), image); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index d96aa564f..f33f77e83 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -123,7 +123,7 @@ void ItemPopup::setItem(const Item *item, bool showImage) } mItemName->adjustSize(); unsigned minWidth = mItemName->getWidth() + 8; - if ((unsigned)getWidth() < minWidth) + if (static_cast(getWidth()) < minWidth) setWidth(minWidth); } } diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 73484f1d5..6eaa2ac4e 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -190,7 +190,7 @@ void OutfitWindow::save() outfitStr += toString(res); if (i < OUTFIT_ITEM_COUNT - 1) outfitStr += " "; - outfitColorsStr += toString((int)mItemColors[o][i]); + outfitColorsStr += toString(static_cast(mItemColors[o][i])); if (i < OUTFIT_ITEM_COUNT - 1) outfitColorsStr += " "; } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index c987843d3..933d2c7cd 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -2205,7 +2205,7 @@ void PlayerListener::action(const gcn::ActionEvent &event) { std::string comment = mDialog->getText(); Being* being = actorSpriteManager->findBeingByName( - mNick, (ActorSprite::Type)mType); + mNick, static_cast(mType)); if (being) being->setComment(comment); Being::saveComment(mNick, comment, mType); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index da61e105b..ed9696892 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -125,7 +125,7 @@ std::string ServersListModel::getElementAt(int elementIndex) void ServersListModel::setVersionString(int index, const std::string &version) { - if (index >= (int)mVersionStrings.size()) + if (index >= static_cast(mVersionStrings.size())) return; if (version.empty()) @@ -632,7 +632,7 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer, // Make sure the current server is mentioned first if (currentServer.isValid()) { - if (index >= 0 && (unsigned)index < mServers.size()) + if (index >= 0 && static_cast(index) < mServers.size()) { mServers[index] = currentServer; } diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 47d53620c..f3b664c9b 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -194,7 +194,7 @@ public: std::string getPlayerAt(int index) const { - if (index < 0 || index >= (signed)mPlayers->size()) + if (index < 0 || index >= static_cast(mPlayers->size())) return ""; return (*mPlayers)[index]; } diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 3aaf93557..fe26d42eb 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -554,8 +554,8 @@ void UpdaterWindow::logic() if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size()) { mProgressBar->setText(strprintf("%d/%d", mUpdateIndex - + mUpdateIndexOffset + 1, (int)mUpdateFiles.size() - + (int)mTempUpdateFiles.size() + 1)); + + mUpdateIndexOffset + 1, static_cast(mUpdateFiles.size()) + + static_cast(mTempUpdateFiles.size()) + 1)); } else { diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index d4c188bfb..0c0f0d3d9 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -199,7 +199,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) // if (debugChatTab) // debugChatTab->chatLog("incorrect player position!"); logger->log("incorrect player position: %d, %d, %d, %d", - player_x, player_y, (int)mPixelViewX, (int)mPixelViewY); + player_x, player_y, static_cast(mPixelViewX), + static_cast(mPixelViewY)); if (player_node) { logger->log("tile position: %d, %d", diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 5856a91b1..47c5616b6 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -232,15 +232,17 @@ void BrowserBox::addRow(const std::string &row, bool atTop) tempRow.substr(nextChar, (nextSpacePos - nextChar))); - if ((x + nextWordWidth + 10) > (unsigned)getWidth()) + if ((x + nextWordWidth + 10) + > static_cast(getWidth())) { x = 15; // Ident in new line y += 1; - j++; + j ++; } } // Wrapping looong lines (brutal force) - else if ((x + 2 * hyphenWidth) > (unsigned)getWidth()) + else if ((x + 2 * hyphenWidth) + > static_cast(getWidth())) { x = 15; // Ident in new line y += 1; @@ -249,7 +251,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop) } setHeight(font->getHeight() * (static_cast( - mTextRows.size()) + y)); + mTextRows.size()) + y)); } else { @@ -423,7 +425,7 @@ int BrowserBox::calcHeight() if (row.find("---", 0) == 0) { const int dashWidth = fontWidthMinus; - for (x = 0; x < (unsigned)getWidth(); x++) + for (x = 0; x < static_cast(getWidth()); x ++) { mLineParts.push_back(LinePart(x, y, selColor, "-", false)); x += dashWidth - 2; @@ -557,9 +559,8 @@ int BrowserBox::calcHeight() width = font->getWidth(part); // Auto wrap mode - if (mMode == AUTO_WRAP && getWidth() > 0 - && width > 0 - && (x + width + 10) > (unsigned)getWidth()) + if (mMode == AUTO_WRAP && getWidth() > 0 && width > 0 + && (x + width + 10) > static_cast(getWidth())) { bool forced = false; @@ -592,9 +593,8 @@ int BrowserBox::calcHeight() else width = font->getWidth(part); } - while (end > start && width > 0 - && (x + width + 10) - > (unsigned)getWidth()); + while (end > start && width > 0 && (x + width + 10) + > static_cast(getWidth())); if (forced) { diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index d620cbb8d..6434f5453 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -348,14 +348,15 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mSelectedRow > 0) { - if (mLinewiseMode && r == (unsigned)mSelectedRow && c == 0) + if (mLinewiseMode && r == static_cast( + mSelectedRow) && c == 0) { graphics->fillRectangle(gcn::Rectangle(0, y_offset, - getWidth(), height)); + getWidth(), height)); } else if (!mLinewiseMode && mSelectedColumn > 0 - && c == (unsigned)mSelectedColumn - && r == (unsigned)mSelectedRow) + && c == static_cast(mSelectedColumn) + && r == static_cast(mSelectedRow)) { graphics->fillRectangle(gcn::Rectangle( x_offset, y_offset, width, height)); diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 490c046c3..8987719da 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -830,8 +830,8 @@ void SetupItemSlider2::updateLabel() int val = mSlider->getValue() - mMin; if (val < 0) val = 0; - else if (val >= (signed)mValues->size()) - val = (signed)mValues->size() - 1; + else if (val >= static_cast(mValues->size())) + val = static_cast(mValues->size()) - 1; std::string str = mValues->at(val); mLabel2->setCaption(str); } diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index e207b0613..a90712340 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -183,7 +183,7 @@ int TextField::getValue() const if (value < mMinimum) return mMinimum; - if (value > (signed)mMaximum) + if (value > static_cast(mMaximum)) return mMaximum; return value; diff --git a/src/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp index f56100b4a..23298ef37 100644 --- a/src/guichan/include/guichan/sdl/sdlpixel.hpp +++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp @@ -244,8 +244,8 @@ namespace gcn break; case 2: - *reinterpret_cast(p) = SDLAlpha16(pixel, *(Uint32 *)p, - color.a, surface->format); + *reinterpret_cast(p) = SDLAlpha16(pixel, + *reinterpret_cast(p), color.a, surface->format); break; case 3: diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp index c8cec6370..ae61a0432 100644 --- a/src/guichan/sdl/sdlgraphics.cpp +++ b/src/guichan/sdl/sdlgraphics.cpp @@ -283,7 +283,8 @@ namespace gcn SDL_LockSurface(mTarget); - Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch + x1 * bpp; + Uint8 *p = static_cast(mTarget->pixels) + + y * mTarget->pitch + x1 * bpp; Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, @@ -298,7 +299,7 @@ namespace gcn case 2: { - Uint16* q = (Uint16*)p; + Uint16* q = reinterpret_cast(p); for (; x1 <= x2; ++x1) *(q++) = pixel; break; @@ -329,7 +330,7 @@ namespace gcn case 4: { - Uint32* q = (Uint32*)p; + Uint32 *q = reinterpret_cast(p); for (; x1 <= x2; ++x1) { if (mAlpha) @@ -395,7 +396,8 @@ namespace gcn SDL_LockSurface(mTarget); - Uint8 *p = (Uint8 *)mTarget->pixels + y1 * mTarget->pitch + x * bpp; + Uint8 *p = static_cast(mTarget->pixels) + + y1 * mTarget->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); @@ -411,9 +413,9 @@ namespace gcn break; case 2: - for (; y1 <= y2; ++y1) + for (; y1 <= y2; ++ y1) { - *(Uint16*)p = pixel; + *reinterpret_cast(p) = pixel; p += mTarget->pitch; } break; @@ -445,9 +447,14 @@ namespace gcn for (; y1 <= y2; ++y1) { if (mAlpha) - *(Uint32*)p = SDLAlpha32(pixel, *(Uint32*)p, mColor.a); + { + *reinterpret_cast(p) = SDLAlpha32(pixel, + *reinterpret_cast(p), mColor.a); + } else - *(Uint32*)p = pixel; + { + *reinterpret_cast(p) = pixel; + } p += mTarget->pitch; } break; diff --git a/src/guichan/sdl/sdlimage.cpp b/src/guichan/sdl/sdlimage.cpp index 4f9b9565c..cf8505c4e 100644 --- a/src/guichan/sdl/sdlimage.cpp +++ b/src/guichan/sdl/sdlimage.cpp @@ -142,8 +142,8 @@ namespace gcn { Uint8 r, g, b, a; - SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format, - &r, &g, &b, &a); + SDL_GetRGBA((static_cast(mSurface->pixels)[i]), + mSurface->format, &r, &g, &b, &a); if (a != 255) { diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp index 451288c77..21f7b5930 100644 --- a/src/guichan/widgets/scrollarea.cpp +++ b/src/guichan/widgets/scrollarea.cpp @@ -325,12 +325,12 @@ namespace gcn if (y < getVerticalMarkerDimension().y) { setVerticalScrollAmount(getVerticalScrollAmount() - - (int)(getChildrenArea().height * 0.95)); + - static_cast(getChildrenArea().height * 0.95)); } else { setVerticalScrollAmount(getVerticalScrollAmount() - + (int)(getChildrenArea().height * 0.95)); + + static_cast(getChildrenArea().height * 0.95)); } } else if (getHorizontalMarkerDimension().isPointInRect(x, y)) @@ -345,12 +345,12 @@ namespace gcn if (x < getHorizontalMarkerDimension().x) { setHorizontalScrollAmount(getHorizontalScrollAmount() - - (int)(getChildrenArea().width * 0.95)); + - static_cast(getChildrenArea().width * 0.95)); } else { setHorizontalScrollAmount(getHorizontalScrollAmount() - + (int)(getChildrenArea().width * 0.95)); + + static_cast(getChildrenArea().width * 0.95)); } } } diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp index 16f7cd8be..36f067eab 100644 --- a/src/guichan/widgets/slider.cpp +++ b/src/guichan/widgets/slider.cpp @@ -245,7 +245,7 @@ namespace gcn else w = getHeight(); - double pos = v / ((double)w - getMarkerLength()); + double pos = v / (static_cast(w) - getMarkerLength()); return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); } @@ -257,7 +257,7 @@ namespace gcn else v = getHeight(); - int w = (int)((v - getMarkerLength()) + int w = static_cast((v - getMarkerLength()) * (value - getScaleStart()) / (getScaleEnd() - getScaleStart())); diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp index 7af00c4c4..3e7178548 100644 --- a/src/guichan/widgets/tabbedarea.cpp +++ b/src/guichan/widgets/tabbedarea.cpp @@ -320,7 +320,7 @@ namespace gcn int index = getSelectedTabIndex(); index++; - if (index >= (int)mTabs.size()) + if (index >= static_cast(mTabs.size())) return; else setSelectedTab(mTabs[index].first); diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp index e78ea91a3..c2cd5586f 100644 --- a/src/guichan/widgets/textbox.cpp +++ b/src/guichan/widgets/textbox.cpp @@ -155,7 +155,7 @@ namespace gcn { mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) mCaretRow = mTextRows.size() - 1; mCaretColumn = getFont()->getStringIndexAt( @@ -193,11 +193,11 @@ namespace gcn else if (key.getValue() == Key::RIGHT) { ++mCaretColumn; - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) { - ++mCaretRow; + ++ mCaretRow; - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) { mCaretRow = mTextRows.size() - 1; if (mCaretRow < 0) @@ -254,14 +254,15 @@ namespace gcn --mCaretRow; } else if (key.getValue() == Key::DELETE - && mCaretColumn < (int)mTextRows[mCaretRow].size() - && mEditable) + && mCaretColumn < static_cast( + mTextRows[mCaretRow].size()) && mEditable) { mTextRows[mCaretRow].erase(mCaretColumn, 1); } else if (key.getValue() == Key::DELETE - && mCaretColumn == (int)mTextRows[mCaretRow].size() - && mCaretRow < ((int)mTextRows.size() - 1) + && mCaretColumn == static_cast( + mTextRows[mCaretRow].size()) + && mCaretRow < (static_cast(mTextRows.size()) - 1) && mEditable) { mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; @@ -291,7 +292,7 @@ namespace gcn / getFont()->getHeight(); mCaretRow += rowsPerPage; - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) mCaretRow = mTextRows.size() - 1; } } @@ -305,7 +306,7 @@ namespace gcn && mEditable) { mTextRows[mCaretRow].insert(mCaretColumn, - std::string(1, (char)key.getValue())); + std::string(1, static_cast(key.getValue()))); ++ mCaretColumn; } @@ -332,9 +333,7 @@ namespace gcn void TextBox::setCaretPosition(unsigned int position) { - int row; - - for (row = 0; row < (int)mTextRows.size(); row++) + for (int row = 0; row < static_cast(mTextRows.size()); row ++) { if (position <= mTextRows[row].size()) { @@ -373,7 +372,7 @@ namespace gcn { mCaretRow = row; - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) mCaretRow = mTextRows.size() - 1; if (mCaretRow < 0) @@ -391,7 +390,7 @@ namespace gcn { mCaretColumn = column; - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) mCaretColumn = mTextRows[mCaretRow].size(); if (mCaretColumn < 0) @@ -431,7 +430,7 @@ namespace gcn int i; std::string text; - for (i = 0; i < (int)mTextRows.size() - 1; ++i) + for (i = 0; i < static_cast(mTextRows.size()) - 1; ++ i) text = text + mTextRows[i] + "\n"; text = text + mTextRows[i]; diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp index d7c5809e6..c7ed8a69e 100644 --- a/src/guichan/widgets/window.cpp +++ b/src/guichan/widgets/window.cpp @@ -137,7 +137,7 @@ namespace gcn mDragOffsetX = mouseEvent.getX(); mDragOffsetY = mouseEvent.getY(); - mMoved = mouseEvent.getY() <= (int)mTitleBarHeight; + mMoved = mouseEvent.getY() <= static_cast(mTitleBarHeight); } void Window::mouseReleased(MouseEvent& mouseEvent A_UNUSED) diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 9dc9d7b73..08af3b2c7 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -274,7 +274,7 @@ bool GuildManager::process(std::string msg) return false; // logger->log("welcome message: %s", msg.c_str()); int pos = msg.find("! ("); - if (pos == (int)std::string::npos) + if (pos == static_cast(std::string::npos)) return false; msg = msg.substr(0, pos); guild->setName(msg); @@ -299,7 +299,7 @@ bool GuildManager::process(std::string msg) return false; pos = msg.find(", Guild:"); - if (pos == (int)std::string::npos) + if (pos == static_cast(std::string::npos)) return false; int level = atoi(msg.substr(0, pos).c_str()); @@ -310,7 +310,7 @@ bool GuildManager::process(std::string msg) msg = msg.substr(pos + strlen(", Guild:")); pos = msg.find(", No. Of Online Players: "); - if (pos == (int)std::string::npos) + if (pos == static_cast(std::string::npos)) return false; msg = msg.substr(0, pos); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b07511196..5114f868c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2064,7 +2064,7 @@ std::string LocalPlayer::getQuickDropCounterString() void LocalPlayer::setQuickDropCounter(int n) { - if (n < 1 || n >= (signed)quickDropCounterSize) + if (n < 1 || n >= static_cast(quickDropCounterSize)) return; mQuickDropCounter = n; config.setValue("quickDropCounter", mQuickDropCounter); diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 0547ed337..5d15d26ac 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -265,7 +265,7 @@ unsigned char *MessageIn::readBytes(int length) #ifdef ENABLEDEBUGLOG std::string str; for (int f = 0; f < length; f ++) - str += strprintf ("%02x", (unsigned)buf[f]); + str += strprintf ("%02x", static_cast(buf[f])); str += " "; for (int f = 0; f < length; f ++) { diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index bfe9eea42..a63af770a 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -229,7 +229,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) return; } - char *start = (char*)msg.readBytes(size); + char *start = reinterpret_cast(msg.readBytes(size)); if (!start) return; @@ -265,7 +265,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) gender = GENDER_FEMALE; } } - arr.push_back(new OnlinePlayer((char*)buf, + arr.push_back(new OnlinePlayer(static_cast(buf), status, level, gender, ver)); buf += strlen(buf) + 1; } diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp index 34e9fcda3..ea4d5e6f3 100644 --- a/src/opengl1graphics.cpp +++ b/src/opengl1graphics.cpp @@ -393,8 +393,10 @@ void OpenGL1Graphics::drawRescaledImagePattern(Image *image, int x, int y, // Draw a set of textured rectangles glBegin(GL_QUADS); - const float scaleFactorW = (float) scaledWidth / image->getWidth(); - const float scaleFactorH = (float) scaledHeight / image->getHeight(); + const float scaleFactorW = static_cast(scaledWidth) + / image->getWidth(); + const float scaleFactorH = static_cast(scaledHeight) + / image->getHeight(); for (int py = 0; py < h; py += ih) { diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index bcf46e18b..d972a738f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -554,8 +554,10 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, { int width = (px + scaledWidth >= w) ? w - px : scaledWidth; int dstX = x + px; - const float visibleFractionW = (float) width / scaledWidth; - const float visibleFractionH = (float) height / scaledHeight; + const float visibleFractionW = static_cast(width) + / scaledWidth; + const float visibleFractionH = static_cast(height) + / scaledHeight; const float texX2 = texX1 + tFractionW * visibleFractionW; const float texY2 = texY1 + tFractionH * visibleFractionH; @@ -597,8 +599,8 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, } else { - const float scaleFactorW = (float) scaledWidth / iw; - const float scaleFactorH = (float) scaledHeight / ih; + const float scaleFactorW = static_cast(scaledWidth) / iw; + const float scaleFactorH = static_cast(scaledHeight) / ih; for (int py = 0; py < h; py += scaledHeight) { diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 90e0c5c93..763b579d0 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -442,9 +442,15 @@ bool runxsel(std::string& text, const char *p1, const char *p2) close(fd[0]); } if (p2) - execl("/usr/bin/xsel", "xsel", p1, p2, (char *)nullptr); + { + execl("/usr/bin/xsel", "xsel", p1, p2, + static_cast(nullptr)); + } else - execl("/usr/bin/xsel", "xsel", p1, (char *)nullptr); + { + execl("/usr/bin/xsel", "xsel", p1, + static_cast(nullptr)); + } exit(1); } diff --git a/src/utils/langs.cpp b/src/utils/langs.cpp index 2efbd781a..c1f9f7ecf 100644 --- a/src/utils/langs.cpp +++ b/src/utils/langs.cpp @@ -44,11 +44,11 @@ std::vector getLang() } int dot = lang.find("."); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) lang = lang.substr(0, dot); langs.push_back(lang); dot = lang.find("_"); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) langs.push_back(lang.substr(0, dot)); return langs; } @@ -78,10 +78,10 @@ std::string getLangShort() } int dot = lang.find("."); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) lang = lang.substr(0, dot); dot = lang.find("_"); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) return lang.substr(0, dot); return lang; } diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index 1960f0dee..2675b89ae 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -29,7 +29,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) { - PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); int pos = 0; if (whence == SEEK_SET) @@ -46,8 +46,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - pos = (int)current; - if (((PHYSFS_sint64)pos) != current) + pos = static_cast(current); + if (static_cast(pos) != current) { SDL_SetError("Can't fit current file position in an int!"); return -1; @@ -67,8 +67,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - pos = (int)len; - if (((PHYSFS_sint64)pos) != len) + pos = static_cast(len); + if (static_cast(pos) != len) { SDL_SetError("Can't fit end-of-file position in an int!"); return -1; @@ -88,7 +88,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos)) + if (!PHYSFS_seek(handle, static_cast(pos))) { SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); return -1; @@ -99,7 +99,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum); if (rc != maxnum) { @@ -107,22 +107,22 @@ static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); } /* if */ - return (int)rc; + return static_cast(rc); } /* physfsrwops_read */ static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num); if (rc != num) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); - return (int) rc; + return static_cast(rc); } /* physfsrwops_write */ static int physfsrwops_close(SDL_RWops *rw) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); if (!PHYSFS_close(handle)) { SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); diff --git a/src/utils/process.cpp b/src/utils/process.cpp index fd0ec0fa8..0106c597d 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -112,12 +112,12 @@ int execFile(std::string pathName, std::string name, if (arg2.empty()) { execl(pathName.c_str(), name.c_str(), - arg1.c_str(), (char *)nullptr); + arg1.c_str(), static_cast(nullptr)); } else { - execl(pathName.c_str(), name.c_str(), - arg1.c_str(), arg2.c_str(), (char *)nullptr); + execl(pathName.c_str(), name.c_str(), arg1.c_str(), + arg2.c_str(), static_cast(nullptr)); } exit(-1); } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 2f478a909..5a7ea87fd 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -522,9 +522,9 @@ std::string stringToHexPath(const std::string &str) if (str.empty()) return ""; - std::string hex = strprintf("%%%2x/", (int)str[0]); + std::string hex = strprintf("%%%2x/", static_cast(str[0])); for (unsigned f = 1; f < str.size(); f ++) - hex += strprintf("%%%2x", (int)str[f]); + hex += strprintf("%%%2x", static_cast(str[f])); return hex; } @@ -600,7 +600,7 @@ bool findCutFirst(std::string &str1, std::string str2) std::string &removeProtocol(std::string &url) { int i = url.find("://"); - if (i != (int)std::string::npos) + if (i != static_cast(std::string::npos)) url = url.substr(i + 3); return url; } -- cgit v1.2.3-70-g09d2 From c85d939d9b3f6c10288dc86ffa7811408e349657 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 28 Feb 2012 02:14:15 +0300 Subject: Add different sound effects for different events. Can be configured in audio tab in settings. --- data/sfx/system/CMakeLists.txt | 16 ++++++++++++ data/sfx/system/Makefile.am | 18 +++++++++++++- data/sfx/system/attention.ogg | Bin 0 -> 10439 bytes data/sfx/system/chat1.ogg | Bin 0 -> 8270 bytes data/sfx/system/chat2.ogg | Bin 0 -> 6341 bytes data/sfx/system/complete.ogg | Bin 0 -> 13971 bytes data/sfx/system/email.ogg | Bin 0 -> 21002 bytes data/sfx/system/error.ogg | Bin 0 -> 7192 bytes data/sfx/system/finish.ogg | Bin 0 -> 12576 bytes data/sfx/system/incoming.ogg | Bin 0 -> 15903 bytes data/sfx/system/move.ogg | Bin 0 -> 6443 bytes data/sfx/system/notify.ogg | Bin 0 -> 9485 bytes data/sfx/system/offline.ogg | Bin 0 -> 7119 bytes data/sfx/system/online.ogg | Bin 0 -> 7883 bytes data/sfx/system/reminder.ogg | Bin 0 -> 7279 bytes data/sfx/system/send.ogg | Bin 0 -> 8205 bytes data/sfx/system/start.ogg | Bin 0 -> 8597 bytes data/sfx/system/watcher.ogg | Bin 0 -> 8919 bytes src/client.cpp | 15 +++++++----- src/defaults.cpp | 7 ++++++ src/game.cpp | 6 ++--- src/gui/changeemaildialog.cpp | 3 ++- src/gui/changepassworddialog.cpp | 3 ++- src/gui/charcreatedialog.cpp | 4 +-- src/gui/charselectdialog.cpp | 2 +- src/gui/confirmdialog.cpp | 2 +- src/gui/editserverdialog.cpp | 2 +- src/gui/okdialog.cpp | 10 +++++++- src/gui/okdialog.h | 11 +++++++-- src/gui/register.cpp | 2 +- src/gui/setup_audio.cpp | 50 ++++++++++++++++++++++++++++++++++++++ src/gui/setup_audio.h | 5 ++++ src/gui/setup_keyboard.cpp | 2 +- src/gui/setup_theme.cpp | 4 +-- src/gui/setup_video.cpp | 16 +++++++----- src/gui/shopwindow.cpp | 2 +- src/gui/socialwindow.cpp | 6 ++--- src/gui/unregisterdialog.cpp | 3 ++- src/gui/widgets/chattab.cpp | 2 +- src/gui/widgets/setupitem.cpp | 40 ++++++++++++++++++++++++++++-- src/gui/widgets/setupitem.h | 21 +++++++++++++++- src/gui/widgets/sliderlist.h | 3 +++ src/localplayer.cpp | 5 ++-- src/net/ea/charserverhandler.cpp | 4 +-- src/net/ea/gamehandler.cpp | 2 +- src/net/ea/playerhandler.cpp | 7 +++--- src/net/manaserv/beinghandler.cpp | 3 ++- src/net/manaserv/charhandler.cpp | 4 +-- src/sound.cpp | 6 +++++ src/sound.h | 2 ++ 50 files changed, 237 insertions(+), 51 deletions(-) create mode 100644 data/sfx/system/attention.ogg create mode 100644 data/sfx/system/chat1.ogg create mode 100644 data/sfx/system/chat2.ogg create mode 100644 data/sfx/system/complete.ogg create mode 100644 data/sfx/system/email.ogg create mode 100644 data/sfx/system/error.ogg create mode 100644 data/sfx/system/finish.ogg create mode 100644 data/sfx/system/incoming.ogg create mode 100644 data/sfx/system/move.ogg create mode 100644 data/sfx/system/notify.ogg create mode 100644 data/sfx/system/offline.ogg create mode 100644 data/sfx/system/online.ogg create mode 100644 data/sfx/system/reminder.ogg create mode 100644 data/sfx/system/send.ogg create mode 100644 data/sfx/system/start.ogg create mode 100644 data/sfx/system/watcher.ogg (limited to 'src/localplayer.cpp') diff --git a/data/sfx/system/CMakeLists.txt b/data/sfx/system/CMakeLists.txt index bf6f0f0f3..0fa325a45 100644 --- a/data/sfx/system/CMakeLists.txt +++ b/data/sfx/system/CMakeLists.txt @@ -1,5 +1,21 @@ SET (FILES + attention.ogg + chat1.ogg + chat2.ogg + complete.ogg + email.ogg + error.ogg + finish.ogg + incoming.ogg + move.ogg + notify.ogg newmessage.ogg + offline.ogg + online.ogg + reminder.ogg + send.ogg + start.ogg + watcher.ogg ) INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/sfx/system) diff --git a/data/sfx/system/Makefile.am b/data/sfx/system/Makefile.am index e744932c3..d46934461 100644 --- a/data/sfx/system/Makefile.am +++ b/data/sfx/system/Makefile.am @@ -1,7 +1,23 @@ systemdir = $(pkgdatadir)/data/sfx/system system_DATA = \ - newmessage.ogg + attention.ogg \ + chat1.ogg \ + chat2.ogg \ + complete.ogg \ + email.ogg \ + error.ogg \ + finish.ogg \ + incoming.ogg \ + move.ogg \ + newmessage.ogg \ + notify.ogg \ + offline.ogg \ + online.ogg \ + reminder.ogg \ + send.ogg \ + start.ogg \ + watcher.ogg EXTRA_DIST = \ $(system_DATA) \ diff --git a/data/sfx/system/attention.ogg b/data/sfx/system/attention.ogg new file mode 100644 index 000000000..929265775 Binary files /dev/null and b/data/sfx/system/attention.ogg differ diff --git a/data/sfx/system/chat1.ogg b/data/sfx/system/chat1.ogg new file mode 100644 index 000000000..ad6c52a1d Binary files /dev/null and b/data/sfx/system/chat1.ogg differ diff --git a/data/sfx/system/chat2.ogg b/data/sfx/system/chat2.ogg new file mode 100644 index 000000000..155b15e1f Binary files /dev/null and b/data/sfx/system/chat2.ogg differ diff --git a/data/sfx/system/complete.ogg b/data/sfx/system/complete.ogg new file mode 100644 index 000000000..0975ff7c8 Binary files /dev/null and b/data/sfx/system/complete.ogg differ diff --git a/data/sfx/system/email.ogg b/data/sfx/system/email.ogg new file mode 100644 index 000000000..afb25909f Binary files /dev/null and b/data/sfx/system/email.ogg differ diff --git a/data/sfx/system/error.ogg b/data/sfx/system/error.ogg new file mode 100644 index 000000000..69dccfe7c Binary files /dev/null and b/data/sfx/system/error.ogg differ diff --git a/data/sfx/system/finish.ogg b/data/sfx/system/finish.ogg new file mode 100644 index 000000000..d8dbbf80f Binary files /dev/null and b/data/sfx/system/finish.ogg differ diff --git a/data/sfx/system/incoming.ogg b/data/sfx/system/incoming.ogg new file mode 100644 index 000000000..a8ff86676 Binary files /dev/null and b/data/sfx/system/incoming.ogg differ diff --git a/data/sfx/system/move.ogg b/data/sfx/system/move.ogg new file mode 100644 index 000000000..e5c703bbf Binary files /dev/null and b/data/sfx/system/move.ogg differ diff --git a/data/sfx/system/notify.ogg b/data/sfx/system/notify.ogg new file mode 100644 index 000000000..95d8fed4a Binary files /dev/null and b/data/sfx/system/notify.ogg differ diff --git a/data/sfx/system/offline.ogg b/data/sfx/system/offline.ogg new file mode 100644 index 000000000..cc1b8e938 Binary files /dev/null and b/data/sfx/system/offline.ogg differ diff --git a/data/sfx/system/online.ogg b/data/sfx/system/online.ogg new file mode 100644 index 000000000..3e55793fd Binary files /dev/null and b/data/sfx/system/online.ogg differ diff --git a/data/sfx/system/reminder.ogg b/data/sfx/system/reminder.ogg new file mode 100644 index 000000000..d7beeed6f Binary files /dev/null and b/data/sfx/system/reminder.ogg differ diff --git a/data/sfx/system/send.ogg b/data/sfx/system/send.ogg new file mode 100644 index 000000000..b5941323d Binary files /dev/null and b/data/sfx/system/send.ogg differ diff --git a/data/sfx/system/start.ogg b/data/sfx/system/start.ogg new file mode 100644 index 000000000..0b1f85643 Binary files /dev/null and b/data/sfx/system/start.ogg differ diff --git a/data/sfx/system/watcher.ogg b/data/sfx/system/watcher.ogg new file mode 100644 index 000000000..9a0dd1af2 Binary files /dev/null and b/data/sfx/system/watcher.ogg differ diff --git a/src/client.cpp b/src/client.cpp index 978c58eef..5f79176c7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1327,14 +1327,16 @@ int Client::gameExec() case STATE_LOGIN_ERROR: logger->log1("State: LOGIN ERROR"); - mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog = new OkDialog(_("Error"), + errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&loginListener); mCurrentDialog = nullptr; // OkDialog deletes itself break; case STATE_ACCOUNTCHANGE_ERROR: logger->log1("State: ACCOUNT CHANGE ERROR"); - mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog = new OkDialog(_("Error"), + errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself break; @@ -1370,7 +1372,7 @@ int Client::gameExec() case STATE_CHANGEPASSWORD_SUCCESS: logger->log1("State: CHANGE PASSWORD SUCCESS"); mCurrentDialog = new OkDialog(_("Password Change"), - _("Password changed successfully!")); + _("Password changed successfully!"), DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself loginData.password = loginData.newPassword; @@ -1390,7 +1392,7 @@ int Client::gameExec() case STATE_CHANGEEMAIL_SUCCESS: logger->log1("State: CHANGE EMAIL SUCCESS"); mCurrentDialog = new OkDialog(_("Email Change"), - _("Email changed successfully!")); + _("Email changed successfully!"), DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself break; @@ -1411,7 +1413,7 @@ int Client::gameExec() Net::getLoginHandler()->disconnect(); mCurrentDialog = new OkDialog(_("Unregister Successful"), - _("Farewell, come back any time...")); + _("Farewell, come back any time..."), DIALOG_ERROR); loginData.clear(); //The errorlistener sets the state to STATE_CHOOSE_SERVER mCurrentDialog->addActionListener(&errorListener); @@ -1468,7 +1470,8 @@ int Client::gameExec() case STATE_ERROR: logger->log1("State: ERROR"); logger->log("Error: %s\n", errorMessage.c_str()); - mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog = new OkDialog(_("Error"), + errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&errorListener); mCurrentDialog = nullptr; // OkDialog deletes itself Net::getGameHandler()->disconnect(); diff --git a/src/defaults.cpp b/src/defaults.cpp index 01907bfe8..cd2911192 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -229,6 +229,13 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "grabinput", false); AddDEF(configData, "gamma", 1); AddDEF(configData, "vsync", 0); + AddDEF(configData, "soundwhisper", "newmessage"); + AddDEF(configData, "soundhighlight", "reminder"); + AddDEF(configData, "soundglobal", "email"); + AddDEF(configData, "sounderror", "error"); + AddDEF(configData, "soundtrade", "start"); + AddDEF(configData, "soundinfo", "notify"); + AddDEF(configData, "soundrequest", "attention"); return configData; } diff --git a/src/game.cpp b/src/game.cpp index e016d02ff..ae8682972 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -561,7 +561,7 @@ void Game::logic() { errorMessage = _("The connection to the server was lost."); disconnectedDialog = new OkDialog(_("Network Error"), - errorMessage, false); + errorMessage, DIALOG_ERROR, false); disconnectedDialog->addActionListener(&errorListener); disconnectedDialog->requestMoveToTop(); } @@ -1796,8 +1796,8 @@ void Game::changeMap(const std::string &mapPath) if (!newMap) { logger->log("Error while loading %s", fullMap.c_str()); - new OkDialog(_("Could Not Load Map"), - strprintf(_("Error while loading %s"), fullMap.c_str())); + new OkDialog(_("Could Not Load Map"), strprintf( + _("Error while loading %s"), fullMap.c_str()), DIALOG_ERROR); } if (mCurrentMap) diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index 518ed3da1..1a468d44f 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -154,7 +154,8 @@ void ChangeEmailDialog::action(const gcn::ActionEvent &event) else if (error == 2) mWrongDataNoticeListener->setTarget(this->mSecondEmailField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); if (dlg) dlg->addActionListener(mWrongDataNoticeListener); } diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 8082b8d58..a58d8616b 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -144,7 +144,8 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) else if (error == 3) mWrongDataNoticeListener->setTarget(this->mSecondPassField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 9f7436ad8..124476f1c 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -270,8 +270,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) else { new OkDialog(_("Error"), - _("Your name needs to be at least 4 characters."), - true, this); + _("Your name needs to be at least 4 characters."), + DIALOG_ERROR, true, this); } } else if (id == "cancel") diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index d2b74a632..b1b8009a4 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -253,7 +253,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) } else { - new OkDialog(_("Error"), _("Incorrect password")); + new OkDialog(_("Error"), _("Incorrect password"), DIALOG_ERROR); } mDeleteIndex = -1; } diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index 22acf5116..b6645db3c 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -97,7 +97,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, } setVisible(true); yesButton->requestFocus(); - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundrequest"); } void ConfirmDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 53e31c3c8..ca1afeaba 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -173,7 +173,7 @@ void EditServerDialog::action(const gcn::ActionEvent &event) { OkDialog *dlg = new OkDialog(_("Error"), _("Please at least type both the address and the port " - "of the server.")); + "of the server."), DIALOG_ERROR); dlg->addActionListener(this); } else diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp index 4a3bdf731..fe22cf008 100644 --- a/src/gui/okdialog.cpp +++ b/src/gui/okdialog.cpp @@ -22,6 +22,8 @@ #include "gui/okdialog.h" +#include "sound.h" + #include "gui/gui.h" #include "gui/widgets/button.h" @@ -34,7 +36,8 @@ #include "debug.h" OkDialog::OkDialog(const std::string &title, const std::string &msg, - bool modal, bool showCenter, Window *parent): + int soundEvent, bool modal, bool showCenter, + Window *parent): Window(title, modal, parent, "ok.xml") { mTextBox = new TextBox; @@ -71,6 +74,11 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, centerHorisontally(); setVisible(true); okButton->requestFocus(); + + if (soundEvent == DIALOG_OK) + sound.playGuiSound("soundinfo"); + else if (soundEvent == DIALOG_ERROR) + sound.playGuiSound("sounderror"); } void OkDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/okdialog.h b/src/gui/okdialog.h index 5705be568..b6f17480b 100644 --- a/src/gui/okdialog.h +++ b/src/gui/okdialog.h @@ -31,6 +31,13 @@ class TextBox; +enum +{ + DIALOG_OK = 0, + DIALOG_ERROR, + DIALOG_SILENCE +}; + /** * An 'Ok' button dialog. * @@ -45,8 +52,8 @@ class OkDialog : public Window, public gcn::ActionListener * @see Window::Window */ OkDialog(const std::string &title, const std::string &msg, - bool modal = true, bool showCenter = true, - Window *parent = nullptr); + int soundEvent = DIALOG_OK, bool modal = true, + bool showCenter = true, Window *parent = nullptr); /** * Called when receiving actions from the widgets. diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 2122e0d6b..bf0cb299e 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -225,7 +225,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mPasswordField); } - OkDialog *dlg = new OkDialog(_("Error"), errorMsg); + OkDialog *dlg = new OkDialog(_("Error"), errorMsg, DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 1f7db484c..a4c3110d9 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -25,9 +25,11 @@ #include "configuration.h" #include "sound.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/layouthelper.h" +#include "gui/widgets/namesmodel.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/setupitem.h" @@ -35,6 +37,19 @@ #include "debug.h" +class SoundsModel : public NamesModel +{ +public: + SoundsModel() + { + mNames.push_back(gettext("(no sound)")); + Theme::fillSoundsList(mNames); + } + + virtual ~SoundsModel() + { } +}; + Setup_Audio::Setup_Audio() { setName(_("Audio")); @@ -44,6 +59,10 @@ Setup_Audio::Setup_Audio() ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); + mSoundModel = new SoundsModel(); + + new SetupItemLabel(_("Basic settings"), "", this); + new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent"); new SetupItemCheckBox(_("Enable music"), "", @@ -61,6 +80,31 @@ Setup_Audio::Setup_Audio() new SetupItemSlider(_("Music volume"), "", "musicVolume", this, "musicVolumeEvent", 0, sound.getMaxVolume(), 150, true); + new SetupItemLabel(_("Sound effects"), "", this); + + new SetupItemSound(_("Information dialog sound"), "", + "soundinfo", this, "soundinfoEvent", mSoundModel); + + new SetupItemSound(_("Request dialog sound"), "", + "soundrequest", this, "soundrequestEvent", mSoundModel); + + new SetupItemSound(_("Whisper message sound"), "", + "soundwhisper", this, "soundwhisperEvent", mSoundModel); + + new SetupItemSound(_("Highlight message sound"), "", + "soundhighlight", this, "soundhighlightEvent", mSoundModel); + + new SetupItemSound(_("Global message sound"), "", + "soundglobal", this, "soundglobalEvent", mSoundModel); + + new SetupItemSound(_("Error message sound"), "", + "sounderror", this, "sounderrorEvent", mSoundModel); + + new SetupItemSound(_("Trade request sound"), "", + "soundtrade", this, "soundtradeEvent", mSoundModel); + + new SetupItemLabel(_("Other"), "", this); + new SetupItemCheckBox(_("Enable mumble voice chat"), "", "enableMumble", this, "enableMumbleEvent"); @@ -70,6 +114,12 @@ Setup_Audio::Setup_Audio() setDimension(gcn::Rectangle(0, 0, 550, 350)); } +Setup_Audio::~Setup_Audio() +{ + delete mSoundModel; + mSoundModel = nullptr; +} + void Setup_Audio::apply() { SetupTabScroll::apply(); diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h index c08c49c7a..21b661bcb 100644 --- a/src/gui/setup_audio.h +++ b/src/gui/setup_audio.h @@ -34,7 +34,12 @@ class Setup_Audio : public SetupTabScroll public: Setup_Audio(); + ~Setup_Audio(); + void apply(); + + private: + gcn::ListModel *mSoundModel; }; #endif diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index bdd7c2083..ef024c5d9 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -131,7 +131,7 @@ void Setup_Keyboard::apply() if (keyboard.hasConflicts()) { new OkDialog(_("Key Conflict(s) Detected."), - keyboard.getBindError()); + keyboard.getBindError(), DIALOG_ERROR); } keyboard.setEnabled(true); keyboard.store(); diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index d3b9d0e3c..7386f496a 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -349,8 +349,8 @@ void Setup_Theme::apply() if (config.getValue("theme", config.getValue("selectedSkin", "")) != mTheme) { - new OkDialog(_("Theme Changed"), - _("Restart your client for the change to take effect.")); + new OkDialog(_("Theme Changed"), _("Restart your client for " + "the change to take effect.")); } config.setValue("selectedSkin", ""); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 6690f1452..24d42c83d 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -393,7 +393,7 @@ void Setup_Video::apply() else { new OkDialog(_("Switching to Full Screen"), - _("Restart needed for changes to take effect.")); + _("Restart needed for changes to take effect.")); } #endif config.setValue("screen", fullscreen); @@ -406,7 +406,7 @@ void Setup_Video::apply() // OpenGL can currently only be changed by restarting, notify user. new OkDialog(_("Changing to OpenGL"), - _("Applying change to OpenGL requires restart.")); + _("Applying change to OpenGL requires restart.")); } mFps = mFpsCheckBox->isSelected() ? @@ -498,13 +498,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) { #if defined(_WIN32) if (width < mainGraphics->mWidth || height < mainGraphics->mHeight) + { new OkDialog(_("Screen Resolution Changed"), - _("Restart your client for the change to take effect.") - + std::string("\n") + - _("Some windows may be moved to fit the lowered resolution.")); + _("Restart your client for the change to take effect.") + + std::string("\n") + _("Some windows may be moved to " + "fit the lowered resolution.")); + } else + { new OkDialog(_("Screen Resolution Changed"), - _("Restart your client for the change to take effect.")); + _("Restart your client for the change to take effect.")); + } #else Client::resize(width, height); #endif diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 1a27b8b0c..33ab32ca5 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -753,7 +753,7 @@ void ShopWindow::processRequest(std::string nick, std::string data, int mode) if (config.getBoolValue("autoShop")) { - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundtrade"); startTrade(); } else diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 287089790..f0ac9e128 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1630,13 +1630,13 @@ void SocialWindow::showPartyCreate() if (player_node->getParty()) { new OkDialog(_("Create Party"), - _("Cannot create party. You are already in a party"), - this); + _("Cannot create party. You are already in a party"), + DIALOG_ERROR, true, true, this); return; } mPartyCreateDialog = new TextDialog(_("Party Name"), - _("Choose your party's name."), this); + _("Choose your party's name."), this); mPartyCreateDialog->setActionEventId("create party"); mPartyCreateDialog->addActionListener(this); } diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index ca21263f1..9ba895ec8 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -134,7 +134,8 @@ void UnRegisterDialog::action(const gcn::ActionEvent &event) { mWrongDataNoticeListener->setTarget(this->mPasswordField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 018e35030..53842e887 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -301,7 +301,7 @@ void ChatTab::chatLog(std::string line, Own own, && !Client::getInputFocused())))) { if (own != BY_SERVER) - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundwhisper"); } } } diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 581002a58..9eedfd58d 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -23,6 +23,7 @@ #include "configuration.h" #include "main.h" #include "logger.h" +#include "sound.h" #include "gui/editdialog.h" #include "gui/gui.h" @@ -872,7 +873,7 @@ SetupItemSliderList::SetupItemSliderList(std::string text, mOnTheFly(onTheFly) { mValueType = VSTR; - createControls(); +// createControls(); } SetupItemSliderList::SetupItemSliderList(std::string text, @@ -892,7 +893,7 @@ SetupItemSliderList::SetupItemSliderList(std::string text, mOnTheFly(onTheFly) { mValueType = VSTR; - createControls(); +// createControls(); } SetupItemSliderList::~SetupItemSliderList() @@ -917,6 +918,8 @@ void SetupItemSliderList::createControls() mHorizont->add(mLabel, 5); mHorizont->add(mSlider); + addMoreControls(); + mParent->getContainer()->add2(mHorizont, true, 4); mParent->addControl(this); mParent->addActionListener(this); @@ -954,3 +957,36 @@ void SetupItemSliderList::apply(std::string eventName) fromWidget(); save(); } + +SetupItemSound::SetupItemSound(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width, bool onTheFly, bool mainConfig) : + SetupItemSliderList(text, description, keyName, parent, eventName, + model, width, onTheFly, mainConfig), + mButton(nullptr) +{ + createControls(); +} + +void SetupItemSound::addMoreControls() +{ + mButton = new Button(_("Play"), mEventName + "_PLAY", this); + mHorizont->add(mButton); +} + +void SetupItemSound::action(const gcn::ActionEvent &event) +{ + if (event.getId() == mEventName + "_PLAY") + { + if (mSlider->getSelected()) + { + sound.playGuiSfx(branding.getStringValue("systemsounds") + + mSlider->getSelectedString() + ".ogg"); + } + } + else + { + SetupItemSliderList::action(event); + } +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index f883a5b94..38dec929e 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -377,10 +377,12 @@ class SetupItemSliderList : public SetupItem void toWidget(); - void action(const gcn::ActionEvent &event); + virtual void action(const gcn::ActionEvent &event); void apply(std::string eventName); + virtual void addMoreControls() = 0; + protected: HorizontContainer *mHorizont; Label *mLabel; @@ -390,4 +392,21 @@ class SetupItemSliderList : public SetupItem bool mOnTheFly; }; +class SetupItemSound : public SetupItemSliderList +{ + public: + SetupItemSound(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width = 150, bool onTheFly = false, + bool mainConfig = true); + + void action(const gcn::ActionEvent &event); + + void addMoreControls(); + + protected: + Button *mButton; +}; + #endif diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h index a7b1a564c..b2239834d 100644 --- a/src/gui/widgets/sliderlist.h +++ b/src/gui/widgets/sliderlist.h @@ -63,6 +63,9 @@ class SliderList : public Container, void adjustSize(); + int getSelected() + { return mSelectedIndex; } + protected: void updateLabel(); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5114f868c..de1304240 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2204,7 +2204,8 @@ void LocalPlayer::changeAwayMode() if (outfitWindow) outfitWindow->wearAwayOutfit(); mAwayDialog = new OkDialog(_("Away"), - config.getStringValue("afkMessage"), true, false); + config.getStringValue("afkMessage"), + DIALOG_SILENCE, true, false); mAwayDialog->addActionListener(mAwayListener); sound.volumeOff(); } @@ -4147,7 +4148,7 @@ void LocalPlayer::checkNewName(Being *being) if (!mWaitFor.empty() && mWaitFor == nick) { debugMsg(_("You see ") + mWaitFor); - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundinfo"); mWaitFor = ""; } } diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 2dc51acf3..67894b0d9 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -167,7 +167,7 @@ void CharServerHandler::processCharCreateFailed(Net::MessageIn &msg) errorMessage = _("Incorrect race."); break; } - new OkDialog(_("Error"), errorMessage); + new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); if (mCharCreateDialog) mCharCreateDialog->unlock(); } @@ -185,7 +185,7 @@ void CharServerHandler::processCharDelete(Net::MessageIn &msg A_UNUSED) void CharServerHandler::processCharDeleteFailed(Net::MessageIn &msg A_UNUSED) { unlockCharSelectDialog(); - new OkDialog(_("Error"), _("Failed to delete character.")); + new OkDialog(_("Error"), _("Failed to delete character."), DIALOG_ERROR); } void CharServerHandler::clear() diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 6d021d6a9..c8c870dbd 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -101,7 +101,7 @@ void GameHandler::processCharSwitchResponse(Net::MessageIn &msg) void GameHandler::processMapQuitResponse(Net::MessageIn &msg) { if (msg.readInt8()) - new OkDialog(_("Game"), _("Request to quit denied!"), nullptr); + new OkDialog(_("Game"), _("Request to quit denied!"), DIALOG_ERROR); } } // namespace Ea diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 27aa4da80..ddcf7d9c0 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -336,7 +336,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) weightNotice = new OkDialog(_("Message"), _("You are carrying more than " "half your weight. You are " - "unable to regain health."), false); + "unable to regain health."), DIALOG_ERROR, false); weightNotice->addActionListener( &weightListener); } @@ -346,7 +346,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) weightNotice = new OkDialog(_("Message"), _("You are carrying less than " "half your weight. You " - "can regain health."), false); + "can regain health."), DIALOG_ERROR, false); weightNotice->addActionListener( &weightListener); } @@ -426,8 +426,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) if (PlayerInfo::getAttribute(HP) == 0 && !deathNotice) { deathNotice = new OkDialog(_("Message"), - randomDeathMessage(), - false); + randomDeathMessage(), false); deathNotice->addActionListener(&deathListener); player_node->setAction(Being::DEAD); } diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index cef4f497a..9468baaa1 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -335,7 +335,8 @@ void BeingHandler::handleBeingActionChangeMessage(Net::MessageIn &msg) }; std::string message(deadMsg[rand() % 13]); message.append(std::string(" ") + _("Press OK to respawn.")); - OkDialog *dlg = new OkDialog(_("You Died"), message, false); + OkDialog *dlg = new OkDialog(_("You Died"), + message, DIALOG_OK, false); dlg->addActionListener(&(ManaServ::respawnListener)); } } diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 300af5a2b..7977df909 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -181,7 +181,7 @@ void CharHandler::handleCharacterCreateResponse(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - new OkDialog(_("Error"), errorMessage); + new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); if (mCharCreateDialog) mCharCreateDialog->unlock(); @@ -224,7 +224,7 @@ void CharHandler::handleCharacterDeleteResponse(Net::MessageIn &msg) default: errorMessage = strprintf(_("Unknown error (%d)."), errMsg); } - new OkDialog(_("Error"), errorMessage); + new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); } mSelectedCharacter = 0; unlockCharSelectDialog(); diff --git a/src/sound.cpp b/src/sound.cpp index 25b37d578..2c7ecb53d 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -325,6 +325,12 @@ void Sound::playSfx(const std::string &path, int x, int y) } } +void Sound::playGuiSound(const std::string &name) +{ + playGuiSfx(branding.getStringValue("systemsounds") + + config.getStringValue(name) + ".ogg"); +} + void Sound::playGuiSfx(const std::string &path) { if (!mInstalled || path.empty() || !mPlayGui) diff --git a/src/sound.h b/src/sound.h index 7f9fb64a4..cfa847a0b 100644 --- a/src/sound.h +++ b/src/sound.h @@ -109,6 +109,8 @@ class Sound : public ConfigListener */ void playGuiSfx(const std::string &path); + void playGuiSound(const std::string &name); + void changeAudio(); void volumeOff(); -- cgit v1.2.3-70-g09d2 From bbf5743dd18e78298376da6f78c71ae2a524c766 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 28 Feb 2012 22:16:23 +0300 Subject: Fix some sound event. Replace hardcoded sound names to constants. Add party/guild sound. --- src/defaults.cpp | 1 + src/gui/confirmdialog.cpp | 2 +- src/gui/okdialog.cpp | 4 ++-- src/gui/setup_audio.cpp | 3 +++ src/gui/shopwindow.cpp | 2 +- src/gui/widgets/chattab.cpp | 21 +++++++++++++++++++-- src/gui/widgets/chattab.h | 2 ++ src/gui/widgets/guildchattab.cpp | 6 ++++++ src/gui/widgets/guildchattab.h | 2 ++ src/localplayer.cpp | 2 +- src/net/ea/gui/guildtab.cpp | 6 ++++++ src/net/ea/gui/guildtab.h | 2 ++ src/net/ea/gui/partytab.cpp | 5 +++++ src/net/ea/gui/partytab.h | 2 ++ src/sound.h | 9 +++++++++ 15 files changed, 62 insertions(+), 7 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/defaults.cpp b/src/defaults.cpp index cd2911192..3e53506b4 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -236,6 +236,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "soundtrade", "start"); AddDEF(configData, "soundinfo", "notify"); AddDEF(configData, "soundrequest", "attention"); + AddDEF(configData, "soundguild", "newmessage"); return configData; } diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index b6645db3c..a2fb7b6cc 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -97,7 +97,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, } setVisible(true); yesButton->requestFocus(); - sound.playGuiSound("soundrequest"); + sound.playGuiSound(SOUND_REQUEST); } void ConfirmDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp index fe22cf008..3259cb6d6 100644 --- a/src/gui/okdialog.cpp +++ b/src/gui/okdialog.cpp @@ -76,9 +76,9 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, okButton->requestFocus(); if (soundEvent == DIALOG_OK) - sound.playGuiSound("soundinfo"); + sound.playGuiSound(SOUND_INFO); else if (soundEvent == DIALOG_ERROR) - sound.playGuiSound("sounderror"); + sound.playGuiSound(SOUND_ERROR); } void OkDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index a4c3110d9..69ca4e759 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -91,6 +91,9 @@ Setup_Audio::Setup_Audio() new SetupItemSound(_("Whisper message sound"), "", "soundwhisper", this, "soundwhisperEvent", mSoundModel); + new SetupItemSound(_("Guild / Party message sound"), "", + "soundguild", this, "soundguildEvent", mSoundModel); + new SetupItemSound(_("Highlight message sound"), "", "soundhighlight", this, "soundhighlightEvent", mSoundModel); diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 33ab32ca5..01b589ab6 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -753,7 +753,7 @@ void ShopWindow::processRequest(std::string nick, std::string data, int mode) if (config.getBoolValue("autoShop")) { - sound.playGuiSound("soundtrade"); + sound.playGuiSound(SOUND_TRADE); startTrade(); } else diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 53842e887..be6a31164 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -289,9 +289,19 @@ void ChatTab::chatLog(std::string line, Own own, if (getFlash() == 0) { if (chatWindow && chatWindow->findHighlight(tmp.text)) + { setFlash(2); + sound.playGuiSound(SOUND_HIGHLIGHT); + } else + { setFlash(1); + } + } + else if (getFlash() == 2) + { + if (chatWindow && chatWindow->findHighlight(tmp.text)) + sound.playGuiSound(SOUND_HIGHLIGHT); } } @@ -300,8 +310,10 @@ void ChatTab::chatLog(std::string line, Own own, || (Client::getIsMinimized() || (!Client::getMouseFocused() && !Client::getInputFocused())))) { - if (own != BY_SERVER) - sound.playGuiSound("soundwhisper"); + if (own == BY_GM) + sound.playGuiSound(SOUND_GLOBAL); + else if (own != BY_SERVER) + playNewMessageSound(); } } } @@ -468,3 +480,8 @@ void ChatTab::addNewRow(std::string &line) } mScrollArea->logic(); } + +void ChatTab::playNewMessageSound() +{ + sound.playGuiSound(SOUND_WHISPER); +} diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h index 912305a63..d67f56b54 100644 --- a/src/gui/widgets/chattab.h +++ b/src/gui/widgets/chattab.h @@ -162,6 +162,8 @@ class ChatTab : public Tab void addNewRow(std::string &line); + virtual void playNewMessageSound(); + protected: friend class ChatWindow; friend class WhisperWindow; diff --git a/src/gui/widgets/guildchattab.cpp b/src/gui/widgets/guildchattab.cpp index a95fca3cf..bad34cfb3 100644 --- a/src/gui/widgets/guildchattab.cpp +++ b/src/gui/widgets/guildchattab.cpp @@ -27,6 +27,7 @@ #include "guild.h" #include "guildmanager.h" #include "localplayer.h" +#include "sound.h" #include "gui/theme.h" @@ -126,3 +127,8 @@ void GuildChatTab::saveToLogFile(std::string &msg) if (chatLogger) chatLogger->log("#Guild", msg); } + +void GuildChatTab::playNewMessageSound() +{ + sound.playGuiSound(SOUND_GUILD); +} diff --git a/src/gui/widgets/guildchattab.h b/src/gui/widgets/guildchattab.h index be6f4d034..e729844f4 100644 --- a/src/gui/widgets/guildchattab.h +++ b/src/gui/widgets/guildchattab.h @@ -44,6 +44,8 @@ class GuildChatTab : public ChatTab int getType() const { return ChatTab::TAB_GUILD; } + void playNewMessageSound(); + protected: void handleInput(const std::string &msg); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index de1304240..f88423f8e 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -4148,7 +4148,7 @@ void LocalPlayer::checkNewName(Being *being) if (!mWaitFor.empty() && mWaitFor == nick) { debugMsg(_("You see ") + mWaitFor); - sound.playGuiSound("soundinfo"); + sound.playGuiSound(SOUND_INFO); mWaitFor = ""; } } diff --git a/src/net/ea/gui/guildtab.cpp b/src/net/ea/gui/guildtab.cpp index 87fc34d94..bd1521b21 100644 --- a/src/net/ea/gui/guildtab.cpp +++ b/src/net/ea/gui/guildtab.cpp @@ -26,6 +26,7 @@ #include "commandhandler.h" #include "guild.h" #include "localplayer.h" +#include "sound.h" #include "gui/theme.h" @@ -151,4 +152,9 @@ void GuildTab::saveToLogFile(std::string &msg) chatLogger->log("#Guild", msg); } +void GuildTab::playNewMessageSound() +{ + sound.playGuiSound(SOUND_GUILD); +} + } // namespace Ea diff --git a/src/net/ea/gui/guildtab.h b/src/net/ea/gui/guildtab.h index 81d971161..22a41ce80 100644 --- a/src/net/ea/gui/guildtab.h +++ b/src/net/ea/gui/guildtab.h @@ -47,6 +47,8 @@ class GuildTab : public ChatTab int getType() const { return ChatTab::TAB_GUILD; } + void playNewMessageSound(); + protected: void handleInput(const std::string &msg); diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index d5e344ac2..e69207842 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -26,6 +26,7 @@ #include "commandhandler.h" #include "localplayer.h" #include "party.h" +#include "sound.h" #include "gui/theme.h" @@ -241,4 +242,8 @@ void PartyTab::saveToLogFile(std::string &msg) chatLogger->log("#Party", msg); } +void PartyTab::playNewMessageSound() +{ + sound.playGuiSound(SOUND_GUILD); +} } // namespace Ea diff --git a/src/net/ea/gui/partytab.h b/src/net/ea/gui/partytab.h index 029d71ac7..931b283dd 100644 --- a/src/net/ea/gui/partytab.h +++ b/src/net/ea/gui/partytab.h @@ -47,6 +47,8 @@ class PartyTab : public ChatTab void saveToLogFile(std::string &msg); + void playNewMessageSound(); + protected: void handleInput(const std::string &msg); diff --git a/src/sound.h b/src/sound.h index cfa847a0b..a967d0a92 100644 --- a/src/sound.h +++ b/src/sound.h @@ -31,6 +31,15 @@ class Music; +const static std::string SOUND_INFO = "soundinfo"; +const static std::string SOUND_ERROR = "sounderror"; +const static std::string SOUND_REQUEST = "soundrequest"; +const static std::string SOUND_TRADE = "soundtrade"; +const static std::string SOUND_WHISPER = "soundwhisper"; +const static std::string SOUND_HIGHLIGHT = "soundhighlight"; +const static std::string SOUND_GLOBAL = "soundglobal"; +const static std::string SOUND_GUILD = "soundguild"; + /** Sound engine * * \ingroup CORE -- cgit v1.2.3-70-g09d2 From 5b4160a49385bc6895681c5d103a4a5716829e4b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 29 Feb 2012 20:45:54 +0300 Subject: Simplify remove listener calls. --- src/actorspritemanager.cpp | 6 +----- src/client.cpp | 6 +----- src/configuration.cpp | 16 ++++++++++++---- src/configuration.h | 2 ++ src/gui/viewport.cpp | 6 +----- src/gui/whoisonline.cpp | 3 +-- src/gui/widgets/avatarlistbox.cpp | 3 +-- src/localplayer.cpp | 11 +---------- src/map.cpp | 4 +--- src/sound.cpp | 6 +----- 10 files changed, 22 insertions(+), 41 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 803a30e7e..758a452b1 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -203,11 +203,7 @@ ActorSpriteManager::ActorSpriteManager() : ActorSpriteManager::~ActorSpriteManager() { - config.removeListener("targetDeadPlayers", this); - config.removeListener("targetOnlyReachable", this); - config.removeListener("cyclePlayers", this); - config.removeListener("cycleMonsters", this); - config.removeListener("extMouseTargeting", this); + config.removeListeners(this); storeAttackList(); clear(); } diff --git a/src/client.cpp b/src/client.cpp index 0324bb8cc..95e49c6aa 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -707,11 +707,7 @@ void Client::gameClear() { if (logger) logger->log1("Quitting1"); - config.removeListener("fpslimit", this); - config.removeListener("guialpha", this); - config.removeListener("gamma", this); - config.removeListener("particleEmitterSkip", this); - config.removeListener("vsync", this); + config.removeListeners(this); SDL_RemoveTimer(mLogicCounterId); SDL_RemoveTimer(mSecondsCounterId); diff --git a/src/configuration.cpp b/src/configuration.cpp index 97540c385..624cf7865 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -617,14 +617,22 @@ void Configuration::write() xmlFreeTextWriter(writer); } -void Configuration::addListener( - const std::string &key, ConfigListener *listener) +void Configuration::addListener(const std::string &key, + ConfigListener *listener) { mListenerMap[key].push_front(listener); } -void Configuration::removeListener( - const std::string &key, ConfigListener *listener) +void Configuration::removeListener(const std::string &key, + ConfigListener *listener) { mListenerMap[key].remove(listener); } + +void Configuration::removeListeners(ConfigListener *listener) +{ + ListenerMapIterator it = mListenerMap.begin(); + ListenerMapIterator it_end = mListenerMap.end(); + for (; it != it_end; ++ it) + (it->second).remove(listener); +} diff --git a/src/configuration.h b/src/configuration.h index 122badfd5..2715ea59c 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -248,6 +248,8 @@ class Configuration : public ConfigurationObject */ void removeListener(const std::string &key, ConfigListener *listener); + void removeListeners(ConfigListener *listener); + void setValue(const std::string &key, const std::string &value); void setSilent(const std::string &key, const std::string &value); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1ef7b1cba..5c50836f6 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -98,11 +98,7 @@ Viewport::Viewport(): Viewport::~Viewport() { - config.removeListener("ScrollLaziness", this); - config.removeListener("ScrollRadius", this); - config.removeListener("showBeingPopup", this); - config.removeListener("selfMouseHeal", this); - config.removeListener("enableLazyScrolling", this); + config.removeListeners(this); delete mPopupMenu; mPopupMenu = nullptr; diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index eba058bd7..734daa7a6 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -131,8 +131,7 @@ WhoIsOnline::WhoIsOnline(): WhoIsOnline::~WhoIsOnline() { - config.removeListener("updateOnlineList", this); - config.removeListener("groupFriends", this); + config.removeListeners(this); if (mThread && SDL_GetThreadID(mThread)) SDL_WaitThread(mThread, nullptr); diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 822e71805..749837f7d 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -74,8 +74,7 @@ AvatarListBox::AvatarListBox(AvatarListModel *model): AvatarListBox::~AvatarListBox() { - config.removeListener("showgender", this); - config.removeListener("showlevel", this); + config.removeListeners(this); instances--; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f88423f8e..1acc6a938 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -205,17 +205,8 @@ LocalPlayer::~LocalPlayer() { logger->log1("LocalPlayer::~LocalPlayer"); - config.removeListener("showownname", this); - config.removeListener("targetDeadPlayers", this); + config.removeListeners(this); serverConfig.removeListener("enableBuggyServers", this); - config.removeListener("syncPlayerMove", this); - config.removeListener("drawPath", this); - config.removeListener("serverAttack", this); - config.removeListener("attackMoving", this); - config.removeListener("showJobExp", this); - config.removeListener("enableAdvert", this); - config.removeListener("tradebot", this); - config.removeListener("targetOnlyReachable", this); delete mAwayDialog; mAwayDialog = nullptr; diff --git a/src/map.cpp b/src/map.cpp index b8767e5e4..d983508b1 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -177,9 +177,7 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): Map::~Map() { - config.removeListener("OverlayDetail", this); - config.removeListener("guialpha", this); - config.removeListener("beingopacity", this); + config.removeListeners(this); // delete metadata, layers, tilesets and overlays delete [] mMetaTiles; diff --git a/src/sound.cpp b/src/sound.cpp index 2c7ecb53d..5b7f1201d 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -66,11 +66,7 @@ Sound::Sound(): Sound::~Sound() { - config.removeListener("playBattleSound", this); - config.removeListener("playGuiSound", this); - config.removeListener("playMusic", this); - config.removeListener("sfxVolume", this); - config.removeListener("musicVolume", this); + config.removeListeners(this); // Unlink the callback function. Mix_HookMusicFinished(nullptr); -- cgit v1.2.3-70-g09d2