diff --git a/apps/openmw/mwgui/spellicons.cpp b/apps/openmw/mwgui/spellicons.cpp index ba94eaba95..a62c70597f 100644 --- a/apps/openmw/mwgui/spellicons.cpp +++ b/apps/openmw/mwgui/spellicons.cpp @@ -48,22 +48,18 @@ namespace MWGui } int w = 2; - + const auto& store = MWBase::Environment::get().getESMStore(); for (const auto& [effectId, effectInfos] : effects) { - const ESM::MagicEffect* effect - = MWBase::Environment::get().getESMStore()->get().find(effectId); + const ESM::MagicEffect* effect = store->get().find(effectId); float remainingDuration = 0; float totalDuration = 0; std::string sourcesDescription; - static const float fadeTime = MWBase::Environment::get() - .getESMStore() - ->get() - .find("fMagicStartIconBlink") - ->mValue.getFloat(); + static const float fadeTime + = store->get().find("fMagicStartIconBlink")->mValue.getFloat(); bool addNewLine = false; for (const MagicEffectInfo& effectInfo : effectInfos) @@ -94,9 +90,10 @@ namespace MWGui } if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute) { + const ESM::Attribute* attribute = store->get().find(effectInfo.mKey.mArg); sourcesDescription += " ("; - sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString( - ESM::Attribute::sGmstAttributeIds[effectInfo.mKey.mArg], {}); + sourcesDescription + += MWBase::Environment::get().getWindowManager()->getGameSettingString(attribute->mName, {}); sourcesDescription += ')'; } ESM::MagicEffect::MagnitudeDisplayType displayType = effect->getMagnitudeDisplayType(); diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index 691f48b53a..9fc86dd0e6 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -54,9 +54,9 @@ namespace MWGui if (effectId != -1) { const ESM::MagicEffect* magicEffect = store.get().find(effectId); + const ESM::Attribute* attribute = store.get().search(effect.mAttribute); - std::string fullEffectName - = MWMechanics::getMagicEffectString(*magicEffect, effect.mAttribute, effect.mSkill); + std::string fullEffectName = MWMechanics::getMagicEffectString(*magicEffect, attribute, effect.mSkill); std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName); if (convert.find(filter) != std::string::npos) { diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index b93146f5f1..594b2e4c02 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -340,20 +340,21 @@ namespace MWGui MWWorld::Ptr player = MWMechanics::getPlayer(); const MWMechanics::NpcStats& PCstats = player.getClass().getNpcStats(player); + const auto& store = MWBase::Environment::get().getESMStore(); std::string detailText; std::stringstream detail; bool first = true; - for (int attribute = 0; attribute < ESM::Attribute::Length; ++attribute) + for (const auto& attribute : store->get()) { - float mult = PCstats.getLevelupAttributeMultiplier(attribute); - mult = std::min(mult, 100 - PCstats.getAttribute(attribute).getBase()); + float mult = PCstats.getLevelupAttributeMultiplier(attribute.mId); + mult = std::min(mult, 100 - PCstats.getAttribute(attribute.mId).getBase()); if (mult > 1) { if (!first) detail << '\n'; - detail << "#{" << MyGUI::TextIterator::toTagsString(ESM::Attribute::sGmstAttributeIds[attribute]) - << "} x" << MyGUI::utility::toString(mult); + detail << "#{" << MyGUI::TextIterator::toTagsString(attribute.mName) << "} x" + << MyGUI::utility::toString(mult); first = false; } } @@ -363,11 +364,7 @@ namespace MWGui MyGUI::Widget* levelWidget; for (int i = 0; i < 2; ++i) { - int max = MWBase::Environment::get() - .getESMStore() - ->get() - .find("iLevelUpTotal") - ->mValue.getInteger(); + int max = store->get().find("iLevelUpTotal")->mValue.getInteger(); getWidget(levelWidget, i == 0 ? "Level_str" : "LevelText"); levelWidget->setUserString( diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index e55fdef51c..5c5d9176ff 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -829,12 +829,14 @@ namespace MWGui void ToolTips::createAttributeToolTip(MyGUI::Widget* widget, int attributeId) { - if (attributeId == -1) + const ESM::Attribute* attribute + = MWBase::Environment::get().getESMStore()->get().search(attributeId); + if (!attribute) return; - const std::string& icon = ESM::Attribute::sAttributeIcons[attributeId]; - const std::string& name = ESM::Attribute::sGmstAttributeIds[attributeId]; - const std::string& desc = ESM::Attribute::sGmstAttributeDescIds[attributeId]; + const std::string& icon = attribute->mIcon; + const std::string& name = attribute->mName; + const std::string& desc = attribute->mDescription; widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipLayout", "AttributeToolTip"); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 51d96c4cdd..10f7345fce 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -378,6 +378,7 @@ namespace MWGui::Widgets const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); const ESM::MagicEffect* magicEffect = store.get().search(mEffectParams.mEffectID); + const ESM::Attribute* attribute = store.get().search(mEffectParams.mAttribute); assert(magicEffect); @@ -393,8 +394,7 @@ namespace MWGui::Widgets std::string sec = " " + std::string{ windowManager->getGameSettingString("ssecond", {}) }; std::string secs = " " + std::string{ windowManager->getGameSettingString("sseconds", {}) }; - std::string spellLine - = MWMechanics::getMagicEffectString(*magicEffect, mEffectParams.mAttribute, mEffectParams.mSkill); + std::string spellLine = MWMechanics::getMagicEffectString(*magicEffect, attribute, mEffectParams.mSkill); if (mEffectParams.mMagnMin || mEffectParams.mMagnMax) { diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 7dee12b6be..3735962a95 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -561,23 +561,23 @@ std::vector MWMechanics::Alchemy::effectsDescription(const MWWorld: std::vector effects; const auto& item = ptr.get()->mBase; - const auto& gmst = MWBase::Environment::get().getESMStore()->get(); - const auto& mgef = MWBase::Environment::get().getESMStore()->get(); - const static auto fWortChanceValue = gmst.find("fWortChanceValue")->mValue.getFloat(); + const auto& store = MWBase::Environment::get().getESMStore(); + const auto& mgef = store->get(); + const static auto fWortChanceValue = store->get().find("fWortChanceValue")->mValue.getFloat(); const auto& data = item->mData; for (auto i = 0; i < 4; ++i) { const auto effectID = data.mEffectID[i]; const auto skillID = data.mSkills[i]; - const auto attributeID = data.mAttributes[i]; if (alchemySkill < fWortChanceValue * (i + 1)) break; if (effectID != -1) { - std::string effect = getMagicEffectString(*mgef.find(effectID), attributeID, skillID); + const ESM::Attribute* attribute = store->get().search(data.mAttributes[i]); + std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skillID); effects.push_back(effect); } diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index 8034b2255a..9f5e781731 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -51,9 +51,9 @@ namespace MWMechanics std::string EffectKey::toString() const { - const ESM::MagicEffect* magicEffect - = MWBase::Environment::get().getESMStore()->get().search(mId); - return getMagicEffectString(*magicEffect, mArg, mArg); + const auto& store = MWBase::Environment::get().getESMStore(); + const ESM::MagicEffect* magicEffect = store->get().search(mId); + return getMagicEffectString(*magicEffect, store->get().find(mArg), mArg); } bool operator<(const EffectKey& left, const EffectKey& right) @@ -227,10 +227,10 @@ namespace MWMechanics } } - std::string getMagicEffectString(const ESM::MagicEffect& effect, int attributeArg, int skillArg) + std::string getMagicEffectString(const ESM::MagicEffect& effect, const ESM::Attribute* attribute, int skillArg) { const bool targetsSkill = effect.mData.mFlags & ESM::MagicEffect::TargetSkill && skillArg != -1; - const bool targetsAttribute = effect.mData.mFlags & ESM::MagicEffect::TargetAttribute && attributeArg != -1; + const bool targetsAttribute = effect.mData.mFlags & ESM::MagicEffect::TargetAttribute && attribute; std::string spellLine; @@ -277,7 +277,7 @@ namespace MWMechanics else if (targetsAttribute) { spellLine += ' '; - spellLine += windowManager->getGameSettingString(ESM::Attribute::sGmstAttributeIds[attributeArg], {}); + spellLine += windowManager->getGameSettingString(attribute->mName, {}); } return spellLine; } diff --git a/apps/openmw/mwmechanics/magiceffects.hpp b/apps/openmw/mwmechanics/magiceffects.hpp index d63db74d3d..d53dd9e21e 100644 --- a/apps/openmw/mwmechanics/magiceffects.hpp +++ b/apps/openmw/mwmechanics/magiceffects.hpp @@ -7,6 +7,7 @@ namespace ESM { + struct Attribute; struct ENAMstruct; struct EffectList; struct MagicEffect; @@ -113,7 +114,7 @@ namespace MWMechanics ///< Return changes from \a prev to \a now. }; - std::string getMagicEffectString(const ESM::MagicEffect& effect, int attributeArg, int skillArg); + std::string getMagicEffectString(const ESM::MagicEffect& effect, const ESM::Attribute* attribute, int skillArg); } #endif diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 0074e8cfb6..92d2ff837f 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -948,14 +948,38 @@ namespace MWWorld } void Store::setUp() { - for (int i = 0; i < ESM::Attribute::Length; ++i) - { - ESM::Attribute newAttribute; - newAttribute.mId = ESM::Attribute::AttributeID(i); - newAttribute.mName = ESM::Attribute::sGmstAttributeIds[i]; - newAttribute.mDescription = ESM::Attribute::sGmstAttributeDescIds[i]; - mStatic.push_back(newAttribute); - } + mStatic.push_back({ .mId = ESM::Attribute::Strength, + .mName = "sAttributeStrength", + .mDescription = "sStrDesc", + .mIcon = "icons\\k\\attribute_strength.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Intelligence, + .mName = "sAttributeIntelligence", + .mDescription = "sIntDesc", + .mIcon = "icons\\k\\attribute_int.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Willpower, + .mName = "sAttributeWillpower", + .mDescription = "sWilDesc", + .mIcon = "icons\\k\\attribute_wilpower.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Agility, + .mName = "sAttributeAgility", + .mDescription = "sAgiDesc", + .mIcon = "icons\\k\\attribute_agility.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Speed, + .mName = "sAttributeSpeed", + .mDescription = "sSpdDesc", + .mIcon = "icons\\k\\attribute_speed.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Endurance, + .mName = "sAttributeEndurance", + .mDescription = "sEndDesc", + .mIcon = "icons\\k\\attribute_endurance.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Personality, + .mName = "sAttributePersonality", + .mDescription = "sPerDesc", + .mIcon = "icons\\k\\attribute_personality.dds" }); + mStatic.push_back({ .mId = ESM::Attribute::Luck, + .mName = "sAttributeLuck", + .mDescription = "sLucDesc", + .mIcon = "icons\\k\\attribute_luck.dds" }); } size_t Store::getSize() const { diff --git a/components/esm/attr.cpp b/components/esm/attr.cpp index cb4e94b773..38119dbc0e 100644 --- a/components/esm/attr.cpp +++ b/components/esm/attr.cpp @@ -15,39 +15,6 @@ const std::string Attribute::sAttributeNames[Attribute::Length] = { "Luck", }; -const std::string Attribute::sGmstAttributeIds[Attribute::Length] = { - "sAttributeStrength", - "sAttributeIntelligence", - "sAttributeWillpower", - "sAttributeAgility", - "sAttributeSpeed", - "sAttributeEndurance", - "sAttributePersonality", - "sAttributeLuck", -}; - -const std::string Attribute::sGmstAttributeDescIds[Attribute::Length] = { - "sStrDesc", - "sIntDesc", - "sWilDesc", - "sAgiDesc", - "sSpdDesc", - "sEndDesc", - "sPerDesc", - "sLucDesc", -}; - -const std::string Attribute::sAttributeIcons[Attribute::Length] = { - "icons\\k\\attribute_strength.dds", - "icons\\k\\attribute_int.dds", - "icons\\k\\attribute_wilpower.dds", - "icons\\k\\attribute_agility.dds", - "icons\\k\\attribute_speed.dds", - "icons\\k\\attribute_endurance.dds", - "icons\\k\\attribute_personality.dds", - "icons\\k\\attribute_luck.dds", -}; - Attribute::AttributeID Attribute::stringToAttributeId(std::string_view attribute) { for (int id = 0; id < Attribute::Length; ++id) diff --git a/components/esm/attr.hpp b/components/esm/attr.hpp index 2d643e2e1b..9c0c4546d0 100644 --- a/components/esm/attr.hpp +++ b/components/esm/attr.hpp @@ -26,12 +26,9 @@ namespace ESM }; AttributeID mId; - std::string mName, mDescription; + std::string mName, mDescription, mIcon; static const std::string sAttributeNames[Length]; - static const std::string sGmstAttributeIds[Length]; - static const std::string sGmstAttributeDescIds[Length]; - static const std::string sAttributeIcons[Length]; static AttributeID stringToAttributeId(std::string_view attribute); };