diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 072b73b50b..6420dbf5e6 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -232,7 +233,7 @@ namespace MWBase virtual void addVisitedLocation(const std::string& name, int x, int y) = 0; /// Hides dialog and schedules dialog to be deleted. - virtual void removeDialog(MWGui::Layout* dialog) = 0; + virtual void removeDialog(std::unique_ptr&& dialog) = 0; ///Gracefully attempts to exit the topmost GUI mode /** No guarantee of actually closing the window **/ diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 5300f00106..b817decad3 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -82,15 +82,6 @@ namespace MWGui CharacterCreation::CharacterCreation(osg::Group* parent, Resource::ResourceSystem* resourceSystem) : mParent(parent) , mResourceSystem(resourceSystem) - , mNameDialog(nullptr) - , mRaceDialog(nullptr) - , mClassChoiceDialog(nullptr) - , mGenerateClassQuestionDialog(nullptr) - , mGenerateClassResultDialog(nullptr) - , mPickClassDialog(nullptr) - , mCreateClassDialog(nullptr) - , mBirthSignDialog(nullptr) - , mReviewDialog(nullptr) , mGenerateClassStep(0) { mCreationStage = CSE_NotStarted; @@ -178,9 +169,8 @@ namespace MWGui switch (id) { case GM_Name: - MWBase::Environment::get().getWindowManager()->removeDialog(mNameDialog); - mNameDialog = nullptr; - mNameDialog = new TextInputDialog(); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mNameDialog)); + mNameDialog = std::make_unique(); mNameDialog->setTextLabel(MWBase::Environment::get().getWindowManager()->getGameSettingString("sName", "Name")); mNameDialog->setTextInput(mPlayerName); mNameDialog->setNextButtonShow(mCreationStage >= CSE_NameChosen); @@ -189,9 +179,8 @@ namespace MWGui break; case GM_Race: - MWBase::Environment::get().getWindowManager()->removeDialog(mRaceDialog); - mRaceDialog = nullptr; - mRaceDialog = new RaceDialog(mParent, mResourceSystem); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mRaceDialog)); + mRaceDialog = std::make_unique(mParent, mResourceSystem); mRaceDialog->setNextButtonShow(mCreationStage >= CSE_RaceChosen); mRaceDialog->setRaceId(mPlayerRaceId); mRaceDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); @@ -202,9 +191,8 @@ namespace MWGui break; case GM_Class: - MWBase::Environment::get().getWindowManager()->removeDialog(mClassChoiceDialog); - mClassChoiceDialog = nullptr; - mClassChoiceDialog = new ClassChoiceDialog(); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mClassChoiceDialog)); + mClassChoiceDialog = std::make_unique(); mClassChoiceDialog->eventButtonSelected += MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); mClassChoiceDialog->setVisible(true); if (mCreationStage < CSE_RaceChosen) @@ -212,9 +200,8 @@ namespace MWGui break; case GM_ClassPick: - MWBase::Environment::get().getWindowManager()->removeDialog(mPickClassDialog); - mPickClassDialog = nullptr; - mPickClassDialog = new PickClassDialog(); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mPickClassDialog)); + mPickClassDialog = std::make_unique(); mPickClassDialog->setNextButtonShow(mCreationStage >= CSE_ClassChosen); mPickClassDialog->setClassId(mPlayerClass.mId); mPickClassDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); @@ -225,9 +212,8 @@ namespace MWGui break; case GM_Birth: - MWBase::Environment::get().getWindowManager()->removeDialog(mBirthSignDialog); - mBirthSignDialog = nullptr; - mBirthSignDialog = new BirthDialog(); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mBirthSignDialog)); + mBirthSignDialog = std::make_unique(); mBirthSignDialog->setNextButtonShow(mCreationStage >= CSE_BirthSignChosen); mBirthSignDialog->setBirthId(mPlayerBirthSignId); mBirthSignDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone); @@ -238,9 +224,9 @@ namespace MWGui break; case GM_ClassCreate: - if (!mCreateClassDialog) + if (mCreateClassDialog == nullptr) { - mCreateClassDialog = new CreateClassDialog(); + mCreateClassDialog = std::make_unique(); mCreateClassDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogDone); mCreateClassDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogBack); } @@ -260,9 +246,8 @@ namespace MWGui mCreationStage = CSE_RaceChosen; break; case GM_Review: - MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); - mReviewDialog = nullptr; - mReviewDialog = new ReviewDialog(); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog)); + mReviewDialog = std::make_unique(); MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -310,16 +295,13 @@ namespace MWGui void CharacterCreation::onReviewDialogDone(WindowBase* parWindow) { - MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); - mReviewDialog = nullptr; - + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog)); MWBase::Environment::get().getWindowManager()->popGuiMode(); } void CharacterCreation::onReviewDialogBack() { - MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); - mReviewDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog)); mCreationStage = CSE_ReviewBack; MWBase::Environment::get().getWindowManager()->popGuiMode(); @@ -328,8 +310,7 @@ namespace MWGui void CharacterCreation::onReviewActivateDialog(int parDialog) { - MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); - mReviewDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog)); mCreationStage = CSE_ReviewNext; MWBase::Environment::get().getWindowManager()->popGuiMode(); @@ -364,8 +345,7 @@ namespace MWGui { mPlayerClass = *klass; } - MWBase::Environment::get().getWindowManager()->removeDialog(mPickClassDialog); - mPickClassDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mPickClassDialog)); } } @@ -386,8 +366,7 @@ namespace MWGui void CharacterCreation::onClassChoice(int _index) { - MWBase::Environment::get().getWindowManager()->removeDialog(mClassChoiceDialog); - mClassChoiceDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mClassChoiceDialog)); MWBase::Environment::get().getWindowManager()->popGuiMode(); @@ -415,8 +394,7 @@ namespace MWGui { mPlayerName = mNameDialog->getTextInput(); MWBase::Environment::get().getMechanicsManager()->setPlayerName(mPlayerName); - MWBase::Environment::get().getWindowManager()->removeDialog(mNameDialog); - mNameDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mNameDialog)); } handleDialogDone(CSE_NameChosen, GM_Race); @@ -438,8 +416,7 @@ namespace MWGui } MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar(); - MWBase::Environment::get().getWindowManager()->removeDialog(mRaceDialog); - mRaceDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mRaceDialog)); } } @@ -465,8 +442,7 @@ namespace MWGui mPlayerBirthSignId = mBirthSignDialog->getBirthId(); if (!mPlayerBirthSignId.empty()) MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(mPlayerBirthSignId); - MWBase::Environment::get().getWindowManager()->removeDialog(mBirthSignDialog); - mBirthSignDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mBirthSignDialog)); } } @@ -539,8 +515,7 @@ namespace MWGui { MWBase::Environment::get().getSoundManager()->stopSay(); - MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassQuestionDialog); - mGenerateClassQuestionDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassQuestionDialog)); if (_index < 0 || _index >= 3) { @@ -657,10 +632,9 @@ namespace MWGui } } - MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassResultDialog); - mGenerateClassResultDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassResultDialog)); - mGenerateClassResultDialog = new GenerateClassResultDialog(); + mGenerateClassResultDialog = std::make_unique(); mGenerateClassResultDialog->setClassId(mGenerateClass); mGenerateClassResultDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassBack); mGenerateClassResultDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassDone); @@ -675,10 +649,9 @@ namespace MWGui return; } - MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassQuestionDialog); - mGenerateClassQuestionDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassQuestionDialog)); - mGenerateClassQuestionDialog = new InfoBoxDialog(); + mGenerateClassQuestionDialog = std::make_unique(); Step step = sGenerateClassSteps(mGenerateClassStep); mGenerateClassResponses[0] = step.mResponses[0].mSpecialization; @@ -699,8 +672,7 @@ namespace MWGui void CharacterCreation::selectGeneratedClass() { - MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassResultDialog); - mGenerateClassResultDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassResultDialog)); MWBase::Environment::get().getMechanicsManager()->setPlayerClass(mGenerateClass); @@ -725,18 +697,7 @@ namespace MWGui handleDialogDone(CSE_ClassChosen, GM_Birth); } - CharacterCreation::~CharacterCreation() - { - delete mNameDialog; - delete mRaceDialog; - delete mClassChoiceDialog; - delete mGenerateClassQuestionDialog; - delete mGenerateClassResultDialog; - delete mPickClassDialog; - delete mCreateClassDialog; - delete mBirthSignDialog; - delete mReviewDialog; - } + CharacterCreation::~CharacterCreation() = default; void CharacterCreation::handleDialogDone(CSE currentStage, int nextMode) { diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp index a6c2d10c2f..e9c21fc212 100644 --- a/apps/openmw/mwgui/charactercreation.hpp +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -5,6 +5,7 @@ #include #include +#include #include "statswatcher.hpp" @@ -61,15 +62,15 @@ namespace MWGui std::map mPlayerSkillValues; //Dialogs - TextInputDialog* mNameDialog; - RaceDialog* mRaceDialog; - ClassChoiceDialog* mClassChoiceDialog; - InfoBoxDialog* mGenerateClassQuestionDialog; - GenerateClassResultDialog* mGenerateClassResultDialog; - PickClassDialog* mPickClassDialog; - CreateClassDialog* mCreateClassDialog; - BirthDialog* mBirthSignDialog; - ReviewDialog* mReviewDialog; + std::unique_ptr mNameDialog; + std::unique_ptr mRaceDialog; + std::unique_ptr mClassChoiceDialog; + std::unique_ptr mGenerateClassQuestionDialog; + std::unique_ptr mGenerateClassResultDialog; + std::unique_ptr mPickClassDialog; + std::unique_ptr mCreateClassDialog; + std::unique_ptr mBirthSignDialog; + std::unique_ptr mReviewDialog; //Player data std::string mPlayerName; diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 9568ba578a..830d9024ce 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -399,10 +399,6 @@ namespace MWGui CreateClassDialog::CreateClassDialog() : WindowModal("openmw_chargen_create_class.layout") - , mSpecDialog(nullptr) - , mAttribDialog(nullptr) - , mSkillDialog(nullptr) - , mDescDialog(nullptr) , mAffectedAttribute(nullptr) , mAffectedSkill(nullptr) { @@ -474,13 +470,7 @@ namespace MWGui update(); } - CreateClassDialog::~CreateClassDialog() - { - delete mSpecDialog; - delete mAttribDialog; - delete mSkillDialog; - delete mDescDialog; - } + CreateClassDialog::~CreateClassDialog() = default; void CreateClassDialog::update() { @@ -554,23 +544,15 @@ namespace MWGui void CreateClassDialog::onDialogCancel() { - MWBase::Environment::get().getWindowManager()->removeDialog(mSpecDialog); - mSpecDialog = nullptr; - - MWBase::Environment::get().getWindowManager()->removeDialog(mAttribDialog); - mAttribDialog = nullptr; - - MWBase::Environment::get().getWindowManager()->removeDialog(mSkillDialog); - mSkillDialog = nullptr; - - MWBase::Environment::get().getWindowManager()->removeDialog(mDescDialog); - mDescDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSpecDialog)); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mAttribDialog)); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSkillDialog)); + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mDescDialog)); } void CreateClassDialog::onSpecializationClicked(MyGUI::Widget* _sender) { - delete mSpecDialog; - mSpecDialog = new SelectSpecializationDialog(); + mSpecDialog = std::make_unique(); mSpecDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); mSpecDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationSelected); mSpecDialog->setVisible(true); @@ -581,8 +563,7 @@ namespace MWGui mSpecializationId = mSpecDialog->getSpecializationId(); setSpecialization(mSpecializationId); - MWBase::Environment::get().getWindowManager()->removeDialog(mSpecDialog); - mSpecDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSpecDialog)); } void CreateClassDialog::setSpecialization(int id) @@ -600,8 +581,7 @@ namespace MWGui void CreateClassDialog::onAttributeClicked(Widgets::MWAttributePtr _sender) { - delete mAttribDialog; - mAttribDialog = new SelectAttributeDialog(); + mAttribDialog = std::make_unique(); mAffectedAttribute = _sender; mAttribDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); mAttribDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeSelected); @@ -622,16 +602,14 @@ namespace MWGui mFavoriteAttribute0->setAttributeId(mFavoriteAttribute1->getAttributeId()); } mAffectedAttribute->setAttributeId(id); - MWBase::Environment::get().getWindowManager()->removeDialog(mAttribDialog); - mAttribDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mAttribDialog)); update(); } void CreateClassDialog::onSkillClicked(Widgets::MWSkillPtr _sender) { - delete mSkillDialog; - mSkillDialog = new SelectSkillDialog(); + mSkillDialog = std::make_unique(); mAffectedSkill = _sender; mSkillDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); mSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSkillSelected); @@ -655,14 +633,13 @@ namespace MWGui } mAffectedSkill->setSkillId(mSkillDialog->getSkillId()); - MWBase::Environment::get().getWindowManager()->removeDialog(mSkillDialog); - mSkillDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSkillDialog)); update(); } void CreateClassDialog::onDescriptionClicked(MyGUI::Widget* _sender) { - mDescDialog = new DescriptionDialog(); + mDescDialog = std::make_unique(); mDescDialog->setTextInput(mDescription); mDescDialog->eventDone += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionEntered); mDescDialog->setVisible(true); @@ -671,8 +648,7 @@ namespace MWGui void CreateClassDialog::onDescriptionEntered(WindowBase* parWindow) { mDescription = mDescDialog->getTextInput(); - MWBase::Environment::get().getWindowManager()->removeDialog(mDescDialog); - mDescDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mDescDialog)); } void CreateClassDialog::onOkClicked(MyGUI::Widget* _sender) diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index f765fa3da2..a927767d9a 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -1,6 +1,8 @@ #ifndef MWGUI_CLASS_H #define MWGUI_CLASS_H +#include + #include #include @@ -322,10 +324,10 @@ namespace MWGui std::vector mSkills; std::string mDescription; - SelectSpecializationDialog *mSpecDialog; - SelectAttributeDialog *mAttribDialog; - SelectSkillDialog *mSkillDialog; - DescriptionDialog *mDescDialog; + std::unique_ptr mSpecDialog; + std::unique_ptr mAttribDialog; + std::unique_ptr mSkillDialog; + std::unique_ptr mDescDialog; ESM::Class::Specialization mSpecializationId; diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp index df6962c78f..3b3a754468 100644 --- a/apps/openmw/mwgui/recharge.cpp +++ b/apps/openmw/mwgui/recharge.cpp @@ -28,7 +28,6 @@ namespace MWGui Recharge::Recharge() : WindowBase("openmw_recharge_dialog.layout") - , mItemSelectionDialog(nullptr) { getWidget(mBox, "Box"); getWidget(mGemBox, "GemBox"); @@ -101,8 +100,7 @@ void Recharge::onCancel(MyGUI::Widget *sender) void Recharge::onSelectItem(MyGUI::Widget *sender) { - delete mItemSelectionDialog; - mItemSelectionDialog = new ItemSelectionDialog("#{sSoulGemsWithSouls}"); + mItemSelectionDialog = std::make_unique("#{sSoulGemsWithSouls}"); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Recharge::onItemSelected); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Recharge::onItemCancel); mItemSelectionDialog->setVisible(true); diff --git a/apps/openmw/mwgui/recharge.hpp b/apps/openmw/mwgui/recharge.hpp index c260b15547..76852f3052 100644 --- a/apps/openmw/mwgui/recharge.hpp +++ b/apps/openmw/mwgui/recharge.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_MWGUI_RECHARGE_H #define OPENMW_MWGUI_RECHARGE_H +#include + #include "windowbase.hpp" namespace MWWorld @@ -31,7 +33,7 @@ protected: ItemWidget* mGemIcon; - ItemSelectionDialog* mItemSelectionDialog; + std::unique_ptr mItemSelectionDialog; MyGUI::TextBox* mChargeLabel; diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp index 351b976033..c3d26ee6f0 100644 --- a/apps/openmw/mwgui/repair.cpp +++ b/apps/openmw/mwgui/repair.cpp @@ -26,7 +26,6 @@ namespace MWGui Repair::Repair() : WindowBase("openmw_repair.layout") - , mItemSelectionDialog(nullptr) { getWidget(mRepairBox, "RepairBox"); getWidget(mToolBox, "ToolBox"); @@ -107,8 +106,7 @@ void Repair::updateRepairView() void Repair::onSelectItem(MyGUI::Widget *sender) { - delete mItemSelectionDialog; - mItemSelectionDialog = new ItemSelectionDialog("#{sRepair}"); + mItemSelectionDialog = std::make_unique("#{sRepair}"); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Repair::onItemSelected); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Repair::onItemCancel); mItemSelectionDialog->setVisible(true); diff --git a/apps/openmw/mwgui/repair.hpp b/apps/openmw/mwgui/repair.hpp index 701009f541..7d992939fc 100644 --- a/apps/openmw/mwgui/repair.hpp +++ b/apps/openmw/mwgui/repair.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_MWGUI_REPAIR_H #define OPENMW_MWGUI_REPAIR_H +#include + #include "windowbase.hpp" #include "../mwmechanics/repair.hpp" @@ -28,7 +30,7 @@ protected: ItemWidget* mToolIcon; - ItemSelectionDialog* mItemSelectionDialog; + std::unique_ptr mItemSelectionDialog; MyGUI::TextBox* mUsesLabel; MyGUI::TextBox* mQualityLabel; diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 6a8beb63fd..e08221bfb5 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -493,8 +493,6 @@ namespace MWGui : mAvailableEffectsList(nullptr) , mUsedEffectsView(nullptr) , mAddEffectDialog() - , mSelectAttributeDialog(nullptr) - , mSelectSkillDialog(nullptr) , mSelectedEffect(0) , mSelectedKnownEffectId(0) , mConstantEffect(false) @@ -584,8 +582,7 @@ namespace MWGui mAddEffectDialog.newEffect(effect); mAddEffectDialog.setAttribute (mSelectAttributeDialog->getAttributeId()); - MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectAttributeDialog); - mSelectAttributeDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectAttributeDialog)); } void EffectEditorBase::onSelectSkill () @@ -595,19 +592,15 @@ namespace MWGui mAddEffectDialog.newEffect(effect); mAddEffectDialog.setSkill (mSelectSkillDialog->getSkillId()); - MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectSkillDialog); - mSelectSkillDialog = nullptr; + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectSkillDialog)); } void EffectEditorBase::onAttributeOrSkillCancel () { - if (mSelectSkillDialog) - MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectSkillDialog); - if (mSelectAttributeDialog) - MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectAttributeDialog); - - mSelectSkillDialog = nullptr; - mSelectAttributeDialog = nullptr; + if (mSelectSkillDialog != nullptr) + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectSkillDialog)); + if (mSelectAttributeDialog != nullptr) + MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectAttributeDialog)); } void EffectEditorBase::onAvailableEffectClicked (MyGUI::Widget* sender) @@ -633,16 +626,14 @@ namespace MWGui if (effect->mData.mFlags & ESM::MagicEffect::TargetSkill) { - delete mSelectSkillDialog; - mSelectSkillDialog = new SelectSkillDialog(); + mSelectSkillDialog = std::make_unique(); mSelectSkillDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel); mSelectSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectSkill); mSelectSkillDialog->setVisible (true); } else if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute) { - delete mSelectAttributeDialog; - mSelectAttributeDialog = new SelectAttributeDialog(); + mSelectAttributeDialog = std::make_unique(); mSelectAttributeDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel); mSelectAttributeDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectAttribute); mSelectAttributeDialog->setVisible (true); diff --git a/apps/openmw/mwgui/spellcreationdialog.hpp b/apps/openmw/mwgui/spellcreationdialog.hpp index 1dd16c33cd..683455d557 100644 --- a/apps/openmw/mwgui/spellcreationdialog.hpp +++ b/apps/openmw/mwgui/spellcreationdialog.hpp @@ -1,6 +1,8 @@ #ifndef MWGUI_SPELLCREATION_H #define MWGUI_SPELLCREATION_H +#include + #include #include @@ -112,8 +114,8 @@ namespace MWGui MyGUI::ScrollView* mUsedEffectsView; EditEffectDialog mAddEffectDialog; - SelectAttributeDialog* mSelectAttributeDialog; - SelectSkillDialog* mSelectSkillDialog; + std::unique_ptr mSelectAttributeDialog; + std::unique_ptr mSelectSkillDialog; int mSelectedEffect; short mSelectedKnownEffectId; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 42e2cc54d7..211a773427 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -565,14 +565,7 @@ namespace MWGui void WindowManager::cleanupGarbage() { // Delete any dialogs which are no longer in use - if (!mGarbageDialogs.empty()) - { - for (Layout* widget : mGarbageDialogs) - { - delete widget; - } - mGarbageDialogs.clear(); - } + mGarbageDialogs.clear(); } void WindowManager::enableScene(bool enable) @@ -691,12 +684,12 @@ namespace MWGui mHud->setDrowningTimeLeft(time, maxTime); } - void WindowManager::removeDialog(Layout*dialog) + void WindowManager::removeDialog(std::unique_ptr&& dialog) { if (!dialog) return; dialog->setVisible(false); - mGarbageDialogs.push_back(dialog); + mGarbageDialogs.push_back(std::move(dialog)); } void WindowManager::exitCurrentGuiMode() diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index ea45e34e94..3d12ca2d96 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -264,7 +265,7 @@ namespace MWGui void addVisitedLocation(const std::string& name, int x, int y) override; ///Hides dialog and schedules dialog to be deleted. - void removeDialog(Layout* dialog) override; + void removeDialog(std::unique_ptr&& dialog) override; ///Gracefully attempts to exit the topmost GUI mode void exitCurrentGuiMode() override; @@ -498,7 +499,7 @@ namespace MWGui SDLUtil::SDLCursorManager* mCursorManager; - std::vector mGarbageDialogs; + std::vector> mGarbageDialogs; void cleanupGarbage(); GuiWindow mShown; // Currently shown windows in inventory mode