Files
UnrealEngineUWP/Engine/Source/Runtime/SkillSystem/Private/GameplayCueView.cpp
Billy Bramer b8d692da28 Merge CLs with refactor of GameplayTags to main. Largely WIP, more changes coming.
[AUTOMERGE]

- Step one of gameplay tag refactor: deletion of un-used and unfixed content

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2067362 by Billy.Bramer on 2014/05/08 16:08:55.

[AUTOMERGE]

Gameplay Tag Refactor

Unshelved from AntonyC's pending changelist '2003772':

#TTP 322200 - Gameplay Tags: Refactor how tags are stored/queried

#proj Fortnite.Editor

#summary Refactored Tags from FName array to a FGamplayTag

#change removed all FName Tags and replaces with FGameplayTag
#added added tag verification so that new tags are not created at runtime
#added added new object version for data upgrade on all tagcontainers to be in new format and only store leaf most tags
#added requestgameplaytag function to FortGlobals, so that the tag manager can be started up before first use
#added New GraphPin for single tags
#change Added mode to SGamplayTagWidget to allow single select
#change PropertyArray fixed to now support empty arrays in the ImportText

---------------------

Additional Changes/Modifications
- Add new BlueprintGameplayTagLibrary to expose tag container functions to blueprints; Will add more in future post-refactor
- Fix bug with AddLeafTagToContainer incorrectly clearing the wrong container
- Remove default parameters for TagContainer.HasTag and fix call-sites to remain logically consistent with old behavior
- Make FName constructor for tag explicit
- Fix incorrect requirements check in combat effect
- Expose tag asset interface to blueprints
- Remove serialization fix-up from game data (manually fixed up)
- Remove version bump and serialization fix-up on tag container (will be re-done from main branch post merge)

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2067378 by Billy.Bramer on 2014/05/08 16:15:42.

[AUTOMERGE]

#UE4 Fixed up GameplayTag usage in the SkillSystem module

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2067576 by Bob.Tellez on 2014/05/08 18:38:58.

[AUTOMERGE]

- Linker build fix on gameplay tags

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2067708 by Billy.Bramer on 2014/05/08 21:18:36.

[AUTOMERGE]

- Minor optimization in header

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2067709 by Billy.Bramer on 2014/05/08 21:22:27.

[AUTOMERGE]

- Gameplay tag refactor, round 3
- Fortnite asset conversion/update

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2068202 by Billy.Bramer on 2014/05/09 11:13:36.

[AUTOMERGE]

- Fix gameplay tag reimporting failing to reinitialize the tag table

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2068787 by Billy.Bramer on 2014/05/09 18:11:23.

[AUTOMERGE]

#UE4 Fixed up GameplayTag usage in the SkillSystem module after merge from main

--------
Integrated using branch Ue4-To-UE4-Fortnite-Simple (reversed) of change#2070710 by Fred.Kimberley on 2014/05/12 15:57:13.

#codereview Fred.Kimberley, David.Ratti

[CL 2078452 by Billy Bramer in Main branch]
2014-05-19 23:21:13 -04:00

