Test for a narration system
This commit is contained in:
parent
4d043122c0
commit
2044b0e5fc
BIN
Pawn_Unreal/Content/Systems/Test/Narration/BP_DialogueTest.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Systems/Test/Narration/BP_DialogueTest.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Systems/Test/Narration/W_TestBubble.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Systems/Test/Narration/W_TestBubble.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -10,7 +10,8 @@ public class Pawn : ModuleRules {
|
||||
"Engine",
|
||||
"InputCore",
|
||||
"Slate",
|
||||
"SlateCore"
|
||||
"SlateCore",
|
||||
"UMG",
|
||||
});
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
36
Pawn_Unreal/Source/Pawn/Public/Narration/PwnDialogue.cpp
Normal file
36
Pawn_Unreal/Source/Pawn/Public/Narration/PwnDialogue.cpp
Normal 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();
|
||||
}
|
||||
30
Pawn_Unreal/Source/Pawn/Public/Narration/PwnDialogue.h
Normal file
30
Pawn_Unreal/Source/Pawn/Public/Narration/PwnDialogue.h
Normal 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;
|
||||
};
|
||||
@ -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());
|
||||
}
|
||||
13
Pawn_Unreal/Source/Pawn/Public/Narration/PwnDialogueBubble.h
Normal file
13
Pawn_Unreal/Source/Pawn/Public/Narration/PwnDialogueBubble.h
Normal 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);
|
||||
|
||||
};
|
||||
@ -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;
|
||||
}
|
||||
@ -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);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user