From 1e97859fbfcf67814491c66f0f0cc0011966faed Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Tue, 26 Apr 2022 14:14:31 +0300 Subject: [PATCH] Fix crash when clicking scenario info during campaign gameplay. --- client/CMakeLists.txt | 2 ++ client/lobby/CBonusSelection.cpp | 4 ++- client/lobby/CBonusSelection.h | 3 +- client/lobby/CCampaignInfoScreen.cpp | 49 ++++++++++++++++++++++++++++ client/lobby/CCampaignInfoScreen.h | 26 +++++++++++++++ client/windows/CAdvmapInterface.cpp | 6 ++-- 6 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 client/lobby/CCampaignInfoScreen.cpp create mode 100644 client/lobby/CCampaignInfoScreen.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1a765f750..f6fc03a77 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -49,6 +49,7 @@ set(client_SRCS lobby/CLobbyScreen.cpp lobby/CSavingScreen.cpp lobby/CScenarioInfoScreen.cpp + lobby/CCampaignInfoScreen.cpp lobby/OptionsTab.cpp lobby/RandomMapTab.cpp lobby/SelectionTab.cpp @@ -121,6 +122,7 @@ set(client_HEADERS lobby/CLobbyScreen.h lobby/CSavingScreen.h lobby/CScenarioInfoScreen.h + lobby/CCampaignInfoScreen.h lobby/OptionsTab.h lobby/RandomMapTab.h lobby/SelectionTab.h diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index cf97b94b0..78b62736b 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -360,6 +360,8 @@ void CBonusSelection::updateAfterStateChange() buttonStart->disable(); buttonRestart->enable(); buttonBack->block(false); + buttonDifficultyLeft->disable(); + buttonDifficultyRight->disable(); } if(CSH->campaignBonus == -1) { @@ -449,7 +451,7 @@ void CBonusSelection::restartMap() close(); LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [=]() { - CSH->startCampaignScenario(); + LOCPLINT->sendCustomEvent(EUserEvent::RESTART_GAME); }, 0); } diff --git a/client/lobby/CBonusSelection.h b/client/lobby/CBonusSelection.h index 9cc819748..9c9c7d178 100644 --- a/client/lobby/CBonusSelection.h +++ b/client/lobby/CBonusSelection.h @@ -18,6 +18,7 @@ class CToggleGroup; class CAnimImage; class CLabel; class CFlagBox; +class ISelectionScreenInfo; /// Campaign screen where you can choose one out of three starting bonuses class CBonusSelection : public CWindowObject @@ -89,4 +90,4 @@ public: std::shared_ptr buttonDifficultyLeft; std::shared_ptr buttonDifficultyRight; std::shared_ptr iconsMapSizes; -}; +}; \ No newline at end of file diff --git a/client/lobby/CCampaignInfoScreen.cpp b/client/lobby/CCampaignInfoScreen.cpp new file mode 100644 index 000000000..ce45bf45c --- /dev/null +++ b/client/lobby/CCampaignInfoScreen.cpp @@ -0,0 +1,49 @@ +/* + * CCampaignInfoScreen.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" + +#include "CCampaignInfoScreen.h" + +#include "../../CCallback.h" +#include "../../lib/CGeneralTextHandler.h" +#include "../../lib/StartInfo.h" +#include "../../lib/mapping/CMapInfo.h" +#include "../gui/CAnimation.h" +#include "../gui/CGuiHandler.h" +#include "../CGameInfo.h" +#include "../CMessage.h" +#include "../CPlayerInterface.h" + +CCampaignInfoScreen::CCampaignInfoScreen() +{ + OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; + localSi = new StartInfo(*LOCPLINT->cb->getStartInfo()); + localMi = new CMapInfo(); + localMi->mapHeader = std::unique_ptr(new CMapHeader(*LOCPLINT->cb->getMapHeader())); + + screenType = ESelectionScreen::scenarioInfo; + + updateAfterStateChange(); +} + +CCampaignInfoScreen::~CCampaignInfoScreen() +{ + vstd::clear_pointer(localSi); + vstd::clear_pointer(localMi); +} + +const CMapInfo * CCampaignInfoScreen::getMapInfo() +{ + return localMi; +} +const StartInfo * CCampaignInfoScreen::getStartInfo() +{ + return localSi; +} diff --git a/client/lobby/CCampaignInfoScreen.h b/client/lobby/CCampaignInfoScreen.h new file mode 100644 index 000000000..bceab47a6 --- /dev/null +++ b/client/lobby/CCampaignInfoScreen.h @@ -0,0 +1,26 @@ +/* + * CCampaignInfoScreen.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "CSelectionBase.h" +#include "CBonusSelection.h" + +class CCampaignInfoScreen : public CBonusSelection, ISelectionScreenInfo +{ + const StartInfo * localSi; + CMapInfo * localMi; + +public: + CCampaignInfoScreen(); + ~CCampaignInfoScreen(); + + const CMapInfo * getMapInfo() override; + const StartInfo * getStartInfo() override; +}; \ No newline at end of file diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index 4372266f4..9959529c2 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -23,7 +23,8 @@ #include "../CMusicHandler.h" #include "../CPlayerInterface.h" #include "../mainmenu/CMainMenu.h" -#include "../lobby/CBonusSelection.h" +#include "../lobby/CSelectionBase.h" +#include "../lobby/CCampaignInfoScreen.h" #include "../lobby/CSavingScreen.h" #include "../lobby/CScenarioInfoScreen.h" #include "../Graphics.h" @@ -51,6 +52,7 @@ #include "../../lib/UnlockGuard.h" #include "../../lib/VCMI_Lib.h" #include "../../lib/StartInfo.h" +#include "../../lib/mapping/CMapInfo.h" #ifdef _MSC_VER #pragma warning (disable : 4355) @@ -1964,7 +1966,7 @@ void CAdventureOptions::showScenarioInfo() { if(LOCPLINT->cb->getStartInfo()->campState) { - GH.pushIntT(); + GH.pushIntT(); } else {