1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

Merge branch 'dialog_unique_ptr' into 'master'

Use std::unique_ptr to manage dialogs lifetime

See merge request OpenMW/openmw!2323
This commit is contained in:
psi29a 2022-08-21 20:04:12 +00:00
commit f888d85429
13 changed files with 86 additions and 158 deletions

View File

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <set> #include <set>
#include <memory>
#include <MyGUI_KeyCode.h> #include <MyGUI_KeyCode.h>
@ -232,7 +233,7 @@ namespace MWBase
virtual void addVisitedLocation(const std::string& name, int x, int y) = 0; virtual void addVisitedLocation(const std::string& name, int x, int y) = 0;
/// Hides dialog and schedules dialog to be deleted. /// Hides dialog and schedules dialog to be deleted.
virtual void removeDialog(MWGui::Layout* dialog) = 0; virtual void removeDialog(std::unique_ptr<MWGui::Layout>&& dialog) = 0;
///Gracefully attempts to exit the topmost GUI mode ///Gracefully attempts to exit the topmost GUI mode
/** No guarantee of actually closing the window **/ /** No guarantee of actually closing the window **/

View File

@ -82,15 +82,6 @@ namespace MWGui
CharacterCreation::CharacterCreation(osg::Group* parent, Resource::ResourceSystem* resourceSystem) CharacterCreation::CharacterCreation(osg::Group* parent, Resource::ResourceSystem* resourceSystem)
: mParent(parent) : mParent(parent)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)
, mNameDialog(nullptr)
, mRaceDialog(nullptr)
, mClassChoiceDialog(nullptr)
, mGenerateClassQuestionDialog(nullptr)
, mGenerateClassResultDialog(nullptr)
, mPickClassDialog(nullptr)
, mCreateClassDialog(nullptr)
, mBirthSignDialog(nullptr)
, mReviewDialog(nullptr)
, mGenerateClassStep(0) , mGenerateClassStep(0)
{ {
mCreationStage = CSE_NotStarted; mCreationStage = CSE_NotStarted;
@ -178,9 +169,8 @@ namespace MWGui
switch (id) switch (id)
{ {
case GM_Name: case GM_Name:
MWBase::Environment::get().getWindowManager()->removeDialog(mNameDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mNameDialog));
mNameDialog = nullptr; mNameDialog = std::make_unique<TextInputDialog>();
mNameDialog = new TextInputDialog();
mNameDialog->setTextLabel(MWBase::Environment::get().getWindowManager()->getGameSettingString("sName", "Name")); mNameDialog->setTextLabel(MWBase::Environment::get().getWindowManager()->getGameSettingString("sName", "Name"));
mNameDialog->setTextInput(mPlayerName); mNameDialog->setTextInput(mPlayerName);
mNameDialog->setNextButtonShow(mCreationStage >= CSE_NameChosen); mNameDialog->setNextButtonShow(mCreationStage >= CSE_NameChosen);
@ -189,9 +179,8 @@ namespace MWGui
break; break;
case GM_Race: case GM_Race:
MWBase::Environment::get().getWindowManager()->removeDialog(mRaceDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mRaceDialog));
mRaceDialog = nullptr; mRaceDialog = std::make_unique<RaceDialog>(mParent, mResourceSystem);
mRaceDialog = new RaceDialog(mParent, mResourceSystem);
mRaceDialog->setNextButtonShow(mCreationStage >= CSE_RaceChosen); mRaceDialog->setNextButtonShow(mCreationStage >= CSE_RaceChosen);
mRaceDialog->setRaceId(mPlayerRaceId); mRaceDialog->setRaceId(mPlayerRaceId);
mRaceDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone); mRaceDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onRaceDialogDone);
@ -202,9 +191,8 @@ namespace MWGui
break; break;
case GM_Class: case GM_Class:
MWBase::Environment::get().getWindowManager()->removeDialog(mClassChoiceDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mClassChoiceDialog));
mClassChoiceDialog = nullptr; mClassChoiceDialog = std::make_unique<ClassChoiceDialog>();
mClassChoiceDialog = new ClassChoiceDialog();
mClassChoiceDialog->eventButtonSelected += MyGUI::newDelegate(this, &CharacterCreation::onClassChoice); mClassChoiceDialog->eventButtonSelected += MyGUI::newDelegate(this, &CharacterCreation::onClassChoice);
mClassChoiceDialog->setVisible(true); mClassChoiceDialog->setVisible(true);
if (mCreationStage < CSE_RaceChosen) if (mCreationStage < CSE_RaceChosen)
@ -212,9 +200,8 @@ namespace MWGui
break; break;
case GM_ClassPick: case GM_ClassPick:
MWBase::Environment::get().getWindowManager()->removeDialog(mPickClassDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mPickClassDialog));
mPickClassDialog = nullptr; mPickClassDialog = std::make_unique<PickClassDialog>();
mPickClassDialog = new PickClassDialog();
mPickClassDialog->setNextButtonShow(mCreationStage >= CSE_ClassChosen); mPickClassDialog->setNextButtonShow(mCreationStage >= CSE_ClassChosen);
mPickClassDialog->setClassId(mPlayerClass.mId); mPickClassDialog->setClassId(mPlayerClass.mId);
mPickClassDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone); mPickClassDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onPickClassDialogDone);
@ -225,9 +212,8 @@ namespace MWGui
break; break;
case GM_Birth: case GM_Birth:
MWBase::Environment::get().getWindowManager()->removeDialog(mBirthSignDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mBirthSignDialog));
mBirthSignDialog = nullptr; mBirthSignDialog = std::make_unique<BirthDialog>();
mBirthSignDialog = new BirthDialog();
mBirthSignDialog->setNextButtonShow(mCreationStage >= CSE_BirthSignChosen); mBirthSignDialog->setNextButtonShow(mCreationStage >= CSE_BirthSignChosen);
mBirthSignDialog->setBirthId(mPlayerBirthSignId); mBirthSignDialog->setBirthId(mPlayerBirthSignId);
mBirthSignDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone); mBirthSignDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone);
@ -238,9 +224,9 @@ namespace MWGui
break; break;
case GM_ClassCreate: case GM_ClassCreate:
if (!mCreateClassDialog) if (mCreateClassDialog == nullptr)
{ {
mCreateClassDialog = new CreateClassDialog(); mCreateClassDialog = std::make_unique<CreateClassDialog>();
mCreateClassDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogDone); mCreateClassDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogDone);
mCreateClassDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogBack); mCreateClassDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onCreateClassDialogBack);
} }
@ -260,9 +246,8 @@ namespace MWGui
mCreationStage = CSE_RaceChosen; mCreationStage = CSE_RaceChosen;
break; break;
case GM_Review: case GM_Review:
MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog));
mReviewDialog = nullptr; mReviewDialog = std::make_unique<ReviewDialog>();
mReviewDialog = new ReviewDialog();
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
@ -310,16 +295,13 @@ namespace MWGui
void CharacterCreation::onReviewDialogDone(WindowBase* parWindow) void CharacterCreation::onReviewDialogDone(WindowBase* parWindow)
{ {
MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog));
mReviewDialog = nullptr;
MWBase::Environment::get().getWindowManager()->popGuiMode(); MWBase::Environment::get().getWindowManager()->popGuiMode();
} }
void CharacterCreation::onReviewDialogBack() void CharacterCreation::onReviewDialogBack()
{ {
MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog));
mReviewDialog = nullptr;
mCreationStage = CSE_ReviewBack; mCreationStage = CSE_ReviewBack;
MWBase::Environment::get().getWindowManager()->popGuiMode(); MWBase::Environment::get().getWindowManager()->popGuiMode();
@ -328,8 +310,7 @@ namespace MWGui
void CharacterCreation::onReviewActivateDialog(int parDialog) void CharacterCreation::onReviewActivateDialog(int parDialog)
{ {
MWBase::Environment::get().getWindowManager()->removeDialog(mReviewDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mReviewDialog));
mReviewDialog = nullptr;
mCreationStage = CSE_ReviewNext; mCreationStage = CSE_ReviewNext;
MWBase::Environment::get().getWindowManager()->popGuiMode(); MWBase::Environment::get().getWindowManager()->popGuiMode();
@ -364,8 +345,7 @@ namespace MWGui
{ {
mPlayerClass = *klass; mPlayerClass = *klass;
} }
MWBase::Environment::get().getWindowManager()->removeDialog(mPickClassDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mPickClassDialog));
mPickClassDialog = nullptr;
} }
} }
@ -386,8 +366,7 @@ namespace MWGui
void CharacterCreation::onClassChoice(int _index) void CharacterCreation::onClassChoice(int _index)
{ {
MWBase::Environment::get().getWindowManager()->removeDialog(mClassChoiceDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mClassChoiceDialog));
mClassChoiceDialog = nullptr;
MWBase::Environment::get().getWindowManager()->popGuiMode(); MWBase::Environment::get().getWindowManager()->popGuiMode();
@ -415,8 +394,7 @@ namespace MWGui
{ {
mPlayerName = mNameDialog->getTextInput(); mPlayerName = mNameDialog->getTextInput();
MWBase::Environment::get().getMechanicsManager()->setPlayerName(mPlayerName); MWBase::Environment::get().getMechanicsManager()->setPlayerName(mPlayerName);
MWBase::Environment::get().getWindowManager()->removeDialog(mNameDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mNameDialog));
mNameDialog = nullptr;
} }
handleDialogDone(CSE_NameChosen, GM_Race); handleDialogDone(CSE_NameChosen, GM_Race);
@ -438,8 +416,7 @@ namespace MWGui
} }
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar(); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar();
MWBase::Environment::get().getWindowManager()->removeDialog(mRaceDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mRaceDialog));
mRaceDialog = nullptr;
} }
} }
@ -465,8 +442,7 @@ namespace MWGui
mPlayerBirthSignId = mBirthSignDialog->getBirthId(); mPlayerBirthSignId = mBirthSignDialog->getBirthId();
if (!mPlayerBirthSignId.empty()) if (!mPlayerBirthSignId.empty())
MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(mPlayerBirthSignId); MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(mPlayerBirthSignId);
MWBase::Environment::get().getWindowManager()->removeDialog(mBirthSignDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mBirthSignDialog));
mBirthSignDialog = nullptr;
} }
} }
@ -539,8 +515,7 @@ namespace MWGui
{ {
MWBase::Environment::get().getSoundManager()->stopSay(); MWBase::Environment::get().getSoundManager()->stopSay();
MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassQuestionDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassQuestionDialog));
mGenerateClassQuestionDialog = nullptr;
if (_index < 0 || _index >= 3) if (_index < 0 || _index >= 3)
{ {
@ -657,10 +632,9 @@ namespace MWGui
} }
} }
MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassResultDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassResultDialog));
mGenerateClassResultDialog = nullptr;
mGenerateClassResultDialog = new GenerateClassResultDialog(); mGenerateClassResultDialog = std::make_unique<GenerateClassResultDialog>();
mGenerateClassResultDialog->setClassId(mGenerateClass); mGenerateClassResultDialog->setClassId(mGenerateClass);
mGenerateClassResultDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassBack); mGenerateClassResultDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassBack);
mGenerateClassResultDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassDone); mGenerateClassResultDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onGenerateClassDone);
@ -675,10 +649,9 @@ namespace MWGui
return; return;
} }
MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassQuestionDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassQuestionDialog));
mGenerateClassQuestionDialog = nullptr;
mGenerateClassQuestionDialog = new InfoBoxDialog(); mGenerateClassQuestionDialog = std::make_unique<InfoBoxDialog>();
Step step = sGenerateClassSteps(mGenerateClassStep); Step step = sGenerateClassSteps(mGenerateClassStep);
mGenerateClassResponses[0] = step.mResponses[0].mSpecialization; mGenerateClassResponses[0] = step.mResponses[0].mSpecialization;
@ -699,8 +672,7 @@ namespace MWGui
void CharacterCreation::selectGeneratedClass() void CharacterCreation::selectGeneratedClass()
{ {
MWBase::Environment::get().getWindowManager()->removeDialog(mGenerateClassResultDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassResultDialog));
mGenerateClassResultDialog = nullptr;
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(mGenerateClass); MWBase::Environment::get().getMechanicsManager()->setPlayerClass(mGenerateClass);
@ -725,18 +697,7 @@ namespace MWGui
handleDialogDone(CSE_ClassChosen, GM_Birth); handleDialogDone(CSE_ClassChosen, GM_Birth);
} }
CharacterCreation::~CharacterCreation() CharacterCreation::~CharacterCreation() = default;
{
delete mNameDialog;
delete mRaceDialog;
delete mClassChoiceDialog;
delete mGenerateClassQuestionDialog;
delete mGenerateClassResultDialog;
delete mPickClassDialog;
delete mCreateClassDialog;
delete mBirthSignDialog;
delete mReviewDialog;
}
void CharacterCreation::handleDialogDone(CSE currentStage, int nextMode) void CharacterCreation::handleDialogDone(CSE currentStage, int nextMode)
{ {

View File

@ -5,6 +5,7 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <memory>
#include "statswatcher.hpp" #include "statswatcher.hpp"
@ -61,15 +62,15 @@ namespace MWGui
std::map<int, MWMechanics::SkillValue> mPlayerSkillValues; std::map<int, MWMechanics::SkillValue> mPlayerSkillValues;
//Dialogs //Dialogs
TextInputDialog* mNameDialog; std::unique_ptr<TextInputDialog> mNameDialog;
RaceDialog* mRaceDialog; std::unique_ptr<RaceDialog> mRaceDialog;
ClassChoiceDialog* mClassChoiceDialog; std::unique_ptr<ClassChoiceDialog> mClassChoiceDialog;
InfoBoxDialog* mGenerateClassQuestionDialog; std::unique_ptr<InfoBoxDialog> mGenerateClassQuestionDialog;
GenerateClassResultDialog* mGenerateClassResultDialog; std::unique_ptr<GenerateClassResultDialog> mGenerateClassResultDialog;
PickClassDialog* mPickClassDialog; std::unique_ptr<PickClassDialog> mPickClassDialog;
CreateClassDialog* mCreateClassDialog; std::unique_ptr<CreateClassDialog> mCreateClassDialog;
BirthDialog* mBirthSignDialog; std::unique_ptr<BirthDialog> mBirthSignDialog;
ReviewDialog* mReviewDialog; std::unique_ptr<ReviewDialog> mReviewDialog;
//Player data //Player data
std::string mPlayerName; std::string mPlayerName;

View File

@ -399,10 +399,6 @@ namespace MWGui
CreateClassDialog::CreateClassDialog() CreateClassDialog::CreateClassDialog()
: WindowModal("openmw_chargen_create_class.layout") : WindowModal("openmw_chargen_create_class.layout")
, mSpecDialog(nullptr)
, mAttribDialog(nullptr)
, mSkillDialog(nullptr)
, mDescDialog(nullptr)
, mAffectedAttribute(nullptr) , mAffectedAttribute(nullptr)
, mAffectedSkill(nullptr) , mAffectedSkill(nullptr)
{ {
@ -474,13 +470,7 @@ namespace MWGui
update(); update();
} }
CreateClassDialog::~CreateClassDialog() CreateClassDialog::~CreateClassDialog() = default;
{
delete mSpecDialog;
delete mAttribDialog;
delete mSkillDialog;
delete mDescDialog;
}
void CreateClassDialog::update() void CreateClassDialog::update()
{ {
@ -554,23 +544,15 @@ namespace MWGui
void CreateClassDialog::onDialogCancel() void CreateClassDialog::onDialogCancel()
{ {
MWBase::Environment::get().getWindowManager()->removeDialog(mSpecDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSpecDialog));
mSpecDialog = nullptr; MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mAttribDialog));
MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSkillDialog));
MWBase::Environment::get().getWindowManager()->removeDialog(mAttribDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mDescDialog));
mAttribDialog = nullptr;
MWBase::Environment::get().getWindowManager()->removeDialog(mSkillDialog);
mSkillDialog = nullptr;
MWBase::Environment::get().getWindowManager()->removeDialog(mDescDialog);
mDescDialog = nullptr;
} }
void CreateClassDialog::onSpecializationClicked(MyGUI::Widget* _sender) void CreateClassDialog::onSpecializationClicked(MyGUI::Widget* _sender)
{ {
delete mSpecDialog; mSpecDialog = std::make_unique<SelectSpecializationDialog>();
mSpecDialog = new SelectSpecializationDialog();
mSpecDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); mSpecDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel);
mSpecDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationSelected); mSpecDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationSelected);
mSpecDialog->setVisible(true); mSpecDialog->setVisible(true);
@ -581,8 +563,7 @@ namespace MWGui
mSpecializationId = mSpecDialog->getSpecializationId(); mSpecializationId = mSpecDialog->getSpecializationId();
setSpecialization(mSpecializationId); setSpecialization(mSpecializationId);
MWBase::Environment::get().getWindowManager()->removeDialog(mSpecDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSpecDialog));
mSpecDialog = nullptr;
} }
void CreateClassDialog::setSpecialization(int id) void CreateClassDialog::setSpecialization(int id)
@ -600,8 +581,7 @@ namespace MWGui
void CreateClassDialog::onAttributeClicked(Widgets::MWAttributePtr _sender) void CreateClassDialog::onAttributeClicked(Widgets::MWAttributePtr _sender)
{ {
delete mAttribDialog; mAttribDialog = std::make_unique<SelectAttributeDialog>();
mAttribDialog = new SelectAttributeDialog();
mAffectedAttribute = _sender; mAffectedAttribute = _sender;
mAttribDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); mAttribDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel);
mAttribDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeSelected); mAttribDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeSelected);
@ -622,16 +602,14 @@ namespace MWGui
mFavoriteAttribute0->setAttributeId(mFavoriteAttribute1->getAttributeId()); mFavoriteAttribute0->setAttributeId(mFavoriteAttribute1->getAttributeId());
} }
mAffectedAttribute->setAttributeId(id); mAffectedAttribute->setAttributeId(id);
MWBase::Environment::get().getWindowManager()->removeDialog(mAttribDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mAttribDialog));
mAttribDialog = nullptr;
update(); update();
} }
void CreateClassDialog::onSkillClicked(Widgets::MWSkillPtr _sender) void CreateClassDialog::onSkillClicked(Widgets::MWSkillPtr _sender)
{ {
delete mSkillDialog; mSkillDialog = std::make_unique<SelectSkillDialog>();
mSkillDialog = new SelectSkillDialog();
mAffectedSkill = _sender; mAffectedSkill = _sender;
mSkillDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); mSkillDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel);
mSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSkillSelected); mSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSkillSelected);
@ -655,14 +633,13 @@ namespace MWGui
} }
mAffectedSkill->setSkillId(mSkillDialog->getSkillId()); mAffectedSkill->setSkillId(mSkillDialog->getSkillId());
MWBase::Environment::get().getWindowManager()->removeDialog(mSkillDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSkillDialog));
mSkillDialog = nullptr;
update(); update();
} }
void CreateClassDialog::onDescriptionClicked(MyGUI::Widget* _sender) void CreateClassDialog::onDescriptionClicked(MyGUI::Widget* _sender)
{ {
mDescDialog = new DescriptionDialog(); mDescDialog = std::make_unique<DescriptionDialog>();
mDescDialog->setTextInput(mDescription); mDescDialog->setTextInput(mDescription);
mDescDialog->eventDone += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionEntered); mDescDialog->eventDone += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionEntered);
mDescDialog->setVisible(true); mDescDialog->setVisible(true);
@ -671,8 +648,7 @@ namespace MWGui
void CreateClassDialog::onDescriptionEntered(WindowBase* parWindow) void CreateClassDialog::onDescriptionEntered(WindowBase* parWindow)
{ {
mDescription = mDescDialog->getTextInput(); mDescription = mDescDialog->getTextInput();
MWBase::Environment::get().getWindowManager()->removeDialog(mDescDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mDescDialog));
mDescDialog = nullptr;
} }
void CreateClassDialog::onOkClicked(MyGUI::Widget* _sender) void CreateClassDialog::onOkClicked(MyGUI::Widget* _sender)

