diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-06-01 01:08:30 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-06-01 01:08:30 +0300 |
commit | 16f6f636aee6acaf52439643502f5ff9cb4ccffc (patch) | |
tree | 9f291e5257e20b0090405d4594553f38a69767ce /src | |
parent | 3fc7fd8473e545265c705504ee0d5f2a70268282 (diff) | |
download | manaplus-16f6f636aee6acaf52439643502f5ff9cb4ccffc.tar.gz manaplus-16f6f636aee6acaf52439643502f5ff9cb4ccffc.tar.bz2 manaplus-16f6f636aee6acaf52439643502f5ff9cb4ccffc.tar.xz manaplus-16f6f636aee6acaf52439643502f5ff9cb4ccffc.zip |
Convert UserColorId enum into strong typed enum.
Diffstat (limited to 'src')
-rw-r--r-- | src/being/being.cpp | 23 | ||||
-rw-r--r-- | src/being/being.h | 14 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 2 | ||||
-rw-r--r-- | src/being/localplayer.h | 5 | ||||
-rw-r--r-- | src/enums/gui/usercolorid.h | 102 | ||||
-rw-r--r-- | src/gui/palette.h | 7 | ||||
-rw-r--r-- | src/gui/userpalette.cpp | 49 | ||||
-rw-r--r-- | src/gui/userpalette.h | 63 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_colors.cpp | 12 | ||||
-rw-r--r-- | src/gui/windows/minimap.cpp | 2 |
10 files changed, 163 insertions, 116 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp index e30a1e477..3503b5259 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -2594,11 +2594,16 @@ void Being::drawSpriteAt(Graphics *const graphics, if (!maxHP) maxHP = mInfo->getMaxHP(); - drawHpBar(graphics, maxHP, mHP, mDamageTaken, - UserColorId::MONSTER_HP, UserColorId::MONSTER_HP2, + drawHpBar(graphics, + maxHP, + mHP, + mDamageTaken, + UserColorId::MONSTER_HP, + UserColorId::MONSTER_HP2, x - 50 + mapTileSize / 2 + mInfo->getHpBarOffsetX(), y + mapTileSize - 6 + mInfo->getHpBarOffsetY(), - 2 * 50, 4); + 2 * 50, + 4); } if (mShowOwnHP && mInfo @@ -2614,9 +2619,15 @@ void Being::drawSpriteAt(Graphics *const graphics, } } -void Being::drawHpBar(Graphics *const graphics, const int maxHP, const int hp, - const int damage, const int color1, const int color2, - const int x, const int y, const int width, +void Being::drawHpBar(Graphics *const graphics, + const int maxHP, + const int hp, + const int damage, + const UserColorIdT color1, + const UserColorIdT color2, + const int x, + const int y, + const int width, const int height) const { if (maxHP <= 0 || !userPalette) diff --git a/src/being/being.h b/src/being/being.h index 6e8588213..ebce57c41 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -25,6 +25,8 @@ #include "enums/being/reachable.h" +#include "enums/gui/usercolorid.h" + #include "enums/simpletypes/move.h" #include "resources/beinginfo.h" @@ -533,9 +535,15 @@ class Being notfinal : public ActorSprite, virtual void drawSpritesSDL(Graphics *const graphics, int posX, int posY) const override final; - void drawHpBar(Graphics *const graphics, const int x, const int y, - const int maxHP, const int hp, const int damage, - const int color1, const int color2, const int width, + void drawHpBar(Graphics *const graphics, + const int maxHP, + const int hp, + const int damage, + const UserColorIdT color1, + const UserColorIdT color2, + const int x, + const int y, + const int width, const int height) const; static void load(); diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index a941dc42c..7eea9c18a 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -1025,7 +1025,7 @@ void LocalPlayer::handleStatusEffect(const StatusEffect *const effect, } void LocalPlayer::addMessageToQueue(const std::string &message, - const int color) + const UserColorIdT color) { if (mMessages.size() < 20) mMessages.push_back(MessagePair(message, color)); diff --git a/src/being/localplayer.h b/src/being/localplayer.h index e5ae09ae9..2425f7502 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -280,7 +280,8 @@ class LocalPlayer final : public Being, void setMap(Map *const map) override final; void addMessageToQueue(const std::string &message, - const int color = UserColorId::EXP_INFO); + const UserColorIdT color + = UserColorId::EXP_INFO); /** * Called when a option (set with config.addListener()) is changed @@ -458,7 +459,7 @@ class LocalPlayer final : public Being, std::vector<int> mStatusEffectIcons; - typedef std::pair<std::string, int> MessagePair; + typedef std::pair<std::string, UserColorIdT> MessagePair; /** Queued messages*/ std::list<MessagePair> mMessages; int mMessageTime; diff --git a/src/enums/gui/usercolorid.h b/src/enums/gui/usercolorid.h index 0a66cf6b9..5087c36f8 100644 --- a/src/enums/gui/usercolorid.h +++ b/src/enums/gui/usercolorid.h @@ -24,57 +24,57 @@ #ifndef ENUMS_GUI_USERCOLORID_H #define ENUMS_GUI_USERCOLORID_H -namespace UserColorId +#include "enums/simpletypes/enumdefines.h" + +enumStart(UserColorId) { - /** List of all colors that are configurable. */ - enum T - { - BEING = 0, - FRIEND, - DISREGARDED, - IGNORED, - ERASED, - PC, - SELF, - GM, - NPC, - MONSTER, - MONSTER_HP, - MONSTER_HP2, - PARTY, - GUILD, - PARTICLE, - PICKUP_INFO, - EXP_INFO, - PLAYER_HP, - PLAYER_HP2, - HIT_PLAYER_MONSTER, - HIT_MONSTER_PLAYER, - HIT_PLAYER_PLAYER, - HIT_CRITICAL, - HIT_LOCAL_PLAYER_MONSTER, - HIT_LOCAL_PLAYER_CRITICAL, - HIT_LOCAL_PLAYER_MISS, - MISS, - PORTAL_HIGHLIGHT, - COLLISION_HIGHLIGHT, - AIR_COLLISION_HIGHLIGHT, - WATER_COLLISION_HIGHLIGHT, - GROUNDTOP_COLLISION_HIGHLIGHT, - WALKABLE_HIGHLIGHT, - ATTACK_RANGE, - ATTACK_RANGE_BORDER, - MONSTER_ATTACK_RANGE, - FLOOR_ITEM_TEXT, - HOME_PLACE, - HOME_PLACE_BORDER, - ROAD_POINT, - NET, - PET, - MERCENARY, - HOMUNCULUS, - USER_COLOR_LAST - }; -} // namespace UserColorId + NO_COLOR = -1, + BEING = 0, + FRIEND, + DISREGARDED, + IGNORED, + ERASED, + PC, + SELF, + GM, + NPC, + MONSTER, + MONSTER_HP, + MONSTER_HP2, + PARTY, + GUILD, + PARTICLE, + PICKUP_INFO, + EXP_INFO, + PLAYER_HP, + PLAYER_HP2, + HIT_PLAYER_MONSTER, + HIT_MONSTER_PLAYER, + HIT_PLAYER_PLAYER, + HIT_CRITICAL, + HIT_LOCAL_PLAYER_MONSTER, + HIT_LOCAL_PLAYER_CRITICAL, + HIT_LOCAL_PLAYER_MISS, + MISS, + PORTAL_HIGHLIGHT, + COLLISION_HIGHLIGHT, + AIR_COLLISION_HIGHLIGHT, + WATER_COLLISION_HIGHLIGHT, + GROUNDTOP_COLLISION_HIGHLIGHT, + WALKABLE_HIGHLIGHT, + ATTACK_RANGE, + ATTACK_RANGE_BORDER, + MONSTER_ATTACK_RANGE, + FLOOR_ITEM_TEXT, + HOME_PLACE, + HOME_PLACE_BORDER, + ROAD_POINT, + NET, + PET, + MERCENARY, + HOMUNCULUS, + USER_COLOR_LAST +} +enumEnd(UserColorId); #endif // ENUMS_GUI_USERCOLORID_H diff --git a/src/gui/palette.h b/src/gui/palette.h index aa7d2ecc8..bee83daf3 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -27,6 +27,7 @@ #include "logger.h" #include "enums/gui/gradienttype.h" +#include "enums/gui/usercolorid.h" #include "gui/color.h" @@ -132,8 +133,10 @@ class Palette notfinal int delay; int committedDelay; - void set(const int type0, const Color &color0, - const GradientTypeT grad0, const int delay0) + void set(const int type0, + const Color &color0, + const GradientTypeT grad0, + const int delay0) { type = type0; color = color0; diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 629caca73..bb82b3b78 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -105,14 +105,14 @@ std::string UserPalette::getConfigName(const std::string &typeName) } UserPalette::UserPalette() : - Palette(UserColorId::USER_COLOR_LAST) + Palette(static_cast<int>(UserColorId::USER_COLOR_LAST)) { - mColors[UserColorId::BEING] = ColorElem(); - mColors[UserColorId::PC] = ColorElem(); - mColors[UserColorId::SELF] = ColorElem(); - mColors[UserColorId::GM] = ColorElem(); - mColors[UserColorId::NPC] = ColorElem(); - mColors[UserColorId::MONSTER] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::BEING)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::PC)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::SELF)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::GM)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::NPC)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::MONSTER)] = ColorElem(); // TRANSLATORS: palette color addColor(UserColorId::BEING, 0xffffff, GradientType::STATIC, _("Being")); @@ -248,20 +248,21 @@ UserPalette::~UserPalette() } } -void UserPalette::setColor(const int type, +void UserPalette::setColor(const UserColorIdT type, const int r, const int g, const int b) { - Color &color = mColors[type].color; + Color &color = mColors[static_cast<size_t>(type)].color; color.r = r; color.g = g; color.b = b; } -void UserPalette::setGradient(const int type, const GradientTypeT grad) +void UserPalette::setGradient(const UserColorIdT type, + const GradientTypeT grad) { - ColorElem *const elem = &mColors[type]; + ColorElem *const elem = &mColors[static_cast<size_t>(type)]; if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC) { @@ -311,12 +312,15 @@ void UserPalette::rollback() FOR_EACH (Colors::iterator, i, mColors) { if (i->grad != i->committedGrad) - setGradient(i->type, i->committedGrad); + setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad); const Color &committedColor = i->committedColor; - setGradientDelay(i->type, i->committedDelay); - setColor(i->type, committedColor.r, - committedColor.g, committedColor.b); + setGradientDelay(static_cast<UserColorIdT>(i->type), + i->committedDelay); + setColor(static_cast<UserColorIdT>(i->type), + committedColor.r, + committedColor.g, + committedColor.b); if (i->grad == GradientType::PULSE) { @@ -331,12 +335,12 @@ void UserPalette::rollback() int UserPalette::getColorTypeAt(const int i) { if (i < 0 || i >= getNumberOfElements()) - return UserColorId::BEING; + return 0; return mColors[i].type; } -void UserPalette::addColor(const unsigned type, +void UserPalette::addColor(const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, @@ -345,10 +349,10 @@ void UserPalette::addColor(const unsigned type, const unsigned maxType = sizeof(ColorTypeNames) / sizeof(ColorTypeNames[0]); - if (type >= maxType) + if (static_cast<unsigned>(type) >= maxType) return; - const std::string &configName = ColorTypeNames[type]; + const std::string &configName = ColorTypeNames[static_cast<size_t>(type)]; char buffer[20]; snprintf(buffer, sizeof(buffer), "0x%06x", rgb); buffer[19] = 0; @@ -365,11 +369,12 @@ void UserPalette::addColor(const unsigned type, configName + "Gradient", static_cast<int>(grad))); delay = config.getValueInt(configName + "Delay", delay); - mColors[type].set(type, trueCol, grad, delay); - mColors[type].text = text; + mColors[static_cast<size_t>(type)].set(static_cast<int>(type), + trueCol, grad, delay); + mColors[static_cast<size_t>(type)].text = text; if (grad != GradientType::STATIC) - mGradVector.push_back(&mColors[type]); + mGradVector.push_back(&mColors[static_cast<size_t>(type)]); } int UserPalette::getIdByChar(const signed char c, bool &valid) const diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h index 525a18492..22203560c 100644 --- a/src/gui/userpalette.h +++ b/src/gui/userpalette.h @@ -24,6 +24,8 @@ #ifndef GUI_USERPALETTE_H #define GUI_USERPALETTE_H +#include "enums/gui/usercolorid.h" + #include "gui/palette.h" #include "gui/models/listmodel.h" @@ -53,10 +55,10 @@ class UserPalette final : public Palette, public ListModel * * @return the requested committed color */ - inline const Color &getCommittedColor(const int type) + inline const Color &getCommittedColor(const UserColorIdT type) const A_WARN_UNUSED { - return mColors[type].committedColor; + return mColors[static_cast<size_t>(type)].committedColor; } /** @@ -66,8 +68,9 @@ class UserPalette final : public Palette, public ListModel * * @return the requested test color */ - inline const Color &getTestColor(const int type) const A_WARN_UNUSED - { return mColors[type].testColor; } + inline const Color &getTestColor(const UserColorIdT type) + const A_WARN_UNUSED + { return mColors[static_cast<size_t>(type)].testColor; } /** * Sets the test color associated with the specified type. @@ -75,8 +78,9 @@ class UserPalette final : public Palette, public ListModel * @param type the color type requested * @param color the color that should be tested */ - inline void setTestColor(const int type, const Color &color) - { mColors[type].testColor = color; } + inline void setTestColor(const UserColorIdT type, + const Color &color) + { mColors[static_cast<size_t>(type)].testColor = color; } /** * Sets the color for the specified type. @@ -86,22 +90,27 @@ class UserPalette final : public Palette, public ListModel * @param g green component * @param b blue component */ - void setColor(const int type, const int r, const int g, const int b); + void setColor(const UserColorIdT type, + const int r, + const int g, + const int b); /** * Sets the gradient type for the specified color. * * @param grad gradient type to set */ - void setGradient(const int type, const GradientTypeT grad); + void setGradient(const UserColorIdT type, + const GradientTypeT grad); /** * Sets the gradient delay for the specified color. * * @param grad gradient type to set */ - void setGradientDelay(const int type, const int delay) - { mColors[type].delay = delay; } + void setGradientDelay(const UserColorIdT type, + const int delay) + { mColors[static_cast<size_t>(type)].delay = delay; } /** * Returns the number of colors known. @@ -150,16 +159,17 @@ class UserPalette final : public Palette, public ListModel * * @return the requested color */ - inline const Color &getColor(int type, + inline const Color &getColor(UserColorIdT type, const int alpha = 255) A_WARN_UNUSED { - if (type >= static_cast<signed>(mColors.size()) || type < 0) + if (static_cast<size_t>(type) >= mColors.size()) { logger->log("incorrect color request type: %d from %u", - type, static_cast<unsigned int>(mColors.size())); - type = 0; + static_cast<int>(type), + static_cast<unsigned int>(mColors.size())); + type = UserColorId::BEING; } - Color* col = &mColors[type].color; + Color* col = &mColors[static_cast<size_t>(type)].color; col->a = alpha; return *col; } @@ -173,8 +183,9 @@ class UserPalette final : public Palette, public ListModel * * @return the gradient type of the color with the given index */ - inline GradientTypeT getGradientType(const int type) const A_WARN_UNUSED - { return mColors[type].grad; } + inline GradientTypeT getGradientType(const UserColorId type) + const A_WARN_UNUSED + { return mColors[static_cast<size_t>(type)].grad; } /** * Gets the gradient delay for the specified type. @@ -183,13 +194,15 @@ class UserPalette final : public Palette, public ListModel * * @return the gradient delay of the color with the given index */ - inline int getGradientDelay(const int type) const A_WARN_UNUSED - { return mColors[type].delay; } + inline int getGradientDelay(const UserColorIdT type) + const A_WARN_UNUSED + { return mColors[static_cast<size_t>(type)].delay; } - inline const Color &getColorWithAlpha(const int type) A_WARN_UNUSED + inline const Color &getColorWithAlpha(const UserColorIdT type) + A_WARN_UNUSED { - Color *const col = &mColors[type].color; - col->a = mColors[type].delay; + Color *const col = &mColors[static_cast<size_t>(type)].color; + col->a = mColors[static_cast<size_t>(type)].delay; return *col; } @@ -230,8 +243,10 @@ class UserPalette final : public Palette, public ListModel * @param rgb default color if not found in config * @param text identifier of color */ - void addColor(const unsigned type, const unsigned rgb, - GradientTypeT grad, const std::string &text, + void addColor(const UserColorIdT type, + const unsigned rgb, + GradientTypeT grad, + const std::string &text, int delay = GRADIENT_DELAY); }; diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index 1ba6461ea..f7a2dcfd6 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -250,7 +250,8 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED) return; mSelected = mColorBox->getSelected(); - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const Color *col = &userPalette->getColor(type); const GradientTypeT grad = userPalette->getGradientType(type); const int delay = userPalette->getGradientDelay(type); @@ -380,7 +381,8 @@ void Setup_Colors::cancel() return; userPalette->rollback(); - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const Color *const col = &userPalette->getColor(type); mGradTypeSlider->setValue(static_cast<int>( userPalette->getGradientType(type))); @@ -397,7 +399,8 @@ void Setup_Colors::updateGradType() return; mSelected = mColorBox->getSelected(); - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const GradientTypeT grad = userPalette->getGradientType(type); mGradTypeText->setCaption( @@ -427,7 +430,8 @@ void Setup_Colors::updateColor() if (mSelected == -1 || !userPalette) return; - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const GradientTypeT grad = static_cast<GradientTypeT>( static_cast<int>(mGradTypeSlider->getValue())); const int delay = static_cast<int>(mGradDelaySlider->getValue()); diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index 2f73d50e6..ea22db3f4 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -312,7 +312,7 @@ void Minimap::draw2(Graphics *const graphics) continue; int dotSize = 2; - int type = UserColorId::PC; + UserColorIdT type = UserColorId::PC; if (being == localPlayer) { |