From 6c96b5653b63bcda2b52912272b3c593de72669a Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Wed, 24 Apr 2019 19:22:47 -0400 Subject: [PATCH] Add a button to delete spells from spellwindow --- apps/openmw/mwgui/spellmodel.cpp | 11 +++++++++++ apps/openmw/mwgui/spellmodel.hpp | 2 ++ apps/openmw/mwgui/spellwindow.cpp | 25 +++++++++++++++++++------ apps/openmw/mwgui/spellwindow.hpp | 1 + files/mygui/openmw_spell_window.layout | 12 ++++++++++-- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index 6dadebca2..d6424c08b 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -148,6 +148,17 @@ namespace MWGui return mSpells.size(); } + SpellModel::ModelIndex SpellModel::getSelectedIndex() const + { + ModelIndex selected = -1; + for (SpellModel::ModelIndex i = 0; i= int(mSpells.size())) diff --git a/apps/openmw/mwgui/spellmodel.hpp b/apps/openmw/mwgui/spellmodel.hpp index 4aa1f9d2a..d191cba0e 100644 --- a/apps/openmw/mwgui/spellmodel.hpp +++ b/apps/openmw/mwgui/spellmodel.hpp @@ -48,6 +48,8 @@ namespace MWGui ///< throws for invalid index size_t getItemCount() const; + ModelIndex getSelectedIndex() const; + ///< returns -1 if nothing is selected private: MWWorld::Ptr mActor; diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 254e731d0..2b1056797 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -1,5 +1,6 @@ #include "spellwindow.hpp" +#include #include #include @@ -36,14 +37,18 @@ namespace MWGui { mSpellIcons = new SpellIcons(); + MyGUI::Button *deleteSpellBtn = nullptr; + getWidget(mSpellView, "SpellView"); getWidget(mEffectBox, "EffectsBox"); getWidget(mFilterEdit, "FilterEdit"); + getWidget(deleteSpellBtn, "DeleteSpellButton"); mFilterEdit->setUserString("IgnoreTabKey", "y"); mSpellView->eventSpellClicked += MyGUI::newDelegate(this, &SpellWindow::onModelIndexSelected); mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &SpellWindow::onFilterChanged); + deleteSpellBtn->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onDeleteClicked); setCoord(498, 300, 302, 300); } @@ -185,6 +190,17 @@ namespace MWGui 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) { MWWorld::Ptr player = MWMechanics::getPlayer(); @@ -222,12 +238,9 @@ namespace MWGui mSpellView->setModel(new SpellModel(MWMechanics::getPlayer(), "")); - SpellModel::ModelIndex selected = 0; - for (SpellModel::ModelIndex i = 0; igetModel()->getItemCount()); ++i) - { - if (mSpellView->getModel()->getItem(i).mSelected) - selected = i; - } + SpellModel::ModelIndex selected = mSpellView->getModel()->getSelectedIndex(); + if (selected < 0) + selected = 0; selected += next ? 1 : -1; int itemcount = mSpellView->getModel()->getItemCount(); diff --git a/apps/openmw/mwgui/spellwindow.hpp b/apps/openmw/mwgui/spellwindow.hpp index ce10770f5..01a9c7392 100644 --- a/apps/openmw/mwgui/spellwindow.hpp +++ b/apps/openmw/mwgui/spellwindow.hpp @@ -33,6 +33,7 @@ namespace MWGui void onSpellSelected(const std::string& spellId); void onModelIndexSelected(SpellModel::ModelIndex index); void onFilterChanged(MyGUI::EditBox *sender); + void onDeleteClicked(MyGUI::Widget *widget); void onDeleteSpellAccept(); void askDeleteSpell(const std::string& spellId); diff --git a/files/mygui/openmw_spell_window.layout b/files/mygui/openmw_spell_window.layout index 8a98c47b2..9959aeb4e 100644 --- a/files/mygui/openmw_spell_window.layout +++ b/files/mygui/openmw_spell_window.layout @@ -13,8 +13,16 @@ - - + + + + + + + + + +