Implement filtering in the spells window

0.6.3
Andrei Kortunov 7 years ago
parent da47fc79f5
commit 9ac752ea70

@ -14,6 +14,9 @@ namespace MWGui
bool shouldAcceptKeyFocus(MyGUI::Widget* w) bool shouldAcceptKeyFocus(MyGUI::Widget* w)
{ {
if (w && w->getUserString("IgnoreTabKey") == "y")
return false;
return w && !w->castType<MyGUI::Window>(false) && w->getInheritedEnabled() && w->getInheritedVisible() && w->getVisible() && w->getEnabled(); return w && !w->castType<MyGUI::Window>(false) && w->getInheritedEnabled() && w->getInheritedVisible() && w->getVisible() && w->getEnabled();
} }

@ -32,10 +32,14 @@ namespace
namespace MWGui namespace MWGui
{ {
SpellModel::SpellModel(const MWWorld::Ptr &actor, const std::string& filter)
: mActor(actor), mFilter(filter)
{
}
SpellModel::SpellModel(const MWWorld::Ptr &actor) SpellModel::SpellModel(const MWWorld::Ptr &actor)
: mActor(actor) : mActor(actor)
{ {
} }
void SpellModel::update() void SpellModel::update()
@ -54,8 +58,13 @@ namespace MWGui
if (spell->mData.mType != ESM::Spell::ST_Power && spell->mData.mType != ESM::Spell::ST_Spell) if (spell->mData.mType != ESM::Spell::ST_Power && spell->mData.mType != ESM::Spell::ST_Spell)
continue; continue;
std::string name = spell->mName;
if (name.find(mFilter) == std::string::npos)
continue;
Spell newSpell; Spell newSpell;
newSpell.mName = spell->mName; newSpell.mName = name;
if (spell->mData.mType == ESM::Spell::ST_Spell) if (spell->mData.mType == ESM::Spell::ST_Spell)
{ {
newSpell.mType = Spell::Type_Spell; newSpell.mType = Spell::Type_Spell;
@ -89,10 +98,15 @@ namespace MWGui
if (enchant->mData.mType != ESM::Enchantment::WhenUsed && enchant->mData.mType != ESM::Enchantment::CastOnce) if (enchant->mData.mType != ESM::Enchantment::WhenUsed && enchant->mData.mType != ESM::Enchantment::CastOnce)
continue; continue;
std::string name = item.getClass().getName(item);
if (name.find(mFilter) == std::string::npos)
continue;
Spell newSpell; Spell newSpell;
newSpell.mItem = item; newSpell.mItem = item;
newSpell.mId = item.getCellRef().getRefId(); newSpell.mId = item.getCellRef().getRefId();
newSpell.mName = item.getClass().getName(item); newSpell.mName = name;
newSpell.mType = Spell::Type_EnchantedItem; newSpell.mType = Spell::Type_EnchantedItem;
newSpell.mSelected = invStore.getSelectedEnchantItem() == it; newSpell.mSelected = invStore.getSelectedEnchantItem() == it;

@ -35,6 +35,7 @@ namespace MWGui
class SpellModel class SpellModel
{ {
public: public:
SpellModel(const MWWorld::Ptr& actor, const std::string& filter);
SpellModel(const MWWorld::Ptr& actor); SpellModel(const MWWorld::Ptr& actor);
typedef int ModelIndex; typedef int ModelIndex;
@ -50,6 +51,8 @@ namespace MWGui
MWWorld::Ptr mActor; MWWorld::Ptr mActor;
std::vector<Spell> mSpells; std::vector<Spell> mSpells;
std::string mFilter;
}; };
} }

@ -2,6 +2,7 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include <MyGUI_EditBox.h>
#include <MyGUI_InputManager.h> #include <MyGUI_InputManager.h>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
@ -38,8 +39,12 @@ namespace MWGui
getWidget(mSpellView, "SpellView"); getWidget(mSpellView, "SpellView");
getWidget(mEffectBox, "EffectsBox"); getWidget(mEffectBox, "EffectsBox");
getWidget(mFilterEdit, "FilterEdit");
mFilterEdit->setUserString("IgnoreTabKey", "y");
mSpellView->eventSpellClicked += MyGUI::newDelegate(this, &SpellWindow::onModelIndexSelected); mSpellView->eventSpellClicked += MyGUI::newDelegate(this, &SpellWindow::onModelIndexSelected);
mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &SpellWindow::onFilterChanged);
setCoord(498, 300, 302, 300); setCoord(498, 300, 302, 300);
} }
@ -64,6 +69,11 @@ namespace MWGui
void SpellWindow::onOpen() void SpellWindow::onOpen()
{ {
// Reset the filter focus when opening the window
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
if (focus == mFilterEdit)
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(NULL);
updateSpells(); updateSpells();
} }
@ -82,7 +92,7 @@ namespace MWGui
{ {
mSpellIcons->updateWidgets(mEffectBox, false); mSpellIcons->updateWidgets(mEffectBox, false);
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer())); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), mFilterEdit->getCaption()));
} }
void SpellWindow::onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped) void SpellWindow::onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped)
@ -167,6 +177,11 @@ namespace MWGui
} }
} }
void SpellWindow::onFilterChanged(MyGUI::EditBox *sender)
{
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), sender->getCaption()));
}
void SpellWindow::onSpellSelected(const std::string& spellId) void SpellWindow::onSpellSelected(const std::string& spellId)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
@ -202,7 +217,7 @@ namespace MWGui
if (stats.isParalyzed() || stats.getKnockedDown() || stats.isDead() || stats.getHitRecovery()) if (stats.isParalyzed() || stats.getKnockedDown() || stats.isDead() || stats.getHitRecovery())
return; return;
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer())); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), mFilterEdit->getCaption()));
SpellModel::ModelIndex selected = 0; SpellModel::ModelIndex selected = 0;
for (SpellModel::ModelIndex i = 0; i<int(mSpellView->getModel()->getItemCount()); ++i) for (SpellModel::ModelIndex i = 0; i<int(mSpellView->getModel()->getItemCount()); ++i)

@ -32,6 +32,7 @@ namespace MWGui
void onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped); void onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped);
void onSpellSelected(const std::string& spellId); void onSpellSelected(const std::string& spellId);
void onModelIndexSelected(SpellModel::ModelIndex index); void onModelIndexSelected(SpellModel::ModelIndex index);
void onFilterChanged(MyGUI::EditBox *sender);
void onDeleteSpellAccept(); void onDeleteSpellAccept();
void askDeleteSpell(const std::string& spellId); void askDeleteSpell(const std::string& spellId);
@ -41,6 +42,7 @@ namespace MWGui
SpellView* mSpellView; SpellView* mSpellView;
SpellIcons* mSpellIcons; SpellIcons* mSpellIcons;
MyGUI::EditBox* mFilterEdit;
private: private:
float mUpdateTimer; float mUpdateTimer;

@ -10,7 +10,11 @@
</Widget> </Widget>
<!-- Spell list --> <!-- Spell list -->
<Widget type="SpellView" skin="MW_SpellView" position="8 38 268 518" align="Left Top Stretch" name="SpellView"> <Widget type="SpellView" skin="MW_SpellView" position="8 38 268 490" align="Left Top Stretch" name="SpellView">
</Widget>
<!-- Search box-->
<Widget type="EditBox" skin="MW_TextBoxEditWithBorder" position="8 535 268 23" align="Left Bottom HStretch" name="FilterEdit">
</Widget> </Widget>
</Widget> </Widget>

Loading…
Cancel
Save