1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-15 04:21:38 +00:00

Extend spell/item search to search by magic effect name

This commit is contained in:
jefetienne 2020-11-17 19:47:56 -05:00
parent f95d2cf54c
commit 2413de38b5
2 changed files with 46 additions and 3 deletions

View File

@ -42,6 +42,44 @@ namespace MWGui
{
}
bool SpellModel::matchingEffectExists(std::string filter, const ESM::EffectList &effects)
{
auto wm = MWBase::Environment::get().getWindowManager();
const MWWorld::ESMStore &store =
MWBase::Environment::get().getWorld()->getStore();
for (unsigned int i = 0; i < effects.mList.size(); ++i)
{
short effectId = effects.mList[i].mEffectID;
const ESM::MagicEffect *magicEffect =
store.get<ESM::MagicEffect>().search(effectId);
if (effectId != -1)
{
std::string effectIDStr = ESM::MagicEffect::effectIdToString(effectId);
std::string fullEffectName = wm->getGameSettingString(effectIDStr, "");
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill && effects.mList[i].mSkill != -1)
{
fullEffectName += " " + wm->getGameSettingString(ESM::Skill::sSkillNameIds[effects.mList[i].mSkill], "");
}
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute && effects.mList[i].mAttribute != -1)
{
fullEffectName += " " + wm->getGameSettingString(ESM::Attribute::sGmstAttributeIds[effects.mList[i].mAttribute], "");
}
std::string convert = Misc::StringUtils::lowerCaseUtf8(fullEffectName);
if (convert.find(filter) != std::string::npos)
{
return true;
}
}
}
return false;
}
void SpellModel::update()
{
mSpells.clear();
@ -61,8 +99,9 @@ namespace MWGui
continue;
std::string name = Misc::StringUtils::lowerCaseUtf8(spell->mName);
if (name.find(filter) == std::string::npos)
if (name.find(filter) == std::string::npos
&& !matchingEffectExists(filter, spell->mEffects))
continue;
Spell newSpell;
@ -103,7 +142,8 @@ namespace MWGui
std::string name = Misc::StringUtils::lowerCaseUtf8(item.getClass().getName(item));
if (name.find(filter) == std::string::npos)
if (name.find(filter) == std::string::npos
&& !matchingEffectExists(filter, enchant->mEffects))
continue;
Spell newSpell;

View File

@ -2,6 +2,7 @@
#define OPENMW_GUI_SPELLMODEL_H
#include "../mwworld/ptr.hpp"
#include <components/esm/effectlist.hpp>
namespace MWGui
{
@ -57,6 +58,8 @@ namespace MWGui
std::vector<Spell> mSpells;
std::string mFilter;
bool matchingEffectExists(std::string filter, const ESM::EffectList &effects);
};
}