Compare commits
3 Commits
f72780bb00
...
6475e1e183
Author | SHA1 | Date | |
---|---|---|---|
6475e1e183 | |||
6ab631515b | |||
d6b143b7b1 |
BIN
Content/Levels/Level.umap
(Stored with Git LFS)
BIN
Content/Levels/Level.umap
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Levels/MainMenu.umap
(Stored with Git LFS)
Normal file
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
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
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
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
BIN
Content/Widgets/MainMenu/BP_MainMenuWidget.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
67
Source/vampires/Widgets/MainMenuWidget.cpp
Normal file
67
Source/vampires/Widgets/MainMenuWidget.cpp
Normal 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);
|
||||||
|
}
|
64
Source/vampires/Widgets/MainMenuWidget.h
Normal file
64
Source/vampires/Widgets/MainMenuWidget.h
Normal 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); }
|
||||||
|
};
|
58
Source/vampires/Widgets/VampireInteractiveWidget.cpp
Normal file
58
Source/vampires/Widgets/VampireInteractiveWidget.cpp
Normal 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();
|
||||||
|
}
|
62
Source/vampires/Widgets/VampireInteractiveWidget.h
Normal file
62
Source/vampires/Widgets/VampireInteractiveWidget.h
Normal 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();
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user