Populate SaveGameScrollBox with SaveGameEntries on NativeConstruct
This commit is contained in:
parent
15fdc538e5
commit
ca8756334a
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
#include "../UI/LoadGameUserWidget.h"
|
#include "../UI/LoadGameUserWidget.h"
|
||||||
|
|
||||||
|
#include "SaveGameEntryUserWidget.h"
|
||||||
|
#include "Blueprint/WidgetTree.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Nakatomi/NakatomiGameInstance.h"
|
||||||
|
|
||||||
void ULoadGameUserWidget::NativeConstruct()
|
void ULoadGameUserWidget::NativeConstruct()
|
||||||
{
|
{
|
||||||
Super::NativeConstruct();
|
Super::NativeConstruct();
|
||||||
|
@ -18,6 +23,22 @@ void ULoadGameUserWidget::NativeConstruct()
|
||||||
CancelButton->OnUnhovered.AddUniqueDynamic(this, &ULoadGameUserWidget::CancelButtonUnhoveredDelegate);
|
CancelButton->OnUnhovered.AddUniqueDynamic(this, &ULoadGameUserWidget::CancelButtonUnhoveredDelegate);
|
||||||
CancelButton->OnUnhovered.AddUniqueDynamic(this, &ULoadGameUserWidget::PlayUnhoveredSound);
|
CancelButton->OnUnhovered.AddUniqueDynamic(this, &ULoadGameUserWidget::PlayUnhoveredSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNakatomiGameInstance* gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()))
|
||||||
|
|
||||||
|
if (gameInstance && IsValid(SaveGameEntryWidgetTemplate))
|
||||||
|
{
|
||||||
|
TArray<FNakatomiSaveFileInfo> SaveFiles = gameInstance->GetAllSaveFilesFromDisk();
|
||||||
|
|
||||||
|
for (FNakatomiSaveFileInfo SaveFile : SaveFiles)
|
||||||
|
{
|
||||||
|
USaveGameEntryUserWidget* SaveGameEntry = WidgetTree->ConstructWidget<USaveGameEntryUserWidget>(
|
||||||
|
SaveGameEntryWidgetTemplate, FName("SaveGameEntry"));
|
||||||
|
|
||||||
|
SaveGameEntry->SetSaveInfo(SaveFile);
|
||||||
|
SavedGamesScrollBox->AddChild(SaveGameEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ULoadGameUserWidget::CancelButtonOnClicked()
|
void ULoadGameUserWidget::CancelButtonOnClicked()
|
||||||
|
|
|
@ -26,6 +26,9 @@ public:
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
UScrollBox* SavedGamesScrollBox;
|
UScrollBox* SavedGamesScrollBox;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
TSubclassOf<class USaveGameEntryUserWidget> SaveGameEntryWidgetTemplate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,17 @@ void USaveGameEntryUserWidget::NativeConstruct()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USaveGameEntryUserWidget::SetSaveInfo()
|
void USaveGameEntryUserWidget::SetSaveInfo(FNakatomiSaveFileInfo SaveFile)
|
||||||
{
|
{
|
||||||
|
SaveFileInfo = SaveFile;
|
||||||
|
PlayerNameTextBlock->SetText(FText::FromString(SaveFileInfo.PlayerName));
|
||||||
|
CurrentLevelTextBlock->SetText(FText::FromString(SaveFileInfo.CurrentLevel));
|
||||||
|
DateTimeSavedTextBlock->SetText(FText::FromString(SaveFileInfo.DateTimeSaved));
|
||||||
}
|
}
|
||||||
|
|
||||||
void USaveGameEntryUserWidget::LoadSaveButtonOnClicked()
|
void USaveGameEntryUserWidget::LoadSaveButtonOnClicked()
|
||||||
{
|
{
|
||||||
|
// TODO: implement loading of stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
void USaveGameEntryUserWidget::LoadSaveButtonHoveredDelegate()
|
void USaveGameEntryUserWidget::LoadSaveButtonHoveredDelegate()
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "NakatomiInteractiveWidget.h"
|
#include "NakatomiInteractiveWidget.h"
|
||||||
#include "Components/Button.h"
|
#include "Components/Button.h"
|
||||||
|
#include "Nakatomi/NakatomiSaveFileInfo.h"
|
||||||
#include "SaveGameEntryUserWidget.generated.h"
|
#include "SaveGameEntryUserWidget.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,11 +30,14 @@ public:
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
UTextBlock* DateTimeSavedTextBlock;
|
UTextBlock* DateTimeSavedTextBlock;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FNakatomiSaveFileInfo SaveFileInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void SetSaveInfo();
|
void SetSaveInfo(FNakatomiSaveFileInfo SaveFile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
|
|
Loading…
Reference in New Issue