Menu #8

Merged
oleg.petruny merged 9 commits from Menu into master 2025-01-13 18:54:47 +00:00
8 changed files with 32 additions and 26 deletions
Showing only changes of commit 498dc7ec8e - Show all commits

Binary file not shown.

View File

@ -10,6 +10,12 @@
#include "PlayerBase.h"
#include "SaveData.h"
namespace
{
constexpr auto saveName = TEXT("Save");
constexpr int32 saveIndex = 0;
}
UCustomGameInstance* UCustomGameInstance::instance = nullptr;
void UCustomGameInstance::Init()
@ -18,7 +24,11 @@ void UCustomGameInstance::Init()
instance = this;
contentLoader = NewObject<UContentLoader>(this);
saveData = Cast<USaveData>(UGameplayStatics::CreateSaveGameObject(USaveData::StaticClass()));
if(auto save = UGameplayStatics::LoadGameFromSlot(saveName, saveIndex))
saveData = Cast<USaveData>(save);
else
saveData = Cast<USaveData>(UGameplayStatics::CreateSaveGameObject(USaveData::StaticClass()));
}
UCustomGameInstance* UCustomGameInstance::Get()
@ -34,6 +44,14 @@ UContentLoader* UCustomGameInstance::GetContentLoader()
return nullptr;
}
bool UCustomGameInstance::IsGameSaved()
{
if(auto GI = Get())
return GI->saveData != nullptr;
return false;
}
void UCustomGameInstance::SaveGame(FName checkpointName)
{
auto levelScript = ALevelBase::Get();
@ -56,12 +74,12 @@ void UCustomGameInstance::SaveGame(FName checkpointName)
else
saveData->playerRightPocketItem = FName(TEXT(""));
UGameplayStatics::SaveGameToSlot(saveData, TEXT("Save"), 0);
UGameplayStatics::SaveGameToSlot(saveData, saveName, saveIndex);
}
void UCustomGameInstance::LoadGame()
{
saveData = Cast<USaveData>(UGameplayStatics::LoadGameFromSlot(TEXT("Save"), 0));
saveData = Cast<USaveData>(UGameplayStatics::LoadGameFromSlot(saveName, saveIndex));
if(!saveData)
return;

View File

@ -23,9 +23,11 @@ public:
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Custom Game Instance"))
static UCustomGameInstance* Get();
UFUNCTION(BlueprintPure)
static class UContentLoader* GetContentLoader();
/** Return true is save data are present and valid */
UFUNCTION(BlueprintPure)
static bool IsGameSaved();
UFUNCTION(BlueprintCallable, Category = Save)
void SaveGame(FName checkpointName);

View File

@ -11,16 +11,6 @@
bool UMainMenuWidget::Initialize()
{
if(ButtonLoadLastSave)
{
auto GI = UCustomGameInstance::Get();
if(GI && GI->saveData)
{
ButtonLoadLastSave->SetIsEnabled(true);
ButtonLoadLastSave->SetRenderOpacity(1.0f);
}
}
//FWidgetAnimationDynamicEvent closeFinished;
//closeFinished.BindDynamic(this, &UMainMenuWidget::Closed);
//BindToAnimationFinished(closeAnimation, closeFinished);

View File

@ -30,13 +30,9 @@ public:
UPROPERTY(BlueprintAssignable)
FMainMenuClosedDelegate OnMainMenuClosedDelegate;
UPROPERTY(meta = (BindWidget))
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
class UMainMenuButtonWidget* ButtonContinue;
UPROPERTY(meta = (BindWidget))
class UMainMenuButtonWidget* ButtonLoadLastSave;
UPROPERTY(meta = (BindWidget))
class UMainMenuButtonWidget* ButtonNewGame;
UPROPERTY(meta = (BindWidget))
class UMainMenuButtonWidget* ButtonOptions;
UPROPERTY(meta = (BindWidget))
class UMainMenuButtonWidget* ButtonCredits;