Fixes for starting dialogue
This commit is contained in:
@@ -44,16 +44,6 @@ void UDialogueComponent::OnDialogueLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
void UDialogueComponent::FilterSpeechData()
|
||||
{
|
||||
ActiveSpeechData.Empty();
|
||||
for (int i = 0; i < SpeechData.Num(); ++i)
|
||||
{
|
||||
//Check if speech event condition is met
|
||||
ActiveSpeechData.Add(SpeechData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void UDialogueComponent::StartDialogueWithNpc()
|
||||
{
|
||||
UDialogueSubsystem* DialogueSubsystem = UDialogueSubsystem::Get(this);
|
||||
@@ -67,8 +57,12 @@ void UDialogueComponent::StartDialogueWithNpc()
|
||||
// answer, and it is the single funnel every dialogue goes through.
|
||||
if (!DialogueSubsystem->StartDialogue(GetOwner())) return;
|
||||
|
||||
USpeechDataAsset* StartingDialogue = NpcBaseCharacter->GetStartingSpeech().Get();
|
||||
TArray<USpeechDataAsset*> StartingDialogues = GetStartingDialogues();
|
||||
if (!StartingDialogues.IsEmpty()) StartingDialogue = StartingDialogues[0];
|
||||
|
||||
MappedDialogueOptions.Empty();
|
||||
TriggerDialogue(NpcBaseCharacter->GetStartingSpeech().Get(), CurrentDialogueReplacementMap);
|
||||
TriggerDialogue(StartingDialogue, CurrentDialogueReplacementMap);
|
||||
}
|
||||
|
||||
void UDialogueComponent::TriggerDialogue_Async(TSoftObjectPtr<USpeechDataAsset> DialogueAssetPath, const TMap<FString, FText>& ReplacementMap)
|
||||
@@ -117,27 +111,19 @@ void UDialogueComponent::TriggerDialogue(USpeechDataAsset* DialogueAssetPath, co
|
||||
DialogueSubsystem->StartDialogue(GetOwner());
|
||||
}
|
||||
|
||||
TArray<USpeechDataAsset*> UDialogueComponent::GetActiveSpeechData() { return ActiveSpeechData; }
|
||||
|
||||
TArray<USpeechDataAsset*> UDialogueComponent::GetStartingDialogues()
|
||||
{
|
||||
TArray<USpeechDataAsset*> TempSpeechData;
|
||||
for (int i = 0; i < ActiveSpeechData.Num(); ++i)
|
||||
for (int i = 0; i < SpeechData.Num(); ++i)
|
||||
{
|
||||
if(ActiveSpeechData[i]->TestRequirements(GetWorld()) && ActiveSpeechData[i]->PlayerAsk.IsEmpty())
|
||||
TempSpeechData.AddUnique(ActiveSpeechData[i]);
|
||||
}
|
||||
|
||||
return TempSpeechData;
|
||||
}
|
||||
|
||||
TArray<USpeechDataAsset*> UDialogueComponent::GetActiveDialogues()
|
||||
{
|
||||
TArray<USpeechDataAsset*> TempSpeechData;
|
||||
for (int i = 0; i < ActiveSpeechData.Num(); ++i)
|
||||
{
|
||||
if(ActiveSpeechData[i]->TestRequirements(GetWorld()) && !ActiveSpeechData[i]->PlayerAsk.IsEmpty())
|
||||
TempSpeechData.AddUnique(ActiveSpeechData[i]);
|
||||
if( !SpeechData[i]->bIsStartingDialogue ||
|
||||
!SpeechData[i]->PlayerAsk.IsEmpty() ||
|
||||
!SpeechData[i]->TestRequirements(GetWorld()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TempSpeechData.AddUnique(SpeechData[i]);
|
||||
}
|
||||
|
||||
return TempSpeechData;
|
||||
@@ -195,7 +181,7 @@ void UDialogueComponent::AdvanceDialogue()
|
||||
}
|
||||
}
|
||||
|
||||
if (!CurrentActiveDialogue->RandomizeLines && (CurrentLineIndex < CurrentActiveDialogue->DialogueLines.Num() - 1))
|
||||
if (CurrentLineIndex < CurrentActiveDialogue->DialogueLines.Num() - 1)
|
||||
{
|
||||
CurrentLineIndex++;
|
||||
DialogueWidget->AdvanceDialogue(CurrentActiveDialogue->DialogueLines[CurrentLineIndex].DialogueLine, CurrentActiveDialogue->DialogueLines[CurrentLineIndex].SpeakerName);
|
||||
|
||||
@@ -19,9 +19,7 @@ class PROJECTELERI_API UDialogueComponent : public UActorComponent
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue")
|
||||
void FilterSpeechData();
|
||||
|
||||
|
||||
// use when you want to chit chat with an npc instead of play a specific dialogue option
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue")
|
||||
void StartDialogueWithNpc();
|
||||
@@ -30,15 +28,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue", meta = (AutoCreateRefTerm = "ReplacementMap"))
|
||||
void TriggerDialogue(USpeechDataAsset* DialogueAssetPath, const TMap<FString, FText>& ReplacementMap);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue")
|
||||
TArray<USpeechDataAsset*> GetActiveSpeechData();
|
||||
|
||||
//Goes through active speech data and returns the all speech data asset without a condition and player ask
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue")
|
||||
TArray<USpeechDataAsset*> GetStartingDialogues();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue")
|
||||
TArray<USpeechDataAsset*> GetActiveDialogues();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Eleri|Dialogue")
|
||||
void SetTextReplacementMap(const TMap<FString, FText>& ReplacementMap);
|
||||
@@ -67,16 +59,12 @@ protected:
|
||||
AActor* OwnerActor;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
AEleriPlayerController* EleriPlayerController;
|
||||
|
||||
TObjectPtr<UWidgetComponent> DialogueWidgetComponent;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UDialogueWidget> DialogueWidget;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<USpeechDataAsset>> SpeechData;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<USpeechDataAsset>> ActiveSpeechData;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
bool bDialogueSelectOpen = false;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "InventoryComponent.h"
|
||||
#include "Speech.h"
|
||||
#include "Misc/DataValidation.h"
|
||||
#include "QuestSystem/QuestSubsystem.h"
|
||||
|
||||
bool FEventRequirement::TestRequirement(const UObject* WorldContext) const
|
||||
@@ -22,14 +23,10 @@ bool FEventRequirement::TestRequirement(const UObject* WorldContext) const
|
||||
if (!GameEventSubsystem) return false;
|
||||
|
||||
const EEventStage EventStage = GameEventSubsystem->GetEventStage(EventAsset);
|
||||
|
||||
if (!bMustAchieveEvent && EventStage != EEventStage::NONE)
|
||||
return false;
|
||||
|
||||
if (bMustAchieveEvent && (GameEventSubsystem->GetEventStage(EventAsset) < Stage))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
return bMustAchieveEvent?
|
||||
EventStage >= Stage :
|
||||
EventStage < Stage;
|
||||
}
|
||||
case EEventRequirementType::Quest:
|
||||
{
|
||||
@@ -96,3 +93,15 @@ FText USpeechDataAsset::ReplaceTextInLine(const FText& Text, TMap<FString, FText
|
||||
|
||||
return FText::Format(Text, Args);
|
||||
}
|
||||
|
||||
EDataValidationResult USpeechDataAsset::IsDataValid(class FDataValidationContext& Context) const
|
||||
{
|
||||
EDataValidationResult Result = Super::IsDataValid(Context);
|
||||
if (bIsStartingDialogue && EventRequirements.IsEmpty())
|
||||
{
|
||||
Context.AddError(FText::FromString(TEXT("Cannot be a starting dialogue without an event requirement")));
|
||||
Result = EDataValidationResult::Invalid;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
FText PlayerAsk;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Eleri|Speech")
|
||||
bool RandomizeLines;
|
||||
bool bIsStartingDialogue;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Eleri|Speech")
|
||||
TArray<FLineData> DialogueLines;
|
||||
@@ -107,4 +107,8 @@ public:
|
||||
FText GetFormattedDialogueLine(const int32 Index, const TMap<FString, FText> ReplacementMap);
|
||||
UFUNCTION(BlueprintPure, Category = "Eleri|Options")
|
||||
static FText ReplaceTextInLine(const FText& Text, TMap<FString, FText> ReplacementMap);
|
||||
|
||||
#if WITH_EDITOR
|
||||
virtual EDataValidationResult IsDataValid(class FDataValidationContext& Context) const override;
|
||||
#endif
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user