From e3300384e1424bd333648319f18ff548f4a6f58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Mon, 27 May 2024 12:19:17 +0200 Subject: [PATCH] Replaced the raw pointers with `unique_ptr`s in the menu state --- src/smw/GSMenu.cpp | 220 +++++++++++++++++++++++---------------------- src/smw/GSMenu.h | 63 ++++++------- 2 files changed, 144 insertions(+), 139 deletions(-) diff --git a/src/smw/GSMenu.cpp b/src/smw/GSMenu.cpp index 9934e1f8..abf7566f 100644 --- a/src/smw/GSMenu.cpp +++ b/src/smw/GSMenu.cpp @@ -114,6 +114,11 @@ extern SoundsList *soundpacklist; extern TourList *tourlist; extern WorldList *worldlist; +// std::uniue_ptr requires that the special member function have access +// to the complete types. +MenuState::MenuState() = default; +MenuState::~MenuState() = default; + MenuState& MenuState::instance() { static MenuState menu; @@ -122,48 +127,47 @@ MenuState& MenuState::instance() bool MenuState::init() { - CreateMenu(); - return true; -} - -void MenuState::CreateMenu() -{ - mMainMenu = new UI_MainMenu(); - - mOptionsMenu = new UI_OptionsMenu(); - mGameplayOptionsMenu = new UI_GameplayOptionsMenu(); - mTeamOptionsMenu = new UI_TeamOptionsMenu(); - mPowerupDropRatesMenu = new UI_PowerupDropRatesMenu(); - mPowerupSettingsMenu = new UI_PowerupSettingsMenu(); - mProjectileLimitsMenu = new UI_ProjectileLimitsMenu(); - mProjectileOptionsMenu = new UI_ProjectileOptionsMenu(); - mGraphicsOptionsMenu = new UI_GraphicsOptionsMenu(); - mEyeCandyOptionsMenu = new UI_EyeCandyOptionsMenu(); - mSoundOptionsMenu = new UI_SoundOptionsMenu(); - - mPlayerControlsSelectMenu = new UI_PlayerControlsSelectMenu(); - mPlayerControlsMenu = new UI_PlayerControlsMenu(); - - mModeOptionsMenu = new UI_ModeOptionsMenu(); - mMatchSelectionMenu = new UI_MatchSelectionMenu(); - mGameSettingsMenu = new UI_GameSettingsMenu(); - mMapFilterEditMenu = new UI_MapFilterEditMenu(); - mTourStopMenu = new UI_TourStopMenu(); - mWorldMenu = new UI_WorldMenu(); - mTeamSelectMenu = new UI_TeamSelectMenu(); - mTournamentScoreboardMenu = new UI_TournamentScoreboardMenu(); - mBonusWheelMenu = new UI_BonusWheelMenu(); - - mNetServersMenu = new UI_NetServersMenu(); - mNetEditServersMenu = new UI_NetEditServersMenu(); - mNetLobbyMenu = new UI_NetLobbyMenu(); - mNetNewRoomMenu = new UI_NetNewRoomMenu(); - mNetNewRoomSettingsMenu = new UI_NetNewRoomSettingsMenu(mGameSettingsMenu); - mNetRoomMenu = new UI_NetRoomMenu(); - - mCurrentMenu = mMainMenu; - + mMainMenu = std::make_unique(); + + // Options menu + mOptionsMenu = std::make_unique(); + mGameplayOptionsMenu = std::make_unique(); + mTeamOptionsMenu = std::make_unique(); + mPowerupDropRatesMenu = std::make_unique(); + mPowerupSettingsMenu = std::make_unique(); + mProjectileLimitsMenu = std::make_unique(); + mProjectileOptionsMenu = std::make_unique(); + mGraphicsOptionsMenu = std::make_unique(); + mEyeCandyOptionsMenu = std::make_unique(); + mSoundOptionsMenu = std::make_unique(); + + // Controls menu + mPlayerControlsSelectMenu = std::make_unique(); + mPlayerControlsMenu = std::make_unique(); + + // Gameplay menu + mModeOptionsMenu = std::make_unique(); + mMatchSelectionMenu = std::make_unique(); + mGameSettingsMenu = std::make_unique(); + mMapFilterEditMenu = std::make_unique(); + mTourStopMenu = std::make_unique(); + mWorldMenu = std::make_unique(); + mTeamSelectMenu = std::make_unique(); + mTournamentScoreboardMenu = std::make_unique(); + mBonusWheelMenu = std::make_unique(); + + // Multiplayer menu + mNetServersMenu = std::make_unique(); + mNetEditServersMenu = std::make_unique(); + mNetLobbyMenu = std::make_unique(); + mNetNewRoomMenu = std::make_unique(); + mNetNewRoomSettingsMenu = std::make_unique(mGameSettingsMenu.get()); + mNetRoomMenu = std::make_unique(); + + mCurrentMenu = mMainMenu.get(); szCurrentMapName = mGameSettingsMenu->miMapField->GetMapName(); + + return true; } //--------------------------------------------------------------- @@ -185,15 +189,15 @@ void MenuState::onEnterState() if (game_values.gamemode->winningteam > -1 && game_values.tournamentwinner == -1 && (((game_values.matchtype == MatchType::SingleGame || game_values.matchtype == MatchType::QuickGame || game_values.matchtype == MatchType::MiniGame || game_values.matchtype == MatchType::Tournament || game_values.matchtype == MatchType::NetGame) && game_values.bonuswheel == 2) || (game_values.matchtype == MatchType::Tour && game_values.tourstops[game_values.tourstopcurrent - 1]->iBonusType))) { mBonusWheelMenu->miBonusWheel->Reset(false); - mCurrentMenu = mBonusWheelMenu; + mCurrentMenu = mBonusWheelMenu.get(); } else if (game_values.matchtype != MatchType::SingleGame && game_values.matchtype != MatchType::QuickGame && game_values.matchtype != MatchType::MiniGame && game_values.matchtype != MatchType::NetGame) { - mCurrentMenu = mTournamentScoreboardMenu; + mCurrentMenu = mTournamentScoreboardMenu.get(); } else if (game_values.matchtype == MatchType::QuickGame) { //Reset back to main menu after quick game - mCurrentMenu = mMainMenu; + mCurrentMenu = mMainMenu.get(); mCurrentMenu->ResetMenu(); } else if (game_values.matchtype == MatchType::NetGame) { - mCurrentMenu = mNetLobbyMenu; + mCurrentMenu = mNetLobbyMenu.get(); mCurrentMenu->ResetMenu(); netplay.joinSuccessful = false; netplay.gameRunning = false; @@ -225,7 +229,7 @@ void MenuState::onEnterState() //If we're suposed to skip the scoreboard, then reset back to the world map if (game_values.worldskipscoreboard) { - mCurrentMenu = mWorldMenu; + mCurrentMenu = mWorldMenu.get(); mCurrentMenu->ResetMenu(); game_values.worldskipscoreboard = false; @@ -369,7 +373,7 @@ void MenuState::onEnterState() } if (game_values.matchtype != MatchType::World && game_values.matchtype != MatchType::QuickGame && game_values.matchtype != MatchType::NetGame) { - if (mCurrentMenu == mGameSettingsMenu || mCurrentMenu == mTournamentScoreboardMenu) + if (mCurrentMenu == mGameSettingsMenu.get() || mCurrentMenu == mTournamentScoreboardMenu.get()) mGameSettingsMenu->miMapField->LoadCurrentMap(); } @@ -436,7 +440,7 @@ void MenuState::update() g_fAutoTest = !g_fAutoTest; if (g_fAutoTest) { - mCurrentMenu = mMainMenu; + mCurrentMenu = mMainMenu.get(); mCurrentMenu->ResetMenu(); LoadScript("Scripts/StartMenuAutomation.txt"); @@ -470,7 +474,7 @@ void MenuState::update() } //If AI is controlling the tournament menu, select the options - if (game_values.matchtype == MatchType::Tournament && iTournamentAITimer > 0 && mCurrentMenu == mGameSettingsMenu && mGameSettingsMenu->IsOnStartBtn()) { + if (game_values.matchtype == MatchType::Tournament && iTournamentAITimer > 0 && mCurrentMenu == mGameSettingsMenu.get() && mGameSettingsMenu->IsOnStartBtn()) { if (--iTournamentAITimer == 0) { iTournamentAIStep++; @@ -568,14 +572,14 @@ void MenuState::update() iDisplayErrorTimer = 0; net_endSession(); - mCurrentMenu = mMainMenu; + mCurrentMenu = mMainMenu.get(); } else if (MENU_CODE_BACK_TO_MATCH_SELECTION_MENU == code) { - mCurrentMenu = mMatchSelectionMenu; + mCurrentMenu = mMatchSelectionMenu.get(); iUnlockMinigameOptionIndex = 0; } else if (MENU_CODE_TO_MATCH_SELECTION_MENU == code) { mMatchSelectionMenu->WorldMapChanged(); - mCurrentMenu = mMatchSelectionMenu; + mCurrentMenu = mMatchSelectionMenu.get(); mCurrentMenu->ResetMenu(); iUnlockMinigameOptionIndex = 0; } else if (MENU_CODE_MATCH_SELECTION_START == code || MENU_CODE_QUICK_GAME_START == code) { @@ -587,7 +591,7 @@ void MenuState::update() game_values.matchtype = mMatchSelectionMenu->GetSelectedMatchType(); mTeamSelectMenu->ResetTeamSelect(); - mCurrentMenu = mTeamSelectMenu; + mCurrentMenu = mTeamSelectMenu.get(); mCurrentMenu->ResetMenu(); printf("Hello\n"); @@ -600,36 +604,36 @@ void MenuState::update() } else if (MENU_CODE_WORLD_MAP_CHANGED == code) { mMatchSelectionMenu->WorldMapChanged(); } else if (MENU_CODE_TO_OPTIONS_MENU == code) { - mCurrentMenu = mOptionsMenu; + mCurrentMenu = mOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_BACK_TO_OPTIONS_MENU == code) { - mCurrentMenu = mOptionsMenu; + mCurrentMenu = mOptionsMenu.get(); } else if (MENU_CODE_TO_NET_SERVERS_MENU == code) { - mCurrentMenu = mNetServersMenu; + mCurrentMenu = mNetServersMenu.get(); mCurrentMenu->ResetMenu(); net_startSession(); } else if (MENU_CODE_BACK_TO_GRAPHIC_OPTIONS_MENU == code) { - mCurrentMenu = mGraphicsOptionsMenu; + mCurrentMenu = mGraphicsOptionsMenu.get(); } else if (MENU_CODE_TO_CONTROLS_MENU == code) { - mCurrentMenu = mPlayerControlsSelectMenu; + mCurrentMenu = mPlayerControlsSelectMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_BACK_TO_CONTROLS_MENU == code) { - mCurrentMenu = mPlayerControlsSelectMenu; + mCurrentMenu = mPlayerControlsSelectMenu.get(); } else if (MENU_CODE_TO_PLAYER_1_CONTROLS == code) { mPlayerControlsMenu->SetPlayer(0); - mCurrentMenu = mPlayerControlsMenu; + mCurrentMenu = mPlayerControlsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_PLAYER_2_CONTROLS == code) { mPlayerControlsMenu->SetPlayer(1); - mCurrentMenu = mPlayerControlsMenu; + mCurrentMenu = mPlayerControlsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_PLAYER_3_CONTROLS == code) { mPlayerControlsMenu->SetPlayer(2); - mCurrentMenu = mPlayerControlsMenu; + mCurrentMenu = mPlayerControlsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_PLAYER_4_CONTROLS == code) { mPlayerControlsMenu->SetPlayer(3); - mCurrentMenu = mPlayerControlsMenu; + mCurrentMenu = mPlayerControlsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TOGGLE_FULLSCREEN == code) { @@ -774,14 +778,14 @@ void MenuState::update() if (mGameSettingsMenu->GetCurrentGameModeID() == game_mode_owned) mGameSettingsMenu->HideGMSettingsBtn(); - mCurrentMenu = mGameSettingsMenu; + mCurrentMenu = mGameSettingsMenu.get(); mCurrentMenu->ResetMenu(); //If it is a tournament, then set the controlling team if (MatchType::Tournament == game_values.matchtype) SetControllingTeamForSettingsMenu(game_values.tournamentcontrolteam, true); } else if (MatchType::Tour == game_values.matchtype) { - mCurrentMenu = mTourStopMenu; + mCurrentMenu = mTourStopMenu.get(); mCurrentMenu->ResetMenu(); } else if (MatchType::World == game_values.matchtype) { game_values.screenfadespeed = 8; @@ -815,9 +819,9 @@ void MenuState::update() ResetTournamentBackToMainMenu(); } else if (game_values.tournamentwinner >= 0) { mBonusWheelMenu->miBonusWheel->Reset(true); - mCurrentMenu = mBonusWheelMenu; + mCurrentMenu = mBonusWheelMenu.get(); } else { - mCurrentMenu = mWorldMenu; + mCurrentMenu = mWorldMenu.get(); mWorldMenu->miWorldStop->Refresh(game_values.tourstopcurrent); fNeedTeamAnnouncement = true; @@ -830,13 +834,13 @@ void MenuState::update() ResetTournamentBackToMainMenu(); } else { mBonusWheelMenu->miBonusWheel->Reset(true); - mCurrentMenu = mBonusWheelMenu; + mCurrentMenu = mBonusWheelMenu.get(); } } else { //Next Tour/Tourament Game if (game_values.matchtype == MatchType::Tour) { - mCurrentMenu = mTourStopMenu; + mCurrentMenu = mTourStopMenu.get(); } else { - mCurrentMenu = mGameSettingsMenu; + mCurrentMenu = mGameSettingsMenu.get(); } } } @@ -851,9 +855,9 @@ void MenuState::update() mWorldMenu->miWorld->DisplayTeamControlAnnouncement(); } else if (MENU_CODE_BACK_TO_GAME_SETUP_MENU_FROM_MODE_SETTINGS == code) { if (netplay.active) - mCurrentMenu = mNetNewRoomSettingsMenu; + mCurrentMenu = mNetNewRoomSettingsMenu.get(); else - mCurrentMenu = mGameSettingsMenu; + mCurrentMenu = mGameSettingsMenu.get(); } else if (MENU_CODE_MODE_CHANGED == code) { game_values.gamemode = gamemodes[mGameSettingsMenu->GetCurrentGameModeID()]; mGameSettingsMenu->RefreshGameModeButtons(); @@ -869,7 +873,7 @@ void MenuState::update() if (iTournamentAITimer > 0) SetControllingTeamForSettingsMenu(-1, false); } else { - mCurrentMenu = mTeamSelectMenu; + mCurrentMenu = mTeamSelectMenu.get(); mCurrentMenu->ResetMenu(); } } else if (MENU_CODE_SOUND_VOLUME_CHANGED == code) { @@ -914,15 +918,15 @@ void MenuState::update() if (mBonusWheelMenu->miBonusWheel->GetPowerupSelectionDone()) { if (game_values.matchtype == MatchType::World) { if (game_values.tournamentwinner == -1) - mCurrentMenu = mTournamentScoreboardMenu; + mCurrentMenu = mTournamentScoreboardMenu.get(); else ResetTournamentBackToMainMenu(); } else { if ((game_values.matchtype == MatchType::Tour || game_values.matchtype == MatchType::Tournament) && game_values.tournamentwinner == -1 && ((game_values.matchtype != MatchType::Tour && game_values.bonuswheel == 2) || (game_values.matchtype == MatchType::Tour && game_values.tourstops[game_values.tourstopcurrent - 1]->iBonusType))) { - mCurrentMenu = mTournamentScoreboardMenu; + mCurrentMenu = mTournamentScoreboardMenu.get(); } else if (game_values.matchtype == MatchType::SingleGame) { - mCurrentMenu = mGameSettingsMenu; + mCurrentMenu = mGameSettingsMenu.get(); mCurrentMenu->ResetMenu(); mGameSettingsMenu->miMapField->LoadCurrentMap(); } else { @@ -931,31 +935,31 @@ void MenuState::update() } } } else if (MENU_CODE_TO_POWERUP_SELECTION_MENU == code) { - mCurrentMenu = mPowerupDropRatesMenu; + mCurrentMenu = mPowerupDropRatesMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_POWERUP_SETTINGS_MENU == code) { - mCurrentMenu = mPowerupSettingsMenu; + mCurrentMenu = mPowerupSettingsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_GRAPHICS_OPTIONS_MENU == code) { - mCurrentMenu = mGraphicsOptionsMenu; + mCurrentMenu = mGraphicsOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_EYECANDY_OPTIONS_MENU == code) { - mCurrentMenu = mEyeCandyOptionsMenu; + mCurrentMenu = mEyeCandyOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_SOUND_OPTIONS_MENU == code) { - mCurrentMenu = mSoundOptionsMenu; + mCurrentMenu = mSoundOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_GAMEPLAY_OPTIONS_MENU == code) { - mCurrentMenu = mGameplayOptionsMenu; + mCurrentMenu = mGameplayOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_TEAM_OPTIONS_MENU == code) { - mCurrentMenu = mTeamOptionsMenu; + mCurrentMenu = mTeamOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_PROJECTILES_OPTIONS_MENU == code) { - mCurrentMenu = mProjectileOptionsMenu; + mCurrentMenu = mProjectileOptionsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_PROJECTILES_LIMITS_MENU == code) { - mCurrentMenu = mProjectileLimitsMenu; + mCurrentMenu = mProjectileLimitsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_MODE_SETTINGS_MENU == code) { if (netplay.active) { @@ -1033,7 +1037,7 @@ void MenuState::update() for (short iPlayer = 0; iPlayer < 4; iPlayer++) game_values.storedpowerups[iPlayer] = -1; } else if (MENU_CODE_MAP_CHANGED == code) { - if (mCurrentMenu == mNetNewRoomSettingsMenu) { + if (mCurrentMenu == mNetNewRoomSettingsMenu.get()) { assert(netplay.active); netplay.mapfilepath = mNetNewRoomSettingsMenu->getCurrentMapPath(); printf("[net] Selected map: %s\n", netplay.mapfilepath.c_str()); @@ -1061,18 +1065,18 @@ void MenuState::update() } else if (MENU_CODE_TO_MAP_FILTER_EDIT == code) { mMapFilterEditMenu->miMapBrowser->Reset(0); - mCurrentMenu = mMapFilterEditMenu; + mCurrentMenu = mMapFilterEditMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_MAP_BROWSER_EXIT == code) { mGameSettingsMenu->miMapField->LoadCurrentMap(); szCurrentMapName = mGameSettingsMenu->miMapField->GetMapName(); - mCurrentMenu = mGameSettingsMenu; + mCurrentMenu = mGameSettingsMenu.get(); //mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_MAP_BROWSER_THUMBNAILS == code) { mMapFilterEditMenu->miMapBrowser->Reset(1); - mCurrentMenu = mMapFilterEditMenu; + mCurrentMenu = mMapFilterEditMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_SAVE_ALL_MAP_THUMBNAILS == code) { ((UI_OptionsMenu*) mCurrentMenu)->showThumbnailsPopup(); @@ -1130,7 +1134,7 @@ void MenuState::update() if (MENU_CODE_TO_NET_SERVERLIST == code) { mNetServersMenu->OpenServerList(); } else if (MENU_CODE_TO_NET_ADDREMOVE_SERVER_MENU == code) { - mCurrentMenu = mNetEditServersMenu; + mCurrentMenu = mNetEditServersMenu.get(); mCurrentMenu->ResetMenu(); mNetEditServersMenu->Restore(); } else if (MENU_CODE_NET_ADDREMOVE_SERVER_ON_ADD_BTN == code) { @@ -1172,13 +1176,13 @@ void MenuState::update() mNetLobbyMenu->Restore(); mNetNewRoomMenu->Restore(); - mCurrentMenu = mNetLobbyMenu; + mCurrentMenu = mNetLobbyMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_NET_NEW_ROOM_LEVEL_SELECT_MENU == code) { - mCurrentMenu = mNetNewRoomSettingsMenu; + mCurrentMenu = mNetNewRoomSettingsMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_TO_NET_NEW_ROOM_SETTINGS_MENU == code) { - mCurrentMenu = mNetNewRoomMenu; + mCurrentMenu = mNetNewRoomMenu.get(); mCurrentMenu->ResetMenu(); } else if (MENU_CODE_NET_CHAT_SEND == code) { if (strlen(netplay.mychatmessage) > 0) @@ -1186,7 +1190,7 @@ void MenuState::update() else code = MENU_CODE_TO_NET_ROOM_MENU; } else if (MENU_CODE_TO_NET_ROOM_MENU == code) { - mCurrentMenu = mNetRoomMenu; + mCurrentMenu = mNetRoomMenu.get(); mCurrentMenu->ResetMenu(); netplay.currentMenuChanged = true; netplay.operationInProgress = false; @@ -1242,7 +1246,7 @@ void MenuState::update() //--------------- draw everything ---------------------- //Don't draw backdrop for world - if (mCurrentMenu != mWorldMenu) + if (mCurrentMenu != mWorldMenu.get()) rm->menu_backdrop.draw(0, 0); else SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); @@ -1394,7 +1398,7 @@ void MenuState::update() } else if (AppState::StartWorld == game_values.appstate) { //Fade to world match type game_values.screenfadespeed = -8; - mCurrentMenu = mWorldMenu; + mCurrentMenu = mWorldMenu.get(); mCurrentMenu->ResetMenu(); rm->backgroundmusic[2].stop(); @@ -1674,7 +1678,7 @@ void MenuState::Exit() void MenuState::ResetTournamentBackToMainMenu() { - mCurrentMenu = mMainMenu; + mCurrentMenu = mMainMenu.get(); mCurrentMenu->ResetMenu(); if (game_values.matchtype != MatchType::SingleGame && game_values.matchtype != MatchType::QuickGame && game_values.matchtype != MatchType::MiniGame && game_values.matchtype != MatchType::NetGame) { @@ -1748,7 +1752,7 @@ void MenuState::GetNextScriptOperation() //slowdowntimer = 0; if (iScriptState == 1) { - if (mCurrentMenu == mGameSettingsMenu) { + if (mCurrentMenu == mGameSettingsMenu.get()) { if (!fScriptRunPreGameOptions) { fScriptRunPreGameOptions = true; LoadScript("Scripts/GameModeOptionsOnly.txt"); @@ -1786,7 +1790,7 @@ void MenuState::GetNextScriptOperation() } game_values.gamemode->setdebuggoal(); - } else if (mCurrentMenu == mTourStopMenu) { + } else if (mCurrentMenu == mTourStopMenu.get()) { static int tournext = RANDOM_INT(200); if (--tournext < 0) { @@ -1799,7 +1803,7 @@ void MenuState::GetNextScriptOperation() return; } else if (iScriptState == 2) { - if (mCurrentMenu == mTournamentScoreboardMenu) { + if (mCurrentMenu == mTournamentScoreboardMenu.get()) { static int scoreboardnext = RANDOM_INT(200); if (--scoreboardnext < 0) { @@ -1809,14 +1813,14 @@ void MenuState::GetNextScriptOperation() } return; - } else if (mCurrentMenu == mGameSettingsMenu) { + } else if (mCurrentMenu == mGameSettingsMenu.get()) { iScriptState = 0; - mCurrentMenu = mMainMenu; + mCurrentMenu = mMainMenu.get(); mCurrentMenu->ResetMenu(); LoadScript("Scripts/StartMenuAutomation.txt"); fScriptRunPreGameOptions = true; return; - } else if (mCurrentMenu == mBonusWheelMenu) { + } else if (mCurrentMenu == mBonusWheelMenu.get()) { static int bonuswheelnext = RANDOM_INT(200) + 300; if (--bonuswheelnext < 0) { @@ -1825,7 +1829,7 @@ void MenuState::GetNextScriptOperation() bonuswheelnext = RANDOM_INT(200) + 300; } return; - } else if (mCurrentMenu == mTourStopMenu) { + } else if (mCurrentMenu == mTourStopMenu.get()) { static int tournext = RANDOM_INT(200); if (--tournext < 0) { @@ -1838,20 +1842,20 @@ void MenuState::GetNextScriptOperation() return; } else if (iScriptState == 3) { - if (mCurrentMenu == mBonusWheelMenu) { + if (mCurrentMenu == mBonusWheelMenu.get()) { game_values.playerInput.outputControls[0].menu_select.fPressed = true; return; - } else if (mCurrentMenu == mGameSettingsMenu) { + } else if (mCurrentMenu == mGameSettingsMenu.get()) { iScriptState = 0; LoadScript("Scripts/GameModeOptionsOnly.txt"); fScriptRunPreGameOptions = true; return; - } else if (mCurrentMenu == mMainMenu) { + } else if (mCurrentMenu == mMainMenu.get()) { iScriptState = 0; LoadScript("Scripts/StartMenuAutomation.txt"); fScriptRunPreGameOptions = true; return; - } else if (mCurrentMenu == mTourStopMenu) { + } else if (mCurrentMenu == mTourStopMenu.get()) { static int tournext = RANDOM_INT(200); if (--tournext < 0) { diff --git a/src/smw/GSMenu.h b/src/smw/GSMenu.h index 05972473..f6c26776 100644 --- a/src/smw/GSMenu.h +++ b/src/smw/GSMenu.h @@ -3,6 +3,7 @@ #include "GameState.h" +#include #include class UI_Menu; @@ -93,8 +94,8 @@ class MenuState : public GameState #endif private: - MenuState() {} - ~MenuState() {} + MenuState(); + ~MenuState(); MenuState(MenuState const&); void operator=(MenuState const&); @@ -110,43 +111,43 @@ class MenuState : public GameState void DisplayControllingTeamMessage(short iControlTeam); - UI_Menu * mCurrentMenu; - UI_MainMenu* mMainMenu; + UI_Menu* mCurrentMenu = nullptr; + std::unique_ptr mMainMenu; // Options menu - UI_OptionsMenu* mOptionsMenu; - UI_GameplayOptionsMenu* mGameplayOptionsMenu; - UI_TeamOptionsMenu* mTeamOptionsMenu; - UI_PowerupDropRatesMenu* mPowerupDropRatesMenu; - UI_PowerupSettingsMenu* mPowerupSettingsMenu; - UI_ProjectileLimitsMenu* mProjectileLimitsMenu; - UI_ProjectileOptionsMenu* mProjectileOptionsMenu; - UI_GraphicsOptionsMenu* mGraphicsOptionsMenu; - UI_EyeCandyOptionsMenu* mEyeCandyOptionsMenu; - UI_SoundOptionsMenu* mSoundOptionsMenu; + std::unique_ptr mOptionsMenu; + std::unique_ptr mGameplayOptionsMenu; + std::unique_ptr mTeamOptionsMenu; + std::unique_ptr mPowerupDropRatesMenu; + std::unique_ptr mPowerupSettingsMenu; + std::unique_ptr mProjectileLimitsMenu; + std::unique_ptr mProjectileOptionsMenu; + std::unique_ptr mGraphicsOptionsMenu; + std::unique_ptr mEyeCandyOptionsMenu; + std::unique_ptr mSoundOptionsMenu; // Controls menu - UI_PlayerControlsSelectMenu* mPlayerControlsSelectMenu; - UI_PlayerControlsMenu* mPlayerControlsMenu; + std::unique_ptr mPlayerControlsSelectMenu; + std::unique_ptr mPlayerControlsMenu; // Gameplay menus - UI_ModeOptionsMenu* mModeOptionsMenu; - UI_MatchSelectionMenu* mMatchSelectionMenu; - UI_GameSettingsMenu* mGameSettingsMenu; - UI_MapFilterEditMenu* mMapFilterEditMenu; - UI_TourStopMenu* mTourStopMenu; - UI_WorldMenu* mWorldMenu; - UI_TeamSelectMenu* mTeamSelectMenu; - UI_TournamentScoreboardMenu* mTournamentScoreboardMenu; - UI_BonusWheelMenu* mBonusWheelMenu; + std::unique_ptr mModeOptionsMenu; + std::unique_ptr mMatchSelectionMenu; + std::unique_ptr mGameSettingsMenu; + std::unique_ptr mMapFilterEditMenu; + std::unique_ptr mTourStopMenu; + std::unique_ptr mWorldMenu; + std::unique_ptr mTeamSelectMenu; + std::unique_ptr mTournamentScoreboardMenu; + std::unique_ptr mBonusWheelMenu; // Multiplayer menu - UI_NetServersMenu* mNetServersMenu; - UI_NetEditServersMenu* mNetEditServersMenu; - UI_NetLobbyMenu* mNetLobbyMenu; - UI_NetNewRoomMenu* mNetNewRoomMenu; - UI_NetNewRoomSettingsMenu* mNetNewRoomSettingsMenu; - UI_NetRoomMenu* mNetRoomMenu; + std::unique_ptr mNetServersMenu; + std::unique_ptr mNetEditServersMenu; + std::unique_ptr mNetLobbyMenu; + std::unique_ptr mNetNewRoomMenu; + std::unique_ptr mNetNewRoomSettingsMenu; + std::unique_ptr mNetRoomMenu; DisplayError iDisplayError; short iDisplayErrorTimer;