1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +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::ConfirmationDialog* getConfirmationDialog() = 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;
/// Make the player use an item, while updating GUI state accordingly

View File

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

View File

@ -34,7 +34,7 @@ namespace MWGui
, mCurrentFilter(FilterType::ByName)
, mModel(nullptr)
, mSortModel(nullptr)
, mAlchemy(new MWMechanics::Alchemy())
, mAlchemy(std::make_unique<MWMechanics::Alchemy>())
, 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<InventoryItemModel>(MWMechanics::getPlayer());
mModel = model.get();
auto sortModel = std::make_unique<SortFilterItemModel>(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;

View File

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

View File

@ -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<CompanionItemModel>(npc);
mModel = model.get();
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mSortModel = sortModel.get();
mFilterEdit->setCaption({});
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
setTitle(npc.getClass().getName(npc));

View File

@ -129,27 +129,29 @@ namespace MWGui
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
std::unique_ptr<ItemModel> 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<PickpocketItemModel>(mPtr, std::make_unique<InventoryItemModel>(container),
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
}
else
mModel = new InventoryItemModel(container);
model = std::make_unique<InventoryItemModel>(container);
}
else
{
mModel = new ContainerItemModel(container);
model = std::make_unique<ContainerItemModel>(container);
}
mDisposeCorpseButton->setVisible(loot);
mModel = model.get();
auto sortModel = std::make_unique<SortFilterItemModel>(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);

View File

@ -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<ResponseCallback> callback)
: WindowModal("openmw_persuasion_dialog.layout")

View File

@ -8,6 +8,7 @@
#include "bookpage.hpp"
#include "../mwbase/dialoguemanager.hpp"
#include "../mwdialogue/keywordsearch.hpp"
#include <MyGUI_Delegate.h>
@ -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
{

View File

@ -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<ItemSelectionDialog>("#{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<ItemSelectionDialog>("#{sSoulGemsWithSouls}");
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel);
mItemSelectionDialog->setVisible(true);

View File

@ -1,6 +1,9 @@
#ifndef MWGUI_ENCHANTINGDIALOG_H
#define MWGUI_ENCHANTINGDIALOG_H
#include <memory>
#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<ItemSelectionDialog> mItemSelectionDialog;
MyGUI::Widget* mChanceLayout;

View File

@ -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<SpellIcons>();
}
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<float>& value)

View File

@ -1,7 +1,10 @@
#ifndef OPENMW_GAME_MWGUI_HUD_H
#define OPENMW_GAME_MWGUI_HUD_H
#include <memory>
#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<SpellIcons> mSpellIcons;
int mEnemyActorId;
float mEnemyHealthTimer;

View File

@ -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<TradeItemModel>(std::make_unique<InventoryItemModel>(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<SortFilterItemModel>(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<InventoryItemModel>(player));
model.setSortByType(false);
model.update();
if (model.getItemCount() == 0)

View File

@ -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<ItemModel> sourceModel)
{
if (mSourceModel == sourceModel)
return;
if (mSourceModel)
{
delete mSourceModel;
mSourceModel = nullptr;
}
mSourceModel = sourceModel;
mSourceModel = std::move(sourceModel);
}
void ProxyItemModel::onClose()

View File

@ -1,6 +1,8 @@
#ifndef MWGUI_ITEM_MODEL_H
#define MWGUI_ITEM_MODEL_H
#include <memory>
#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<ItemModel> sourceModel);
ModelIndex mapToSource (ModelIndex index);
ModelIndex mapFromSource (ModelIndex index);
bool usesContainer(const MWWorld::Ptr& container) override;
protected:
ItemModel* mSourceModel;
std::unique_ptr<ItemModel> mSourceModel;
};
}

View File

@ -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<SortFilterItemModel>(std::make_unique<InventoryItemModel>(container));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
}

View File

@ -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);

View File

@ -16,23 +16,13 @@ namespace MWGui
{
ItemView::ItemView()
: mModel(nullptr)
, mScrollView(nullptr)
: mScrollView(nullptr)
{
}
ItemView::~ItemView()
void ItemView::setModel(std::unique_ptr<ItemModel> 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<ItemWidget>("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;

View File

@ -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<ItemModel> model);
typedef MyGUI::delegates::CMultiDelegate1<ItemModel::ModelIndex> 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<ItemModel> mModel;
MyGUI::ScrollView* mScrollView;
};

View File

@ -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> 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()

View File

@ -18,7 +18,7 @@ namespace MWGui
JournalWindow();
/// 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
virtual ~JournalWindow () {}

View File

@ -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<SaveGameDialog>();
if (name == "loadgame")
mSaveGameDialog->setLoadOrSave(true);
else if (name == "savegame")

View File

@ -1,6 +1,9 @@
#ifndef OPENMW_GAME_MWGUI_MAINMENU_H
#define OPENMW_GAME_MWGUI_MAINMENU_H
#include <memory>
#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<SaveGameDialog> mSaveGameDialog;
};
}

