forked from teamnwah/openmw-tes3coop
Implement filtering in the spells window
This commit is contained in:
parent
da47fc79f5
commit
9ac752ea70
6 changed files with 47 additions and 6 deletions
|
@ -14,6 +14,9 @@ namespace MWGui
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,14 @@ namespace
|
|||
namespace MWGui
|
||||
{
|
||||
|
||||
SpellModel::SpellModel(const MWWorld::Ptr &actor, const std::string& filter)
|
||||
: mActor(actor), mFilter(filter)
|
||||
{
|
||||
}
|
||||
|
||||
SpellModel::SpellModel(const MWWorld::Ptr &actor)
|
||||
: mActor(actor)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SpellModel::update()
|
||||
|
@ -54,8 +58,13 @@ namespace MWGui
|
|||
if (spell->mData.mType != ESM::Spell::ST_Power && spell->mData.mType != ESM::Spell::ST_Spell)
|
||||
continue;
|
||||
|
||||
std::string name = spell->mName;
|
||||
|
||||
if (name.find(mFilter) == std::string::npos)
|
||||
continue;
|
||||
|
||||
Spell newSpell;
|
||||
newSpell.mName = spell->mName;
|
||||
newSpell.mName = name;
|
||||
if (spell->mData.mType == ESM::Spell::ST_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)
|
||||
continue;
|
||||
|
||||
std::string name = item.getClass().getName(item);
|
||||
|
||||
if (name.find(mFilter) == std::string::npos)
|
||||
continue;
|
||||
|
||||
Spell newSpell;
|
||||
newSpell.mItem = item;
|
||||
newSpell.mId = item.getCellRef().getRefId();
|
||||
newSpell.mName = item.getClass().getName(item);
|
||||
newSpell.mName = name;
|
||||
newSpell.mType = Spell::Type_EnchantedItem;
|
||||
newSpell.mSelected = invStore.getSelectedEnchantItem() == it;
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace MWGui
|
|||
class SpellModel
|
||||
{
|
||||
public:
|
||||
SpellModel(const MWWorld::Ptr& actor, const std::string& filter);
|
||||
SpellModel(const MWWorld::Ptr& actor);
|
||||
|
||||
typedef int ModelIndex;
|
||||
|
@ -50,6 +51,8 @@ namespace MWGui
|
|||
MWWorld::Ptr mActor;
|
||||
|
||||
std::vector<Spell> mSpells;
|
||||
|
||||
std::string mFilter;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <MyGUI_EditBox.h>
|
||||
#include <MyGUI_InputManager.h>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
@ -38,8 +39,12 @@ namespace MWGui
|
|||
|
||||
getWidget(mSpellView, "SpellView");
|
||||
getWidget(mEffectBox, "EffectsBox");
|
||||
getWidget(mFilterEdit, "FilterEdit");
|
||||
|
||||
mFilterEdit->setUserString("IgnoreTabKey", "y");
|
||||
|
||||
mSpellView->eventSpellClicked += MyGUI::newDelegate(this, &SpellWindow::onModelIndexSelected);
|
||||
mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &SpellWindow::onFilterChanged);
|
||||
|
||||
setCoord(498, 300, 302, 300);
|
||||
}
|
||||
|
@ -64,6 +69,11 @@ namespace MWGui
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -82,7 +92,7 @@ namespace MWGui
|
|||
{
|
||||
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)
|
||||
|
@ -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)
|
||||
{
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
|
@ -202,7 +217,7 @@ namespace MWGui
|
|||
if (stats.isParalyzed() || stats.getKnockedDown() || stats.isDead() || stats.getHitRecovery())
|
||||
return;
|
||||
|
||||
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer()));
|
||||
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), mFilterEdit->getCaption()));
|
||||
|
||||
SpellModel::ModelIndex selected = 0;
|
||||
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 onSpellSelected(const std::string& spellId);
|
||||
void onModelIndexSelected(SpellModel::ModelIndex index);
|
||||
void onFilterChanged(MyGUI::EditBox *sender);
|
||||
void onDeleteSpellAccept();
|
||||
void askDeleteSpell(const std::string& spellId);
|
||||
|
||||
|
@ -41,6 +42,7 @@ namespace MWGui
|
|||
|
||||
SpellView* mSpellView;
|
||||
SpellIcons* mSpellIcons;
|
||||
MyGUI::EditBox* mFilterEdit;
|
||||
|
||||
private:
|
||||
float mUpdateTimer;
|
||||
|
|
|
@ -10,7 +10,11 @@
|
|||
</Widget>
|
||||
|
||||
<!-- 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>
|
||||
|
|
Loading…
Reference in a new issue