Test for a narration system

This commit is contained in:
Robin Alonzo 2023-10-14 23:08:39 +02:00
parent 4d043122c0
commit 2044b0e5fc
9 changed files with 123 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -10,7 +10,8 @@ public class Pawn : ModuleRules {
"Engine", "Engine",
"InputCore", "InputCore",
"Slate", "Slate",
"SlateCore" "SlateCore",
"UMG",
}); });
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange(new string[] { });

View File

@ -0,0 +1,36 @@
#include "PwnDialogue.h"
#include "PwnDialogueBubble.h"
#include "UPwnNarrationLibrary.h"
#include "Blueprint/UserWidget.h"
#include "GameFramework/GameSession.h"
#include "Kismet/GameplayStatics.h"
UPwnDialogue* UPwnDialogue::Dialogue(const UObject* WorldContextObject, UObject* Actor, const FText& Text)
{
UPwnDialogue* Dialogue = NewObject<UPwnDialogue>();
Dialogue->Actor = Actor;
Dialogue->Text = &Text;
Dialogue->WorldContext = WorldContextObject;
return Dialogue;
}
void UPwnDialogue::Activate()
{
auto playerController = UGameplayStatics::GetPlayerController(WorldContext, 0);
UPwnDialogueBubble* bubble = Cast<UPwnDialogueBubble>(CreateWidget<UUserWidget>(playerController, UPwnNarrationLibrary::BubbleWidgetClass));
if(!bubble)
{
UE_LOG(LogTemp, Error, TEXT("Failed creating bubble widget"));
}
UE_LOG(LogTemp, Display, TEXT("Tout va bien"));
bubble->Init(Actor, *Text);
//Appeler ça quand on veut passer au dialogue suivant
Next.Broadcast();
}

View File

@ -0,0 +1,30 @@
#pragma once
#include "Kismet/BlueprintAsyncActionBase.h"
#include "PwnDialogue.generated.h"
class UPwnDialogueBubble;
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FPwnDialogueNext);
UCLASS()
class PAWN_API UPwnDialogue : public UBlueprintAsyncActionBase
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintAssignable)
FPwnDialogueNext Next;
private:
UObject* Actor;
const FText* Text;
const UObject* WorldContext;
public:
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"), Category = "Narration")
static UPwnDialogue* Dialogue(const UObject* WorldContextObject, UObject* Actor, const FText& Text);
virtual void Activate() override;
};

View File

@ -0,0 +1,8 @@
#include "PwnDialogueBubble.h"
#include "Logging/StructuredLog.h"
void UPwnDialogueBubble::Init(const UObject* Actor, const FText& Text)
{
UE_LOGFMT(LogTemp, Display, "Init bubble with text: {0}", *Text.ToString());
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "Blueprint/UserWidget.h"
#include "PwnDialogueBubble.generated.h"
UCLASS()
class PAWN_API UPwnDialogueBubble : public UUserWidget
{
GENERATED_BODY()
public:
void Init(const UObject* Actor, const FText& Text);
};

View File

@ -0,0 +1,12 @@
#include "UPwnNarrationLibrary.h"
#include "PwnDialogue.h"
class UPwnDialogueBubble;
TSubclassOf<UPwnDialogueBubble> UPwnNarrationLibrary::BubbleWidgetClass;
void UPwnNarrationLibrary::SetDialogueUIWidget(TSubclassOf<UPwnDialogueBubble> _Widget)
{
UPwnNarrationLibrary::BubbleWidgetClass = _Widget;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "PwnDialogueBubble.h"
#include "UPwnNarrationLibrary.generated.h"
UCLASS()
class PAWN_API UPwnNarrationLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
static TSubclassOf<UPwnDialogueBubble> BubbleWidgetClass;
UFUNCTION(BlueprintCallable, Category = "Narration")
static void SetDialogueUIWidget(TSubclassOf<UPwnDialogueBubble> Widget);
};