View File

@ -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<MessageBox*>::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<int>(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<MessageBox>(*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<InteractiveMessageBox>(*this, std::string{message}, buttons);
mLastButtonPressed = -1;
return true;
@ -145,12 +131,10 @@ namespace MWGui
bool MessageBoxManager::removeMessageBox (MessageBox *msgbox)
{
std::vector<MessageBox*>::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<MessageBox*> MessageBoxManager::getActiveMessageBoxes()
const std::vector<std::unique_ptr<MessageBox>>& 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);
}

View File

@ -1,6 +1,8 @@
#ifndef MWGUI_MESSAGE_BOX_H
#define MWGUI_MESSAGE_BOX_H
#include <memory>
#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<MessageBox*> getActiveMessageBoxes();
const std::vector<std::unique_ptr<MessageBox>>& getActiveMessageBoxes() const;
private:
std::vector<MessageBox*> mMessageBoxes;
InteractiveMessageBox* mInterMessageBoxe;
std::vector<std::unique_ptr<MessageBox>> mMessageBoxes;
std::unique_ptr<InteractiveMessageBox> mInterMessageBoxe;
MessageBox* mStaticMessageBox;
float mMessageBoxSpeed;
int mLastButtonPressed;

View File

@ -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<ItemModel> 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();

View File

@ -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<ItemModel> sourceModel, bool hideItems = true);
bool allowedToUseItems() const override;
ItemStack getItem (ModelIndex index) override;

View File

