Implemented UGadgetMenu and it's Functionality

This commit is contained in:
Rafal Swierczek 2023-10-30 18:00:41 +00:00
parent c53b7c7988
commit 6a14693826
9 changed files with 85 additions and 31 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0ec223a4fa2f994a882c313b35e5f7f2314e2f8a974c0fcb16b0959c4509a8e9
size 22424
oid sha256:99736a10befa7b16850c07090ed7d29a0c63d5d4181cacdf73f855190c61c1dd
size 16928

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:80d409292ad4439737a74a463d528e19c92b5f2673d56712ca2778019a9ad7f6
size 459303
oid sha256:46c1dbc7d35d69ea66831390e74563f3dc3dfbdcdc2c09fa0887195d6c231104
size 460293

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bb9e2bad3be7351df336b7d68ea591f059abe8dc84cd11bfd10dd3bc41003b15
oid sha256:d607b449f6cba630df205824ffa12e8dba978263858fcc7a0f6089612f21f28b
size 66790690

View File

@ -11,7 +11,8 @@
"AdditionalDependencies": [
"Engine",
"AIModule",
"CoreUObject"
"CoreUObject",
"UMG"
]
}
],

View File

@ -29,19 +29,24 @@ void AGadgetTutorialStation::Tick(float DeltaTime)
void AGadgetTutorialStation::Interact()
{
// opens up pick gadget widget
if (GadgetsArray.IsEmpty()) return;
// Setup Widget so it can be seen and interacted with
FInputModeUIOnly InputMode;
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PickGadgetWidget = CreateWidget<UUserWidget>(GetWorld(), PickGadgetWidgetClass);
PickGadgetWidget->AddToViewport(3);
PlayerController->SetInputMode(InputMode);
PlayerController->bShowMouseCursor = true;
PlayerController->bEnableClickEvents = true;
PlayerController->bEnableMouseOverEvents = true;
// Set up gadget menu's behaviours
GadgetMenu = Cast<UGadgetMenu>(PickGadgetWidget);
GadgetMenu->CloseMenuDelegate.AddDynamic(this, &AGadgetTutorialStation::CloseWidget);
GadgetMenu->NextGadgetDelegate.AddDynamic(this, &AGadgetTutorialStation::NextGadget);
GadgetMenu->PreviousGadgetDelegate.AddDynamic(this, &AGadgetTutorialStation::PreviousGadget);
GadgetMenu->SelectGadgetDelegate.AddDynamic(this, &AGadgetTutorialStation::SelectGadget);
}
void AGadgetTutorialStation::InteractPrompt()
@ -49,7 +54,7 @@ void AGadgetTutorialStation::InteractPrompt()
}
FGadgetInfo AGadgetTutorialStation::NextGadget()
void AGadgetTutorialStation::NextGadget()
{
FGadgetInfo GadgetInfo;
// Either wrap around to the beginning or increment gadget index
@ -58,10 +63,11 @@ FGadgetInfo AGadgetTutorialStation::NextGadget()
GadgetInfo.GadgetIcon = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetIcon();
GadgetInfo.GadgetDesc = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetDesc();
GadgetInfo.GadgetName = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetName();
return GadgetInfo;
GadgetMenu->UpdateDisplayedGadget(GadgetInfo);
}
FGadgetInfo AGadgetTutorialStation::PreviousGadget()
void AGadgetTutorialStation::PreviousGadget()
{
FGadgetInfo GadgetInfo;
// Either wrap around to the end or decrement gadget index
@ -70,7 +76,8 @@ FGadgetInfo AGadgetTutorialStation::PreviousGadget()
GadgetInfo.GadgetIcon = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetIcon();
GadgetInfo.GadgetDesc = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetDesc();
GadgetInfo.GadgetName = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetName();
return GadgetInfo;
GadgetMenu->UpdateDisplayedGadget(GadgetInfo);
}
void AGadgetTutorialStation::SelectGadget()

View File

@ -5,24 +5,10 @@
#include "CoreMinimal.h"
#include "EndlessVendetta/GadgetSystem/GadgetBase.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "EndlessVendetta/UserWidgets/GadgetMenu.h"
#include "GameFramework/Actor.h"
#include "GadgetTutorialStation.generated.h"
USTRUCT(BlueprintType)
struct FGadgetInfo
{
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite, Category = "Gadget")
UTexture2D* GadgetIcon;
UPROPERTY(BlueprintReadWrite, Category = "Gadget")
FString GadgetDesc;
UPROPERTY(BlueprintReadWrite, Category = "Gadget")
FString GadgetName;
};
UCLASS()
class ENDLESSVENDETTA_API AGadgetTutorialStation : public AActor, public IInteractionInterface
{
@ -32,12 +18,14 @@ class ENDLESSVENDETTA_API AGadgetTutorialStation : public AActor, public IIntera
TArray<TSubclassOf<AGadgetBase>> GadgetsArray;
UPROPERTY(EditDefaultsOnly, Category = "Gadgets")
TSubclassOf<UUserWidget> PickGadgetWidgetClass;
TSubclassOf<UGadgetMenu> PickGadgetWidgetClass;
int GadgetIndex = 0;
UUserWidget* PickGadgetWidget;
UGadgetMenu* GadgetMenu;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
@ -47,10 +35,10 @@ protected:
void InteractPrompt() override;
UFUNCTION(BlueprintCallable)
FGadgetInfo NextGadget();
void NextGadget();
UFUNCTION(BlueprintCallable)
FGadgetInfo PreviousGadget();
void PreviousGadget();
UFUNCTION(BlueprintCallable)
void SelectGadget();

View File

@ -0,0 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "GadgetMenu.h"

View File

@ -0,0 +1,50 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "GadgetMenu.generated.h"
USTRUCT(BlueprintType)
struct FGadgetInfo
{
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite, Category = "Gadget")
UTexture2D* GadgetIcon;
UPROPERTY(BlueprintReadWrite, Category = "Gadget")
FString GadgetDesc;
UPROPERTY(BlueprintReadWrite, Category = "Gadget")
FString GadgetName;
};
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCloseMenu);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FNextGadget);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FPreviousGadget);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FSelectGadget);
UCLASS()
class ENDLESSVENDETTA_API UGadgetMenu : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintCallable)
FCloseMenu CloseMenuDelegate;
UPROPERTY(BlueprintCallable)
FCloseMenu NextGadgetDelegate;
UPROPERTY(BlueprintCallable)
FCloseMenu PreviousGadgetDelegate;
UPROPERTY(BlueprintCallable)
FCloseMenu SelectGadgetDelegate;
UFUNCTION(BlueprintImplementableEvent)
void UpdateDisplayedGadget(FGadgetInfo GadgetInfo);
};