diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 95eb3e68df..efca05d0cd 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -150,7 +150,7 @@ namespace MWBase virtual MWGui::CountDialog* getCountDialog() = 0; virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0; - virtual const std::vector getActiveMessageBoxes() = 0; + virtual const std::vector>& getActiveMessageBoxes() const = 0; virtual MWGui::PostProcessorHud* getPostProcessorHud() = 0; /// Make the player use an item, while updating GUI state accordingly diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index a7920b553f..2b15379aa7 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -125,8 +125,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - std::unique_ptr action ( - new MWWorld::ActionApply (ptr, ref->mBase->mId)); + auto action = std::make_unique(ptr, ref->mBase->mId); action->setSound ("Drink"); diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 557cb3df4a..b7fa3d71a9 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -34,7 +34,7 @@ namespace MWGui , mCurrentFilter(FilterType::ByName) , mModel(nullptr) , mSortModel(nullptr) - , mAlchemy(new MWMechanics::Alchemy()) + , mAlchemy(std::make_unique()) , mApparatus (4) , mIngredients (4) { @@ -245,13 +245,15 @@ namespace MWGui mAlchemy->clear(); mAlchemy->setAlchemist (MWMechanics::getPlayer()); - mModel = new InventoryItemModel(MWMechanics::getPlayer()); - mSortModel = new SortFilterItemModel(mModel); + auto model = std::make_unique(MWMechanics::getPlayer()); + mModel = model.get(); + auto sortModel = std::make_unique(std::move(model)); + mSortModel = sortModel.get(); mSortModel->setFilter(SortFilterItemModel::Filter_OnlyIngredients); - mItemView->setModel (mSortModel); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); - mNameEdit->setCaption(""); + mNameEdit->setCaption({}); mBrewCountEdit->setValue(1); int index = 0; diff --git a/apps/openmw/mwgui/alchemywindow.hpp b/apps/openmw/mwgui/alchemywindow.hpp index 33bd1f9743..afc00e2bfb 100644 --- a/apps/openmw/mwgui/alchemywindow.hpp +++ b/apps/openmw/mwgui/alchemywindow.hpp @@ -12,10 +12,7 @@ #include "windowbase.hpp" -namespace MWMechanics -{ - class Alchemy; -} +#include "../mwmechanics/alchemy.hpp" namespace MWGui { diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp index 45c5eb9f83..99ed2d995c 100644 --- a/apps/openmw/mwgui/companionwindow.cpp +++ b/apps/openmw/mwgui/companionwindow.cpp @@ -123,11 +123,12 @@ void CompanionWindow::setPtr(const MWWorld::Ptr& npc) { mPtr = npc; updateEncumbranceBar(); - - mModel = new CompanionItemModel(npc); - mSortModel = new SortFilterItemModel(mModel); - mFilterEdit->setCaption(std::string()); - mItemView->setModel(mSortModel); + auto model = std::make_unique(npc); + mModel = model.get(); + auto sortModel = std::make_unique(std::move(model)); + mSortModel = sortModel.get(); + mFilterEdit->setCaption({}); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); setTitle(npc.getClass().getName(npc)); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 8478fc46e0..ad23af4711 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -129,27 +129,29 @@ namespace MWGui bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead(); + std::unique_ptr model; if (mPtr.getClass().hasInventoryStore(mPtr)) { if (mPtr.getClass().isNpc() && !loot && !lootAnyway) { // we are stealing stuff - mModel = new PickpocketItemModel(mPtr, new InventoryItemModel(container), + model = std::make_unique(mPtr, std::make_unique(container), !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown()); } else - mModel = new InventoryItemModel(container); + model = std::make_unique(container); } else { - mModel = new ContainerItemModel(container); + model = std::make_unique(container); } mDisposeCorpseButton->setVisible(loot); + mModel = model.get(); + auto sortModel = std::make_unique(std::move(model)); + mSortModel = sortModel.get(); - mSortModel = new SortFilterItemModel(mModel); - - mItemView->setModel (mSortModel); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 080a9f6fd0..78735540e0 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -32,31 +32,15 @@ namespace MWGui { - - class ResponseCallback : public MWBase::DialogueManager::ResponseCallback + void ResponseCallback::addResponse(const std::string& title, const std::string& text) { - public: - ResponseCallback(DialogueWindow* win, bool needMargin=true) - : mWindow(win) - , mNeedMargin(needMargin) - { + mWindow->addResponse(title, text, mNeedMargin); + } - } - - void addResponse(const std::string& title, const std::string& text) override - { - mWindow->addResponse(title, text, mNeedMargin); - } - - void updateTopics() - { - mWindow->updateTopics(); - } - - private: - DialogueWindow* mWindow; - bool mNeedMargin; - }; + void ResponseCallback::updateTopics() const + { + mWindow->updateTopics(); + } PersuasionDialog::PersuasionDialog(std::unique_ptr callback) : WindowModal("openmw_persuasion_dialog.layout") diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index 7965a7cb24..27547ca046 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -8,6 +8,7 @@ #include "bookpage.hpp" +#include "../mwbase/dialoguemanager.hpp" #include "../mwdialogue/keywordsearch.hpp" #include @@ -20,7 +21,21 @@ namespace Gui namespace MWGui { - class ResponseCallback; + class DialogueWindow; + + class ResponseCallback : public MWBase::DialogueManager::ResponseCallback + { + DialogueWindow* mWindow; + bool mNeedMargin; + + public: + ResponseCallback(DialogueWindow* win, bool needMargin = true) : mWindow(win), mNeedMargin(needMargin) + {} + + void addResponse(const std::string& title, const std::string& text) override; + + void updateTopics() const; + }; class PersuasionDialog : public WindowModal { diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index cb4203eb1c..582aeded24 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -34,7 +34,6 @@ namespace MWGui EnchantingDialog::EnchantingDialog() : WindowBase("openmw_enchanting_dialog.layout") , EffectEditorBase(EffectEditorBase::Enchanting) - , mItemSelectionDialog(nullptr) { getWidget(mName, "NameEdit"); getWidget(mCancelButton, "CancelButton"); @@ -62,11 +61,6 @@ namespace MWGui mName->eventEditSelectAccept += MyGUI::newDelegate(this, &EnchantingDialog::onAccept); } - EnchantingDialog::~EnchantingDialog() - { - delete mItemSelectionDialog; - } - void EnchantingDialog::onOpen() { center(); @@ -195,8 +189,7 @@ namespace MWGui { if (mEnchanting.getOldItem().isEmpty()) { - delete mItemSelectionDialog; - mItemSelectionDialog = new ItemSelectionDialog("#{sEnchantItems}"); + mItemSelectionDialog = std::make_unique("#{sEnchantItems}"); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onItemSelected); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onItemCancel); mItemSelectionDialog->setVisible(true); @@ -250,8 +243,7 @@ namespace MWGui { if (mEnchanting.getGem().isEmpty()) { - delete mItemSelectionDialog; - mItemSelectionDialog = new ItemSelectionDialog("#{sSoulGemsWithSouls}"); + mItemSelectionDialog = std::make_unique("#{sSoulGemsWithSouls}"); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel); mItemSelectionDialog->setVisible(true); diff --git a/apps/openmw/mwgui/enchantingdialog.hpp b/apps/openmw/mwgui/enchantingdialog.hpp index 52f3aa34b8..14157d800e 100644 --- a/apps/openmw/mwgui/enchantingdialog.hpp +++ b/apps/openmw/mwgui/enchantingdialog.hpp @@ -1,6 +1,9 @@ #ifndef MWGUI_ENCHANTINGDIALOG_H #define MWGUI_ENCHANTINGDIALOG_H +#include + +#include "itemselection.hpp" #include "spellcreationdialog.hpp" #include "../mwmechanics/enchanting.hpp" @@ -8,14 +11,13 @@ namespace MWGui { - class ItemSelectionDialog; class ItemWidget; class EnchantingDialog : public WindowBase, public ReferenceInterface, public EffectEditorBase { public: EnchantingDialog(); - virtual ~EnchantingDialog(); + virtual ~EnchantingDialog() = default; void onOpen() override; @@ -48,7 +50,7 @@ namespace MWGui void onTypeButtonClicked(MyGUI::Widget* sender); void onAccept(MyGUI::EditBox* sender); - ItemSelectionDialog* mItemSelectionDialog; + std::unique_ptr mItemSelectionDialog; MyGUI::Widget* mChanceLayout; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 1d6b981bcd..028da083f5 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -163,7 +163,7 @@ namespace MWGui mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver); mMainWidget->eventMouseLostFocus += MyGUI::newDelegate(this, &HUD::onWorldMouseLostFocus); - mSpellIcons = new SpellIcons(); + mSpellIcons = std::make_unique(); } HUD::~HUD() @@ -171,8 +171,6 @@ namespace MWGui mMainWidget->eventMouseLostFocus.clear(); mMainWidget->eventMouseMove.clear(); mMainWidget->eventMouseButtonClick.clear(); - - delete mSpellIcons; } void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat& value) diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index ef591bec97..aacca60a52 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -1,7 +1,10 @@ #ifndef OPENMW_GAME_MWGUI_HUD_H #define OPENMW_GAME_MWGUI_HUD_H +#include + #include "mapwindow.hpp" +#include "spellicons.hpp" #include "statswatcher.hpp" namespace MWWorld @@ -12,7 +15,6 @@ namespace MWWorld namespace MWGui { class DragAndDrop; - class SpellIcons; class ItemWidget; class SpellWidget; @@ -95,7 +97,7 @@ namespace MWGui bool mWorldMouseOver; - SpellIcons* mSpellIcons; + std::unique_ptr mSpellIcons; int mEnemyActorId; float mEnemyHealthTimer; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 1dfaa0d047..8a3a72d2b0 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -122,17 +122,20 @@ namespace MWGui void InventoryWindow::updatePlayer() { mPtr = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - mTradeModel = new TradeItemModel(new InventoryItemModel(mPtr), MWWorld::Ptr()); + auto tradeModel = std::make_unique(std::make_unique(mPtr), MWWorld::Ptr()); + mTradeModel = tradeModel.get(); if (mSortModel) // reuse existing SortModel when possible to keep previous category/filter settings - mSortModel->setSourceModel(mTradeModel); + mSortModel->setSourceModel(std::move(tradeModel)); else - mSortModel = new SortFilterItemModel(mTradeModel); + { + auto sortModel = std::make_unique(std::move(tradeModel)); + mSortModel = sortModel.get(); + mItemView->setModel(std::move(sortModel)); + } mSortModel->setNameFilter(mFilterEdit->getCaption()); - mItemView->setModel(mSortModel); - mFilterAll->setStateSelected(true); mFilterWeapon->setStateSelected(false); mFilterApparel->setStateSelected(false); @@ -776,7 +779,7 @@ namespace MWGui ItemModel::ModelIndex selected = -1; // not using mSortFilterModel as we only need sorting, not filtering - SortFilterItemModel model(new InventoryItemModel(player)); + SortFilterItemModel model(std::make_unique(player)); model.setSortByType(false); model.update(); if (model.getItemCount() == 0) diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 165e9ba2aa..55b2994199 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -79,17 +79,6 @@ namespace MWGui return true; } - - ProxyItemModel::ProxyItemModel() - : mSourceModel(nullptr) - { - } - - ProxyItemModel::~ProxyItemModel() - { - delete mSourceModel; - } - bool ProxyItemModel::allowedToUseItems() const { return mSourceModel->allowedToUseItems(); @@ -134,18 +123,9 @@ namespace MWGui return mSourceModel->getIndex(item); } - void ProxyItemModel::setSourceModel(ItemModel *sourceModel) + void ProxyItemModel::setSourceModel(std::unique_ptr sourceModel) { - if (mSourceModel == sourceModel) - return; - - if (mSourceModel) - { - delete mSourceModel; - mSourceModel = nullptr; - } - - mSourceModel = sourceModel; + mSourceModel = std::move(sourceModel); } void ProxyItemModel::onClose() diff --git a/apps/openmw/mwgui/itemmodel.hpp b/apps/openmw/mwgui/itemmodel.hpp index d538a040db..9ddcaffc50 100644 --- a/apps/openmw/mwgui/itemmodel.hpp +++ b/apps/openmw/mwgui/itemmodel.hpp @@ -1,6 +1,8 @@ #ifndef MWGUI_ITEM_MODEL_H #define MWGUI_ITEM_MODEL_H +#include + #include "../mwworld/ptr.hpp" namespace MWGui @@ -87,8 +89,8 @@ namespace MWGui class ProxyItemModel : public ItemModel { public: - ProxyItemModel(); - virtual ~ProxyItemModel(); + ProxyItemModel() = default; + virtual ~ProxyItemModel() = default; bool allowedToUseItems() const override; @@ -101,14 +103,14 @@ namespace MWGui ModelIndex getIndex (const ItemStack &item) override; /// @note Takes ownership of the passed pointer. - void setSourceModel(ItemModel* sourceModel); + void setSourceModel(std::unique_ptr sourceModel); ModelIndex mapToSource (ModelIndex index); ModelIndex mapFromSource (ModelIndex index); bool usesContainer(const MWWorld::Ptr& container) override; protected: - ItemModel* mSourceModel; + std::unique_ptr mSourceModel; }; } diff --git a/apps/openmw/mwgui/itemselection.cpp b/apps/openmw/mwgui/itemselection.cpp index 23f1398eaa..1a34f5d623 100644 --- a/apps/openmw/mwgui/itemselection.cpp +++ b/apps/openmw/mwgui/itemselection.cpp @@ -13,7 +13,6 @@ namespace MWGui ItemSelectionDialog::ItemSelectionDialog(const std::string &label) : WindowModal("openmw_itemselection_dialog.layout") , mSortModel(nullptr) - , mModel(nullptr) { getWidget(mItemView, "ItemView"); mItemView->eventItemClicked += MyGUI::newDelegate(this, &ItemSelectionDialog::onSelectedItem); @@ -37,9 +36,9 @@ namespace MWGui void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container) { - mModel = new InventoryItemModel(container); - mSortModel = new SortFilterItemModel(mModel); - mItemView->setModel(mSortModel); + auto sortModel = std::make_unique(std::make_unique(container)); + mSortModel = sortModel.get(); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); } diff --git a/apps/openmw/mwgui/itemselection.hpp b/apps/openmw/mwgui/itemselection.hpp index 6132bac7af..27eed8ea51 100644 --- a/apps/openmw/mwgui/itemselection.hpp +++ b/apps/openmw/mwgui/itemselection.hpp @@ -14,7 +14,6 @@ namespace MWGui { class ItemView; class SortFilterItemModel; - class InventoryItemModel; class ItemSelectionDialog : public WindowModal { @@ -36,7 +35,6 @@ namespace MWGui private: ItemView* mItemView; SortFilterItemModel* mSortModel; - InventoryItemModel* mModel; void onSelectedItem(int index); diff --git a/apps/openmw/mwgui/itemview.cpp b/apps/openmw/mwgui/itemview.cpp index 14f2c1dd9b..ba12d622c5 100644 --- a/apps/openmw/mwgui/itemview.cpp +++ b/apps/openmw/mwgui/itemview.cpp @@ -16,23 +16,13 @@ namespace MWGui { ItemView::ItemView() - : mModel(nullptr) - , mScrollView(nullptr) + : mScrollView(nullptr) { } -ItemView::~ItemView() +void ItemView::setModel(std::unique_ptr model) { - delete mModel; -} - -void ItemView::setModel(ItemModel *model) -{ - if (mModel == model) - return; - - delete mModel; - mModel = model; + mModel = std::move(model); update(); } @@ -114,7 +104,7 @@ void ItemView::update() ItemWidget* itemWidget = dragArea->createWidget("MW_ItemIcon", MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default); itemWidget->setUserString("ToolTipType", "ItemModelIndex"); - itemWidget->setUserData(std::make_pair(i, mModel)); + itemWidget->setUserData(std::make_pair(i, mModel.get())); ItemWidget::ItemState state = ItemWidget::None; if (item.mType == ItemStack::Type_Barter) state = ItemWidget::Barter; diff --git a/apps/openmw/mwgui/itemview.hpp b/apps/openmw/mwgui/itemview.hpp index 4074e55e48..e2f882e618 100644 --- a/apps/openmw/mwgui/itemview.hpp +++ b/apps/openmw/mwgui/itemview.hpp @@ -13,13 +13,12 @@ namespace MWGui MYGUI_RTTI_DERIVED(ItemView) public: ItemView(); - ~ItemView() override; /// Register needed components with MyGUI's factory manager static void registerComponents (); /// Takes ownership of \a model - void setModel (ItemModel* model); + void setModel(std::unique_ptr model); typedef MyGUI::delegates::CMultiDelegate1 EventHandle_ModelIndex; typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void; @@ -44,7 +43,7 @@ namespace MWGui void onSelectedBackground (MyGUI::Widget* sender); void onMouseWheelMoved(MyGUI::Widget* _sender, int _rel); - ItemModel* mModel; + std::unique_ptr mModel; MyGUI::ScrollView* mScrollView; }; diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index 45d5b6aa80..7009e66110 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -648,9 +648,9 @@ namespace } // glue the implementation to the interface -MWGui::JournalWindow * MWGui::JournalWindow::create (JournalViewModel::Ptr Model, bool questList, ToUTF8::FromType encoding) +std::unique_ptr MWGui::JournalWindow::create(JournalViewModel::Ptr Model, bool questList, ToUTF8::FromType encoding) { - return new JournalWindowImpl (Model, questList, encoding); + return std::make_unique(Model, questList, encoding); } MWGui::JournalWindow::JournalWindow() diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp index c18e6e4c08..0f3071f113 100644 --- a/apps/openmw/mwgui/journalwindow.hpp +++ b/apps/openmw/mwgui/journalwindow.hpp @@ -18,7 +18,7 @@ namespace MWGui JournalWindow(); /// construct a new instance of the one JournalWindow implementation - static JournalWindow * create (std::shared_ptr Model, bool questList, ToUTF8::FromType encoding); + static std::unique_ptr create(std::shared_ptr Model, bool questList, ToUTF8::FromType encoding); /// destroy this instance of the JournalWindow implementation virtual ~JournalWindow () {} diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index d77a2d0bcd..f178576f12 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -28,7 +28,6 @@ namespace MWGui , mBackground(nullptr) , mVideoBackground(nullptr) , mVideo(nullptr) - , mSaveGameDialog(nullptr) { getWidget(mVersionText, "VersionText"); mVersionText->setCaption(versionDescription); @@ -38,11 +37,6 @@ namespace MWGui updateMenu(); } - MainMenu::~MainMenu() - { - delete mSaveGameDialog; - } - void MainMenu::onResChange(int w, int h) { mWidth = w; @@ -133,7 +127,7 @@ namespace MWGui else { if (!mSaveGameDialog) - mSaveGameDialog = new SaveGameDialog(); + mSaveGameDialog = std::make_unique(); if (name == "loadgame") mSaveGameDialog->setLoadOrSave(true); else if (name == "savegame") diff --git a/apps/openmw/mwgui/mainmenu.hpp b/apps/openmw/mwgui/mainmenu.hpp index 560eb93dcc..2ca3844f37 100644 --- a/apps/openmw/mwgui/mainmenu.hpp +++ b/apps/openmw/mwgui/mainmenu.hpp @@ -1,6 +1,9 @@ #ifndef OPENMW_GAME_MWGUI_MAINMENU_H #define OPENMW_GAME_MWGUI_MAINMENU_H +#include + +#include "savegamedialog.hpp" #include "windowbase.hpp" namespace Gui @@ -17,7 +20,6 @@ namespace MWGui { class BackgroundImage; - class SaveGameDialog; class VideoWidget; class MainMenu : public WindowBase @@ -30,7 +32,6 @@ namespace MWGui public: MainMenu(int w, int h, const VFS::Manager* vfs, const std::string& versionDescription); - ~MainMenu(); void onResChange(int w, int h) override; @@ -61,7 +62,7 @@ namespace MWGui void updateMenu(); - SaveGameDialog* mSaveGameDialog; + std::unique_ptr mSaveGameDialog; }; } diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index e1ea0a46b9..4e163f7d37 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -18,7 +18,6 @@ namespace MWGui MessageBoxManager::MessageBoxManager (float timePerChar) { - mInterMessageBoxe = nullptr; mStaticMessageBox = nullptr; mLastButtonPressed = -1; mMessageBoxSpeed = timePerChar; @@ -39,31 +38,22 @@ namespace MWGui if (mInterMessageBoxe) { mInterMessageBoxe->setVisible(false); - - delete mInterMessageBoxe; - mInterMessageBoxe = nullptr; + mInterMessageBoxe.reset(); } - for (MessageBox* messageBox : mMessageBoxes) - { - if (messageBox == mStaticMessageBox) - mStaticMessageBox = nullptr; - delete messageBox; - } mMessageBoxes.clear(); + mStaticMessageBox = nullptr; mLastButtonPressed = -1; } void MessageBoxManager::onFrame (float frameDuration) { - std::vector::iterator it; - for(it = mMessageBoxes.begin(); it != mMessageBoxes.end();) + for(auto it = mMessageBoxes.begin(); it != mMessageBoxes.end();) { (*it)->mCurrentTime += frameDuration; - if((*it)->mCurrentTime >= (*it)->mMaxTime && *it != mStaticMessageBox) + if((*it)->mCurrentTime >= (*it)->mMaxTime && it->get() != mStaticMessageBox) { - delete *it; it = mMessageBoxes.erase(it); } else @@ -71,7 +61,7 @@ namespace MWGui } float height = 0; - it = mMessageBoxes.begin(); + auto it = mMessageBoxes.begin(); while(it != mMessageBoxes.end()) { (*it)->update(static_cast(height)); @@ -82,8 +72,7 @@ namespace MWGui if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) { mLastButtonPressed = mInterMessageBoxe->readPressedButton(); mInterMessageBoxe->setVisible(false); - delete mInterMessageBoxe; - mInterMessageBoxe = nullptr; + mInterMessageBoxe.reset(); MWBase::Environment::get().getInputManager()->changeInputMode( MWBase::Environment::get().getWindowManager()->isGuiMode()); } @@ -91,25 +80,24 @@ namespace MWGui void MessageBoxManager::createMessageBox(std::string_view message, bool stat) { - MessageBox *box = new MessageBox(*this, message); + auto box = std::make_unique(*this, message); box->mCurrentTime = 0; auto realMessage = MyGUI::LanguageManager::getInstance().replaceTags({message.data(), message.size()}); box->mMaxTime = realMessage.length()*mMessageBoxSpeed; if(stat) - mStaticMessageBox = box; + mStaticMessageBox = box.get(); box->setVisible(mVisible); - mMessageBoxes.push_back(box); + mMessageBoxes.push_back(std::move(box)); if(mMessageBoxes.size() > 3) { - delete *mMessageBoxes.begin(); mMessageBoxes.erase(mMessageBoxes.begin()); } int height = 0; - for (MessageBox* messageBox : mMessageBoxes) + for (const auto& messageBox : mMessageBoxes) { messageBox->update(height); height += messageBox->getHeight(); @@ -128,11 +116,9 @@ namespace MWGui { Log(Debug::Warning) << "Warning: replacing an interactive message box that was not answered yet"; mInterMessageBoxe->setVisible(false); - delete mInterMessageBoxe; - mInterMessageBoxe = nullptr; } - mInterMessageBoxe = new InteractiveMessageBox(*this, std::string{message}, buttons); + mInterMessageBoxe = std::make_unique(*this, std::string{message}, buttons); mLastButtonPressed = -1; return true; @@ -145,12 +131,10 @@ namespace MWGui bool MessageBoxManager::removeMessageBox (MessageBox *msgbox) { - std::vector::iterator it; - for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it) + for(auto it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it) { - if((*it) == msgbox) + if(it->get() == msgbox) { - delete (*it); mMessageBoxes.erase(it); return true; } @@ -158,7 +142,7 @@ namespace MWGui return false; } - const std::vector MessageBoxManager::getActiveMessageBoxes() + const std::vector>& MessageBoxManager::getActiveMessageBoxes() const { return mMessageBoxes; } @@ -174,7 +158,7 @@ namespace MWGui void MessageBoxManager::setVisible(bool value) { mVisible = value; - for (MessageBox* messageBox : mMessageBoxes) + for (const auto& messageBox : mMessageBoxes) messageBox->setVisible(value); } diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 7552bb50d6..3fec60caee 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -1,6 +1,8 @@ #ifndef MWGUI_MESSAGE_BOX_H #define MWGUI_MESSAGE_BOX_H +#include + #include "windowbase.hpp" namespace MyGUI @@ -28,7 +30,7 @@ namespace MWGui int getMessagesCount(); - const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe; } + const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe.get(); } /// Remove all message boxes void clear(); @@ -47,11 +49,11 @@ namespace MWGui void setVisible(bool value); - const std::vector getActiveMessageBoxes(); + const std::vector>& getActiveMessageBoxes() const; private: - std::vector mMessageBoxes; - InteractiveMessageBox* mInterMessageBoxe; + std::vector> mMessageBoxes; + std::unique_ptr mInterMessageBoxe; MessageBox* mStaticMessageBox; float mMessageBoxSpeed; int mLastButtonPressed; diff --git a/apps/openmw/mwgui/pickpocketitemmodel.cpp b/apps/openmw/mwgui/pickpocketitemmodel.cpp index 976485c23a..aca1b7392b 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.cpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.cpp @@ -17,11 +17,11 @@ namespace MWGui { - PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, ItemModel *sourceModel, bool hideItems) + PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, std::unique_ptr sourceModel, bool hideItems) : mActor(actor), mPickpocketDetected(false) { MWWorld::Ptr player = MWMechanics::getPlayer(); - mSourceModel = sourceModel; + mSourceModel = std::move(sourceModel); float chance = player.getClass().getSkill(player, ESM::Skill::Sneak); mSourceModel->update(); diff --git a/apps/openmw/mwgui/pickpocketitemmodel.hpp b/apps/openmw/mwgui/pickpocketitemmodel.hpp index e28af73d78..ec18f13609 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.hpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.hpp @@ -10,7 +10,7 @@ namespace MWGui class PickpocketItemModel : public ProxyItemModel { public: - PickpocketItemModel (const MWWorld::Ptr& thief, ItemModel* sourceModel, bool hideItems=true); + PickpocketItemModel(const MWWorld::Ptr& thief, std::unique_ptr sourceModel, bool hideItems = true); bool allowedToUseItems() const override; ItemStack getItem (ModelIndex index) override; diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index d028c263b9..c661b59f17 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -39,9 +39,6 @@ namespace MWGui , mKey(std::vector(10)) , mSelected(nullptr) , mActivated(nullptr) - , mAssignDialog(nullptr) - , mItemSelectionDialog(nullptr) - , mMagicSelectionDialog(nullptr) { getWidget(mOkButton, "OKButton"); @@ -74,13 +71,6 @@ namespace MWGui } } - QuickKeysMenu::~QuickKeysMenu() - { - delete mAssignDialog; - delete mItemSelectionDialog; - delete mMagicSelectionDialog; - } - inline void QuickKeysMenu::validate(int index) { MWWorld::Ptr player = MWMechanics::getPlayer(); @@ -194,7 +184,7 @@ namespace MWGui // open assign dialog if (!mAssignDialog) - mAssignDialog = new QuickKeysMenuAssign(this); + mAssignDialog = std::make_unique(this); mAssignDialog->setVisible(true); } @@ -208,7 +198,7 @@ namespace MWGui { if (!mItemSelectionDialog) { - mItemSelectionDialog = new ItemSelectionDialog("#{sQuickMenu6}"); + mItemSelectionDialog = std::make_unique("#{sQuickMenu6}"); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItem); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItemCancel); } @@ -223,7 +213,7 @@ namespace MWGui { if (!mMagicSelectionDialog) { - mMagicSelectionDialog = new MagicSelectionDialog(this); + mMagicSelectionDialog = std::make_unique(this); } mMagicSelectionDialog->setVisible(true); diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp index 6343dfc879..2c28bfee61 100644 --- a/apps/openmw/mwgui/quickkeysmenu.hpp +++ b/apps/openmw/mwgui/quickkeysmenu.hpp @@ -1,15 +1,16 @@ #ifndef MWGUI_QUICKKEYS_H #define MWGUI_QUICKKEYS_H -#include "windowbase.hpp" +#include +#include "itemselection.hpp" #include "spellmodel.hpp" +#include "windowbase.hpp" namespace MWGui { class QuickKeysMenuAssign; - class ItemSelectionDialog; class MagicSelectionDialog; class ItemWidget; class SpellView; @@ -18,7 +19,6 @@ namespace MWGui { public: QuickKeysMenu(); - ~QuickKeysMenu(); void onResChange(int, int) override { center(); } @@ -71,9 +71,9 @@ namespace MWGui MyGUI::EditBox* mInstructionLabel; MyGUI::Button* mOkButton; - QuickKeysMenuAssign* mAssignDialog; - ItemSelectionDialog* mItemSelectionDialog; - MagicSelectionDialog* mMagicSelectionDialog; + std::unique_ptr mAssignDialog; + std::unique_ptr mItemSelectionDialog; + std::unique_ptr mMagicSelectionDialog; void onQuickKeyButtonClicked(MyGUI::Widget* sender); void onOkButtonClicked(MyGUI::Widget* sender); diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp index 4c6a80540d..cbebb0cc68 100644 --- a/apps/openmw/mwgui/recharge.cpp +++ b/apps/openmw/mwgui/recharge.cpp @@ -47,7 +47,7 @@ void Recharge::onOpen() { center(); - SortFilterItemModel * model = new SortFilterItemModel(new InventoryItemModel(MWMechanics::getPlayer())); + SortFilterItemModel * model = new SortFilterItemModel(std::make_unique(MWMechanics::getPlayer())); model->setFilter(SortFilterItemModel::Filter_OnlyRechargable); mBox->setModel(model); diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp index c3d26ee6f0..9917e03f9b 100644 --- a/apps/openmw/mwgui/repair.cpp +++ b/apps/openmw/mwgui/repair.cpp @@ -46,7 +46,7 @@ void Repair::onOpen() { center(); - SortFilterItemModel * model = new SortFilterItemModel(new InventoryItemModel(MWMechanics::getPlayer())); + SortFilterItemModel * model = new SortFilterItemModel(std::make_unique(MWMechanics::getPlayer())); model->setFilter(SortFilterItemModel::Filter_OnlyRepairable); mRepairBox->setModel(model); diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 650257736f..09ecdb54e5 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -152,14 +152,12 @@ namespace namespace MWGui { - SortFilterItemModel::SortFilterItemModel(ItemModel *sourceModel) + SortFilterItemModel::SortFilterItemModel(std::unique_ptr sourceModel) : mCategory(Category_All) , mFilter(0) , mSortByType(true) - , mNameFilter("") - , mEffectFilter("") { - mSourceModel = sourceModel; + mSourceModel = std::move(sourceModel); } bool SortFilterItemModel::allowedToUseItems() const diff --git a/apps/openmw/mwgui/sortfilteritemmodel.hpp b/apps/openmw/mwgui/sortfilteritemmodel.hpp index 64a01f71bd..2640737a89 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.hpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.hpp @@ -9,7 +9,7 @@ namespace MWGui class SortFilterItemModel : public ProxyItemModel { public: - SortFilterItemModel (ItemModel* sourceModel); + SortFilterItemModel(std::unique_ptr sourceModel); void update() override; diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 20db95fc19..f41990ac41 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -34,7 +34,7 @@ namespace MWGui , mSpellView(nullptr) , mUpdateTimer(0.0f) { - mSpellIcons = new SpellIcons(); + mSpellIcons = std::make_unique(); MyGUI::Widget* deleteButton; getWidget(deleteButton, "DeleteSpellButton"); @@ -54,11 +54,6 @@ namespace MWGui mFilterEdit->setSize(filterWidth, mFilterEdit->getSize().height); } - SpellWindow::~SpellWindow() - { - delete mSpellIcons; - } - void SpellWindow::onPinToggled() { Settings::Manager::setBool("spells pin", "Windows", mPinned); diff --git a/apps/openmw/mwgui/spellwindow.hpp b/apps/openmw/mwgui/spellwindow.hpp index 786a7d877f..f7176bebd6 100644 --- a/apps/openmw/mwgui/spellwindow.hpp +++ b/apps/openmw/mwgui/spellwindow.hpp @@ -1,20 +1,20 @@ #ifndef MWGUI_SPELLWINDOW_H #define MWGUI_SPELLWINDOW_H -#include "windowpinnablebase.hpp" +#include +#include "spellicons.hpp" #include "spellmodel.hpp" +#include "windowpinnablebase.hpp" namespace MWGui { - class SpellIcons; class SpellView; class SpellWindow : public WindowPinnableBase, public NoDrop { public: SpellWindow(DragAndDrop* drag); - virtual ~SpellWindow(); void updateSpells(); @@ -41,7 +41,7 @@ namespace MWGui void onOpen() override; SpellView* mSpellView; - SpellIcons* mSpellIcons; + std::unique_ptr mSpellIcons; MyGUI::EditBox* mFilterEdit; private: diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index 667832b05d..22973ee91a 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -10,10 +10,10 @@ namespace MWGui { - TradeItemModel::TradeItemModel(ItemModel *sourceModel, const MWWorld::Ptr& merchant) + TradeItemModel::TradeItemModel(std::unique_ptr sourceModel, const MWWorld::Ptr& merchant) : mMerchant(merchant) { - mSourceModel = sourceModel; + mSourceModel = std::move(sourceModel); } bool TradeItemModel::allowedToUseItems() const diff --git a/apps/openmw/mwgui/tradeitemmodel.hpp b/apps/openmw/mwgui/tradeitemmodel.hpp index 53b616aeda..5a22bab8d3 100644 --- a/apps/openmw/mwgui/tradeitemmodel.hpp +++ b/apps/openmw/mwgui/tradeitemmodel.hpp @@ -13,7 +13,7 @@ namespace MWGui class TradeItemModel : public ProxyItemModel { public: - TradeItemModel (ItemModel* sourceModel, const MWWorld::Ptr& merchant); + TradeItemModel(std::unique_ptr sourceModel, const MWWorld::Ptr& merchant); bool allowedToUseItems() const override; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 7fe7cc2877..3abe10a6fb 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -114,9 +114,11 @@ namespace MWGui std::vector worldItems; MWBase::Environment::get().getWorld()->getItemsOwnedBy(actor, worldItems); - mTradeModel = new TradeItemModel(new ContainerItemModel(itemSources, worldItems), mPtr); - mSortModel = new SortFilterItemModel(mTradeModel); - mItemView->setModel (mSortModel); + auto tradeModel = std::make_unique(std::make_unique(itemSources, worldItems), mPtr); + mTradeModel = tradeModel.get(); + auto sortModel = std::make_unique(std::move(tradeModel)); + mSortModel = sortModel.get(); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); updateLabels(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 600e77ae51..51867fc322 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include // For BT_NO_PROFILE @@ -24,9 +23,6 @@ #include -#include -#include - #include #include @@ -71,17 +67,13 @@ #include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/actorutil.hpp" -#include "../mwrender/localmap.hpp" #include "../mwrender/postprocessor.hpp" #include "console.hpp" #include "journalwindow.hpp" #include "journalviewmodel.hpp" -#include "charactercreation.hpp" #include "dialogue.hpp" #include "statswindow.hpp" -#include "messagebox.hpp" -#include "tooltips.hpp" #include "scrollwindow.hpp" #include "bookwindow.hpp" #include "hud.hpp" @@ -105,7 +97,6 @@ #include "cursor.hpp" #include "merchantrepair.hpp" #include "repair.hpp" -#include "soulgemdialog.hpp" #include "companionwindow.hpp" #include "inventorywindow.hpp" #include "bookpage.hpp" @@ -117,7 +108,6 @@ #include "debugwindow.hpp" #include "postprocessorhud.hpp" #include "spellview.hpp" -#include "draganddrop.hpp" #include "container.hpp" #include "controllers.hpp" #include "jailscreen.hpp" @@ -142,13 +132,9 @@ namespace MWGui , mCurrentModals() , mHud(nullptr) , mMap(nullptr) - , mLocalMapRender(nullptr) - , mToolTips(nullptr) , mStatsWindow(nullptr) - , mMessageBoxManager(nullptr) , mConsole(nullptr) , mDialogueWindow(nullptr) - , mDragAndDrop(nullptr) , mInventoryWindow(nullptr) , mScrollWindow(nullptr) , mBookWindow(nullptr) @@ -160,7 +146,6 @@ namespace MWGui , mQuickKeysMenu(nullptr) , mLoadingScreen(nullptr) , mWaitDialog(nullptr) - , mSoulgemDialog(nullptr) , mVideoBackground(nullptr) , mVideoWidget(nullptr) , mWerewolfFader(nullptr) @@ -172,7 +157,6 @@ namespace MWGui , mJailScreen(nullptr) , mContainerWindow(nullptr) , mTranslationDataStorage (translationDataStorage) - , mCharGen(nullptr) , mInputBlocker(nullptr) , mCrosshairEnabled(Settings::Manager::getBool ("crosshair", "HUD")) , mSubtitlesEnabled(Settings::Manager::getBool ("subtitles", "GUI")) @@ -182,9 +166,7 @@ namespace MWGui , mCursorVisible(true) , mCursorActive(true) , mPlayerBounty(-1) - , mGui(nullptr) , mGuiModes() - , mCursorManager(nullptr) , mGarbageDialogs() , mShown(GW_ALL) , mForceHidden(GW_None) @@ -196,11 +178,11 @@ namespace MWGui , mWindowVisible(true) { mScalingFactor = std::clamp(Settings::Manager::getFloat("scaling factor", "GUI"), 0.5f, 8.f); - mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getImageManager(), + mGuiPlatform = std::make_unique(viewer, guiRoot, resourceSystem->getImageManager(), resourceSystem->getVFS(), mScalingFactor, "mygui", (std::filesystem::path(logpath) / "MyGUI.log").generic_string()); - mGui = new MyGUI::Gui; + mGui = std::make_unique(); mGui->initialise(""); createTextures(); @@ -242,11 +224,12 @@ namespace MWGui mKeyboardNavigation->setEnabled(keyboardNav); Gui::ImageButton::setDefaultNeedKeyFocus(keyboardNav); - mLoadingScreen = new LoadingScreen(mResourceSystem, mViewer); - mWindows.push_back(mLoadingScreen); + auto loadingScreen = std::make_unique(mResourceSystem, mViewer); + mLoadingScreen = loadingScreen.get(); + mWindows.push_back(std::move(loadingScreen)); //set up the hardware cursor manager - mCursorManager = new SDLUtil::SDLCursorManager(); + mCursorManager = std::make_unique(); MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange); @@ -281,7 +264,7 @@ namespace MWGui mShowOwned = Settings::Manager::getInt("show owned", "Game"); - mVideoWrapper = new SDLUtil::VideoWrapper(window, viewer); + mVideoWrapper = std::make_unique(window, viewer); mVideoWrapper->setGammaContrast(Settings::Manager::getFloat("gamma", "Video"), Settings::Manager::getFloat("contrast", "Video")); @@ -299,157 +282,176 @@ namespace MWGui mTextColours.loadColours(); - mDragAndDrop = new DragAndDrop(); + mDragAndDrop = std::make_unique(); - Recharge* recharge = new Recharge(); - mGuiModeStates[GM_Recharge] = GuiModeState(recharge); - mWindows.push_back(recharge); + auto recharge = std::make_unique(); + mGuiModeStates[GM_Recharge] = GuiModeState(recharge.get()); + mWindows.push_back(std::move(recharge)); - MainMenu* menu = new MainMenu(w, h, mResourceSystem->getVFS(), mVersionDescription); - mGuiModeStates[GM_MainMenu] = GuiModeState(menu); - mWindows.push_back(menu); + auto menu = std::make_unique(w, h, mResourceSystem->getVFS(), mVersionDescription); + mGuiModeStates[GM_MainMenu] = GuiModeState(menu.get()); + mWindows.push_back(std::move(menu)); - mLocalMapRender = new MWRender::LocalMap(mViewer->getSceneData()->asGroup()); - mMap = new MapWindow(mCustomMarkers, mDragAndDrop, mLocalMapRender, mWorkQueue); - mWindows.push_back(mMap); + mLocalMapRender = std::make_unique(mViewer->getSceneData()->asGroup()); + auto map = std::make_unique(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get(), mWorkQueue); + mMap = map.get(); + mWindows.push_back(std::move(map)); mMap->renderGlobalMap(); trackWindow(mMap, "map"); - mStatsWindow = new StatsWindow(mDragAndDrop); - mWindows.push_back(mStatsWindow); + auto statsWindow = std::make_unique(mDragAndDrop.get()); + mStatsWindow = statsWindow.get(); + mWindows.push_back(std::move(statsWindow)); trackWindow(mStatsWindow, "stats"); - mInventoryWindow = new InventoryWindow(mDragAndDrop, mViewer->getSceneData()->asGroup(), mResourceSystem); - mWindows.push_back(mInventoryWindow); + auto inventoryWindow = std::make_unique(mDragAndDrop.get(), mViewer->getSceneData()->asGroup(), mResourceSystem); + mInventoryWindow = inventoryWindow.get(); + mWindows.push_back(std::move(inventoryWindow)); - mSpellWindow = new SpellWindow(mDragAndDrop); - mWindows.push_back(mSpellWindow); + auto spellWindow = std::make_unique(mDragAndDrop.get()); + mSpellWindow = spellWindow.get(); + mWindows.push_back(std::move(spellWindow)); trackWindow(mSpellWindow, "spells"); mGuiModeStates[GM_Inventory] = GuiModeState({mMap, mInventoryWindow, mSpellWindow, mStatsWindow}); mGuiModeStates[GM_None] = GuiModeState({mMap, mInventoryWindow, mSpellWindow, mStatsWindow}); - mTradeWindow = new TradeWindow(); - mWindows.push_back(mTradeWindow); + auto tradeWindow = std::make_unique(); + mTradeWindow = tradeWindow.get(); + mWindows.push_back(std::move(tradeWindow)); trackWindow(mTradeWindow, "barter"); mGuiModeStates[GM_Barter] = GuiModeState({mInventoryWindow, mTradeWindow}); - mConsole = new Console(w,h, mConsoleOnlyScripts); - mWindows.push_back(mConsole); + auto console = std::make_unique(w,h, mConsoleOnlyScripts); + mConsole = console.get(); + mWindows.push_back(std::move(console)); trackWindow(mConsole, "console"); bool questList = mResourceSystem->getVFS()->exists("textures/tx_menubook_options_over.dds"); - JournalWindow* journal = JournalWindow::create(JournalViewModel::create (), questList, mEncoding); - mWindows.push_back(journal); - mGuiModeStates[GM_Journal] = GuiModeState(journal); + auto journal = JournalWindow::create(JournalViewModel::create(), questList, mEncoding); + mGuiModeStates[GM_Journal] = GuiModeState(journal.get()); mGuiModeStates[GM_Journal].mCloseSound = "book close"; mGuiModeStates[GM_Journal].mOpenSound = "book open"; + mWindows.push_back(std::move(journal)); - mMessageBoxManager = new MessageBoxManager(mStore->get().find("fMessageTimePerChar")->mValue.getFloat()); + mMessageBoxManager = std::make_unique(mStore->get().find("fMessageTimePerChar")->mValue.getFloat()); - SpellBuyingWindow* spellBuyingWindow = new SpellBuyingWindow(); - mWindows.push_back(spellBuyingWindow); - mGuiModeStates[GM_SpellBuying] = GuiModeState(spellBuyingWindow); + auto spellBuyingWindow = std::make_unique(); + mGuiModeStates[GM_SpellBuying] = GuiModeState(spellBuyingWindow.get()); + mWindows.push_back(std::move(spellBuyingWindow)); - TravelWindow* travelWindow = new TravelWindow(); - mWindows.push_back(travelWindow); - mGuiModeStates[GM_Travel] = GuiModeState(travelWindow); + auto travelWindow = std::make_unique(); + mGuiModeStates[GM_Travel] = GuiModeState(travelWindow.get()); + mWindows.push_back(std::move(travelWindow)); - mDialogueWindow = new DialogueWindow(); - mWindows.push_back(mDialogueWindow); + auto dialogueWindow = std::make_unique(); + mDialogueWindow = dialogueWindow.get(); + mWindows.push_back(std::move(dialogueWindow)); trackWindow(mDialogueWindow, "dialogue"); mGuiModeStates[GM_Dialogue] = GuiModeState(mDialogueWindow); mTradeWindow->eventTradeDone += MyGUI::newDelegate(mDialogueWindow, &DialogueWindow::onTradeComplete); - mContainerWindow = new ContainerWindow(mDragAndDrop); - mWindows.push_back(mContainerWindow); + auto containerWindow = std::make_unique(mDragAndDrop.get()); + mContainerWindow = containerWindow.get(); + mWindows.push_back(std::move(containerWindow)); trackWindow(mContainerWindow, "container"); mGuiModeStates[GM_Container] = GuiModeState({mContainerWindow, mInventoryWindow}); - mHud = new HUD(mCustomMarkers, mDragAndDrop, mLocalMapRender); - mWindows.push_back(mHud); + auto hud = std::make_unique(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get()); + mHud = hud.get(); + mWindows.push_back(std::move(hud)); - mToolTips = new ToolTips(); + mToolTips = std::make_unique(); - mScrollWindow = new ScrollWindow(); - mWindows.push_back(mScrollWindow); + auto scrollWindow = std::make_unique(); + mScrollWindow = scrollWindow.get(); + mWindows.push_back(std::move(scrollWindow)); mGuiModeStates[GM_Scroll] = GuiModeState(mScrollWindow); mGuiModeStates[GM_Scroll].mOpenSound = "scroll"; mGuiModeStates[GM_Scroll].mCloseSound = "scroll"; - mBookWindow = new BookWindow(); - mWindows.push_back(mBookWindow); + auto bookWindow = std::make_unique(); + mBookWindow = bookWindow.get(); + mWindows.push_back(std::move(bookWindow)); mGuiModeStates[GM_Book] = GuiModeState(mBookWindow); mGuiModeStates[GM_Book].mOpenSound = "book open"; mGuiModeStates[GM_Book].mCloseSound = "book close"; - mCountDialog = new CountDialog(); - mWindows.push_back(mCountDialog); + auto countDialog = std::make_unique(); + mCountDialog = countDialog.get(); + mWindows.push_back(std::move(countDialog)); - mSettingsWindow = new SettingsWindow(); - mWindows.push_back(mSettingsWindow); + auto settingsWindow = std::make_unique(); + mSettingsWindow = settingsWindow.get(); + mWindows.push_back(std::move(settingsWindow)); trackWindow(mSettingsWindow, "settings"); mGuiModeStates[GM_Settings] = GuiModeState(mSettingsWindow); - mConfirmationDialog = new ConfirmationDialog(); - mWindows.push_back(mConfirmationDialog); + auto confirmationDialog = std::make_unique(); + mConfirmationDialog = confirmationDialog.get(); + mWindows.push_back(std::move(confirmationDialog)); - AlchemyWindow* alchemyWindow = new AlchemyWindow(); - mWindows.push_back(alchemyWindow); - trackWindow(alchemyWindow, "alchemy"); - mGuiModeStates[GM_Alchemy] = GuiModeState(alchemyWindow); + auto alchemyWindow = std::make_unique(); + trackWindow(alchemyWindow.get(), "alchemy"); + mGuiModeStates[GM_Alchemy] = GuiModeState(alchemyWindow.get()); + mWindows.push_back(std::move(alchemyWindow)); - mQuickKeysMenu = new QuickKeysMenu(); - mWindows.push_back(mQuickKeysMenu); + auto quickKeysMenu = std::make_unique(); + mQuickKeysMenu = quickKeysMenu.get(); + mWindows.push_back(std::move(quickKeysMenu)); mGuiModeStates[GM_QuickKeysMenu] = GuiModeState(mQuickKeysMenu); - LevelupDialog* levelupDialog = new LevelupDialog(); - mWindows.push_back(levelupDialog); - mGuiModeStates[GM_Levelup] = GuiModeState(levelupDialog); + auto levelupDialog = std::make_unique(); + mGuiModeStates[GM_Levelup] = GuiModeState(levelupDialog.get()); + mWindows.push_back(std::move(levelupDialog)); - mWaitDialog = new WaitDialog(); - mWindows.push_back(mWaitDialog); + auto waitDialog = std::make_unique(); + mWaitDialog = waitDialog.get(); + mWindows.push_back(std::move(waitDialog)); mGuiModeStates[GM_Rest] = GuiModeState({mWaitDialog->getProgressBar(), mWaitDialog}); - SpellCreationDialog* spellCreationDialog = new SpellCreationDialog(); - mWindows.push_back(spellCreationDialog); - mGuiModeStates[GM_SpellCreation] = GuiModeState(spellCreationDialog); + auto spellCreationDialog = std::make_unique(); + mGuiModeStates[GM_SpellCreation] = GuiModeState(spellCreationDialog.get()); + mWindows.push_back(std::move(spellCreationDialog)); - EnchantingDialog* enchantingDialog = new EnchantingDialog(); - mWindows.push_back(enchantingDialog); - mGuiModeStates[GM_Enchanting] = GuiModeState(enchantingDialog); + auto enchantingDialog = std::make_unique(); + mGuiModeStates[GM_Enchanting] = GuiModeState(enchantingDialog.get()); + mWindows.push_back(std::move(enchantingDialog)); - TrainingWindow* trainingWindow = new TrainingWindow(); - mWindows.push_back(trainingWindow); - mGuiModeStates[GM_Training] = GuiModeState({trainingWindow->getProgressBar(), trainingWindow}); + auto trainingWindow = std::make_unique(); + mGuiModeStates[GM_Training] = GuiModeState({trainingWindow->getProgressBar(), trainingWindow.get()}); + mWindows.push_back(std::move(trainingWindow)); - MerchantRepair* merchantRepair = new MerchantRepair(); - mWindows.push_back(merchantRepair); - mGuiModeStates[GM_MerchantRepair] = GuiModeState(merchantRepair); + auto merchantRepair = std::make_unique(); + mGuiModeStates[GM_MerchantRepair] = GuiModeState(merchantRepair.get()); + mWindows.push_back(std::move(merchantRepair)); - Repair* repair = new Repair(); - mWindows.push_back(repair); - mGuiModeStates[GM_Repair] = GuiModeState(repair); + auto repair = std::make_unique(); + mGuiModeStates[GM_Repair] = GuiModeState(repair.get()); + mWindows.push_back(std::move(repair)); - mSoulgemDialog = new SoulgemDialog(mMessageBoxManager); + mSoulgemDialog = std::make_unique(mMessageBoxManager.get()); - CompanionWindow* companionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager); - mWindows.push_back(companionWindow); - trackWindow(companionWindow, "companion"); - mGuiModeStates[GM_Companion] = GuiModeState({mInventoryWindow, companionWindow}); + auto companionWindow = std::make_unique(mDragAndDrop.get(), mMessageBoxManager.get()); + trackWindow(companionWindow.get(), "companion"); + mGuiModeStates[GM_Companion] = GuiModeState({mInventoryWindow, companionWindow.get()}); + mWindows.push_back(std::move(companionWindow)); - mJailScreen = new JailScreen(); - mWindows.push_back(mJailScreen); + auto jailScreen = std::make_unique(); + mJailScreen = jailScreen.get(); + mWindows.push_back(std::move(jailScreen)); mGuiModeStates[GM_Jail] = GuiModeState(mJailScreen); std::string werewolfFaderTex = "textures\\werewolfoverlay.dds"; if (mResourceSystem->getVFS()->exists(werewolfFaderTex)) { - mWerewolfFader = new ScreenFader(werewolfFaderTex); - mWindows.push_back(mWerewolfFader); + auto werewolfFader = std::make_unique(werewolfFaderTex); + mWerewolfFader = werewolfFader.get(); + mWindows.push_back(std::move(werewolfFader)); } - mBlindnessFader = new ScreenFader("black"); - mWindows.push_back(mBlindnessFader); + auto blindnessFader = std::make_unique("black"); + mBlindnessFader = blindnessFader.get(); + mWindows.push_back(std::move(blindnessFader)); // fall back to player_hit_01.dds if bm_player_hit_01.dds is not available std::string hitFaderTexture = "textures\\bm_player_hit_01.dds"; @@ -460,24 +462,28 @@ namespace MWGui hitFaderTexture = "textures\\player_hit_01.dds"; hitFaderCoord = MyGUI::FloatCoord(0.2, 0.25, 0.6, 0.5); } - mHitFader = new ScreenFader(hitFaderTexture, hitFaderLayout, hitFaderCoord); - mWindows.push_back(mHitFader); + auto hitFader = std::make_unique(hitFaderTexture, hitFaderLayout, hitFaderCoord); + mHitFader = hitFader.get(); + mWindows.push_back(std::move(hitFader)); - mScreenFader = new ScreenFader("black"); - mWindows.push_back(mScreenFader); + auto screenFader = std::make_unique("black"); + mScreenFader = screenFader.get(); + mWindows.push_back(std::move(screenFader)); - mDebugWindow = new DebugWindow(); - mWindows.push_back(mDebugWindow); + auto debugWindow = std::make_unique(); + mDebugWindow = debugWindow.get(); + mWindows.push_back(std::move(debugWindow)); - mPostProcessorHud = new PostProcessorHud(); - mWindows.push_back(mPostProcessorHud); + auto postProcessorHud = std::make_unique(); + mPostProcessorHud = postProcessorHud.get(); + mWindows.push_back(std::move(postProcessorHud)); trackWindow(mPostProcessorHud, "postprocessor"); mInputBlocker = MyGUI::Gui::getInstance().createWidget("",0,0,w,h,MyGUI::Align::Stretch,"InputBlocker"); mHud->setVisible(true); - mCharGen = new CharacterCreation(mViewer->getSceneData()->asGroup(), mResourceSystem); + mCharGen = std::make_unique(mViewer->getSceneData()->asGroup(), mResourceSystem); updatePinnedWindows(); @@ -486,7 +492,7 @@ namespace MWGui mStatsWatcher->addListener(mHud); mStatsWatcher->addListener(mStatsWindow); - mStatsWatcher->addListener(mCharGen); + mStatsWatcher->addListener(mCharGen.get()); } int WindowManager::getFontHeight() const @@ -500,10 +506,9 @@ namespace MWGui { disallowAll(); - mStatsWatcher->removeListener(mCharGen); - delete mCharGen; - mCharGen = new CharacterCreation(mViewer->getSceneData()->asGroup(), mResourceSystem); - mStatsWatcher->addListener(mCharGen); + mStatsWatcher->removeListener(mCharGen.get()); + mCharGen = std::make_unique(mViewer->getSceneData()->asGroup(), mResourceSystem); + mStatsWatcher->addListener(mCharGen.get()); } else allow(GW_ALL); @@ -525,17 +530,9 @@ namespace MWGui MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear(); MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear(); - for (WindowBase* window : mWindows) - delete window; mWindows.clear(); - - delete mMessageBoxManager; - delete mLocalMapRender; - delete mCharGen; - delete mDragAndDrop; - delete mSoulgemDialog; - delete mCursorManager; - delete mToolTips; + mMessageBoxManager.reset(); + mToolTips.reset(); mKeyboardNavigation.reset(); @@ -544,11 +541,8 @@ namespace MWGui mFontLoader.reset(); mGui->shutdown(); - delete mGui; mGuiPlatform->shutdown(); - delete mGuiPlatform; - delete mVideoWrapper; } catch(const MyGUI::Exception& e) { @@ -700,7 +694,7 @@ namespace MWGui } GuiModeState& state = mGuiModeStates[mGuiModes.back()]; - for (WindowBase* window : state.mWindows) + for (const auto& window : state.mWindows) { if (!window->exit()) { @@ -773,7 +767,7 @@ namespace MWGui mMessageBoxManager->removeStaticMessageBox(); } - const std::vector WindowManager::getActiveMessageBoxes() + const std::vector>& WindowManager::getActiveMessageBoxes() const { return mMessageBoxManager->getActiveMessageBoxes(); } @@ -1164,7 +1158,7 @@ namespace MWGui it->first->setSize(size); } - for (WindowBase* window : mWindows) + for (const auto& window : mWindows) window->onResChange(x, y); // TODO: check if any windows are now off-screen and move them back if so @@ -1726,7 +1720,7 @@ namespace MWGui { mPlayerBounty = -1; - for (WindowBase* window : mWindows) + for (const auto& window : mWindows) window->clear(); if (mLocalMapRender) @@ -2270,8 +2264,8 @@ namespace MWGui void WindowManager::GuiModeState::update(bool visible) { - for (unsigned int i=0; isetVisible(visible); + for (const auto& window : mWindows) + window->setVisible(visible); } void WindowManager::watchActor(const MWWorld::Ptr& ptr) @@ -2299,7 +2293,7 @@ namespace MWGui void WindowManager::onDeleteCustomData(const MWWorld::Ptr& ptr) { - for(auto* window : mWindows) + for(const auto& window : mWindows) window->onDeleteCustomData(ptr); } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 0b506d17a2..107bfdeb75 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -14,22 +14,32 @@ #include #include "../mwbase/windowmanager.hpp" +#include "../mwrender/localmap.hpp" +#include +#include #include +#include +#include #include #include -#include +#include "charactercreation.hpp" +#include "draganddrop.hpp" #include "mapwindow.hpp" +#include "messagebox.hpp" +#include "soulgemdialog.hpp" #include "statswatcher.hpp" #include "textcolours.hpp" +#include "tooltips.hpp" +#include "windowbase.hpp" +#include #include #include namespace MyGUI { - class Gui; class Widget; class Window; class UString; @@ -70,42 +80,21 @@ namespace SceneUtil class WorkQueue; } -namespace SDLUtil -{ - class SDLCursorManager; - class VideoWrapper; -} - -namespace osgMyGUI -{ - class Platform; -} - namespace Gui { class FontLoader; } -namespace MWRender -{ - class LocalMap; -} - namespace MWGui { - class WindowBase; class HUD; class MapWindow; class MainMenu; class StatsWindow; class InventoryWindow; struct JournalWindow; - class CharacterCreation; - class DragAndDrop; - class ToolTips; class TextInputDialog; class InfoBoxDialog; - class MessageBoxManager; class SettingsWindow; class AlchemyWindow; class QuickKeysMenu; @@ -117,7 +106,6 @@ namespace MWGui class TrainingWindow; class SpellIcons; class MerchantRepair; - class SoulgemDialog; class Recharge; class CompanionWindow; class VideoWidget; @@ -190,7 +178,7 @@ namespace MWGui MWGui::CountDialog* getCountDialog() override; MWGui::ConfirmationDialog* getConfirmationDialog() override; MWGui::TradeWindow* getTradeWindow() override; - const std::vector getActiveMessageBoxes() override; + const std::vector>& getActiveMessageBoxes() const override; MWGui::PostProcessorHud* getPostProcessorHud() override; /// Make the player use an item, while updating GUI state accordingly @@ -401,7 +389,7 @@ namespace MWGui Resource::ResourceSystem* mResourceSystem; osg::ref_ptr mWorkQueue; - osgMyGUI::Platform* mGuiPlatform; + std::unique_ptr mGuiPlatform; osgViewer::Viewer* mViewer; std::unique_ptr mFontLoader; @@ -424,13 +412,13 @@ namespace MWGui HUD *mHud; MapWindow *mMap; - MWRender::LocalMap* mLocalMapRender; - ToolTips *mToolTips; + std::unique_ptr mLocalMapRender; + std::unique_ptr mToolTips; StatsWindow *mStatsWindow; - MessageBoxManager *mMessageBoxManager; + std::unique_ptr mMessageBoxManager; Console *mConsole; DialogueWindow *mDialogueWindow; - DragAndDrop* mDragAndDrop; + std::unique_ptr mDragAndDrop; InventoryWindow *mInventoryWindow; ScrollWindow* mScrollWindow; BookWindow* mBookWindow; @@ -442,7 +430,7 @@ namespace MWGui QuickKeysMenu* mQuickKeysMenu; LoadingScreen* mLoadingScreen; WaitDialog* mWaitDialog; - SoulgemDialog* mSoulgemDialog; + std::unique_ptr mSoulgemDialog; MyGUI::ImageBox* mVideoBackground; VideoWidget* mVideoWidget; ScreenFader* mWerewolfFader; @@ -454,11 +442,11 @@ namespace MWGui JailScreen* mJailScreen; ContainerWindow* mContainerWindow; - std::vector mWindows; + std::vector> mWindows; Translation::Storage& mTranslationDataStorage; - CharacterCreation* mCharGen; + std::unique_ptr mCharGen; MyGUI::Widget* mInputBlocker; @@ -474,7 +462,7 @@ namespace MWGui void setCursorVisible(bool visible) override; - MyGUI::Gui *mGui; // Gui + std::unique_ptr mGui; // Gui struct GuiModeState { @@ -498,7 +486,7 @@ namespace MWGui // The currently active stack of GUI modes (top mode is the one we are in). std::vector mGuiModes; - SDLUtil::SDLCursorManager* mCursorManager; + std::unique_ptr mCursorManager; std::vector> mGarbageDialogs; void cleanupGarbage(); @@ -531,7 +519,7 @@ namespace MWGui std::unique_ptr mKeyboardNavigation; - SDLUtil::VideoWrapper* mVideoWrapper; + std::unique_ptr mVideoWrapper; float mScalingFactor; diff --git a/apps/openmw/mwinput/actionmanager.cpp b/apps/openmw/mwinput/actionmanager.cpp index 458066a5ee..610f88cef9 100644 --- a/apps/openmw/mwinput/actionmanager.cpp +++ b/apps/openmw/mwinput/actionmanager.cpp @@ -97,8 +97,8 @@ namespace MWInput if (playerPtr.getClass().getEncumbrance(playerPtr) > playerPtr.getClass().getCapacity(playerPtr)) { player.setAutoMove (false); - std::vector msgboxs = MWBase::Environment::get().getWindowManager()->getActiveMessageBoxes(); - const std::vector::iterator it = std::find_if(msgboxs.begin(), msgboxs.end(), [](MWGui::MessageBox*& msgbox) + const auto& msgboxs = MWBase::Environment::get().getWindowManager()->getActiveMessageBoxes(); + auto it = std::find_if(msgboxs.begin(), msgboxs.end(), [](const std::unique_ptr& msgbox) { return (msgbox->getMessage() == "#{sNotifyMessage59}"); });