Add a button to delete spells from spellwindow

pull/541/head
Ilya Zhuravlev 6 years ago
parent 7941fd6780
commit 6c96b5653b

@ -148,6 +148,17 @@ namespace MWGui
return mSpells.size(); return mSpells.size();
} }
SpellModel::ModelIndex SpellModel::getSelectedIndex() const
{
ModelIndex selected = -1;
for (SpellModel::ModelIndex i = 0; i<int(getItemCount()); ++i)
{
if (getItem(i).mSelected)
selected = i;
}
return selected;
}
Spell SpellModel::getItem(ModelIndex index) const Spell SpellModel::getItem(ModelIndex index) const
{ {
if (index < 0 || index >= int(mSpells.size())) if (index < 0 || index >= int(mSpells.size()))

@ -48,6 +48,8 @@ namespace MWGui
///< throws for invalid index ///< throws for invalid index
size_t getItemCount() const; size_t getItemCount() const;
ModelIndex getSelectedIndex() const;
///< returns -1 if nothing is selected
private: private:
MWWorld::Ptr mActor; MWWorld::Ptr mActor;

@ -1,5 +1,6 @@
#include "spellwindow.hpp" #include "spellwindow.hpp"
#include <MyGUI_Button.h>
#include <MyGUI_EditBox.h> #include <MyGUI_EditBox.h>
#include <MyGUI_InputManager.h> #include <MyGUI_InputManager.h>
@ -36,14 +37,18 @@ namespace MWGui
{ {
mSpellIcons = new SpellIcons(); mSpellIcons = new SpellIcons();
MyGUI::Button *deleteSpellBtn = nullptr;
getWidget(mSpellView, "SpellView"); getWidget(mSpellView, "SpellView");
getWidget(mEffectBox, "EffectsBox"); getWidget(mEffectBox, "EffectsBox");
getWidget(mFilterEdit, "FilterEdit"); getWidget(mFilterEdit, "FilterEdit");
getWidget(deleteSpellBtn, "DeleteSpellButton");
mFilterEdit->setUserString("IgnoreTabKey", "y"); 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); mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &SpellWindow::onFilterChanged);
deleteSpellBtn->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onDeleteClicked);
setCoord(498, 300, 302, 300); setCoord(498, 300, 302, 300);
} }
@ -185,6 +190,17 @@ namespace MWGui
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), sender->getCaption())); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), sender->getCaption()));
} }
void SpellWindow::onDeleteClicked(MyGUI::Widget *widget)
{
SpellModel::ModelIndex selected = mSpellView->getModel()->getSelectedIndex();
if (selected < 0)
return;
const Spell& spell = mSpellView->getModel()->getItem(selected);
if (spell.mType != Spell::Type_EnchantedItem)
askDeleteSpell(spell.mId);
}
void SpellWindow::onSpellSelected(const std::string& spellId) void SpellWindow::onSpellSelected(const std::string& spellId)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
@ -222,12 +238,9 @@ namespace MWGui
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), "")); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), ""));
SpellModel::ModelIndex selected = 0; SpellModel::ModelIndex selected = mSpellView->getModel()->getSelectedIndex();
for (SpellModel::ModelIndex i = 0; i<int(mSpellView->getModel()->getItemCount()); ++i) if (selected < 0)
{ selected = 0;
if (mSpellView->getModel()->getItem(i).mSelected)
selected = i;
}
selected += next ? 1 : -1; selected += next ? 1 : -1;
int itemcount = mSpellView->getModel()->getItemCount(); int itemcount = mSpellView->getModel()->getItemCount();

@ -33,6 +33,7 @@ namespace MWGui
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 onFilterChanged(MyGUI::EditBox *sender);
void onDeleteClicked(MyGUI::Widget *widget);
void onDeleteSpellAccept(); void onDeleteSpellAccept();
void askDeleteSpell(const std::string& spellId); void askDeleteSpell(const std::string& spellId);

@ -13,8 +13,16 @@
<Widget type="SpellView" skin="MW_SpellView" position="8 38 268 490" align="Left Top Stretch" name="SpellView"> <Widget type="SpellView" skin="MW_SpellView" position="8 38 268 490" align="Left Top Stretch" name="SpellView">
</Widget> </Widget>
<!-- Search box--> <Widget type="Widget" position="8 535 268 23" align="Left Bottom HStretch">
<Widget type="EditBox" skin="MW_TextBoxEditWithBorder" position="8 535 268 23" align="Left Bottom HStretch" name="FilterEdit"> <!-- Spell deletion button -->
<Widget type="Button" skin="MW_Button" align="Right Bottom" position="150 0 118 24" name="DeleteSpellButton">
<Property key="Caption" value="Delete Spell"/>
<Property key="NeedKey" value="false"/>
</Widget>
<!-- Search box-->
<Widget type="EditBox" skin="MW_TextBoxEditWithBorder" position="0 0 142 23" align="Left Bottom HStretch" name="FilterEdit">
</Widget>
</Widget> </Widget>
</Widget> </Widget>

Loading…
Cancel
Save