Compare commits

..

3 Commits

Author SHA1 Message Date
baz
6475e1e183 Add basic main menu 2025-05-07 01:44:02 +01:00
baz
6ab631515b Add MainMenuWidget 2025-05-07 01:07:02 +01:00
baz
d6b143b7b1 Add VampireInteractiveWidget 2025-05-07 00:57:23 +01:00
10 changed files with 268 additions and 2 deletions

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

Binary file not shown.

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

Binary file not shown.

BIN
Content/Levels/MainMenu/BP_MainMenuGameMode.uasset (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

BIN
Content/Levels/MainMenu/NS_MainMenu.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Widgets/MainMenu/BP_MainMenuWidget.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,67 @@
// Louis Hobbs | 2024-2025
#include "MainMenuWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Components/Button.h"
#include "Kismet/GameplayStatics.h"
void UMainMenuWidget::NativeConstruct()
{
Super::NativeConstruct();
if (NewGameButton)
{
NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuWidget::NewGameButtonOnClicked);
NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuWidget::PlayClickedSound);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuWidget::PlayHoveredSound);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuWidget::NewGameTextBlockHoveredDelegate);
NewGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuWidget::NewGameTextBlockUnhoveredDelegate);
NewGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuWidget::PlayUnhoveredSound);
}
if (QuitButton)
{
QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuWidget::QuitButtonOnClicked);
QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuWidget::PlayClickedSound);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuWidget::PlayHoveredSound);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuWidget::QuitTextBlockHoveredDelegate);
QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuWidget::QuitTextBlockUnhoveredDelegate);
QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuWidget::PlayUnhoveredSound);
}
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, this, EMouseLockMode::LockAlways);
PlayerController->bShowMouseCursor = true;
}
}
void UMainMenuWidget::NewGameButtonOnClicked()
{
if (!NewGameLevel.IsNull())
{
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NewGameLevel);
}
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
PlayerController->bShowMouseCursor = false;
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
}
SetIsFocusable(false);
}
void UMainMenuWidget::QuitButtonOnClicked()
{
// TODO: Add platform specific Exit requests
// This is not a bit deal for the moment as we are only building for windows
// For some reason the generic version does not work the same as FWindowsPlatformMisc
FWindowsPlatformMisc::RequestExit(false);
}

View File

@ -0,0 +1,64 @@
// Louis Hobbs | 2024-2025
#pragma once
#include "CoreMinimal.h"
#include "VampireInteractiveWidget.h"
#include "MainMenuWidget.generated.h"
class UButton;
/**
*
*/
UCLASS()
class VAMPIRES_API UMainMenuWidget : public UVampireInteractiveWidget
{
GENERATED_BODY()
// TODO: Add options menu
public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UButton> NewGameButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UTextBlock> NewGameTextBlock;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UButton> QuitButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UTextBlock> QuitTextBlock;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> NewGameMenuWidget;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSoftObjectPtr<UWorld> NewGameLevel;
private:
UPROPERTY()
TObjectPtr<UUserWidget> currentNewGameWidget;
public:
virtual void NativeConstruct() override;
private:
UFUNCTION()
void NewGameButtonOnClicked();
UFUNCTION()
void QuitButtonOnClicked();
UFUNCTION()
void NewGameTextBlockHoveredDelegate() { SetTextBlockHovered(NewGameTextBlock); }
UFUNCTION()
void NewGameTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(NewGameTextBlock); }
UFUNCTION()
void QuitTextBlockHoveredDelegate() { SetTextBlockHovered(QuitTextBlock); }
UFUNCTION()
void QuitTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(QuitTextBlock); }
};

View File

@ -0,0 +1,58 @@
// Louis Hobbs | 2024-2025
#include "VampireInteractiveWidget.h"
#include "Components/TextBlock.h"
#include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h"
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* userWidget)
{
if (userWidget)
{
PreviousScreen = 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

@ -0,0 +1,62 @@
// Louis Hobbs | 2024-2025
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "VampireInteractiveWidget.generated.h"
class UTextBlock;
/**
*
*/
UCLASS()
class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonHoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonUnhoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonClickedSound;
protected:
UPROPERTY()
TObjectPtr<UUserWidget> PreviousScreen;
public:
UFUNCTION()
void SetReturnScreen(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();
};