1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 08:45:39 +00:00

Merge branch 'point_point' into 'master'

Use unique_ptr in more places

See merge request OpenMW/openmw!2354
This commit is contained in:
psi29a 2022-09-01 22:30:25 +00:00
commit 18439f4195
41 changed files with 306 additions and 393 deletions

View file

@ -150,7 +150,7 @@ namespace MWBase
virtual MWGui::CountDialog* getCountDialog() = 0; virtual MWGui::CountDialog* getCountDialog() = 0;
virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0;
virtual MWGui::TradeWindow* getTradeWindow() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0;
virtual const std::vector<MWGui::MessageBox*> getActiveMessageBoxes() = 0; virtual const std::vector<std::unique_ptr<MWGui::MessageBox>>& getActiveMessageBoxes() const = 0;
virtual MWGui::PostProcessorHud* getPostProcessorHud() = 0; virtual MWGui::PostProcessorHud* getPostProcessorHud() = 0;
/// Make the player use an item, while updating GUI state accordingly /// Make the player use an item, while updating GUI state accordingly

View file

@ -125,8 +125,7 @@ namespace MWClass
MWWorld::LiveCellRef<ESM::Potion> *ref = MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>(); ptr.get<ESM::Potion>();
std::unique_ptr<MWWorld::Action> action ( auto action = std::make_unique<MWWorld::ActionApply>(ptr, ref->mBase->mId);
new MWWorld::ActionApply (ptr, ref->mBase->mId));
action->setSound ("Drink"); action->setSound ("Drink");

View file