View File

@ -1,6 +1,8 @@
#ifndef MWGUI_CLASS_H #ifndef MWGUI_CLASS_H
#define MWGUI_CLASS_H #define MWGUI_CLASS_H
#include <memory>
#include <MyGUI_EditBox.h> #include <MyGUI_EditBox.h>
#include <components/esm/attr.hpp> #include <components/esm/attr.hpp>
@ -322,10 +324,10 @@ namespace MWGui
std::vector<Widgets::MWSkillPtr> mSkills; std::vector<Widgets::MWSkillPtr> mSkills;
std::string mDescription; std::string mDescription;
SelectSpecializationDialog *mSpecDialog; std::unique_ptr<SelectSpecializationDialog> mSpecDialog;
SelectAttributeDialog *mAttribDialog; std::unique_ptr<SelectAttributeDialog> mAttribDialog;
SelectSkillDialog *mSkillDialog; std::unique_ptr<SelectSkillDialog> mSkillDialog;
DescriptionDialog *mDescDialog; std::unique_ptr<DescriptionDialog> mDescDialog;
ESM::Class::Specialization mSpecializationId; ESM::Class::Specialization mSpecializationId;

View File

@ -28,7 +28,6 @@ namespace MWGui
Recharge::Recharge() Recharge::Recharge()
: WindowBase("openmw_recharge_dialog.layout") : WindowBase("openmw_recharge_dialog.layout")
, mItemSelectionDialog(nullptr)
{ {
getWidget(mBox, "Box"); getWidget(mBox, "Box");
getWidget(mGemBox, "GemBox"); getWidget(mGemBox, "GemBox");
@ -101,8 +100,7 @@ void Recharge::onCancel(MyGUI::Widget *sender)
void Recharge::onSelectItem(MyGUI::Widget *sender) void Recharge::onSelectItem(MyGUI::Widget *sender)
{ {
delete mItemSelectionDialog; mItemSelectionDialog = std::make_unique<ItemSelectionDialog>("#{sSoulGemsWithSouls}");
mItemSelectionDialog = new ItemSelectionDialog("#{sSoulGemsWithSouls}");
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Recharge::onItemSelected); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Recharge::onItemSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Recharge::onItemCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Recharge::onItemCancel);
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);

View File

@ -1,6 +1,8 @@
#ifndef OPENMW_MWGUI_RECHARGE_H #ifndef OPENMW_MWGUI_RECHARGE_H
#define OPENMW_MWGUI_RECHARGE_H #define OPENMW_MWGUI_RECHARGE_H
#include <memory>
#include "windowbase.hpp" #include "windowbase.hpp"
namespace MWWorld namespace MWWorld
@ -31,7 +33,7 @@ protected:
ItemWidget* mGemIcon; ItemWidget* mGemIcon;
ItemSelectionDialog* mItemSelectionDialog; std::unique_ptr<ItemSelectionDialog> mItemSelectionDialog;
MyGUI::TextBox* mChargeLabel; MyGUI::TextBox* mChargeLabel;

View File

@ -26,7 +26,6 @@ namespace MWGui
Repair::Repair() Repair::Repair()
: WindowBase("openmw_repair.layout") : WindowBase("openmw_repair.layout")
, mItemSelectionDialog(nullptr)
{ {
getWidget(mRepairBox, "RepairBox"); getWidget(mRepairBox, "RepairBox");
getWidget(mToolBox, "ToolBox"); getWidget(mToolBox, "ToolBox");
@ -107,8 +106,7 @@ void Repair::updateRepairView()
void Repair::onSelectItem(MyGUI::Widget *sender) void Repair::onSelectItem(MyGUI::Widget *sender)
{ {
delete mItemSelectionDialog; mItemSelectionDialog = std::make_unique<ItemSelectionDialog>("#{sRepair}");
mItemSelectionDialog = new ItemSelectionDialog("#{sRepair}");
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Repair::onItemSelected); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Repair::onItemSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Repair::onItemCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Repair::onItemCancel);
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);

View File

@ -1,6 +1,8 @@
#ifndef OPENMW_MWGUI_REPAIR_H #ifndef OPENMW_MWGUI_REPAIR_H
#define OPENMW_MWGUI_REPAIR_H #define OPENMW_MWGUI_REPAIR_H
#include <memory>
#include "windowbase.hpp" #include "windowbase.hpp"
#include "../mwmechanics/repair.hpp" #include "../mwmechanics/repair.hpp"
@ -28,7 +30,7 @@ protected:
ItemWidget* mToolIcon; ItemWidget* mToolIcon;
ItemSelectionDialog* mItemSelectionDialog; std::unique_ptr<ItemSelectionDialog> mItemSelectionDialog;
MyGUI::TextBox* mUsesLabel; MyGUI::TextBox* mUsesLabel;
MyGUI::TextBox* mQualityLabel; MyGUI::TextBox* mQualityLabel;

View File

@ -493,8 +493,6 @@ namespace MWGui
: mAvailableEffectsList(nullptr) : mAvailableEffectsList(nullptr)
, mUsedEffectsView(nullptr) , mUsedEffectsView(nullptr)
, mAddEffectDialog() , mAddEffectDialog()
, mSelectAttributeDialog(nullptr)
, mSelectSkillDialog(nullptr)
, mSelectedEffect(0) , mSelectedEffect(0)
, mSelectedKnownEffectId(0) , mSelectedKnownEffectId(0)
, mConstantEffect(false) , mConstantEffect(false)
@ -584,8 +582,7 @@ namespace MWGui
mAddEffectDialog.newEffect(effect); mAddEffectDialog.newEffect(effect);
mAddEffectDialog.setAttribute (mSelectAttributeDialog->getAttributeId()); mAddEffectDialog.setAttribute (mSelectAttributeDialog->getAttributeId());
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectAttributeDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectAttributeDialog));
mSelectAttributeDialog = nullptr;
} }
void EffectEditorBase::onSelectSkill () void EffectEditorBase::onSelectSkill ()
@ -595,19 +592,15 @@ namespace MWGui
mAddEffectDialog.newEffect(effect); mAddEffectDialog.newEffect(effect);
mAddEffectDialog.setSkill (mSelectSkillDialog->getSkillId()); mAddEffectDialog.setSkill (mSelectSkillDialog->getSkillId());
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectSkillDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectSkillDialog));
mSelectSkillDialog = nullptr;
} }
void EffectEditorBase::onAttributeOrSkillCancel () void EffectEditorBase::onAttributeOrSkillCancel ()
{ {
if (mSelectSkillDialog) if (mSelectSkillDialog != nullptr)
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectSkillDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectSkillDialog));
if (mSelectAttributeDialog) if (mSelectAttributeDialog != nullptr)
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectAttributeDialog); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mSelectAttributeDialog));
mSelectSkillDialog = nullptr;
mSelectAttributeDialog = nullptr;
} }
void EffectEditorBase::onAvailableEffectClicked (MyGUI::Widget* sender) void EffectEditorBase::onAvailableEffectClicked (MyGUI::Widget* sender)
@ -633,16 +626,14 @@ namespace MWGui
if (effect->mData.mFlags & ESM::MagicEffect::TargetSkill) if (effect->mData.mFlags & ESM::MagicEffect::TargetSkill)
{ {
delete mSelectSkillDialog; mSelectSkillDialog = std::make_unique<SelectSkillDialog>();
mSelectSkillDialog = new SelectSkillDialog();
mSelectSkillDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel); mSelectSkillDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel);
mSelectSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectSkill); mSelectSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectSkill);
mSelectSkillDialog->setVisible (true); mSelectSkillDialog->setVisible (true);
} }
else if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute) else if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute)
{ {
delete mSelectAttributeDialog; mSelectAttributeDialog = std::make_unique<SelectAttributeDialog>();
mSelectAttributeDialog = new SelectAttributeDialog();
mSelectAttributeDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel); mSelectAttributeDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel);
mSelectAttributeDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectAttribute); mSelectAttributeDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectAttribute);
mSelectAttributeDialog->setVisible (true); mSelectAttributeDialog->setVisible (true);

