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/gui/viewport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 2e1e15c92..d4c188bfb 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -879,7 +879,7 @@ bool Viewport::isPopupMenuVisible() void Viewport::moveCameraToActor(int actorId, int x, int y) { - if (!player_node) + if (!player_node || !actorSpriteManager) return; Actor *actor = actorSpriteManager->findBeing(actorId); -- 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/gui/viewport.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 8e6dd0db3a9e1bfb15068098029c25c334ca8f67 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 29 Feb 2012 04:27:38 +0300 Subject: Allow use context menu in minimap. --- src/gui/minimap.cpp | 26 +++++++++++++++++++------- src/gui/minimap.h | 2 ++ src/gui/popupmenu.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/gui/popupmenu.h | 2 ++ src/gui/viewport.cpp | 5 +++++ src/gui/viewport.h | 2 ++ 6 files changed, 67 insertions(+), 7 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index b4747b7c0..b76e71069 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -401,17 +401,29 @@ void Minimap::mouseReleased(gcn::MouseEvent &event) { gcn::Window::mouseReleased(event); - if (!player_node) + if (!player_node || !viewport) return; if (event.getButton() == gcn::MouseEvent::LEFT) { - const gcn::Rectangle a = getChildrenArea(); - const int x = event.getX() - a.x; - const int y = event.getY() - a.y; + int x = event.getX(); + int y = event.getY(); + screenToMap(x, y); - player_node->navigateTo((x - mMapOriginX + mWidthProportion) - / mWidthProportion, (y - mMapOriginY + mHeightProportion) - / mHeightProportion); + player_node->navigateTo(x, y); } + else if (event.getButton() == gcn::MouseEvent::RIGHT) + { + int x = event.getX(); + int y = event.getY(); + screenToMap(x, y); + viewport->showMapPopup(x, y); + } +} + +void Minimap::screenToMap(int &x, int &y) +{ + const gcn::Rectangle a = getChildrenArea(); + x = (x - a.x - mMapOriginX + mWidthProportion) / mWidthProportion; + y = (y - a.y - mMapOriginY + mHeightProportion) / mHeightProportion; } diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 8b7da5849..12835edd5 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -60,6 +60,8 @@ class Minimap : public Window void mouseReleased(gcn::MouseEvent &event); + void screenToMap(int &x, int &y); + private: Image *mMapImage; float mWidthProportion; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 933d2c7cd..5e5f310dc 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -579,6 +579,25 @@ void PopupMenu::showPopup(int x, int y, MapItem *mapItem) showPopup(x, y); } +void PopupMenu::showMapPopup(int x, int y, int x2, int y2) +{ + mX = x2; + mY = y2; + + mBrowserBox->clearRows(); + + mBrowserBox->addRow(_("Map Item")); + + if (player_node && player_node->isGM()) + mBrowserBox->addRow("warp map", _("Warp")); + mBrowserBox->addRow("move", _("Move")); + mBrowserBox->addRow("movecamera", _("Move camera")); + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow("cancel", _("Cancel")); + + showPopup(x, y); +} + void PopupMenu::showOutfitsPopup(int x, int y) { mX = x; @@ -1161,6 +1180,16 @@ void PopupMenu::handleLink(const std::string &link, } } } + else if (link == "move" && (mX || mY)) + { + if (player_node) + player_node->navigateTo(mX, mY); + } + else if (link == "movecamera" && (mX || mY)) + { + if (viewport) + viewport->moveCameraToPosition(mX * 32, mY * 32); + } else if (link == "split" && mItem) { ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, @@ -1304,6 +1333,14 @@ void PopupMenu::handleLink(const std::string &link, mMapItem->getX(), mMapItem->getY()); } } + else if (link == "warp map" && (mX || mY)) + { + if (Game::instance()) + { + Net::getAdminHandler()->warp(Game::instance()->getCurrentMapName(), + mX, mY); + } + } else if (link == "remove map" && mMapItem) { if (viewport) diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 8b9107300..f616e46ee 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -142,6 +142,8 @@ class PopupMenu : public Popup, public LinkHandler void showUndressPopup(int x, int y, Being *being, Item *item); + void showMapPopup(int x, int y, int x2, int y2); + /** * Shows the related popup menu when right click on the chat * at the specified mouse coordinates. diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 0c0f0d3d9..17f40121e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -706,6 +706,11 @@ void Viewport::showUndressPopup(int x, int y, Being *being, Item *item) mPopupMenu->showUndressPopup(x, y, being, item); } +void Viewport::showMapPopup(int x, int y) +{ + mPopupMenu->showMapPopup(getMouseX(), getMouseY(), x, y); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index ccb8124ba..ae6ff3d49 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -173,6 +173,8 @@ class Viewport : public WindowContainer, public gcn::MouseListener, void showUndressPopup(int x, int y, Being *being, Item *item); + void showMapPopup(int x, int y); + /** * Closes the popup menu. Needed for when the player dies or switching * maps. -- cgit v1.2.3-70-g09d2 From e70d551884c0e11408176086a25d359987090003 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 29 Feb 2012 04:53:49 +0300 Subject: Allow open conext menu from free tile if in free camera mode. Menu is same as in minimap. --- src/gui/viewport.cpp | 9 +++++++-- src/net/ea/playerhandler.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 17f40121e..1ef7b1cba 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -413,7 +413,6 @@ void Viewport::mousePressed(gcn::MouseEvent &event) return; // Check if we are alive and kickin' -// if (!mMap || !player_node || !player_node->isAlive()) if (!mMap || !player_node) return; @@ -422,7 +421,6 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (Being::isTalking()) return; - const int pixelX = event.getX() + static_cast(mPixelViewX); const int pixelY = event.getY() + static_cast(mPixelViewY); @@ -461,6 +459,13 @@ void Viewport::mousePressed(gcn::MouseEvent &event) mPopupMenu->showPopup(event.getX(), event.getY(), mHoverSign); return; } + else if (mCameraMode) + { + mPopupMenu->showMapPopup(event.getX(), event.getY(), + (getMouseX() + getCameraX()) / mMap->getTileWidth(), + (getMouseY() + getCameraY()) / mMap->getTileHeight()); + return; + } } // If a popup is active, just remove it diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index ddcf7d9c0..df28b4c1c 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -28,6 +28,7 @@ #include "playerinfo.h" #include "units.h" +#include "gui/ministatuswindow.h" #include "gui/okdialog.h" #include "gui/skilldialog.h" #include "gui/statuswindow.h" @@ -257,7 +258,12 @@ void PlayerHandler::processPlayerWarp(Net::MessageIn &msg) static_cast(scrollOffsetY)); if (viewport) + { + viewport->returnCamera(); + if (miniStatusWindow) + miniStatusWindow->updateStatus(); viewport->scrollBy(scrollOffsetX, scrollOffsetY); + } } void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) -- 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/gui/viewport.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