Skip to content

Commit

Permalink
WIP #31 added HUD class for menu and updated WotGameplayStatics to wr…
Browse files Browse the repository at this point in the history
…ap showing/hiding the main menu
  • Loading branch information
finger563 committed Jun 10, 2022
1 parent 430ce35 commit 226ab14
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
19 changes: 19 additions & 0 deletions unreal/Source/VoxelRPG/Private/UI/WotHUD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "UI/WotHUD.h"
#include "UI/WotUserWidget.h"
#include <GameFramework/PlayerController.h>

void AWotHUD::ShowMainMenu()
{
APlayerController* PC = Cast<APlayerController>(GetOwner());
MainMenu = CreateWidget<UWotUserWidget>(PC, MainMenuClass);

MainMenu->AddToViewport();
}

void AWotHUD::HideMainMenu()
{
if (MainMenu) {
MainMenu->RemoveFromViewport();
MainMenu = nullptr;
}
}
16 changes: 16 additions & 0 deletions unreal/Source/VoxelRPG/Private/WotGameplayStatics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#include "WotGameplayStatics.h"
#include "Engine/UserInterfaceSettings.h"
#include <Kismet/GameplayStatics.h>
#include "UI/WotHUD.h"

void UWotGameplayStatics::ShowMainMenu(const UObject* WorldContextObject, const int PlayerIndex)
{
APlayerController* PC = UGameplayStatics::GetPlayerController(WorldContextObject, PlayerIndex);
AWotHUD* HUD = PC->GetHUD<AWotHUD>();
HUD->ShowMainMenu();
}

void UWotGameplayStatics::HideMainMenu(const UObject* WorldContextObject, const int PlayerIndex)
{
APlayerController* PC = UGameplayStatics::GetPlayerController(WorldContextObject, PlayerIndex);
AWotHUD* HUD = PC->GetHUD<AWotHUD>();
HUD->HideMainMenu();
}

void UWotGameplayStatics::SetUIScale( float CustomUIScale )
{
Expand Down
29 changes: 29 additions & 0 deletions unreal/Source/VoxelRPG/Public/UI/WotHUD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/HUD.h"
#include "WotHUD.generated.h"

class UWotUserWidget;

UCLASS()
class VOXELRPG_API AWotHUD : public AHUD
{
GENERATED_BODY()

public:

UFUNCTION(BlueprintCallable)
void ShowMainMenu();

UFUNCTION(BlueprintCallable)
void HideMainMenu();

protected:

UPROPERTY(EditDefaultsOnly)
TSubclassOf<UWotUserWidget> MainMenuClass;

UPROPERTY()
UWotUserWidget* MainMenu;
};
7 changes: 7 additions & 0 deletions unreal/Source/VoxelRPG/Public/WotGameplayStatics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class UWotGameplayStatics : public UBlueprintFunctionLibrary
GENERATED_BODY()

public:

UFUNCTION( BlueprintCallable, Category = "User Interface" )
static void ShowMainMenu(const UObject* WorldContextObject, const int PlayerIndex=0);

UFUNCTION( BlueprintCallable, Category = "User Interface" )
static void HideMainMenu(const UObject* WorldContextObject, const int PlayerIndex=0);

// Custom UI scale 1.0f == 100%, 2.0f == 200%, 0.5f == 50% etc.
UFUNCTION( BlueprintCallable, Category = "User Interface" )
static void SetUIScale( float CustomUIScale );
Expand Down

0 comments on commit 226ab14

Please sign in to comment.