From 82d2c217210dbd058a26fc25905d65c50aa33688 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 23 May 2024 23:27:13 +0100 Subject: [PATCH] Refactor OptionsUI functionality into NakatomiInteractiveWidget --- .../UI/LoadGame/BP_LoadGameUserWidget.uasset | 3 +++ Source/Nakatomi/OptionsUIWidget.cpp | 14 +------------- Source/Nakatomi/OptionsUIWidget.h | 6 ------ .../Nakatomi/UI/NakatomiInteractiveWidget.cpp | 18 ++++++++++++++++++ Source/Nakatomi/UI/NakatomiInteractiveWidget.h | 12 +++++++++++- 5 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 Content/UI/LoadGame/BP_LoadGameUserWidget.uasset diff --git a/Content/UI/LoadGame/BP_LoadGameUserWidget.uasset b/Content/UI/LoadGame/BP_LoadGameUserWidget.uasset new file mode 100644 index 0000000..8cfd236 --- /dev/null +++ b/Content/UI/LoadGame/BP_LoadGameUserWidget.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:826461985252a8ed8586c65bb96be2485c84581c8e3ff8fa803a2065105f7244 +size 23116 diff --git a/Source/Nakatomi/OptionsUIWidget.cpp b/Source/Nakatomi/OptionsUIWidget.cpp index 78061b5..fe0a3b9 100644 --- a/Source/Nakatomi/OptionsUIWidget.cpp +++ b/Source/Nakatomi/OptionsUIWidget.cpp @@ -109,21 +109,9 @@ void UOptionsUIWidget::NativeConstruct() SetIsFocusable(true); } -void UOptionsUIWidget::SetReturnScreen(UUserWidget* userWidget) -{ - if (userWidget) - { - PreviousScreen = userWidget; - } -} - void UOptionsUIWidget::BackButtonOnClicked() { - // TODO: Implement Functionality - GEngine->GameUserSettings->ApplySettings(false); - - this->RemoveFromParent(); - PreviousScreen->AddToViewport(); + ReturnToPreviousScreen(); } void UOptionsUIWidget::ResetToDefaultsButtonOnClicked() diff --git a/Source/Nakatomi/OptionsUIWidget.h b/Source/Nakatomi/OptionsUIWidget.h index 8453436..0b7d06f 100644 --- a/Source/Nakatomi/OptionsUIWidget.h +++ b/Source/Nakatomi/OptionsUIWidget.h @@ -51,15 +51,9 @@ public: UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UTextBlock* ResetToDefaultsTextBlock; - -private: - - UUserWidget* PreviousScreen; public: virtual void NativeConstruct() override; - - void SetReturnScreen(UUserWidget* userWidget); private: diff --git a/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp b/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp index ad7503a..636204e 100644 --- a/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp +++ b/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp @@ -3,6 +3,7 @@ #include "../UI/NakatomiInteractiveWidget.h" +#include "GameFramework/GameUserSettings.h" #include "Kismet/GameplayStatics.h" void UNakatomiInteractiveWidget::PlayHoveredSound() @@ -38,3 +39,20 @@ void UNakatomiInteractiveWidget::PlayClickedSound() UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound); } } + +void UNakatomiInteractiveWidget::ReturnToPreviousScreen() +{ + // TODO: Implement Functionality + GEngine->GameUserSettings->ApplySettings(false); + + this->RemoveFromParent(); + PreviousScreen->AddToViewport(); +} + +void UNakatomiInteractiveWidget::SetReturnScreen(UUserWidget* userWidget) +{ + if (userWidget) + { + PreviousScreen = userWidget; + } +} diff --git a/Source/Nakatomi/UI/NakatomiInteractiveWidget.h b/Source/Nakatomi/UI/NakatomiInteractiveWidget.h index e2bb91b..7053362 100644 --- a/Source/Nakatomi/UI/NakatomiInteractiveWidget.h +++ b/Source/Nakatomi/UI/NakatomiInteractiveWidget.h @@ -32,6 +32,14 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) USoundBase* ButtonClickedSound; +protected: + UUserWidget* PreviousScreen; + +public: + + UFUNCTION() + void SetReturnScreen(UUserWidget* userWidget); + protected: UFUNCTION() void PlayHoveredSound(); @@ -47,5 +55,7 @@ protected: UFUNCTION() void PlayClickedSound(); - + + UFUNCTION() + void ReturnToPreviousScreen(); };