Use std::unique_ptr in WindowManager

This commit is contained in:
Evil Eye 2022-08-31 21:07:59 +02:00
parent 1b9da77455
commit f4bc06604a
4 changed files with 149 additions and 145 deletions

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

@ -142,13 +142,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 +156,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 +167,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 +176,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 +188,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 +234,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 +274,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 +292,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 +472,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 +502,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 +516,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 +540,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 +551,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 +704,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())
{ {
@ -1164,7 +1168,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 +1730,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 +2274,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 +2303,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

@ -401,7 +401,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 +424,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 +442,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 +454,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 +474,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 +498,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 +531,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;