A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgEvent.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#include "DlgEvent.h"
3
4#include "DlgConstants.h"
5#include "DlgContext.h"
8#include "DlgHelper.h"
9#include "Logging/DlgLogger.h"
10
11void FDlgEvent::Call(UDlgContext& Context, const FString& ContextString, UObject* Participant) const
12{
13 const bool bHasParticipant = ValidateIsParticipantValid(
14 Context,
15 FString::Printf(TEXT("%s::Call"), *ContextString),
17 );
18
19 // We don't care if it has a participant, but warn nonetheless by calling validate it before this
21 {
22 if (CustomEvent == nullptr)
23 {
25 TEXT("Custom Event is empty (not valid). Ignoring. Context:\n\t%s, Participant = %s"),
26 *Context.GetContextString(), Participant ? *Participant->GetPathName() : TEXT("INVALID")
27 );
28 return;
29 }
30
32 return;
33 }
34
35 // Must have participant from this point onwards
36 if (MustHaveParticipant() && !bHasParticipant)
37 {
38 return;
39 }
40 switch (EventType)
41 {
43 IDlgDialogueParticipant::Execute_OnDialogueEvent(Participant, &Context, EventName);
44 break;
45
47 IDlgDialogueParticipant::Execute_ModifyIntValue(Participant, EventName, bDelta, IntValue);
48 break;
50 IDlgDialogueParticipant::Execute_ModifyFloatValue(Participant, EventName, bDelta, FloatValue);
51 break;
53 IDlgDialogueParticipant::Execute_ModifyBoolValue(Participant, EventName, bValue);
54 break;
56 IDlgDialogueParticipant::Execute_ModifyNameValue(Participant, EventName, NameValue);
57 break;
58
60 FNYReflectionHelper::ModifyVariable<FNYIntProperty>(Participant, EventName, IntValue, bDelta);
61 break;
63 FNYReflectionHelper::ModifyVariable<FNYFloatProperty>(Participant, EventName, FloatValue, bDelta);
64 break;
66 FNYReflectionHelper::SetVariable<FNYBoolProperty>(Participant, EventName, bValue);
67 break;
69 FNYReflectionHelper::SetVariable<FNYNameProperty>(Participant, EventName, NameValue);
70 break;
71
72 default:
73 checkNoEntry();
74 }
75}
76
77bool FDlgEvent::ValidateIsParticipantValid(const UDlgContext& Context, const FString& ContextString, const UObject* Participant) const
78{
79 if (IsValid(Participant))
80 {
81 return true;
82 }
83
85 {
87 TEXT("%s - Event FAILED because the PARTICIPANT is INVALID. \nContext:\n\t%s, \n\tParticipantName = %s, EventType = %s, EventName = %s, CustomEvent = %s"),
88 *ContextString, *Context.GetContextString(), *ParticipantName.ToString(), *EventTypeToString(EventType), *EventName.ToString(), *GetCustomEventName()
89 );
90 }
91 else
92 {
94 TEXT("%s - Event WARNING because the PARTICIPANT is INVALID. The call will NOT FAIL, but the participant is not present. \nContext:\n\t%s, \n\tParticipantName = %s, EventType = %s, EventName = %s, CustomEvent = %s"),
95 *ContextString, *Context.GetContextString(), *ParticipantName.ToString(), *EventTypeToString(EventType), *EventName.ToString(), *GetCustomEventName()
96 );
97 }
98
99 return false;
100}
101
103{
104 FString EnumValue;
105 FDlgHelper::ConvertEnumToString<EDlgEventType>(TEXT("EDlgEventType"), Type, false, EnumValue);
106 return EnumValue;
107}
EDlgEventType
UENUM(BlueprintType)
Definition DlgEvent.h:16
@ ModifyClassFloatVariable
static FDlgLogger & Get()
Definition DlgLogger.h:24
void Warningf(const FmtType &Fmt, Types... Args)
Definition INYLogger.h:308
void Errorf(const FmtType &Fmt, Types... Args)
Definition INYLogger.h:305
UCLASS(BlueprintType)
Definition DlgContext.h:96
FString GetContextString() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Context")
void EnterEvent(UDlgContext *Context, UObject *Participant)
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Dialogue", DisplayName = "Enter")
int32 IntValue
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:156
bool MustHaveParticipant() const
Definition DlgEvent.h:123
FName NameValue
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:172
static FString EventTypeToString(EDlgEventType Type)
Definition DlgEvent.cpp:102
FName EventName
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:148
bool bValue
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:188
FString GetCustomEventName() const
Definition DlgEvent.h:87
UDlgEventCustom * CustomEvent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced, Category = "Dialogue|Event")
Definition DlgEvent.h:200
bool bDelta
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:180
void Call(UDlgContext &Context, const FString &ContextString, UObject *Participant) const
Definition DlgEvent.cpp:11
bool ValidateIsParticipantValid(const UDlgContext &Context, const FString &ContextString, const UObject *Participant) const
Definition DlgEvent.cpp:77
EDlgEventType EventType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:140
float FloatValue
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:164
FName ParticipantName
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Definition DlgEvent.h:132