View File

@ -1,6 +1,8 @@
#ifndef MWGUI_SPELLCREATION_H #ifndef MWGUI_SPELLCREATION_H
#define MWGUI_SPELLCREATION_H #define MWGUI_SPELLCREATION_H
#include <memory>
#include <components/esm3/loadmgef.hpp> #include <components/esm3/loadmgef.hpp>
#include <components/esm3/loadspel.hpp> #include <components/esm3/loadspel.hpp>
@ -112,8 +114,8 @@ namespace MWGui
MyGUI::ScrollView* mUsedEffectsView; MyGUI::ScrollView* mUsedEffectsView;
EditEffectDialog mAddEffectDialog; EditEffectDialog mAddEffectDialog;
SelectAttributeDialog* mSelectAttributeDialog; std::unique_ptr<SelectAttributeDialog> mSelectAttributeDialog;
SelectSkillDialog* mSelectSkillDialog; std::unique_ptr<SelectSkillDialog> mSelectSkillDialog;
int mSelectedEffect; int mSelectedEffect;
short mSelectedKnownEffectId; short mSelectedKnownEffectId;

View File

@ -565,14 +565,7 @@ namespace MWGui
void WindowManager::cleanupGarbage() void WindowManager::cleanupGarbage()
{ {
// Delete any dialogs which are no longer in use // Delete any dialogs which are no longer in use
if (!mGarbageDialogs.empty()) mGarbageDialogs.clear();
{
for (Layout* widget : mGarbageDialogs)
{
delete widget;
}
mGarbageDialogs.clear();
}
} }
void WindowManager::enableScene(bool enable) void WindowManager::enableScene(bool enable)
@ -691,12 +684,12 @@ namespace MWGui
mHud->setDrowningTimeLeft(time, maxTime); mHud->setDrowningTimeLeft(time, maxTime);
} }
void WindowManager::removeDialog(Layout*dialog) void WindowManager::removeDialog(std::unique_ptr<Layout>&& dialog)
{ {
if (!dialog) if (!dialog)
return; return;
dialog->setVisible(false); dialog->setVisible(false);
mGarbageDialogs.push_back(dialog); mGarbageDialogs.push_back(std::move(dialog));
} }
void WindowManager::exitCurrentGuiMode() void WindowManager::exitCurrentGuiMode()

View File

@ -9,6 +9,7 @@
#include <stack> #include <stack>
#include <vector> #include <vector>
#include <memory>
#include <osg/ref_ptr> #include <osg/ref_ptr>
@ -264,7 +265,7 @@ namespace MWGui
void addVisitedLocation(const std::string& name, int x, int y) override; void addVisitedLocation(const std::string& name, int x, int y) override;
///Hides dialog and schedules dialog to be deleted. ///Hides dialog and schedules dialog to be deleted.
void removeDialog(Layout* dialog) override; void removeDialog(std::unique_ptr<Layout>&& dialog) override;
///Gracefully attempts to exit the topmost GUI mode ///Gracefully attempts to exit the topmost GUI mode
void exitCurrentGuiMode() override; void exitCurrentGuiMode() override;
@ -498,7 +499,7 @@ namespace MWGui
SDLUtil::SDLCursorManager* mCursorManager; SDLUtil::SDLCursorManager* mCursorManager;
std::vector<Layout*> mGarbageDialogs; std::vector<std::unique_ptr<Layout>> mGarbageDialogs;
void cleanupGarbage(); void cleanupGarbage();
GuiWindow mShown; // Currently shown windows in inventory mode GuiWindow mShown; // Currently shown windows in inventory mode