@ -34,7 +34,7 @@ namespace MWGui
, mCurrentFilter(FilterType::ByName) , mCurrentFilter(FilterType::ByName)
, mModel(nullptr) , mModel(nullptr)
, mSortModel(nullptr) , mSortModel(nullptr)
, mAlchemy(new MWMechanics::Alchemy()) , mAlchemy(std::make_unique<MWMechanics::Alchemy>())
, mApparatus (4) , mApparatus (4)
, mIngredients (4) , mIngredients (4)
{ {
@ -245,13 +245,15 @@ namespace MWGui
mAlchemy->clear(); mAlchemy->clear();
mAlchemy->setAlchemist (MWMechanics::getPlayer()); mAlchemy->setAlchemist (MWMechanics::getPlayer());
mModel = new InventoryItemModel(MWMechanics::getPlayer()); auto model = std::make_unique<InventoryItemModel>(MWMechanics::getPlayer());
mSortModel = new SortFilterItemModel(mModel); mModel = model.get();
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mSortModel = sortModel.get();
mSortModel->setFilter(SortFilterItemModel::Filter_OnlyIngredients); mSortModel->setFilter(SortFilterItemModel::Filter_OnlyIngredients);
mItemView->setModel (mSortModel); mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars(); mItemView->resetScrollBars();
mNameEdit->setCaption(""); mNameEdit->setCaption({});
mBrewCountEdit->setValue(1); mBrewCountEdit->setValue(1);
int index = 0; int index = 0;

View file

@ -12,10 +12,7 @@
#include "windowbase.hpp" #include "windowbase.hpp"
namespace MWMechanics #include "../mwmechanics/alchemy.hpp"
{
class Alchemy;
}
namespace MWGui namespace MWGui
{ {

View file

@ -123,11 +123,12 @@ void CompanionWindow::setPtr(const MWWorld::Ptr& npc)
{ {
mPtr = npc; mPtr = npc;
updateEncumbranceBar(); updateEncumbranceBar();
auto model = std::make_unique<CompanionItemModel>(npc);
mModel = new CompanionItemModel(npc); mModel = model.get();
mSortModel = new SortFilterItemModel(mModel); auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mFilterEdit->setCaption(std::string()); mSortModel = sortModel.get();
mItemView->setModel(mSortModel); mFilterEdit->setCaption({});
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars(); mItemView->resetScrollBars();
setTitle(npc.getClass().getName(npc)); setTitle(npc.getClass().getName(npc));

View file

@ -129,27 +129,29 @@ namespace MWGui
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead(); bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
std::unique_ptr<ItemModel> model;
if (mPtr.getClass().hasInventoryStore(mPtr)) if (mPtr.getClass().hasInventoryStore(mPtr))
{ {
if (mPtr.getClass().isNpc() && !loot && !lootAnyway) if (mPtr.getClass().isNpc() && !loot && !lootAnyway)
{ {
// we are stealing stuff // we are stealing stuff
mModel = new PickpocketItemModel(mPtr, new InventoryItemModel(container), model = std::make_unique<PickpocketItemModel>(mPtr, std::make_unique<InventoryItemModel>(container),
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown()); !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
} }
else else
mModel = new InventoryItemModel(container); model = std::make_unique<InventoryItemModel>(container);
} }
else else
{ {
mModel = new ContainerItemModel(container); model = std::make_unique<ContainerItemModel>(container);
} }
mDisposeCorpseButton->setVisible(loot); mDisposeCorpseButton->setVisible(loot);
mModel = model.get();
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mSortModel = sortModel.get();
mSortModel = new SortFilterItemModel(mModel); mItemView->setModel(std::move(sortModel));
mItemView->setModel (mSortModel);
mItemView->resetScrollBars(); mItemView->resetScrollBars();
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);

View file

@ -32,31 +32,15 @@
namespace MWGui namespace MWGui
{ {
void ResponseCallback::addResponse(const std::string& title, const std::string& text)
class ResponseCallback : public MWBase::DialogueManager::ResponseCallback
{ {
public: mWindow->addResponse(title, text, mNeedMargin);
ResponseCallback(DialogueWindow* win, bool needMargin=true) }
: mWindow(win)
, mNeedMargin(needMargin)
{
} void ResponseCallback::updateTopics() const
{
void addResponse(const std::string& title, const std::string& text) override mWindow->updateTopics();
{ }
mWindow->addResponse(title, text, mNeedMargin);
}
void updateTopics()
{
mWindow->updateTopics();
}
private:
DialogueWindow* mWindow;
bool mNeedMargin;
};
PersuasionDialog::PersuasionDialog(std::unique_ptr<ResponseCallback> callback) PersuasionDialog::PersuasionDialog(std::unique_ptr<ResponseCallback> callback)
: WindowModal("openmw_persuasion_dialog.layout") : WindowModal("openmw_persuasion_dialog.layout")

View file

@ -8,6 +8,7 @@
#include "bookpage.hpp" #include "bookpage.hpp"
#include "../mwbase/dialoguemanager.hpp"
#include "../mwdialogue/keywordsearch.hpp" #include "../mwdialogue/keywordsearch.hpp"
#include <MyGUI_Delegate.h> #include <MyGUI_Delegate.h>
@ -20,7 +21,21 @@ namespace Gui
namespace MWGui 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 class PersuasionDialog : public WindowModal
{ {

View file

@ -34,7 +34,6 @@ namespace MWGui
EnchantingDialog::EnchantingDialog() EnchantingDialog::EnchantingDialog()
: WindowBase("openmw_enchanting_dialog.layout") : WindowBase("openmw_enchanting_dialog.layout")
, EffectEditorBase(EffectEditorBase::Enchanting) , EffectEditorBase(EffectEditorBase::Enchanting)
, mItemSelectionDialog(nullptr)
{ {
getWidget(mName, "NameEdit"); getWidget(mName, "NameEdit");
getWidget(mCancelButton, "CancelButton"); getWidget(mCancelButton, "CancelButton");
@ -62,11 +61,6 @@ namespace MWGui
mName->eventEditSelectAccept += MyGUI::newDelegate(this, &EnchantingDialog::onAccept); mName->eventEditSelectAccept += MyGUI::newDelegate(this, &EnchantingDialog::onAccept);
} }
EnchantingDialog::~EnchantingDialog()
{
delete mItemSelectionDialog;
}
void EnchantingDialog::onOpen() void EnchantingDialog::onOpen()
{ {
center(); center();
@ -195,8 +189,7 @@ namespace MWGui
{ {
if (mEnchanting.getOldItem().isEmpty()) if (mEnchanting.getOldItem().isEmpty())
{ {
delete mItemSelectionDialog; mItemSelectionDialog = std::make_unique<ItemSelectionDialog>("#{sEnchantItems}");
mItemSelectionDialog = new ItemSelectionDialog("#{sEnchantItems}");
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onItemSelected); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onItemSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onItemCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onItemCancel);
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);
@ -250,8 +243,7 @@ namespace MWGui
{ {
if (mEnchanting.getGem().isEmpty()) if (mEnchanting.getGem().isEmpty())
{ {
delete mItemSelectionDialog; mItemSelectionDialog = std::make_unique<ItemSelectionDialog>("#{sSoulGemsWithSouls}");
mItemSelectionDialog = new ItemSelectionDialog("#{sSoulGemsWithSouls}");
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel);
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);

View file

@ -1,6 +1,9 @@
#ifndef MWGUI_ENCHANTINGDIALOG_H #ifndef MWGUI_ENCHANTINGDIALOG_H
#define MWGUI_ENCHANTINGDIALOG_H #define MWGUI_ENCHANTINGDIALOG_H
#include <memory>
#include "itemselection.hpp"
#include "spellcreationdialog.hpp" #include "spellcreationdialog.hpp"
#include "../mwmechanics/enchanting.hpp" #include "../mwmechanics/enchanting.hpp"
@ -8,14 +11,13 @@
namespace MWGui namespace MWGui
{ {
class ItemSelectionDialog;
class ItemWidget; class ItemWidget;
class EnchantingDialog : public WindowBase, public ReferenceInterface, public EffectEditorBase class EnchantingDialog : public WindowBase, public ReferenceInterface, public EffectEditorBase
{ {
public: public:
EnchantingDialog(); EnchantingDialog();
virtual ~EnchantingDialog(); virtual ~EnchantingDialog() = default;
void onOpen() override; void onOpen() override;
@ -48,7 +50,7 @@ namespace MWGui
void onTypeButtonClicked(MyGUI::Widget* sender); void onTypeButtonClicked(MyGUI::Widget* sender);
void onAccept(MyGUI::EditBox* sender); void onAccept(MyGUI::EditBox* sender);
ItemSelectionDialog* mItemSelectionDialog; std::unique_ptr<ItemSelectionDialog> mItemSelectionDialog;
MyGUI::Widget* mChanceLayout; MyGUI::Widget* mChanceLayout;

View file

@ -163,7 +163,7 @@ namespace MWGui
mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver); mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver);
mMainWidget->eventMouseLostFocus += MyGUI::newDelegate(this, &HUD::onWorldMouseLostFocus); mMainWidget->eventMouseLostFocus += MyGUI::newDelegate(this, &HUD::onWorldMouseLostFocus);
mSpellIcons = new SpellIcons(); mSpellIcons = std::make_unique<SpellIcons>();
} }
HUD::~HUD() HUD::~HUD()
@ -171,8 +171,6 @@ namespace MWGui
mMainWidget->eventMouseLostFocus.clear(); mMainWidget->eventMouseLostFocus.clear();
mMainWidget->eventMouseMove.clear(); mMainWidget->eventMouseMove.clear();
mMainWidget->eventMouseButtonClick.clear(); mMainWidget->eventMouseButtonClick.clear();
delete mSpellIcons;
} }
void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<float>& value) void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<float>& value)

View file

@ -1,7 +1,10 @@
#ifndef OPENMW_GAME_MWGUI_HUD_H #ifndef OPENMW_GAME_MWGUI_HUD_H
#define OPENMW_GAME_MWGUI_HUD_H #define OPENMW_GAME_MWGUI_HUD_H
#include <memory>
#include "mapwindow.hpp" #include "mapwindow.hpp"
#include "spellicons.hpp"
#include "statswatcher.hpp" #include "statswatcher.hpp"
namespace MWWorld namespace MWWorld
@ -12,7 +15,6 @@ namespace MWWorld
namespace MWGui namespace MWGui
{ {
class DragAndDrop; class DragAndDrop;
class SpellIcons;
class ItemWidget; class ItemWidget;
class SpellWidget; class SpellWidget;
@ -95,7 +97,7 @@ namespace MWGui
bool mWorldMouseOver; bool mWorldMouseOver;
SpellIcons* mSpellIcons; std::unique_ptr<SpellIcons> mSpellIcons;
int mEnemyActorId; int mEnemyActorId;
float mEnemyHealthTimer; float mEnemyHealthTimer;

View file

@ -122,17 +122,20 @@ namespace MWGui
void InventoryWindow::updatePlayer() void InventoryWindow::updatePlayer()
{ {
mPtr = MWBase::Environment::get().getWorld ()->getPlayerPtr(); mPtr = MWBase::Environment::get().getWorld ()->getPlayerPtr();
mTradeModel = new TradeItemModel(new InventoryItemModel(mPtr), MWWorld::Ptr()); auto tradeModel = std::make_unique<TradeItemModel>(std::make_unique<InventoryItemModel>(mPtr), MWWorld::Ptr());
mTradeModel = tradeModel.get();
if (mSortModel) // reuse existing SortModel when possible to keep previous category/filter settings if (mSortModel) // reuse existing SortModel when possible to keep previous category/filter settings
mSortModel->setSourceModel(mTradeModel); mSortModel->setSourceModel(std::move(tradeModel));
else else
mSortModel = new SortFilterItemModel(mTradeModel); {
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(tradeModel));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
}
mSortModel->setNameFilter(mFilterEdit->getCaption()); mSortModel->setNameFilter(mFilterEdit->getCaption());
mItemView->setModel(mSortModel);
mFilterAll->setStateSelected(true); mFilterAll->setStateSelected(true);
mFilterWeapon->setStateSelected(false); mFilterWeapon->setStateSelected(false);
mFilterApparel->setStateSelected(false); mFilterApparel->setStateSelected(false);
@ -776,7 +779,7 @@ namespace MWGui
ItemModel::ModelIndex selected = -1; ItemModel::ModelIndex selected = -1;
// not using mSortFilterModel as we only need sorting, not filtering // not using mSortFilterModel as we only need sorting, not filtering
SortFilterItemModel model(new InventoryItemModel(player)); SortFilterItemModel model(std::make_unique<InventoryItemModel>(player));
model.setSortByType(false); model.setSortByType(false);
model.update(); model.update();
if (model.getItemCount() == 0) if (model.getItemCount() == 0)

View file

@ -79,17 +79,6 @@ namespace MWGui
return true; return true;
} }
ProxyItemModel::ProxyItemModel()
: mSourceModel(nullptr)
{
}
ProxyItemModel::~ProxyItemModel()
{
delete mSourceModel;
}
bool ProxyItemModel::allowedToUseItems() const bool ProxyItemModel::allowedToUseItems() const
{ {
return mSourceModel->allowedToUseItems(); return mSourceModel->allowedToUseItems();
@ -134,18 +123,9 @@ namespace MWGui
return mSourceModel->getIndex(item); return mSourceModel->getIndex(item);
} }
void ProxyItemModel::setSourceModel(ItemModel *sourceModel) void ProxyItemModel::setSourceModel(std::unique_ptr<ItemModel> sourceModel)
{ {
if (mSourceModel == sourceModel) mSourceModel = std::move(sourceModel);
return;
if (mSourceModel)
{
delete mSourceModel;
mSourceModel = nullptr;
}
mSourceModel = sourceModel;
} }
void ProxyItemModel::onClose() void ProxyItemModel::onClose()

View file

@ -1,6 +1,8 @@
#ifndef MWGUI_ITEM_MODEL_H #ifndef MWGUI_ITEM_MODEL_H
#define MWGUI_ITEM_MODEL_H #define MWGUI_ITEM_MODEL_H
#include <memory>
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
namespace MWGui namespace MWGui
@ -87,8 +89,8 @@ namespace MWGui
class ProxyItemModel : public ItemModel class ProxyItemModel : public ItemModel
{ {
public: public:
ProxyItemModel(); ProxyItemModel() = default;
virtual ~ProxyItemModel(); virtual ~ProxyItemModel() = default;
bool allowedToUseItems() const override; bool allowedToUseItems() const override;
@ -101,14 +103,14 @@ namespace MWGui
ModelIndex getIndex (const ItemStack &item) override; ModelIndex getIndex (const ItemStack &item) override;
/// @note Takes ownership of the passed pointer. /// @note Takes ownership of the passed pointer.
void setSourceModel(ItemModel* sourceModel); void setSourceModel(std::unique_ptr<ItemModel> sourceModel);
ModelIndex mapToSource (ModelIndex index); ModelIndex mapToSource (ModelIndex index);
ModelIndex mapFromSource (ModelIndex index); ModelIndex mapFromSource (ModelIndex index);
bool usesContainer(const MWWorld::Ptr& container) override; bool usesContainer(const MWWorld::Ptr& container) override;
protected: protected:
ItemModel* mSourceModel; std::unique_ptr<ItemModel> mSourceModel;
}; };
} }

View file

@ -13,7 +13,6 @@ namespace MWGui
ItemSelectionDialog::ItemSelectionDialog(const std::string &label) ItemSelectionDialog::ItemSelectionDialog(const std::string &label)
: WindowModal("openmw_itemselection_dialog.layout") : WindowModal("openmw_itemselection_dialog.layout")
, mSortModel(nullptr) , mSortModel(nullptr)
, mModel(nullptr)
{ {
getWidget(mItemView, "ItemView"); getWidget(mItemView, "ItemView");
mItemView->eventItemClicked += MyGUI::newDelegate(this, &ItemSelectionDialog::onSelectedItem); mItemView->eventItemClicked += MyGUI::newDelegate(this, &ItemSelectionDialog::onSelectedItem);
@ -37,9 +36,9 @@ namespace MWGui
void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container) void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container)
{ {
mModel = new InventoryItemModel(container); auto sortModel = std::make_unique<SortFilterItemModel>(std::make_unique<InventoryItemModel>(container));
mSortModel = new SortFilterItemModel(mModel); mSortModel = sortModel.get();
mItemView->setModel(mSortModel); mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars(); mItemView->resetScrollBars();
} }

View file

@ -14,7 +14,6 @@ namespace MWGui
{ {
class ItemView; class ItemView;
class SortFilterItemModel; class SortFilterItemModel;
class InventoryItemModel;
class ItemSelectionDialog : public WindowModal class ItemSelectionDialog : public WindowModal
{ {
@ -36,7 +35,6 @@ namespace MWGui
private: private:
ItemView* mItemView; ItemView* mItemView;
SortFilterItemModel* mSortModel; SortFilterItemModel* mSortModel;
InventoryItemModel* mModel;
void onSelectedItem(int index); void onSelectedItem(int index);

View file

@ -16,23 +16,13 @@ namespace MWGui
{ {
ItemView::ItemView() ItemView::ItemView()
: mModel(nullptr) : mScrollView(nullptr)
, mScrollView(nullptr)
{ {
} }
ItemView::~ItemView() void ItemView::setModel(std::unique_ptr<ItemModel> model)
{ {
delete mModel; mModel = std::move(model);
}
void ItemView::setModel(ItemModel *model)
{
if (mModel == model)
return;
delete mModel;
mModel = model;
update(); update();
} }
@ -114,7 +104,7 @@ void ItemView::update()
ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon", ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default); MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default);
itemWidget->setUserString("ToolTipType", "ItemModelIndex"); itemWidget->setUserString("ToolTipType", "ItemModelIndex");
itemWidget->setUserData(std::make_pair(i, mModel)); itemWidget->setUserData(std::make_pair(i, mModel.get()));
ItemWidget::ItemState state = ItemWidget::None; ItemWidget::ItemState state = ItemWidget::None;
if (item.mType == ItemStack::Type_Barter) if (item.mType == ItemStack::Type_Barter)
state = ItemWidget::Barter; state = ItemWidget::Barter;

View file

@ -13,13 +13,12 @@ namespace MWGui
MYGUI_RTTI_DERIVED(ItemView) MYGUI_RTTI_DERIVED(ItemView)
public: public:
ItemView(); ItemView();
~ItemView() override;
/// Register needed components with MyGUI's factory manager /// Register needed components with MyGUI's factory manager
static void registerComponents (); static void registerComponents ();
/// Takes ownership of \a model /// Takes ownership of \a model
void setModel (ItemModel* model); void setModel(std::unique_ptr<ItemModel> model);
typedef MyGUI::delegates::CMultiDelegate1<ItemModel::ModelIndex> EventHandle_ModelIndex; typedef MyGUI::delegates::CMultiDelegate1<ItemModel::ModelIndex> EventHandle_ModelIndex;
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void; typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
@ -44,7 +43,7 @@ namespace MWGui
void onSelectedBackground (MyGUI::Widget* sender); void onSelectedBackground (MyGUI::Widget* sender);
void onMouseWheelMoved(MyGUI::Widget* _sender, int _rel); void onMouseWheelMoved(MyGUI::Widget* _sender, int _rel);
ItemModel* mModel; std::unique_ptr<ItemModel> mModel;
MyGUI::ScrollView* mScrollView; MyGUI::ScrollView* mScrollView;
}; };

View file

@ -648,9 +648,9 @@ namespace
} }
// glue the implementation to the interface // glue the implementation to the interface
MWGui::JournalWindow * MWGui::JournalWindow::create (JournalViewModel::Ptr Model, bool questList, ToUTF8::FromType encoding) std::unique_ptr<MWGui::JournalWindow> MWGui::JournalWindow::create(JournalViewModel::Ptr Model, bool questList, ToUTF8::FromType encoding)
{ {
return new JournalWindowImpl (Model, questList, encoding); return std::make_unique<JournalWindowImpl>(Model, questList, encoding);
} }
MWGui::JournalWindow::JournalWindow() MWGui::JournalWindow::JournalWindow()

View file

@ -18,7 +18,7 @@ namespace MWGui
JournalWindow(); JournalWindow();
/// construct a new instance of the one JournalWindow implementation /// construct a new instance of the one JournalWindow implementation
static JournalWindow * create (std::shared_ptr <JournalViewModel> Model, bool questList, ToUTF8::FromType encoding); static std::unique_ptr<JournalWindow> create(std::shared_ptr<JournalViewModel> Model, bool questList, ToUTF8::FromType encoding);
/// destroy this instance of the JournalWindow implementation /// destroy this instance of the JournalWindow implementation
virtual ~JournalWindow () {} virtual ~JournalWindow () {}

View file

@ -28,7 +28,6 @@ namespace MWGui
, mBackground(nullptr) , mBackground(nullptr)
, mVideoBackground(nullptr) , mVideoBackground(nullptr)
, mVideo(nullptr) , mVideo(nullptr)
, mSaveGameDialog(nullptr)
{ {
getWidget(mVersionText, "VersionText"); getWidget(mVersionText, "VersionText");
mVersionText->setCaption(versionDescription); mVersionText->setCaption(versionDescription);
@ -38,11 +37,6 @@ namespace MWGui
updateMenu(); updateMenu();
} }
MainMenu::~MainMenu()
{
delete mSaveGameDialog;
}
void MainMenu::onResChange(int w, int h) void MainMenu::onResChange(int w, int h)
{ {
mWidth = w; mWidth = w;
@ -133,7 +127,7 @@ namespace MWGui
else else
{ {
if (!mSaveGameDialog) if (!mSaveGameDialog)
mSaveGameDialog = new SaveGameDialog(); mSaveGameDialog = std::make_unique<SaveGameDialog>();
if (name == "loadgame") if (name == "loadgame")
mSaveGameDialog->setLoadOrSave(true); mSaveGameDialog->setLoadOrSave(true);
else if (name == "savegame") else if (name == "savegame")

View file

@ -1,6 +1,9 @@
#ifndef OPENMW_GAME_MWGUI_MAINMENU_H #ifndef OPENMW_GAME_MWGUI_MAINMENU_H
#define OPENMW_GAME_MWGUI_MAINMENU_H #define OPENMW_GAME_MWGUI_MAINMENU_H
#include <memory>
#include "savegamedialog.hpp"
#include "windowbase.hpp" #include "windowbase.hpp"
namespace Gui namespace Gui
@ -17,7 +20,6 @@ namespace MWGui
{ {
class BackgroundImage; class BackgroundImage;
class SaveGameDialog;
class VideoWidget; class VideoWidget;
class MainMenu : public WindowBase class MainMenu : public WindowBase
@ -30,7 +32,6 @@ namespace MWGui
public: public:
MainMenu(int w, int h, const VFS::Manager* vfs, const std::string& versionDescription); MainMenu(int w, int h, const VFS::Manager* vfs, const std::string& versionDescription);
~MainMenu();
void onResChange(int w, int h) override; void onResChange(int w, int h) override;
@ -61,7 +62,7 @@ namespace MWGui
void updateMenu(); void updateMenu();
SaveGameDialog* mSaveGameDialog; std::unique_ptr<SaveGameDialog> mSaveGameDialog;
}; };
} }

View file

@ -18,7 +18,6 @@ namespace MWGui
MessageBoxManager::MessageBoxManager (float timePerChar) MessageBoxManager::MessageBoxManager (float timePerChar)
{ {
mInterMessageBoxe = nullptr;
mStaticMessageBox = nullptr; mStaticMessageBox = nullptr;
mLastButtonPressed = -1; mLastButtonPressed = -1;
mMessageBoxSpeed = timePerChar; mMessageBoxSpeed = timePerChar;
@ -39,31 +38,22 @@ namespace MWGui
if (mInterMessageBoxe) if (mInterMessageBoxe)
{ {
mInterMessageBoxe->setVisible(false); mInterMessageBoxe->setVisible(false);
mInterMessageBoxe.reset();
delete mInterMessageBoxe;
mInterMessageBoxe = nullptr;
} }
for (MessageBox* messageBox : mMessageBoxes)
{
if (messageBox == mStaticMessageBox)
mStaticMessageBox = nullptr;
delete messageBox;
}
mMessageBoxes.clear(); mMessageBoxes.clear();
mStaticMessageBox = nullptr;
mLastButtonPressed = -1; mLastButtonPressed = -1;
} }
void MessageBoxManager::onFrame (float frameDuration) void MessageBoxManager::onFrame (float frameDuration)
{ {
std::vector<MessageBox*>::iterator it; for(auto it = mMessageBoxes.begin(); it != mMessageBoxes.end();)
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end();)
{ {
(*it)->mCurrentTime += frameDuration; (*it)->mCurrentTime += frameDuration;
if((*it)->mCurrentTime >= (*it)->mMaxTime && *it != mStaticMessageBox) if((*it)->mCurrentTime >= (*it)->mMaxTime && it->get() != mStaticMessageBox)
{ {
delete *it;
it = mMessageBoxes.erase(it); it = mMessageBoxes.erase(it);
} }
else else
@ -71,7 +61,7 @@ namespace MWGui
} }
float height = 0; float height = 0;
it = mMessageBoxes.begin(); auto it = mMessageBoxes.begin();
while(it != mMessageBoxes.end()) while(it != mMessageBoxes.end())
{ {
(*it)->update(static_cast<int>(height)); (*it)->update(static_cast<int>(height));
@ -82,8 +72,7 @@ namespace MWGui
if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) { if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) {
mLastButtonPressed = mInterMessageBoxe->readPressedButton(); mLastButtonPressed = mInterMessageBoxe->readPressedButton();
mInterMessageBoxe->setVisible(false); mInterMessageBoxe->setVisible(false);
delete mInterMessageBoxe; mInterMessageBoxe.reset();
mInterMessageBoxe = nullptr;
MWBase::Environment::get().getInputManager()->changeInputMode( MWBase::Environment::get().getInputManager()->changeInputMode(
MWBase::Environment::get().getWindowManager()->isGuiMode()); MWBase::Environment::get().getWindowManager()->isGuiMode());
} }
@ -91,25 +80,24 @@ namespace MWGui
void MessageBoxManager::createMessageBox(std::string_view message, bool stat) void MessageBoxManager::createMessageBox(std::string_view message, bool stat)
{ {
MessageBox *box = new MessageBox(*this, message); auto box = std::make_unique<MessageBox>(*this, message);
box->mCurrentTime = 0; box->mCurrentTime = 0;
auto realMessage = MyGUI::LanguageManager::getInstance().replaceTags({message.data(), message.size()}); auto realMessage = MyGUI::LanguageManager::getInstance().replaceTags({message.data(), message.size()});
box->mMaxTime = realMessage.length()*mMessageBoxSpeed; box->mMaxTime = realMessage.length()*mMessageBoxSpeed;
if(stat) if(stat)
mStaticMessageBox = box; mStaticMessageBox = box.get();
box->setVisible(mVisible); box->setVisible(mVisible);
mMessageBoxes.push_back(box); mMessageBoxes.push_back(std::move(box));
if(mMessageBoxes.size() > 3) { if(mMessageBoxes.size() > 3) {
delete *mMessageBoxes.begin();
mMessageBoxes.erase(mMessageBoxes.begin()); mMessageBoxes.erase(mMessageBoxes.begin());
} }
int height = 0; int height = 0;
for (MessageBox* messageBox : mMessageBoxes) for (const auto& messageBox : mMessageBoxes)
{ {
messageBox->update(height); messageBox->update(height);
height += messageBox->getHeight(); height += messageBox->getHeight();
@ -128,11 +116,9 @@ namespace MWGui
{ {
Log(Debug::Warning) << "Warning: replacing an interactive message box that was not answered yet"; Log(Debug::Warning) << "Warning: replacing an interactive message box that was not answered yet";
mInterMessageBoxe->setVisible(false); mInterMessageBoxe->setVisible(false);
delete mInterMessageBoxe;
mInterMessageBoxe = nullptr;
} }
mInterMessageBoxe = new InteractiveMessageBox(*this, std::string{message}, buttons); mInterMessageBoxe = std::make_unique<InteractiveMessageBox>(*this, std::string{message}, buttons);
mLastButtonPressed = -1; mLastButtonPressed = -1;
return true; return true;
@ -145,12 +131,10 @@ namespace MWGui
bool MessageBoxManager::removeMessageBox (MessageBox *msgbox) bool MessageBoxManager::removeMessageBox (MessageBox *msgbox)
{ {
std::vector<MessageBox*>::iterator it; for(auto it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it)
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it)
{ {
if((*it) == msgbox) if(it->get() == msgbox)
{ {
delete (*it);
mMessageBoxes.erase(it); mMessageBoxes.erase(it);
return true; return true;
} }
@ -158,7 +142,7 @@ namespace MWGui
return false; return false;
} }
const std::vector<MessageBox*> MessageBoxManager::getActiveMessageBoxes() const std::vector<std::unique_ptr<MessageBox>>& MessageBoxManager::getActiveMessageBoxes() const
{ {
return mMessageBoxes; return mMessageBoxes;
} }
@ -174,7 +158,7 @@ namespace MWGui
void MessageBoxManager::setVisible(bool value) void MessageBoxManager::setVisible(bool value)
{ {
mVisible = value; mVisible = value;
for (MessageBox* messageBox : mMessageBoxes) for (const auto& messageBox : mMessageBoxes)
messageBox->setVisible(value); messageBox->setVisible(value);
} }

View file

@ -1,6 +1,8 @@
#ifndef MWGUI_MESSAGE_BOX_H #ifndef MWGUI_MESSAGE_BOX_H
#define MWGUI_MESSAGE_BOX_H #define MWGUI_MESSAGE_BOX_H
#include <memory>
#include "windowbase.hpp" #include "windowbase.hpp"
namespace MyGUI namespace MyGUI
@ -28,7 +30,7 @@ namespace MWGui
int getMessagesCount(); int getMessagesCount();
const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe; } const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe.get(); }
/// Remove all message boxes /// Remove all message boxes
void clear(); void clear();
@ -47,11 +49,11 @@ namespace MWGui
void setVisible(bool value); void setVisible(bool value);
const std::vector<MessageBox*> getActiveMessageBoxes(); const std::vector<std::unique_ptr<MessageBox>>& getActiveMessageBoxes() const;
private: private:
std::vector<MessageBox*> mMessageBoxes; std::vector<std::unique_ptr<MessageBox>> mMessageBoxes;
InteractiveMessageBox* mInterMessageBoxe; std::unique_ptr<InteractiveMessageBox> mInterMessageBoxe;
MessageBox* mStaticMessageBox; MessageBox* mStaticMessageBox;
float mMessageBoxSpeed; float mMessageBoxSpeed;
int mLastButtonPressed; int mLastButtonPressed;

View file

@ -17,11 +17,11 @@
namespace MWGui namespace MWGui
{ {
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, ItemModel *sourceModel, bool hideItems) PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, std::unique_ptr<ItemModel> sourceModel, bool hideItems)
: mActor(actor), mPickpocketDetected(false) : mActor(actor), mPickpocketDetected(false)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
mSourceModel = sourceModel; mSourceModel = std::move(sourceModel);
float chance = player.getClass().getSkill(player, ESM::Skill::Sneak); float chance = player.getClass().getSkill(player, ESM::Skill::Sneak);
mSourceModel->update(); mSourceModel->update();

View file

@ -10,7 +10,7 @@ namespace MWGui
class PickpocketItemModel : public ProxyItemModel class PickpocketItemModel : public ProxyItemModel
{ {
public: public:
PickpocketItemModel (const MWWorld::Ptr& thief, ItemModel* sourceModel, bool hideItems=true); PickpocketItemModel(const MWWorld::Ptr& thief, std::unique_ptr<ItemModel> sourceModel, bool hideItems = true);
bool allowedToUseItems() const override; bool allowedToUseItems() const override;
ItemStack getItem (ModelIndex index) override; ItemStack getItem (ModelIndex index) override;

View file

@ -39,9 +39,6 @@ namespace MWGui
, mKey(std::vector<keyData>(10)) , mKey(std::vector<keyData>(10))
, mSelected(nullptr) , mSelected(nullptr)
, mActivated(nullptr) , mActivated(nullptr)
, mAssignDialog(nullptr)
, mItemSelectionDialog(nullptr)
, mMagicSelectionDialog(nullptr)
{ {
getWidget(mOkButton, "OKButton"); getWidget(mOkButton, "OKButton");
@ -74,13 +71,6 @@ namespace MWGui
} }
} }
QuickKeysMenu::~QuickKeysMenu()
{
delete mAssignDialog;
delete mItemSelectionDialog;
delete mMagicSelectionDialog;
}
inline void QuickKeysMenu::validate(int index) inline void QuickKeysMenu::validate(int index)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
@ -194,7 +184,7 @@ namespace MWGui
// open assign dialog // open assign dialog
if (!mAssignDialog) if (!mAssignDialog)
mAssignDialog = new QuickKeysMenuAssign(this); mAssignDialog = std::make_unique<QuickKeysMenuAssign>(this);
mAssignDialog->setVisible(true); mAssignDialog->setVisible(true);
} }
@ -208,7 +198,7 @@ namespace MWGui
{ {
if (!mItemSelectionDialog) if (!mItemSelectionDialog)
{ {
mItemSelectionDialog = new ItemSelectionDialog("#{sQuickMenu6}"); mItemSelectionDialog = std::make_unique<ItemSelectionDialog>("#{sQuickMenu6}");
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItem); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItem);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItemCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItemCancel);
} }
@ -223,7 +213,7 @@ namespace MWGui
{ {
if (!mMagicSelectionDialog) if (!mMagicSelectionDialog)
{ {
mMagicSelectionDialog = new MagicSelectionDialog(this); mMagicSelectionDialog = std::make_unique<MagicSelectionDialog>(this);
} }
mMagicSelectionDialog->setVisible(true); mMagicSelectionDialog->setVisible(true);

View file

@ -1,15 +1,16 @@
#ifndef MWGUI_QUICKKEYS_H #ifndef MWGUI_QUICKKEYS_H
#define MWGUI_QUICKKEYS_H #define MWGUI_QUICKKEYS_H
#include "windowbase.hpp" #include <memory>
#include "itemselection.hpp"
#include "spellmodel.hpp" #include "spellmodel.hpp"
#include "windowbase.hpp"
namespace MWGui namespace MWGui
{ {
class QuickKeysMenuAssign; class QuickKeysMenuAssign;
class ItemSelectionDialog;
class MagicSelectionDialog; class MagicSelectionDialog;
class ItemWidget; class ItemWidget;
class SpellView; class SpellView;
@ -18,7 +19,6 @@ namespace MWGui
{ {
public: public:
QuickKeysMenu(); QuickKeysMenu();
~QuickKeysMenu();
void onResChange(int, int) override { center(); } void onResChange(int, int) override { center(); }
@ -71,9 +71,9 @@ namespace MWGui
MyGUI::EditBox* mInstructionLabel; MyGUI::EditBox* mInstructionLabel;
MyGUI::Button* mOkButton; MyGUI::Button* mOkButton;
QuickKeysMenuAssign* mAssignDialog; std::unique_ptr<QuickKeysMenuAssign> mAssignDialog;
ItemSelectionDialog* mItemSelectionDialog; std::unique_ptr<ItemSelectionDialog> mItemSelectionDialog;
MagicSelectionDialog* mMagicSelectionDialog; std::unique_ptr<MagicSelectionDialog> mMagicSelectionDialog;
void onQuickKeyButtonClicked(MyGUI::Widget* sender); void onQuickKeyButtonClicked(MyGUI::Widget* sender);
void onOkButtonClicked(MyGUI::Widget* sender); void onOkButtonClicked(MyGUI::Widget* sender);

View file

@ -47,7 +47,7 @@ void Recharge::onOpen()
{ {
center(); center();
SortFilterItemModel * model = new SortFilterItemModel(new InventoryItemModel(MWMechanics::getPlayer())); SortFilterItemModel * model = new SortFilterItemModel(std::make_unique<InventoryItemModel>(MWMechanics::getPlayer()));
model->setFilter(SortFilterItemModel::Filter_OnlyRechargable); model->setFilter(SortFilterItemModel::Filter_OnlyRechargable);
mBox->setModel(model); mBox->setModel(model);

View file

@ -46,7 +46,7 @@ void Repair::onOpen()
{ {
center(); center();
SortFilterItemModel * model = new SortFilterItemModel(new InventoryItemModel(MWMechanics::getPlayer())); SortFilterItemModel * model = new SortFilterItemModel(std::make_unique<InventoryItemModel>(MWMechanics::getPlayer()));
model->setFilter(SortFilterItemModel::Filter_OnlyRepairable); model->setFilter(SortFilterItemModel::Filter_OnlyRepairable);
mRepairBox->setModel(model); mRepairBox->setModel(model);

View file

@ -152,14 +152,12 @@ namespace
namespace MWGui namespace MWGui
{ {
SortFilterItemModel::SortFilterItemModel(ItemModel *sourceModel) SortFilterItemModel::SortFilterItemModel(std::unique_ptr<ItemModel> sourceModel)
: mCategory(Category_All) : mCategory(Category_All)
, mFilter(0) , mFilter(0)
, mSortByType(true) , mSortByType(true)
, mNameFilter("")
, mEffectFilter("")
{ {
mSourceModel = sourceModel; mSourceModel = std::move(sourceModel);
} }
bool SortFilterItemModel::allowedToUseItems() const bool SortFilterItemModel::allowedToUseItems() const

View file

@ -9,7 +9,7 @@ namespace MWGui
class SortFilterItemModel : public ProxyItemModel class SortFilterItemModel : public ProxyItemModel
{ {
public: public:
SortFilterItemModel (ItemModel* sourceModel); SortFilterItemModel(std::unique_ptr<ItemModel> sourceModel);
void update() override; void update() override;

View file

@ -34,7 +34,7 @@ namespace MWGui
, mSpellView(nullptr) , mSpellView(nullptr)
, mUpdateTimer(0.0f) , mUpdateTimer(0.0f)
{ {
mSpellIcons = new SpellIcons(); mSpellIcons = std::make_unique<SpellIcons>();
MyGUI::Widget* deleteButton; MyGUI::Widget* deleteButton;
getWidget(deleteButton, "DeleteSpellButton"); getWidget(deleteButton, "DeleteSpellButton");
@ -54,11 +54,6 @@ namespace MWGui
mFilterEdit->setSize(filterWidth, mFilterEdit->getSize().height); mFilterEdit->setSize(filterWidth, mFilterEdit->getSize().height);
} }
SpellWindow::~SpellWindow()
{
delete mSpellIcons;
}
void SpellWindow::onPinToggled() void SpellWindow::onPinToggled()
{ {
Settings::Manager::setBool("spells pin", "Windows", mPinned); Settings::Manager::setBool("spells pin", "Windows", mPinned);

View file

@ -1,20 +1,20 @@
#ifndef MWGUI_SPELLWINDOW_H #ifndef MWGUI_SPELLWINDOW_H
#define MWGUI_SPELLWINDOW_H #define MWGUI_SPELLWINDOW_H
#include "windowpinnablebase.hpp" #include <memory>
#include "spellicons.hpp"
#include "spellmodel.hpp" #include "spellmodel.hpp"
#include "windowpinnablebase.hpp"
namespace MWGui namespace MWGui
{ {
class SpellIcons;
class SpellView; class SpellView;
class SpellWindow : public WindowPinnableBase, public NoDrop class SpellWindow : public WindowPinnableBase, public NoDrop
{ {
public: public:
SpellWindow(DragAndDrop* drag); SpellWindow(DragAndDrop* drag);
virtual ~SpellWindow();
void updateSpells(); void updateSpells();
@ -41,7 +41,7 @@ namespace MWGui
void onOpen() override; void onOpen() override;
SpellView* mSpellView; SpellView* mSpellView;
SpellIcons* mSpellIcons; std::unique_ptr<SpellIcons> mSpellIcons;
MyGUI::EditBox* mFilterEdit; MyGUI::EditBox* mFilterEdit;
private: private:

View file

@ -10,10 +10,10 @@
namespace MWGui namespace MWGui
{ {
TradeItemModel::TradeItemModel(ItemModel *sourceModel, const MWWorld::Ptr& merchant) TradeItemModel::TradeItemModel(std::unique_ptr<ItemModel> sourceModel, const MWWorld::Ptr& merchant)
: mMerchant(merchant) : mMerchant(merchant)
{ {
mSourceModel = sourceModel; mSourceModel = std::move(sourceModel);
} }
bool TradeItemModel::allowedToUseItems() const bool TradeItemModel::allowedToUseItems() const

View file

@ -13,7 +13,7 @@ namespace MWGui
class TradeItemModel : public ProxyItemModel class TradeItemModel : public ProxyItemModel
{ {
public: public:
TradeItemModel (ItemModel* sourceModel, const MWWorld::Ptr& merchant); TradeItemModel(std::unique_ptr<ItemModel> sourceModel, const MWWorld::Ptr& merchant);
bool allowedToUseItems() const override; bool allowedToUseItems() const override;

View file

@ -114,9 +114,11 @@ namespace MWGui
std::vector<MWWorld::Ptr> worldItems; std::vector<MWWorld::Ptr> worldItems;
MWBase::Environment::get().getWorld()->getItemsOwnedBy(actor, worldItems); MWBase::Environment::get().getWorld()->getItemsOwnedBy(actor, worldItems);
mTradeModel = new TradeItemModel(new ContainerItemModel(itemSources, worldItems), mPtr); auto tradeModel = std::make_unique<TradeItemModel>(std::make_unique<ContainerItemModel>(itemSources, worldItems), mPtr);
mSortModel = new SortFilterItemModel(mTradeModel); mTradeModel = tradeModel.get();
mItemView->setModel (mSortModel); auto sortModel = std::make_unique<SortFilterItemModel>(std::move(tradeModel));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars(); mItemView->resetScrollBars();
updateLabels(); updateLabels();

View file

@ -13,7 +13,6 @@
#include <MyGUI_LanguageManager.h> #include <MyGUI_LanguageManager.h>
#include <MyGUI_PointerManager.h> #include <MyGUI_PointerManager.h>
#include <MyGUI_InputManager.h> #include <MyGUI_InputManager.h>
#include <MyGUI_Gui.h>
#include <MyGUI_ClipboardManager.h> #include <MyGUI_ClipboardManager.h>
// For BT_NO_PROFILE // For BT_NO_PROFILE
@ -24,9 +23,6 @@
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/sdlutil/sdlcursormanager.hpp>
#include <components/sdlutil/sdlvideowrapper.hpp>
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp> #include <components/esm3/esmwriter.hpp>
@ -71,17 +67,13 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwrender/localmap.hpp"
#include "../mwrender/postprocessor.hpp" #include "../mwrender/postprocessor.hpp"
#include "console.hpp" #include "console.hpp"
#include "journalwindow.hpp" #include "journalwindow.hpp"
#include "journalviewmodel.hpp" #include "journalviewmodel.hpp"
#include "charactercreation.hpp"
#include "dialogue.hpp" #include "dialogue.hpp"
#include "statswindow.hpp" #include "statswindow.hpp"
#include "messagebox.hpp"
#include "tooltips.hpp"
#include "scrollwindow.hpp" #include "scrollwindow.hpp"
#include "bookwindow.hpp" #include "bookwindow.hpp"
#include "hud.hpp" #include "hud.hpp"
@ -105,7 +97,6 @@
#include "cursor.hpp" #include "cursor.hpp"
#include "merchantrepair.hpp" #include "merchantrepair.hpp"
#include "repair.hpp" #include "repair.hpp"
#include "soulgemdialog.hpp"
#include "companionwindow.hpp" #include "companionwindow.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
#include "bookpage.hpp" #include "bookpage.hpp"
@ -117,7 +108,6 @@
#include "debugwindow.hpp" #include "debugwindow.hpp"
#include "postprocessorhud.hpp" #include "postprocessorhud.hpp"
#include "spellview.hpp" #include "spellview.hpp"
#include "draganddrop.hpp"
#include "container.hpp" #include "container.hpp"
#include "controllers.hpp" #include "controllers.hpp"
#include "jailscreen.hpp" #include "jailscreen.hpp"
@ -142,13 +132,9 @@ namespace MWGui
, mCurrentModals() , mCurrentModals()
, mHud(nullptr) , mHud(nullptr)
, mMap(nullptr) , mMap(nullptr)
, mLocalMapRender(nullptr)
, mToolTips(nullptr)
, mStatsWindow(nullptr) , mStatsWindow(nullptr)
, mMessageBoxManager(nullptr)
, mConsole(nullptr) , mConsole(nullptr)
, mDialogueWindow(nullptr) , mDialogueWindow(nullptr)
, mDragAndDrop(nullptr)
, mInventoryWindow(nullptr) , mInventoryWindow(nullptr)
, mScrollWindow(nullptr) , mScrollWindow(nullptr)
, mBookWindow(nullptr) , mBookWindow(nullptr)
@ -160,7 +146,6 @@ namespace MWGui
, mQuickKeysMenu(nullptr) , mQuickKeysMenu(nullptr)
, mLoadingScreen(nullptr) , mLoadingScreen(nullptr)
, mWaitDialog(nullptr) , mWaitDialog(nullptr)
, mSoulgemDialog(nullptr)
, mVideoBackground(nullptr) , mVideoBackground(nullptr)
, mVideoWidget(nullptr) , mVideoWidget(nullptr)
, mWerewolfFader(nullptr) , mWerewolfFader(nullptr)
@ -172,7 +157,6 @@ namespace MWGui
, mJailScreen(nullptr) , mJailScreen(nullptr)
, mContainerWindow(nullptr) , mContainerWindow(nullptr)
, mTranslationDataStorage (translationDataStorage) , mTranslationDataStorage (translationDataStorage)
, mCharGen(nullptr)
, mInputBlocker(nullptr) , mInputBlocker(nullptr)
, mCrosshairEnabled(Settings::Manager::getBool ("crosshair", "HUD")) , mCrosshairEnabled(Settings::Manager::getBool ("crosshair", "HUD"))
, mSubtitlesEnabled(Settings::Manager::getBool ("subtitles", "GUI")) , mSubtitlesEnabled(Settings::Manager::getBool ("subtitles", "GUI"))
@ -182,9 +166,7 @@ namespace MWGui
, mCursorVisible(true) , mCursorVisible(true)
, mCursorActive(true) , mCursorActive(true)
, mPlayerBounty(-1) , mPlayerBounty(-1)
, mGui(nullptr)
, mGuiModes() , mGuiModes()
, mCursorManager(nullptr)
, mGarbageDialogs() , mGarbageDialogs()
, mShown(GW_ALL) , mShown(GW_ALL)
, mForceHidden(GW_None) , mForceHidden(GW_None)
@ -196,11 +178,11 @@ namespace MWGui
, mWindowVisible(true) , mWindowVisible(true)
{ {
mScalingFactor = std::clamp(Settings::Manager::getFloat("scaling factor", "GUI"), 0.5f, 8.f); 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<osgMyGUI::Platform>(viewer, guiRoot, resourceSystem->getImageManager(),
resourceSystem->getVFS(), mScalingFactor, "mygui", resourceSystem->getVFS(), mScalingFactor, "mygui",
(std::filesystem::path(logpath) / "MyGUI.log").generic_string()); (std::filesystem::path(logpath) / "MyGUI.log").generic_string());
mGui = new MyGUI::Gui; mGui = std::make_unique<MyGUI::Gui>();
mGui->initialise(""); mGui->initialise("");
createTextures(); createTextures();
@ -242,11 +224,12 @@ namespace MWGui
mKeyboardNavigation->setEnabled(keyboardNav); mKeyboardNavigation->setEnabled(keyboardNav);
Gui::ImageButton::setDefaultNeedKeyFocus(keyboardNav); Gui::ImageButton::setDefaultNeedKeyFocus(keyboardNav);
mLoadingScreen = new LoadingScreen(mResourceSystem, mViewer); auto loadingScreen = std::make_unique<LoadingScreen>(mResourceSystem, mViewer);
mWindows.push_back(mLoadingScreen); mLoadingScreen = loadingScreen.get();
mWindows.push_back(std::move(loadingScreen));
//set up the hardware cursor manager //set up the hardware cursor manager
mCursorManager = new SDLUtil::SDLCursorManager(); mCursorManager = std::make_unique<SDLUtil::SDLCursorManager>();
MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange); MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange);
@ -281,7 +264,7 @@ namespace MWGui
mShowOwned = Settings::Manager::getInt("show owned", "Game"); mShowOwned = Settings::Manager::getInt("show owned", "Game");
mVideoWrapper = new SDLUtil::VideoWrapper(window, viewer); mVideoWrapper = std::make_unique<SDLUtil::VideoWrapper>(window, viewer);
mVideoWrapper->setGammaContrast(Settings::Manager::getFloat("gamma", "Video"), mVideoWrapper->setGammaContrast(Settings::Manager::getFloat("gamma", "Video"),
Settings::Manager::getFloat("contrast", "Video")); Settings::Manager::getFloat("contrast", "Video"));
@ -299,157 +282,176 @@ namespace MWGui
mTextColours.loadColours(); mTextColours.loadColours();
mDragAndDrop = new DragAndDrop(); mDragAndDrop = std::make_unique<DragAndDrop>();
Recharge* recharge = new Recharge(); auto recharge = std::make_unique<Recharge>();
mGuiModeStates[GM_Recharge] = GuiModeState(recharge); mGuiModeStates[GM_Recharge] = GuiModeState(recharge.get());
mWindows.push_back(recharge); mWindows.push_back(std::move(recharge));
MainMenu* menu = new MainMenu(w, h, mResourceSystem->getVFS(), mVersionDescription); auto menu = std::make_unique<MainMenu>(w, h, mResourceSystem->getVFS(), mVersionDescription);
mGuiModeStates[GM_MainMenu] = GuiModeState(menu); mGuiModeStates[GM_MainMenu] = GuiModeState(menu.get());
mWindows.push_back(menu); mWindows.push_back(std::move(menu));
mLocalMapRender = new MWRender::LocalMap(mViewer->getSceneData()->asGroup()); mLocalMapRender = std::make_unique<MWRender::LocalMap>(mViewer->getSceneData()->asGroup());
mMap = new MapWindow(mCustomMarkers, mDragAndDrop, mLocalMapRender, mWorkQueue); auto map = std::make_unique<MapWindow>(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get(), mWorkQueue);
mWindows.push_back(mMap); mMap = map.get();
mWindows.push_back(std::move(map));
mMap->renderGlobalMap(); mMap->renderGlobalMap();
trackWindow(mMap, "map"); trackWindow(mMap, "map");
mStatsWindow = new StatsWindow(mDragAndDrop); auto statsWindow = std::make_unique<StatsWindow>(mDragAndDrop.get());
mWindows.push_back(mStatsWindow); mStatsWindow = statsWindow.get();
mWindows.push_back(std::move(statsWindow));
trackWindow(mStatsWindow, "stats"); trackWindow(mStatsWindow, "stats");
mInventoryWindow = new InventoryWindow(mDragAndDrop, mViewer->getSceneData()->asGroup(), mResourceSystem); auto inventoryWindow = std::make_unique<InventoryWindow>(mDragAndDrop.get(), mViewer->getSceneData()->asGroup(), mResourceSystem);
mWindows.push_back(mInventoryWindow); mInventoryWindow = inventoryWindow.get();
mWindows.push_back(std::move(inventoryWindow));
mSpellWindow = new SpellWindow(mDragAndDrop); auto spellWindow = std::make_unique<SpellWindow>(mDragAndDrop.get());
mWindows.push_back(mSpellWindow); mSpellWindow = spellWindow.get();
mWindows.push_back(std::move(spellWindow));
trackWindow(mSpellWindow, "spells"); trackWindow(mSpellWindow, "spells");
mGuiModeStates[GM_Inventory] = GuiModeState({mMap, mInventoryWindow, mSpellWindow, mStatsWindow}); mGuiModeStates[GM_Inventory] = GuiModeState({mMap, mInventoryWindow, mSpellWindow, mStatsWindow});
mGuiModeStates[GM_None] = GuiModeState({mMap, mInventoryWindow, mSpellWindow, mStatsWindow}); mGuiModeStates[GM_None] = GuiModeState({mMap, mInventoryWindow, mSpellWindow, mStatsWindow});
mTradeWindow = new TradeWindow(); auto tradeWindow = std::make_unique<TradeWindow>();
mWindows.push_back(mTradeWindow); mTradeWindow = tradeWindow.get();
mWindows.push_back(std::move(tradeWindow));
trackWindow(mTradeWindow, "barter"); trackWindow(mTradeWindow, "barter");
mGuiModeStates[GM_Barter] = GuiModeState({mInventoryWindow, mTradeWindow}); mGuiModeStates[GM_Barter] = GuiModeState({mInventoryWindow, mTradeWindow});
mConsole = new Console(w,h, mConsoleOnlyScripts); auto console = std::make_unique<Console>(w,h, mConsoleOnlyScripts);
mWindows.push_back(mConsole); mConsole = console.get();
mWindows.push_back(std::move(console));
trackWindow(mConsole, "console"); trackWindow(mConsole, "console");
bool questList = mResourceSystem->getVFS()->exists("textures/tx_menubook_options_over.dds"); bool questList = mResourceSystem->getVFS()->exists("textures/tx_menubook_options_over.dds");
JournalWindow* journal = JournalWindow::create(JournalViewModel::create (), questList, mEncoding); auto journal = JournalWindow::create(JournalViewModel::create(), questList, mEncoding);
mWindows.push_back(journal); mGuiModeStates[GM_Journal] = GuiModeState(journal.get());
mGuiModeStates[GM_Journal] = GuiModeState(journal);
mGuiModeStates[GM_Journal].mCloseSound = "book close"; mGuiModeStates[GM_Journal].mCloseSound = "book close";
mGuiModeStates[GM_Journal].mOpenSound = "book open"; mGuiModeStates[GM_Journal].mOpenSound = "book open";
mWindows.push_back(std::move(journal));
mMessageBoxManager = new MessageBoxManager(mStore->get<ESM::GameSetting>().find("fMessageTimePerChar")->mValue.getFloat()); mMessageBoxManager = std::make_unique<MessageBoxManager>(mStore->get<ESM::GameSetting>().find("fMessageTimePerChar")->mValue.getFloat());
SpellBuyingWindow* spellBuyingWindow = new SpellBuyingWindow(); auto spellBuyingWindow = std::make_unique<SpellBuyingWindow>();
mWindows.push_back(spellBuyingWindow); mGuiModeStates[GM_SpellBuying] = GuiModeState(spellBuyingWindow.get());
mGuiModeStates[GM_SpellBuying] = GuiModeState(spellBuyingWindow); mWindows.push_back(std::move(spellBuyingWindow));
TravelWindow* travelWindow = new TravelWindow(); auto travelWindow = std::make_unique<TravelWindow>();
mWindows.push_back(travelWindow); mGuiModeStates[GM_Travel] = GuiModeState(travelWindow.get());
mGuiModeStates[GM_Travel] = GuiModeState(travelWindow); mWindows.push_back(std::move(travelWindow));
mDialogueWindow = new DialogueWindow(); auto dialogueWindow = std::make_unique<DialogueWindow>();
mWindows.push_back(mDialogueWindow); mDialogueWindow = dialogueWindow.get();
mWindows.push_back(std::move(dialogueWindow));
trackWindow(mDialogueWindow, "dialogue"); trackWindow(mDialogueWindow, "dialogue");
mGuiModeStates[GM_Dialogue] = GuiModeState(mDialogueWindow); mGuiModeStates[GM_Dialogue] = GuiModeState(mDialogueWindow);
mTradeWindow->eventTradeDone += MyGUI::newDelegate(mDialogueWindow, &DialogueWindow::onTradeComplete); mTradeWindow->eventTradeDone += MyGUI::newDelegate(mDialogueWindow, &DialogueWindow::onTradeComplete);
mContainerWindow = new ContainerWindow(mDragAndDrop); auto containerWindow = std::make_unique<ContainerWindow>(mDragAndDrop.get());
mWindows.push_back(mContainerWindow); mContainerWindow = containerWindow.get();
mWindows.push_back(std::move(containerWindow));
trackWindow(mContainerWindow, "container"); trackWindow(mContainerWindow, "container");
mGuiModeStates[GM_Container] = GuiModeState({mContainerWindow, mInventoryWindow}); mGuiModeStates[GM_Container] = GuiModeState({mContainerWindow, mInventoryWindow});
mHud = new HUD(mCustomMarkers, mDragAndDrop, mLocalMapRender); auto hud = std::make_unique<HUD>(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get());
mWindows.push_back(mHud); mHud = hud.get();
mWindows.push_back(std::move(hud));
mToolTips = new ToolTips(); mToolTips = std::make_unique<ToolTips>();
mScrollWindow = new ScrollWindow(); auto scrollWindow = std::make_unique<ScrollWindow>();
mWindows.push_back(mScrollWindow); mScrollWindow = scrollWindow.get();
mWindows.push_back(std::move(scrollWindow));
mGuiModeStates[GM_Scroll] = GuiModeState(mScrollWindow); mGuiModeStates[GM_Scroll] = GuiModeState(mScrollWindow);
mGuiModeStates[GM_Scroll].mOpenSound = "scroll"; mGuiModeStates[GM_Scroll].mOpenSound = "scroll";
mGuiModeStates[GM_Scroll].mCloseSound = "scroll"; mGuiModeStates[GM_Scroll].mCloseSound = "scroll";
mBookWindow = new BookWindow(); auto bookWindow = std::make_unique<BookWindow>();
mWindows.push_back(mBookWindow); mBookWindow = bookWindow.get();
mWindows.push_back(std::move(bookWindow));
mGuiModeStates[GM_Book] = GuiModeState(mBookWindow); mGuiModeStates[GM_Book] = GuiModeState(mBookWindow);
mGuiModeStates[GM_Book].mOpenSound = "book open"; mGuiModeStates[GM_Book].mOpenSound = "book open";
mGuiModeStates[GM_Book].mCloseSound = "book close"; mGuiModeStates[GM_Book].mCloseSound = "book close";
mCountDialog = new CountDialog(); auto countDialog = std::make_unique<CountDialog>();
mWindows.push_back(mCountDialog); mCountDialog = countDialog.get();
mWindows.push_back(std::move(countDialog));
mSettingsWindow = new SettingsWindow(); auto settingsWindow = std::make_unique<SettingsWindow>();
mWindows.push_back(mSettingsWindow); mSettingsWindow = settingsWindow.get();
mWindows.push_back(std::move(settingsWindow));
trackWindow(mSettingsWindow, "settings"); trackWindow(mSettingsWindow, "settings");
mGuiModeStates[GM_Settings] = GuiModeState(mSettingsWindow); mGuiModeStates[GM_Settings] = GuiModeState(mSettingsWindow);
mConfirmationDialog = new ConfirmationDialog(); auto confirmationDialog = std::make_unique<ConfirmationDialog>();
mWindows.push_back(mConfirmationDialog); mConfirmationDialog = confirmationDialog.get();
mWindows.push_back(std::move(confirmationDialog));
AlchemyWindow* alchemyWindow = new AlchemyWindow(); auto alchemyWindow = std::make_unique<AlchemyWindow>();
mWindows.push_back(alchemyWindow); trackWindow(alchemyWindow.get(), "alchemy");
trackWindow(alchemyWindow, "alchemy"); mGuiModeStates[GM_Alchemy] = GuiModeState(alchemyWindow.get());
mGuiModeStates[GM_Alchemy] = GuiModeState(alchemyWindow); mWindows.push_back(std::move(alchemyWindow));
mQuickKeysMenu = new QuickKeysMenu(); auto quickKeysMenu = std::make_unique<QuickKeysMenu>();
mWindows.push_back(mQuickKeysMenu); mQuickKeysMenu = quickKeysMenu.get();
mWindows.push_back(std::move(quickKeysMenu));
mGuiModeStates[GM_QuickKeysMenu] = GuiModeState(mQuickKeysMenu); mGuiModeStates[GM_QuickKeysMenu] = GuiModeState(mQuickKeysMenu);
LevelupDialog* levelupDialog = new LevelupDialog(); auto levelupDialog = std::make_unique<LevelupDialog>();
mWindows.push_back(levelupDialog); mGuiModeStates[GM_Levelup] = GuiModeState(levelupDialog.get());
mGuiModeStates[GM_Levelup] = GuiModeState(levelupDialog); mWindows.push_back(std::move(levelupDialog));
mWaitDialog = new WaitDialog(); auto waitDialog = std::make_unique<WaitDialog>();
mWindows.push_back(mWaitDialog); mWaitDialog = waitDialog.get();
mWindows.push_back(std::move(waitDialog));
mGuiModeStates[GM_Rest] = GuiModeState({mWaitDialog->getProgressBar(), mWaitDialog}); mGuiModeStates[GM_Rest] = GuiModeState({mWaitDialog->getProgressBar(), mWaitDialog});
SpellCreationDialog* spellCreationDialog = new SpellCreationDialog(); auto spellCreationDialog = std::make_unique<SpellCreationDialog>();
mWindows.push_back(spellCreationDialog); mGuiModeStates[GM_SpellCreation] = GuiModeState(spellCreationDialog.get());
mGuiModeStates[GM_SpellCreation] = GuiModeState(spellCreationDialog); mWindows.push_back(std::move(spellCreationDialog));
EnchantingDialog* enchantingDialog = new EnchantingDialog(); auto enchantingDialog = std::make_unique<EnchantingDialog>();
mWindows.push_back(enchantingDialog); mGuiModeStates[GM_Enchanting] = GuiModeState(enchantingDialog.get());
mGuiModeStates[GM_Enchanting] = GuiModeState(enchantingDialog); mWindows.push_back(std::move(enchantingDialog));
TrainingWindow* trainingWindow = new TrainingWindow(); auto trainingWindow = std::make_unique<TrainingWindow>();
mWindows.push_back(trainingWindow); mGuiModeStates[GM_Training] = GuiModeState({trainingWindow->getProgressBar(), trainingWindow.get()});
mGuiModeStates[GM_Training] = GuiModeState({trainingWindow->getProgressBar(), trainingWindow}); mWindows.push_back(std::move(trainingWindow));
MerchantRepair* merchantRepair = new MerchantRepair(); auto merchantRepair = std::make_unique<MerchantRepair>();
mWindows.push_back(merchantRepair); mGuiModeStates[GM_MerchantRepair] = GuiModeState(merchantRepair.get());
mGuiModeStates[GM_MerchantRepair] = GuiModeState(merchantRepair); mWindows.push_back(std::move(merchantRepair));
Repair* repair = new Repair(); auto repair = std::make_unique<Repair>();
mWindows.push_back(repair); mGuiModeStates[GM_Repair] = GuiModeState(repair.get());
mGuiModeStates[GM_Repair] = GuiModeState(repair); mWindows.push_back(std::move(repair));
mSoulgemDialog = new SoulgemDialog(mMessageBoxManager); mSoulgemDialog = std::make_unique<SoulgemDialog>(mMessageBoxManager.get());
CompanionWindow* companionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager); auto companionWindow = std::make_unique<CompanionWindow>(mDragAndDrop.get(), mMessageBoxManager.get());
mWindows.push_back(companionWindow); trackWindow(companionWindow.get(), "companion");
trackWindow(companionWindow, "companion"); mGuiModeStates[GM_Companion] = GuiModeState({mInventoryWindow, companionWindow.get()});
mGuiModeStates[GM_Companion] = GuiModeState({mInventoryWindow, companionWindow}); mWindows.push_back(std::move(companionWindow));
mJailScreen = new JailScreen(); auto jailScreen = std::make_unique<JailScreen>();
mWindows.push_back(mJailScreen); mJailScreen = jailScreen.get();
mWindows.push_back(std::move(jailScreen));
mGuiModeStates[GM_Jail] = GuiModeState(mJailScreen); mGuiModeStates[GM_Jail] = GuiModeState(mJailScreen);
std::string werewolfFaderTex = "textures\\werewolfoverlay.dds"; std::string werewolfFaderTex = "textures\\werewolfoverlay.dds";
if (mResourceSystem->getVFS()->exists(werewolfFaderTex)) if (mResourceSystem->getVFS()->exists(werewolfFaderTex))
{ {
mWerewolfFader = new ScreenFader(werewolfFaderTex); auto werewolfFader = std::make_unique<ScreenFader>(werewolfFaderTex);
mWindows.push_back(mWerewolfFader); mWerewolfFader = werewolfFader.get();
mWindows.push_back(std::move(werewolfFader));
} }
mBlindnessFader = new ScreenFader("black"); auto blindnessFader = std::make_unique<ScreenFader>("black");
mWindows.push_back(mBlindnessFader); 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 // 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"; std::string hitFaderTexture = "textures\\bm_player_hit_01.dds";
@ -460,24 +462,28 @@ namespace MWGui
hitFaderTexture = "textures\\player_hit_01.dds"; hitFaderTexture = "textures\\player_hit_01.dds";
hitFaderCoord = MyGUI::FloatCoord(0.2, 0.25, 0.6, 0.5); hitFaderCoord = MyGUI::FloatCoord(0.2, 0.25, 0.6, 0.5);
} }
mHitFader = new ScreenFader(hitFaderTexture, hitFaderLayout, hitFaderCoord); auto hitFader = std::make_unique<ScreenFader>(hitFaderTexture, hitFaderLayout, hitFaderCoord);
mWindows.push_back(mHitFader); mHitFader = hitFader.get();
mWindows.push_back(std::move(hitFader));
mScreenFader = new ScreenFader("black"); auto screenFader = std::make_unique<ScreenFader>("black");
mWindows.push_back(mScreenFader); mScreenFader = screenFader.get();
mWindows.push_back(std::move(screenFader));
mDebugWindow = new DebugWindow(); auto debugWindow = std::make_unique<DebugWindow>();
mWindows.push_back(mDebugWindow); mDebugWindow = debugWindow.get();
mWindows.push_back(std::move(debugWindow));
mPostProcessorHud = new PostProcessorHud(); auto postProcessorHud = std::make_unique<PostProcessorHud>();
mWindows.push_back(mPostProcessorHud); mPostProcessorHud = postProcessorHud.get();
mWindows.push_back(std::move(postProcessorHud));
trackWindow(mPostProcessorHud, "postprocessor"); trackWindow(mPostProcessorHud, "postprocessor");
mInputBlocker = MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Stretch,"InputBlocker"); mInputBlocker = MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Stretch,"InputBlocker");
mHud->setVisible(true); mHud->setVisible(true);
mCharGen = new CharacterCreation(mViewer->getSceneData()->asGroup(), mResourceSystem); mCharGen = std::make_unique<CharacterCreation>(mViewer->getSceneData()->asGroup(), mResourceSystem);
updatePinnedWindows(); updatePinnedWindows();
@ -486,7 +492,7 @@ namespace MWGui
mStatsWatcher->addListener(mHud); mStatsWatcher->addListener(mHud);
mStatsWatcher->addListener(mStatsWindow); mStatsWatcher->addListener(mStatsWindow);
mStatsWatcher->addListener(mCharGen); mStatsWatcher->addListener(mCharGen.get());
} }
int WindowManager::getFontHeight() const int WindowManager::getFontHeight() const
@ -500,10 +506,9 @@ namespace MWGui
{ {
disallowAll(); disallowAll();
mStatsWatcher->removeListener(mCharGen); mStatsWatcher->removeListener(mCharGen.get());
delete mCharGen; mCharGen = std::make_unique<CharacterCreation>(mViewer->getSceneData()->asGroup(), mResourceSystem);
mCharGen = new CharacterCreation(mViewer->getSceneData()->asGroup(), mResourceSystem); mStatsWatcher->addListener(mCharGen.get());
mStatsWatcher->addListener(mCharGen);
} }
else else
allow(GW_ALL); allow(GW_ALL);
@ -525,17 +530,9 @@ namespace MWGui
MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear(); MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear();
MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear(); MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear();
for (WindowBase* window : mWindows)
delete window;
mWindows.clear(); mWindows.clear();
mMessageBoxManager.reset();
delete mMessageBoxManager; mToolTips.reset();
delete mLocalMapRender;
delete mCharGen;
delete mDragAndDrop;
delete mSoulgemDialog;
delete mCursorManager;
delete mToolTips;
mKeyboardNavigation.reset(); mKeyboardNavigation.reset();
@ -544,11 +541,8 @@ namespace MWGui
mFontLoader.reset(); mFontLoader.reset();
mGui->shutdown(); mGui->shutdown();
delete mGui;
mGuiPlatform->shutdown(); mGuiPlatform->shutdown();
delete mGuiPlatform;
delete mVideoWrapper;
} }
catch(const MyGUI::Exception& e) catch(const MyGUI::Exception& e)
{ {
@ -700,7 +694,7 @@ namespace MWGui
} }
GuiModeState& state = mGuiModeStates[mGuiModes.back()]; GuiModeState& state = mGuiModeStates[mGuiModes.back()];
for (WindowBase* window : state.mWindows) for (const auto& window : state.mWindows)
{ {
if (!window->exit()) if (!window->exit())
{ {
@ -773,7 +767,7 @@ namespace MWGui
mMessageBoxManager->removeStaticMessageBox(); mMessageBoxManager->removeStaticMessageBox();
} }
const std::vector<MWGui::MessageBox*> WindowManager::getActiveMessageBoxes() const std::vector<std::unique_ptr<MWGui::MessageBox>>& WindowManager::getActiveMessageBoxes() const
{ {
return mMessageBoxManager->getActiveMessageBoxes(); return mMessageBoxManager->getActiveMessageBoxes();
} }
@ -1164,7 +1158,7 @@ namespace MWGui
it->first->setSize(size); it->first->setSize(size);
} }
for (WindowBase* window : mWindows) for (const auto& window : mWindows)
window->onResChange(x, y); window->onResChange(x, y);
// TODO: check if any windows are now off-screen and move them back if so // TODO: check if any windows are now off-screen and move them back if so
@ -1726,7 +1720,7 @@ namespace MWGui
{ {
mPlayerBounty = -1; mPlayerBounty = -1;
for (WindowBase* window : mWindows) for (const auto& window : mWindows)
window->clear(); window->clear();
if (mLocalMapRender) if (mLocalMapRender)
@ -2270,8 +2264,8 @@ namespace MWGui
void WindowManager::GuiModeState::update(bool visible) void WindowManager::GuiModeState::update(bool visible)
{ {
for (unsigned int i=0; i<mWindows.size(); ++i) for (const auto& window : mWindows)
mWindows[i]->setVisible(visible); window->setVisible(visible);
} }
void WindowManager::watchActor(const MWWorld::Ptr& ptr) void WindowManager::watchActor(const MWWorld::Ptr& ptr)
@ -2299,7 +2293,7 @@ namespace MWGui
void WindowManager::onDeleteCustomData(const MWWorld::Ptr& ptr) void WindowManager::onDeleteCustomData(const MWWorld::Ptr& ptr)
{ {
for(auto* window : mWindows) for(const auto& window : mWindows)
window->onDeleteCustomData(ptr); window->onDeleteCustomData(ptr);
} }

View file

@ -14,22 +14,32 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwrender/localmap.hpp"
#include <components/misc/guarded.hpp>
#include <components/myguiplatform/myguiplatform.hpp>
#include <components/sdlutil/events.hpp> #include <components/sdlutil/events.hpp>
#include <components/sdlutil/sdlcursormanager.hpp>
#include <components/sdlutil/sdlvideowrapper.hpp>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <components/to_utf8/to_utf8.hpp> #include <components/to_utf8/to_utf8.hpp>
#include <components/misc/guarded.hpp>
#include "charactercreation.hpp"
#include "draganddrop.hpp"
#include "mapwindow.hpp" #include "mapwindow.hpp"
#include "messagebox.hpp"
#include "soulgemdialog.hpp"
#include "statswatcher.hpp" #include "statswatcher.hpp"
#include "textcolours.hpp" #include "textcolours.hpp"
#include "tooltips.hpp"
#include "windowbase.hpp"
#include <MyGUI_Gui.h>
#include <MyGUI_KeyCode.h> #include <MyGUI_KeyCode.h>
#include <MyGUI_Types.h> #include <MyGUI_Types.h>
namespace MyGUI namespace MyGUI
{ {
class Gui;
class Widget; class Widget;
class Window; class Window;
class UString; class UString;
@ -70,42 +80,21 @@ namespace SceneUtil
class WorkQueue; class WorkQueue;
} }
namespace SDLUtil
{
class SDLCursorManager;
class VideoWrapper;
}
namespace osgMyGUI
{
class Platform;
}
namespace Gui namespace Gui
{ {
class FontLoader; class FontLoader;
} }
namespace MWRender
{
class LocalMap;
}
namespace MWGui namespace MWGui
{ {
class WindowBase;
class HUD; class HUD;
class MapWindow; class MapWindow;
class MainMenu; class MainMenu;
class StatsWindow; class StatsWindow;
class InventoryWindow; class InventoryWindow;
struct JournalWindow; struct JournalWindow;
class CharacterCreation;
class DragAndDrop;
class ToolTips;
class TextInputDialog; class TextInputDialog;
class InfoBoxDialog; class InfoBoxDialog;
class MessageBoxManager;
class SettingsWindow; class SettingsWindow;
class AlchemyWindow; class AlchemyWindow;
class QuickKeysMenu; class QuickKeysMenu;
@ -117,7 +106,6 @@ namespace MWGui
class TrainingWindow; class TrainingWindow;
class SpellIcons; class SpellIcons;
class MerchantRepair; class MerchantRepair;
class SoulgemDialog;
class Recharge; class Recharge;
class CompanionWindow; class CompanionWindow;
class VideoWidget; class VideoWidget;
@ -190,7 +178,7 @@ namespace MWGui
MWGui::CountDialog* getCountDialog() override; MWGui::CountDialog* getCountDialog() override;
MWGui::ConfirmationDialog* getConfirmationDialog() override; MWGui::ConfirmationDialog* getConfirmationDialog() override;
MWGui::TradeWindow* getTradeWindow() override; MWGui::TradeWindow* getTradeWindow() override;
const std::vector<MWGui::MessageBox*> getActiveMessageBoxes() override; const std::vector<std::unique_ptr<MWGui::MessageBox>>& getActiveMessageBoxes() const override;
MWGui::PostProcessorHud* getPostProcessorHud() override; MWGui::PostProcessorHud* getPostProcessorHud() override;
/// Make the player use an item, while updating GUI state accordingly /// Make the player use an item, while updating GUI state accordingly
@ -401,7 +389,7 @@ namespace MWGui
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue; osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
osgMyGUI::Platform* mGuiPlatform; std::unique_ptr<osgMyGUI::Platform> mGuiPlatform;
osgViewer::Viewer* mViewer; osgViewer::Viewer* mViewer;
std::unique_ptr<Gui::FontLoader> mFontLoader; std::unique_ptr<Gui::FontLoader> mFontLoader;
@ -424,13 +412,13 @@ namespace MWGui
HUD *mHud; HUD *mHud;
MapWindow *mMap; MapWindow *mMap;
MWRender::LocalMap* mLocalMapRender; std::unique_ptr<MWRender::LocalMap> mLocalMapRender;
ToolTips *mToolTips; std::unique_ptr<ToolTips> mToolTips;
StatsWindow *mStatsWindow; StatsWindow *mStatsWindow;
MessageBoxManager *mMessageBoxManager; std::unique_ptr<MessageBoxManager> mMessageBoxManager;
Console *mConsole; Console *mConsole;
DialogueWindow *mDialogueWindow; DialogueWindow *mDialogueWindow;
DragAndDrop* mDragAndDrop; std::unique_ptr<DragAndDrop> mDragAndDrop;
InventoryWindow *mInventoryWindow; InventoryWindow *mInventoryWindow;
ScrollWindow* mScrollWindow; ScrollWindow* mScrollWindow;
BookWindow* mBookWindow; BookWindow* mBookWindow;
@ -442,7 +430,7 @@ namespace MWGui
QuickKeysMenu* mQuickKeysMenu; QuickKeysMenu* mQuickKeysMenu;
LoadingScreen* mLoadingScreen; LoadingScreen* mLoadingScreen;
WaitDialog* mWaitDialog; WaitDialog* mWaitDialog;
SoulgemDialog* mSoulgemDialog; std::unique_ptr<SoulgemDialog> mSoulgemDialog;
MyGUI::ImageBox* mVideoBackground; MyGUI::ImageBox* mVideoBackground;
VideoWidget* mVideoWidget; VideoWidget* mVideoWidget;
ScreenFader* mWerewolfFader; ScreenFader* mWerewolfFader;
@ -454,11 +442,11 @@ namespace MWGui
JailScreen* mJailScreen; JailScreen* mJailScreen;
ContainerWindow* mContainerWindow; ContainerWindow* mContainerWindow;
std::vector<WindowBase*> mWindows; std::vector<std::unique_ptr<WindowBase>> mWindows;
Translation::Storage& mTranslationDataStorage; Translation::Storage& mTranslationDataStorage;
CharacterCreation* mCharGen; std::unique_ptr<CharacterCreation> mCharGen;
MyGUI::Widget* mInputBlocker; MyGUI::Widget* mInputBlocker;
@ -474,7 +462,7 @@ namespace MWGui
void setCursorVisible(bool visible) override; void setCursorVisible(bool visible) override;
MyGUI::Gui *mGui; // Gui std::unique_ptr<MyGUI::Gui> mGui; // Gui
struct GuiModeState struct GuiModeState
{ {
@ -498,7 +486,7 @@ namespace MWGui
// The currently active stack of GUI modes (top mode is the one we are in). // The currently active stack of GUI modes (top mode is the one we are in).
std::vector<GuiMode> mGuiModes; std::vector<GuiMode> mGuiModes;
SDLUtil::SDLCursorManager* mCursorManager; std::unique_ptr<SDLUtil::SDLCursorManager> mCursorManager;
std::vector<std::unique_ptr<Layout>> mGarbageDialogs; std::vector<std::unique_ptr<Layout>> mGarbageDialogs;
void cleanupGarbage(); void cleanupGarbage();
@ -531,7 +519,7 @@ namespace MWGui
std::unique_ptr<KeyboardNavigation> mKeyboardNavigation; std::unique_ptr<KeyboardNavigation> mKeyboardNavigation;
SDLUtil::VideoWrapper* mVideoWrapper; std::unique_ptr<SDLUtil::VideoWrapper> mVideoWrapper;
float mScalingFactor; float mScalingFactor;

View file

@ -97,8 +97,8 @@ namespace MWInput
if (playerPtr.getClass().getEncumbrance(playerPtr) > playerPtr.getClass().getCapacity(playerPtr)) if (playerPtr.getClass().getEncumbrance(playerPtr) > playerPtr.getClass().getCapacity(playerPtr))
{ {
player.setAutoMove (false); player.setAutoMove (false);
std::vector<MWGui::MessageBox*> msgboxs = MWBase::Environment::get().getWindowManager()->getActiveMessageBoxes(); const auto& msgboxs = MWBase::Environment::get().getWindowManager()->getActiveMessageBoxes();
const std::vector<MWGui::MessageBox*>::iterator it = std::find_if(msgboxs.begin(), msgboxs.end(), [](MWGui::MessageBox*& msgbox) auto it = std::find_if(msgboxs.begin(), msgboxs.end(), [](const std::unique_ptr<MWGui::MessageBox>& msgbox)
{ {
return (msgbox->getMessage() == "#{sNotifyMessage59}"); return (msgbox->getMessage() == "#{sNotifyMessage59}");
}); });