202 lines
5.7 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "SkillSystemModulePrivatePCH.h"
#include "ParticleDefinitions.h"
#include "SoundDefinitions.h"
UGameplayCueView::UGameplayCueView(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void FGameplayCueHandler::GameplayCueActivated(const FGameplayTagContainer & GameplayCueTags, float NormalizedMagnitude)
{
check(Owner);
for (auto TagIt = GameplayCueTags.CreateConstIterator(); TagIt; ++TagIt)
{
for (UGameplayCueView * Def : Definitions)
{
for (FGameplayCueViewInfo & View : Def->Views)
{
if (View.CueType == EGameplayCueEvent::Applied && View.Tags.HasTag(*TagIt, EGameplayTagMatchType::IncludeParentTags, EGameplayTagMatchType::Explicit))
{
View.SpawnViewEffects(Owner, NULL);
}
}
}
}
}
void FGameplayCueHandler::GameplayCueExecuted(const FGameplayTagContainer & GameplayCueTags, float NormalizedMagnitude)
{
check(Owner);
for (auto TagIt = GameplayCueTags.CreateConstIterator(); TagIt; ++TagIt)
{
for (UGameplayCueView * Def : Definitions)
{
for (FGameplayCueViewInfo & View : Def->Views)
{
if (View.CueType == EGameplayCueEvent::Executed && View.Tags.HasTag(*TagIt, EGameplayTagMatchType::IncludeParentTags, EGameplayTagMatchType::Explicit))
{
View.SpawnViewEffects(Owner, NULL);
}
}
}
}
}
void FGameplayCueHandler::GameplayCueAdded(const FGameplayTagContainer & GameplayCueTags, float NormalizedMagnitude)
{
check(Owner);
for (auto TagIt = GameplayCueTags.CreateConstIterator(); TagIt; ++TagIt)
{
TArray<TSharedPtr<FGameplayCueViewEffects> > &Effects = SpawnedViewEffects.FindOrAdd(*TagIt);
// Clear old effects if they existed? This will vary case to case. Removing old effects is the easiest approach
ClearEffects(Effects);
check(Effects.Num() == 0);
// Add new effects
for (UGameplayCueView * Def : Definitions)
{
for (FGameplayCueViewInfo & View : Def->Views)
{
if (View.CueType == EGameplayCueEvent::Added && View.Tags.HasTag(*TagIt, EGameplayTagMatchType::IncludeParentTags, EGameplayTagMatchType::Explicit))
{
TSharedPtr<FGameplayCueViewEffects> SpawnedEffects = View.SpawnViewEffects(Owner, &SpawnedObjects);
Effects.Add(SpawnedEffects);
}
}
}
}
}
void FGameplayCueHandler::GameplayCueRemoved(const FGameplayTagContainer & GameplayCueTags, float NormalizedMagnitude)
{
check(Owner);
for (auto TagIt = GameplayCueTags.CreateConstIterator(); TagIt; ++TagIt)
{
TArray<TSharedPtr<FGameplayCueViewEffects> > *Effects = SpawnedViewEffects.Find(*TagIt);
if (Effects)
{
ClearEffects(*Effects);
SpawnedViewEffects.Remove(*TagIt);
}
// Add new effects
for (UGameplayCueView * Def : Definitions)
{
for (FGameplayCueViewInfo & View : Def->Views)
{
if (View.CueType == EGameplayCueEvent::Removed && View.Tags.HasTag(*TagIt, EGameplayTagMatchType::IncludeParentTags, EGameplayTagMatchType::Explicit))
{
View.SpawnViewEffects(Owner, NULL);
}
}
}
}
}
void FGameplayCueHandler::ClearEffects(TArray< TSharedPtr<FGameplayCueViewEffects> > &Effects)
{
bool RemovedSomething = false;
for (TSharedPtr<FGameplayCueViewEffects> &EffectPtr : Effects)
{
if (!EffectPtr.IsValid())
{
continue;
}
FGameplayCueViewEffects &Effect = *EffectPtr.Get();
if (Effect.SpawnedActor.IsValid())
{
Effect.SpawnedActor->Destroy();
RemovedSomething = true;
}
if (Effect.AudioComponent.IsValid())
{
Effect.AudioComponent->Stop();
RemovedSomething = true;
}
if (Effect.ParticleSystemComponent.IsValid())
{
Effect.ParticleSystemComponent->DestroyComponent();
RemovedSomething = true;
}
}
Effects.Empty();
// Cleanup flat array
if (RemovedSomething)
{
for (int32 idx=0; idx < SpawnedObjects.Num(); ++idx)
{
UObject *Obj = SpawnedObjects[idx];
if (!Obj || Obj->IsPendingKill())
{
SpawnedObjects.RemoveAtSwap(idx);
idx--;
}
}
}
}
TSharedPtr<FGameplayCueViewEffects> FGameplayCueViewInfo::SpawnViewEffects(AActor *Owner, TArray<UObject*> *SpawnedObjects) const
{
check(Owner);
TSharedPtr<FGameplayCueViewEffects> SpawnedEffects = TSharedPtr<FGameplayCueViewEffects>(new FGameplayCueViewEffects());
if (Sound)
{
SpawnedEffects->AudioComponent = UGameplayStatics::PlaySoundAttached(Sound, Owner->GetRootComponent());
if (SpawnedObjects)
{
SpawnedObjects->Add(SpawnedEffects->AudioComponent.Get());
}
}
if (ParticleSystem)
{
SpawnedEffects->ParticleSystemComponent = UGameplayStatics::SpawnEmitterAttached(ParticleSystem, Owner->GetRootComponent());
if (SpawnedObjects)
{
SpawnedObjects->Add(SpawnedEffects->ParticleSystemComponent.Get());
}
else if (SpawnedEffects->ParticleSystemComponent.IsValid())
{
for (int32 EmitterIndx = 0; EmitterIndx < SpawnedEffects->ParticleSystemComponent->EmitterInstances.Num(); EmitterIndx++)
{
if (SpawnedEffects->ParticleSystemComponent->EmitterInstances[EmitterIndx] &&
SpawnedEffects->ParticleSystemComponent->EmitterInstances[EmitterIndx]->CurrentLODLevel &&
SpawnedEffects->ParticleSystemComponent->EmitterInstances[EmitterIndx]->CurrentLODLevel->RequiredModule &&
SpawnedEffects->ParticleSystemComponent->EmitterInstances[EmitterIndx]->CurrentLODLevel->RequiredModule->EmitterLoops == 0)
{
SKILL_LOG(Warning, TEXT("%s - particle system has a looping emitter...."), *SpawnedEffects->ParticleSystemComponent->GetName());
break;
}
}
}
}
if (ActorClass)
{
FVector Location = Owner->GetActorLocation();
FRotator Rotation = Owner->GetActorRotation();
SpawnedEffects->SpawnedActor = Owner->GetWorld()->SpawnActor(ActorClass, &Location, &Rotation);
if (SpawnedObjects)
{
SpawnedObjects->Add(SpawnedEffects->SpawnedActor.Get());
}
}
return SpawnedEffects;
}