diff options
Diffstat (limited to 'src/gui/windows/outfitwindow.cpp')
-rw-r--r-- | src/gui/windows/outfitwindow.cpp | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index d547e5486..42d689802 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -1,11 +1,11 @@ /* - * The ManaPlus Client + * The ManaVerse Client * Copyright (C) 2007-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers * Copyright (C) 2011-2020 The ManaPlus Developers - * Copyright (C) 2020-2023 The ManaVerse Developers + * Copyright (C) 2020-2025 The ManaVerse Developers * - * This file is part of The ManaPlus Client. + * This file is part of The ManaVerse Client. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -151,30 +151,17 @@ void OutfitWindow::load() std::string buf; std::stringstream ss(outfit); - STD_VECTOR<int> tokens; - - while (ss >> buf) - tokens.push_back(atoi(buf.c_str())); - - for (size_t i = 0, sz = tokens.size(); - i < sz && i < OUTFIT_ITEM_COUNT; i++) + for (size_t i = 0; (ss >> buf) && i < OUTFIT_ITEM_COUNT; i++) { - mItems[o][i] = tokens[i]; + mItems[o][i] = atoi(buf.c_str()); } outfit = cfg->getValue("OutfitColor" + toString(o), "1"); std::stringstream ss2(outfit); - tokens.clear(); - - STD_VECTOR<unsigned char> tokens2; - while (ss2 >> buf) - tokens2.push_back(CAST_U8(atoi(buf.c_str()))); - - for (size_t i = 0, sz = tokens2.size(); - i < sz && i < OUTFIT_ITEM_COUNT; i++) + for (size_t i = 0; (ss2 >> buf) && i < OUTFIT_ITEM_COUNT; i++) { - mItemColors[o][i] = fromInt(tokens2[i], ItemColor); + mItemColors[o][i] = fromInt(CAST_U8(atoi(buf.c_str())), ItemColor); } mItemsUnequip[o] = cfg->getValueBool("OutfitUnequip" + toString(o), @@ -194,31 +181,41 @@ void OutfitWindow::save() const std::string outfitColorsStr; for (unsigned o = 0; o < OUTFITS_COUNT; o++) { - bool good = false; + bool isEmpty = true; for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++) { const int val = mItems[o][i]; - const int res = val != 0 ? val : -1; - if (res != -1) - good = true; + // Not sure why, but "empty" is stored as -1 instead of 0. + int res; + if (val == 0) + res = -1; + else + { + isEmpty = false; + res = val; + } + outfitStr.append(toString(res)); + outfitColorsStr.append(toString(CAST_S32(mItemColors[o][i]))); + if (i < OUTFIT_ITEM_COUNT - 1) + { outfitStr.append(" "); - outfitColorsStr.append(toString(CAST_S32( - toInt(mItemColors[o][i], int)))); - if (i < OUTFIT_ITEM_COUNT - 1) outfitColorsStr.append(" "); + } } - if (good) + + if (isEmpty) { - serverConfig.setValue("Outfit" + toString(o), outfitStr); - serverConfig.setValue("OutfitColor" + toString(o), - outfitColorsStr); + serverConfig.deleteKey("Outfit" + toString(o)); + serverConfig.deleteKey("OutfitColor" + toString(o)); } else { - serverConfig.deleteKey("Outfit" + toString(o)); - serverConfig.deleteKey("OutfitColor" + toString(o)); + serverConfig.setValue("Outfit" + toString(o), + outfitStr); + serverConfig.setValue("OutfitColor" + toString(o), + outfitColorsStr); } if (mItemsUnequip[o]) |