Compare commits

...

2 Commits

Author SHA1 Message Date
baz
6ec8588020 Final Widget cleanup for now 2025-09-09 23:01:16 +01:00
baz
7e940e33fd Convert Game Over Widget to Custom Button 2025-09-09 23:00:57 +01:00
9 changed files with 29 additions and 130 deletions

BIN
Content/Levels/MainMenu/MainMenu.umap (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

View File

@ -3,8 +3,7 @@
#include "GameOverWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Components/Button.h"
#include "CustomButton.h"
#include "Components/TextBlock.h"
#include "Kismet/GameplayStatics.h"
#include "vampires/VampireGameInstance.h"
@ -13,12 +12,22 @@ void UGameOverWidget::NativeConstruct()
{
Super::NativeConstruct();
SetIsFocusable(false);
if (ReturnButton)
{
ReturnButton->OnClicked.AddUniqueDynamic(this, &UGameOverWidget::ReturnButtonOnClicked);
ReturnButton->OnHovered.AddUniqueDynamic(this, &UGameOverWidget::ReturnButtonOnHovered);
ReturnButton->OnUnhovered.AddUniqueDynamic(this, &UGameOverWidget::ReturnButtonOnUnhovered);
ReturnButton->OnFocused.AddUniqueDynamic(this, &UGameOverWidget::ReturnButtonOnFocused);
}
ReturnButton->SetKeyboardFocus();
}
FReply UGameOverWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
CurrentFocus->SetKeyboardFocus();
return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent);
}
void UGameOverWidget::SetGameInfo(int Level, float Timer, int Kill, int Gold)
@ -52,8 +61,6 @@ void UGameOverWidget::SetGameInfo(int Level, float Timer, int Kill, int Gold)
void UGameOverWidget::ReturnButtonOnClicked()
{
PlayClickedSound();
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
{
if (!GameInstance->MainMenuWorld.IsNull())
@ -69,14 +76,7 @@ void UGameOverWidget::ReturnButtonOnClicked()
}
}
void UGameOverWidget::ReturnButtonOnHovered()
void UGameOverWidget::ReturnButtonOnFocused(FFocusEvent InFocusEvent)
{
SetTextBlockHovered(ReturnBlock);
PlayHoveredSound();
}
void UGameOverWidget::ReturnButtonOnUnhovered()
{
SetTextBlockUnhovered(ReturnBlock);
PlayUnhoveredSound();
SetCurrentFocus(ReturnButton);
}

View File

@ -4,11 +4,10 @@
#include "CoreMinimal.h"
#include "VampireInteractiveWidget.h"
#include "Blueprint/UserWidget.h"
#include "GameOverWidget.generated.h"
class UCustomButton;
class UTextBlock;
class UButton;
/**
*
*/
@ -18,10 +17,7 @@ class VAMPIRES_API UGameOverWidget : public UVampireInteractiveWidget
GENERATED_BODY()
UPROPERTY(meta=(BindWidget))
TObjectPtr<UButton> ReturnButton;
UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> ReturnBlock;
TObjectPtr<UCustomButton> ReturnButton;
UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> LevelBlock;
@ -37,6 +33,8 @@ class VAMPIRES_API UGameOverWidget : public UVampireInteractiveWidget
virtual void NativeConstruct() override;
virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
public:
void SetGameInfo(int Level, float Timer, int Kill, int Gold);
@ -45,8 +43,5 @@ private:
void ReturnButtonOnClicked();
UFUNCTION()
void ReturnButtonOnHovered();
UFUNCTION()
void ReturnButtonOnUnhovered();
void ReturnButtonOnFocused(FFocusEvent InFocusEvent);
};

View File

@ -6,6 +6,7 @@
#include "VampireInteractiveWidget.h"
#include "LevelUpWidget.generated.h"
class UCustomButton;
class UUpgradeButtonWidget;
class UScrollBox;
class UUpgradeButtonDataObject;

View File

@ -37,6 +37,8 @@ void UMainMenuWidget::NativeConstruct()
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, NewGameButton, EMouseLockMode::LockAlways);
PlayerController->bShowMouseCursor = true;
}
NewGameButton->SetKeyboardFocus();
}
FReply UMainMenuWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)

View File

@ -6,6 +6,7 @@
#include "VampireInteractiveWidget.h"
#include "OptionsMenuWidget.generated.h"
class UTextBlock;
class UCustomSlider;
class UCustomComboBoxString;
class USlider;

View File

@ -3,9 +3,6 @@
#include "VampireInteractiveWidget.h"
#include "Components/TextBlock.h"
#include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h"
#include "vampires/DetectGamepad.h"
void UVampireInteractiveWidget::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
@ -20,57 +17,7 @@ FReply UVampireInteractiveWidget::NativeOnMouseButtonUp(const FGeometry& InGeome
return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent);
}
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* UserWidget)
{
if (UserWidget)
{
PreviousScreen = UserWidget;
}
}
void UVampireInteractiveWidget::SetCurrentFocus(UUserWidget* UserWidget)
{
CurrentFocus = UserWidget;
}
void UVampireInteractiveWidget::PlayHoveredSound()
{
if (ButtonHoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}
void UVampireInteractiveWidget::SetTextBlockHovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonHoveredTextColor));
}
void UVampireInteractiveWidget::SetTextBlockUnhovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor));
}
void UVampireInteractiveWidget::PlayUnhoveredSound()
{
if (ButtonUnhoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
}
}
void UVampireInteractiveWidget::PlayClickedSound()
{
if (ButtonClickedSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonClickedSound);
}
}
void UVampireInteractiveWidget::ReturnToPreviousScreen()
{
GEngine->GameUserSettings->ApplySettings(false);
this->RemoveFromParent();
PreviousScreen->AddToViewport();
}

View File

@ -6,9 +6,6 @@
#include "Blueprint/UserWidget.h"
#include "VampireInteractiveWidget.generated.h"
class UCustomButton;
class UButton;
class UTextBlock;
/**
*
*/
@ -17,31 +14,9 @@ class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
{
GENERATED_BODY()
// TODO: Remove a lot of this stuff that has now been replaced by UCustomButton
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Widget Settings | Sound")
TObjectPtr<USoundBase> ButtonHoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Widget Settings | Color")
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Widget Settings | Color")
FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Widget Settings | Sound")
TObjectPtr<USoundBase> ButtonUnhoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Widget Settings | Sound")
TObjectPtr<USoundBase> ButtonClickedSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Widget Settings")
TArray<TObjectPtr<UButton>> InteractableButtons;
TObjectPtr<UUserWidget> CurrentFocus;
UPROPERTY()
TObjectPtr<UUserWidget> PreviousScreen;
TObjectPtr<UUserWidget> CurrentFocus;
bool GamepadConnected = false;
@ -50,28 +25,6 @@ protected:
virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
public:
UFUNCTION()
void SetReturnScreen(UUserWidget* UserWidget);
UFUNCTION()
void SetCurrentFocus(UUserWidget* UserWidget);
protected:
UFUNCTION()
void PlayHoveredSound();
UFUNCTION()
void SetTextBlockHovered(UTextBlock* TextBlock);
UFUNCTION()
void SetTextBlockUnhovered(UTextBlock* TextBlock);
UFUNCTION()
void PlayUnhoveredSound();
UFUNCTION()
void PlayClickedSound();
UFUNCTION()
void ReturnToPreviousScreen();
};