@ -39,9 +39,6 @@ namespace MWGui
, mKey(std::vector<keyData>(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<QuickKeysMenuAssign>(this);
mAssignDialog->setVisible(true);
}
@ -208,7 +198,7 @@ namespace MWGui
{
if (!mItemSelectionDialog)
{
mItemSelectionDialog = new ItemSelectionDialog("#{sQuickMenu6}");
mItemSelectionDialog = std::make_unique<ItemSelectionDialog>("#{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<MagicSelectionDialog>(this);
}
mMagicSelectionDialog->setVisible(true);

View File

@ -1,15 +1,16 @@
#ifndef MWGUI_QUICKKEYS_H
#define MWGUI_QUICKKEYS_H
#include "windowbase.hpp"
#include <memory>
#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<QuickKeysMenuAssign> mAssignDialog;
std::unique_ptr<ItemSelectionDialog> mItemSelectionDialog;
std::unique_ptr<MagicSelectionDialog> mMagicSelectionDialog;
void onQuickKeyButtonClicked(MyGUI::Widget* sender);
void onOkButtonClicked(MyGUI::Widget* sender);

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ namespace MWGui
, mSpellView(nullptr)
, mUpdateTimer(0.0f)
{
mSpellIcons = new SpellIcons();
mSpellIcons = std::make_unique<SpellIcons>();
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);

View File

@ -1,20 +1,20 @@
#ifndef MWGUI_SPELLWINDOW_H
#define MWGUI_SPELLWINDOW_H
#include "windowpinnablebase.hpp"
#include <memory>
#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<SpellIcons> mSpellIcons;
MyGUI::EditBox* mFilterEdit;
private:

View File

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

View File

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

View File

@ -114,9 +114,11 @@ namespace MWGui
std::vector<MWWorld::Ptr> 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<TradeItemModel>(std::make_unique<ContainerItemModel>(itemSources, worldItems), mPtr);
mTradeModel = tradeModel.get();
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(tradeModel));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
updateLabels();

View File

@ -13,7 +13,6 @@
#include <MyGUI_LanguageManager.h>
#include <MyGUI_PointerManager.h>
#include <MyGUI_InputManager.h>
#include <MyGUI_Gui.h>
#include <MyGUI_ClipboardManager.h>
// For BT_NO_PROFILE
@ -24,9 +23,6 @@
#include <components/debug/debuglog.hpp>
#include <components/sdlutil/sdlcursormanager.hpp>
#include <components/sdlutil/sdlvideowrapper.hpp>
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
@ -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<osgMyGUI::Platform>(viewer, guiRoot, resourceSystem->getImageManager(),
resourceSystem->getVFS(), mScalingFactor, "mygui",
(std::filesystem::path(logpath) / "MyGUI.log").generic_string());
mGui = new MyGUI::Gui;
mGui = std::make_unique<MyGUI::Gui>();
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<LoadingScreen>(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<SDLUtil::SDLCursorManager>();
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<SDLUtil::VideoWrapper>(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<DragAndDrop>();
Recharge* recharge = new Recharge();
mGuiModeStates[GM_Recharge] = GuiModeState(recharge);
mWindows.push_back(recharge);
auto recharge = std::make_unique<Recharge>();
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<MainMenu>(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<MWRender::LocalMap>(mViewer->getSceneData()->asGroup());
auto map = std::make_unique<MapWindow>(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<StatsWindow>(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<InventoryWindow>(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<SpellWindow>(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<TradeWindow>();
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<Console>(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<ESM::GameSetting>().find("fMessageTimePerChar")->mValue.getFloat());
mMessageBoxManager = std::make_unique<MessageBoxManager>(mStore->get<ESM::GameSetting>().find("fMessageTimePerChar")->mValue.getFloat());
SpellBuyingWindow* spellBuyingWindow = new SpellBuyingWindow();
mWindows.push_back(spellBuyingWindow);
mGuiModeStates[GM_SpellBuying] = GuiModeState(spellBuyingWindow);
auto spellBuyingWindow = std::make_unique<SpellBuyingWindow>();
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<TravelWindow>();
mGuiModeStates[GM_Travel] = GuiModeState(travelWindow.get());
mWindows.push_back(std::move(travelWindow));
mDialogueWindow = new DialogueWindow();
mWindows.push_back(mDialogueWindow);
auto dialogueWindow = std::make_unique<DialogueWindow>();
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<ContainerWindow>(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<HUD>(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get());
mHud = hud.get();
mWindows.push_back(std::move(hud));
mToolTips = new ToolTips();
mToolTips = std::make_unique<ToolTips>();
mScrollWindow = new ScrollWindow();
mWindows.push_back(mScrollWindow);
auto scrollWindow = std::make_unique<ScrollWindow>();
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<BookWindow>();
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<CountDialog>();
mCountDialog = countDialog.get();
mWindows.push_back(std::move(countDialog));
mSettingsWindow = new SettingsWindow();
mWindows.push_back(mSettingsWindow);
auto settingsWindow = std::make_unique<SettingsWindow>();
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<ConfirmationDialog>();
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<AlchemyWindow>();
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<QuickKeysMenu>();
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<LevelupDialog>();
mGuiModeStates[GM_Levelup] = GuiModeState(levelupDialog.get());
mWindows.push_back(std::move(levelupDialog));
mWaitDialog = new WaitDialog();
mWindows.push_back(mWaitDialog);
auto waitDialog = std::make_unique<WaitDialog>();
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<SpellCreationDialog>();
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<EnchantingDialog>();
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<TrainingWindow>();
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<MerchantRepair>();
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<Repair>();
mGuiModeStates[GM_Repair] = GuiModeState(repair.get());
mWindows.push_back(std::move(repair));
mSoulgemDialog = new SoulgemDialog(mMessageBoxManager);
mSoulgemDialog = std::make_unique<SoulgemDialog>(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<CompanionWindow>(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<JailScreen>();
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<ScreenFader>(werewolfFaderTex);
mWerewolfFader = werewolfFader.get();
mWindows.push_back(std::move(werewolfFader));
}
mBlindnessFader = new ScreenFader("black");
mWindows.push_back(mBlindnessFader);
auto blindnessFader = std::make_unique<ScreenFader>("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<ScreenFader>(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<ScreenFader>("black");
mScreenFader = screenFader.get();
mWindows.push_back(std::move(screenFader));
mDebugWindow = new DebugWindow();
mWindows.push_back(mDebugWindow);
auto debugWindow = std::make_unique<DebugWindow>();
mDebugWindow = debugWindow.get();
mWindows.push_back(std::move(debugWindow));
mPostProcessorHud = new PostProcessorHud();
mWindows.push_back(mPostProcessorHud);
auto postProcessorHud = std::make_unique<PostProcessorHud>();
mPostProcessorHud = postProcessorHud.get();
mWindows.push_back(std::move(postProcessorHud));
trackWindow(mPostProcessorHud, "postprocessor");
mInputBlocker = MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Stretch,"InputBlocker");
mHud->setVisible(true);
mCharGen = new CharacterCreation(mViewer->getSceneData()->asGroup(), mResourceSystem);
mCharGen = std::make_unique<CharacterCreation>(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<CharacterCreation>(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<MWGui::MessageBox*> WindowManager::getActiveMessageBoxes()
const std::vector<std::unique_ptr<MWGui::MessageBox>>& 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; i<mWindows.size(); ++i)
mWindows[i]->setVisible(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);
}

View File

@ -14,22 +14,32 @@
#include <osg/ref_ptr>
#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/sdlcursormanager.hpp>
#include <components/sdlutil/sdlvideowrapper.hpp>
#include <components/settings/settings.hpp>
#include <components/to_utf8/to_utf8.hpp>
#include <components/misc/guarded.hpp>
#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 <MyGUI_Gui.h>
#include <MyGUI_KeyCode.h>
#include <MyGUI_Types.h>
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<MWGui::MessageBox*> getActiveMessageBoxes() override;
const std::vector<std::unique_ptr<MWGui::MessageBox>>& 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<SceneUtil::WorkQueue> mWorkQueue;
osgMyGUI::Platform* mGuiPlatform;
std::unique_ptr<osgMyGUI::Platform> mGuiPlatform;
osgViewer::Viewer* mViewer;
std::unique_ptr<Gui::FontLoader> mFontLoader;
@ -424,13 +412,13 @@ namespace MWGui
HUD *mHud;
MapWindow *mMap;
MWRender::LocalMap* mLocalMapRender;
ToolTips *mToolTips;
std::unique_ptr<MWRender::LocalMap> mLocalMapRender;
std::unique_ptr<ToolTips> mToolTips;
StatsWindow *mStatsWindow;
MessageBoxManager *mMessageBoxManager;
std::unique_ptr<MessageBoxManager> mMessageBoxManager;
Console *mConsole;
DialogueWindow *mDialogueWindow;
DragAndDrop* mDragAndDrop;
std::unique_ptr<DragAndDrop> mDragAndDrop;
InventoryWindow *mInventoryWindow;
ScrollWindow* mScrollWindow;
BookWindow* mBookWindow;
@ -442,7 +430,7 @@ namespace MWGui
QuickKeysMenu* mQuickKeysMenu;
LoadingScreen* mLoadingScreen;
WaitDialog* mWaitDialog;
SoulgemDialog* mSoulgemDialog;
std::unique_ptr<SoulgemDialog> mSoulgemDialog;
MyGUI::ImageBox* mVideoBackground;
VideoWidget* mVideoWidget;
ScreenFader* mWerewolfFader;
@ -454,11 +442,11 @@ namespace MWGui
JailScreen* mJailScreen;
ContainerWindow* mContainerWindow;
std::vector<WindowBase*> mWindows;
std::vector<std::unique_ptr<WindowBase>> mWindows;
Translation::Storage& mTranslationDataStorage;
CharacterCreation* mCharGen;
std::unique_ptr<CharacterCreation> mCharGen;
MyGUI::Widget* mInputBlocker;
@ -474,7 +462,7 @@ namespace MWGui
void setCursorVisible(bool visible) override;
MyGUI::Gui *mGui; // Gui
std::unique_ptr<MyGUI::Gui> 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<GuiMode> mGuiModes;
SDLUtil::SDLCursorManager* mCursorManager;
std::unique_ptr<SDLUtil::SDLCursorManager> mCursorManager;
std::vector<std::unique_ptr<Layout>> mGarbageDialogs;
void cleanupGarbage();
@ -531,7 +519,7 @@ namespace MWGui
std::unique_ptr<KeyboardNavigation> mKeyboardNavigation;
SDLUtil::VideoWrapper* mVideoWrapper;
std::unique_ptr<SDLUtil::VideoWrapper> mVideoWrapper;
float mScalingFactor;

View File

@ -97,8 +97,8 @@ namespace MWInput
if (playerPtr.getClass().getEncumbrance(playerPtr) > playerPtr.getClass().getCapacity(playerPtr))
{
player.setAutoMove (false);
std::vector<MWGui::MessageBox*> msgboxs = MWBase::Environment::get().getWindowManager()->getActiveMessageBoxes();
const std::vector<MWGui::MessageBox*>::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<MWGui::MessageBox>& msgbox)
{
return (msgbox->getMessage() == "#{sNotifyMessage59}");
});