Updated Base Gadget Class to Include UI Info

This commit is contained in:
Rafal Swierczek 2023-10-28 17:36:54 +01:00
parent 3b5a2b6119
commit c53b7c7988
29 changed files with 245 additions and 30 deletions

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:11b576c026267200d7fd27692a546054b7374aca9f8f27c768a33463f121b517
size 100970

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6e36749adcb26155cc5778616c16725b1b07791a69e13d915c60637c0c298454
size 112834

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ae808ffd2860b39caf2e3f45d99a2c4f2a1132080068bc782f9a478883a00aa6
size 73431

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:43d7ee43bc719045255002dcc02a74860889783dcea8744b7268ca6e1a40ba11
size 150538

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5fab63c70404d783d490b959d5a59076b65e935ffb44fe9a90681236ba83efaa
size 157565

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:36ce86af4f5aea5d620295cd12b2ace3d2fe8cb3f79176981f904c77eb61294a
size 147943

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:840b5c9edd522548cd3b4b52a3c8a4a90a18f452ef07db4c7de688e130745888
size 156457

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

@ -53,6 +53,16 @@ protected:
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
UInputAction* ActivateAction;
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
UTexture2D* GadgetIcon;
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
FString GadgetDesc;
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
FString GadgetName;
// Used by child classes to run custom gadget behaviour
virtual void Activate();
@ -84,6 +94,21 @@ public:
{
return GadgetRotation;
}
UTexture2D* GetGadgetIcon()
{
return IsValid(GadgetIcon) ? GadgetIcon : nullptr;
}
FString GetGadgetDesc()
{
return GadgetDesc;
}
FString GetGadgetName()
{
return GadgetName;
}
// Sets default values for this actor's properties
AGadgetBase();

View File

@ -0,0 +1,101 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "GadgetTutorialStation.h"
#include "Blueprint/UserWidget.h"
// Sets default values
AGadgetTutorialStation::AGadgetTutorialStation()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AGadgetTutorialStation::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AGadgetTutorialStation::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AGadgetTutorialStation::Interact()
{
// opens up pick gadget widget
if (GadgetsArray.IsEmpty()) return;
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;
}
void AGadgetTutorialStation::InteractPrompt()
{
}
FGadgetInfo AGadgetTutorialStation::NextGadget()
{
FGadgetInfo GadgetInfo;
// Either wrap around to the beginning or increment gadget index
GadgetIndex = GadgetIndex >= GadgetsArray.Num() - 1 ? 0 : GadgetIndex + 1;
GadgetInfo.GadgetIcon = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetIcon();
GadgetInfo.GadgetDesc = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetDesc();
GadgetInfo.GadgetName = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetName();
return GadgetInfo;
}
FGadgetInfo AGadgetTutorialStation::PreviousGadget()
{
FGadgetInfo GadgetInfo;
// Either wrap around to the end or decrement gadget index
GadgetIndex = GadgetIndex <= 0 ? GadgetsArray.Num() - 1 : GadgetIndex - 1;
GadgetInfo.GadgetIcon = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetIcon();
GadgetInfo.GadgetDesc = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetDesc();
GadgetInfo.GadgetName = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetName();
return GadgetInfo;
}
void AGadgetTutorialStation::SelectGadget()
{
// Give Player the gadget
// Despawn current gadgetRange
// Spawn in the correct gadget range for the gadget
UE_LOG(LogTemp, Warning, TEXT("Gadget Selected: %s"), *GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GetGadgetName());
}
void AGadgetTutorialStation::CloseWidget()
{
// close the widget
if (IsValid(PickGadgetWidget)) PickGadgetWidget->RemoveFromParent();
CollectGarbage(RF_PendingKill);
FInputModeGameOnly InputMode;
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(InputMode);
PlayerController->bShowMouseCursor = false;
PlayerController->bEnableClickEvents = false;
PlayerController->bEnableMouseOverEvents = false;
}

View File

@ -0,0 +1,68 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "EndlessVendetta/GadgetSystem/GadgetBase.h"
#include "EndlessVendetta/InteractionInterface.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
{
GENERATED_BODY()
UPROPERTY(EditDefaultsOnly, Category = "Gadgets")
TArray<TSubclassOf<AGadgetBase>> GadgetsArray;
UPROPERTY(EditDefaultsOnly, Category = "Gadgets")
TSubclassOf<UUserWidget> PickGadgetWidgetClass;
int GadgetIndex = 0;
UUserWidget* PickGadgetWidget;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
void Interact() override;\
void InteractPrompt() override;
UFUNCTION(BlueprintCallable)
FGadgetInfo NextGadget();
UFUNCTION(BlueprintCallable)
FGadgetInfo PreviousGadget();
UFUNCTION(BlueprintCallable)
void SelectGadget();
UFUNCTION(BlueprintCallable)
void CloseWidget();
public:
// Sets default values for this actor's properties
AGadgetTutorialStation();
// Called every frame
virtual void Tick(float DeltaTime) override;
};