Add MVP frontend audio hooks

This commit is contained in:
2026-05-19 12:35:30 -07:00
parent f6e126aabb
commit d0ad64418d
5 changed files with 99 additions and 1 deletions
@@ -14,6 +14,7 @@
#include "Components/VerticalBoxSlot.h"
#include "GameFramework/PlayerController.h"
#include "InputCoreTypes.h"
#include "Kismet/GameplayStatics.h"
#include "Styling/CoreStyle.h"
#include "TimerManager.h"
@@ -48,18 +49,21 @@ FReply UAgrarianMvpFrontendWidget::NativeOnKeyDown(const FGeometry& InGeometry,
const FKey Key = InKeyEvent.GetKey();
if (Key == EKeys::Left || Key == EKeys::A)
{
PlayUiSound(UiSelectionSound);
SetSelectedCharacterArchetype(EAgrarianMvpCharacterArchetype::YoungAdultMale);
return FReply::Handled();
}
if (Key == EKeys::Right || Key == EKeys::D)
{
PlayUiSound(UiSelectionSound);
SetSelectedCharacterArchetype(EAgrarianMvpCharacterArchetype::YoungAdultFemale);
return FReply::Handled();
}
if (Key == EKeys::Enter || Key == EKeys::SpaceBar)
{
PlayUiSound(UiConfirmSound);
ConfirmActiveScreen();
return FReply::Handled();
}
@@ -69,12 +73,14 @@ FReply UAgrarianMvpFrontendWidget::NativeOnKeyDown(const FGeometry& InGeometry,
const FKey Key = InKeyEvent.GetKey();
if (Key == EKeys::Enter || Key == EKeys::SpaceBar)
{
PlayUiSound(UiConfirmSound);
ConfirmActiveScreen();
return FReply::Handled();
}
if (Key == EKeys::BackSpace || Key == EKeys::Escape)
{
PlayUiSound(UiBackSound);
BackFromActiveScreen();
return FReply::Handled();
}
@@ -84,6 +90,7 @@ FReply UAgrarianMvpFrontendWidget::NativeOnKeyDown(const FGeometry& InGeometry,
const FKey Key = InKeyEvent.GetKey();
if (Key == EKeys::Enter || Key == EKeys::SpaceBar)
{
PlayUiSound(UiConfirmSound);
ConfirmActiveScreen();
return FReply::Handled();
}
@@ -93,12 +100,14 @@ FReply UAgrarianMvpFrontendWidget::NativeOnKeyDown(const FGeometry& InGeometry,
const FKey Key = InKeyEvent.GetKey();
if (Key == EKeys::Enter || Key == EKeys::SpaceBar || Key == EKeys::Escape)
{
PlayUiSound(UiConfirmSound);
ConfirmActiveScreen();
return FReply::Handled();
}
if (Key == EKeys::Q)
{
PlayUiSound(UiSaveQuitSound);
SaveAndQuit();
return FReply::Handled();
}
@@ -466,6 +475,14 @@ UButton* UAgrarianMvpFrontendWidget::AddButton(UVerticalBox* Parent, const FText
return Button;
}
void UAgrarianMvpFrontendWidget::PlayUiSound(USoundBase* Sound) const
{
if (Sound)
{
UGameplayStatics::PlaySound2D(this, Sound);
}
}
void UAgrarianMvpFrontendWidget::FocusPrimaryButton()
{
if (PrimaryFocusButton)
@@ -480,26 +497,31 @@ void UAgrarianMvpFrontendWidget::FocusPrimaryButton()
void UAgrarianMvpFrontendWidget::HandlePrimaryActionClicked()
{
PlayUiSound(UiConfirmSound);
ConfirmActiveScreen();
}
void UAgrarianMvpFrontendWidget::HandleBackClicked()
{
PlayUiSound(UiBackSound);
BackFromActiveScreen();
}
void UAgrarianMvpFrontendWidget::HandleSaveAndQuitClicked()
{
PlayUiSound(UiSaveQuitSound);
SaveAndQuit();
}
void UAgrarianMvpFrontendWidget::HandleMaleCharacterClicked()
{
PlayUiSound(UiSelectionSound);
SetSelectedCharacterArchetype(EAgrarianMvpCharacterArchetype::YoungAdultMale);
}
void UAgrarianMvpFrontendWidget::HandleFemaleCharacterClicked()
{
PlayUiSound(UiSelectionSound);
SetSelectedCharacterArchetype(EAgrarianMvpCharacterArchetype::YoungAdultFemale);
}
@@ -7,6 +7,7 @@
#include "AgrarianMvpFrontendWidget.generated.h"
class UButton;
class USoundBase;
class UTextBlock;
class UVerticalBox;
@@ -57,6 +58,18 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
bool bUseHighContrast = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI|Audio")
TObjectPtr<USoundBase> UiConfirmSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI|Audio")
TObjectPtr<USoundBase> UiBackSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI|Audio")
TObjectPtr<USoundBase> UiSelectionSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI|Audio")
TObjectPtr<USoundBase> UiSaveQuitSound;
UFUNCTION(BlueprintCallable, Category = "Agrarian|MVP UI")
void SetActiveScreen(EAgrarianMvpFrontendScreen NewScreen);
@@ -90,6 +103,7 @@ private:
void RebuildFrontendTree();
UTextBlock* AddText(UVerticalBox* Parent, const FText& Text, int32 FontSize, bool bBold, const FLinearColor& Color, float BottomPadding);
UButton* AddButton(UVerticalBox* Parent, const FText& Text, const FLinearColor& NormalColor, const FLinearColor& HoveredColor, float BottomPadding);
void PlayUiSound(USoundBase* Sound) const;
UFUNCTION()
void FocusPrimaryButton();