CogAbility: Apply tweaks at start and when an new actor is spawned

The data asset is now loaded directly by the windows.
This commit is contained in:
Arnaud Jamin
2023-10-22 01:37:26 -04:00
parent 4c9f731475
commit 6f54b429f0
45 changed files with 257 additions and 138 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,6 +4,7 @@
#include "CogDebugSettings.h" #include "CogDebugSettings.h"
#include "CogEngineDataAsset.h" #include "CogEngineDataAsset.h"
#include "CogImGuiHelper.h" #include "CogImGuiHelper.h"
#include "CogWindowHelper.h"
#include "Components/BoxComponent.h" #include "Components/BoxComponent.h"
#include "Components/CapsuleComponent.h" #include "Components/CapsuleComponent.h"
#include "Components/PrimitiveComponent.h" #include "Components/PrimitiveComponent.h"
@@ -26,6 +27,8 @@ void UCogEngineWindow_Collisions::RenderHelp()
UCogEngineWindow_Collisions::UCogEngineWindow_Collisions() UCogEngineWindow_Collisions::UCogEngineWindow_Collisions()
{ {
bHasMenu = true; bHasMenu = true;
SetAsset(FCogWindowHelper::GetFirstAssetByClass<UCogEngineDataAsset>());
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -3,8 +3,16 @@
#include "CogEngineDataAsset.h" #include "CogEngineDataAsset.h"
#include "CogEngineReplicator.h" #include "CogEngineReplicator.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
//--------------------------------------------------------------------------------------------------------------------------
UCogEngineWindow_Spawns::UCogEngineWindow_Spawns()
{
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogEngineDataAsset>();
}
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Spawns::RenderHelp() void UCogEngineWindow_Spawns::RenderHelp()
{ {
@@ -15,11 +15,7 @@ public:
UCogEngineWindow_Collisions(); UCogEngineWindow_Collisions();
const UCogEngineDataAsset* GetAsset() const { return Asset.Get(); } protected:
void SetAsset(const UCogEngineDataAsset* Value);
private:
virtual void ResetConfig() override; virtual void ResetConfig() override;
@@ -27,6 +23,8 @@ private:
virtual void RenderContent() override; virtual void RenderContent() override;
virtual void SetAsset(const UCogEngineDataAsset* Value);
struct FChannel struct FChannel
{ {
bool IsValid = false; bool IsValid = false;
@@ -15,9 +15,7 @@ class COGENGINE_API UCogEngineWindow_Spawns : public UCogWindow
public: public:
const UCogEngineDataAsset* GetAsset() const { return Asset.Get(); } UCogEngineWindow_Spawns();
void SetAsset(const UCogEngineDataAsset* Value) { Asset = Value; }
protected: protected:
@@ -42,7 +42,10 @@ private:
void Initialize(); void Initialize();
FCogImguiTextureManager TextureManager; FCogImguiTextureManager TextureManager;
ImFontAtlas DefaultFontAtlas; ImFontAtlas DefaultFontAtlas;
bool bEnabledInput = true; bool bEnabledInput = true;
bool bIsInitialized = false; bool bIsInitialized = false;
}; };
@@ -0,0 +1,27 @@
#pragma once
#include "CoreMinimal.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "AssetRegistry/IAssetRegistry.h"
class COGWINDOW_API FCogWindowHelper
{
public:
template<typename T>
static T* GetFirstAssetByClass()
{
IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();
TArray<FAssetData> Assets;
AssetRegistry.GetAssetsByClass(T::StaticClass()->GetClassPathName(), Assets, true);
if (Assets.Num() == 0)
{
return nullptr;
}
UObject* Asset = Assets[0].GetAsset();
T* CastedAsset = Cast<T>(Asset);
return CastedAsset;
}
};
@@ -2,6 +2,8 @@
#include "AbilitySystemComponent.h" #include "AbilitySystemComponent.h"
#include "AbilitySystemGlobals.h" #include "AbilitySystemGlobals.h"
#include "CogAbilityDataAsset.h"
#include "CogWindowHelper.h"
#include "Components/SceneComponent.h" #include "Components/SceneComponent.h"
#include "EngineUtils.h" #include "EngineUtils.h"
#include "GameplayEffect.h" #include "GameplayEffect.h"
@@ -52,6 +54,8 @@ ACogAbilityReplicator::ACogAbilityReplicator(const FObjectInitializer& ObjectIni
bReplicates = true; bReplicates = true;
bOnlyRelevantToOwner = true; bOnlyRelevantToOwner = true;
AbilityAsset = FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>();
#endif // !UE_BUILD_SHIPPING #endif // !UE_BUILD_SHIPPING
} }
@@ -74,6 +78,18 @@ void ACogAbilityReplicator::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
OwnerPlayerController = Cast<APlayerController>(GetOwner()); OwnerPlayerController = Cast<APlayerController>(GetOwner());
OnAnyActorSpawnedHandle = GetWorld()->AddOnActorSpawnedHandler(FOnActorSpawned::FDelegate::CreateUObject(this, &ACogAbilityReplicator::OnAnyActorSpawned));
ApplyAllTweaksOnAllActors();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
GetWorld()->RemoveOnActorSpawnedHandler(OnAnyActorSpawnedHandle);
Super::EndPlay(EndPlayReason);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -216,59 +232,76 @@ void ACogAbilityReplicator::Server_ResetAllTweaks_Implementation()
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::SetTweakValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 TweakCategoryIndex, float Value) void ACogAbilityReplicator::OnAnyActorSpawned(AActor* Actor)
{ {
Server_SetTweakValue(TweaksAsset, TweakIndex, TweakCategoryIndex, Value); if (AbilityAsset->ActorRootClass != nullptr && Actor->GetClass()->IsChildOf(AbilityAsset->ActorRootClass) == false)
{
return;
}
int32 TweakCategoryIndex = FindTweakCategoryFromActor(Actor);
if (TweakCategoryIndex == INDEX_NONE)
{
return;
}
ApplyAllTweaksOnActor(TweakCategoryIndex, Actor);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::Server_SetTweakValue_Implementation(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 TweakCategoryIndex, float Value) void ACogAbilityReplicator::SetTweakValue(int32 TweakIndex, int32 TweakCategoryIndex, float Value)
{ {
if (TweaksAsset == nullptr) Server_SetTweakValue(TweakIndex, TweakCategoryIndex, Value);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::Server_SetTweakValue_Implementation(int32 TweakIndex, int32 TweakCategoryIndex, float Value)
{
if (AbilityAsset == nullptr)
{ {
return; return;
} }
if (TweaksAsset->Tweaks.IsValidIndex(TweakIndex) == false) if (AbilityAsset->Tweaks.IsValidIndex(TweakIndex) == false)
{ {
return; return;
} }
if (TweaksAsset->TweaksCategories.IsValidIndex(TweakCategoryIndex) == false) if (AbilityAsset->TweaksCategories.IsValidIndex(TweakCategoryIndex) == false)
{ {
return; return;
} }
SetTweakCurrentValue(TweaksAsset, TweakIndex, TweakCategoryIndex, Value); SetTweakCurrentValue(TweakIndex, TweakCategoryIndex, Value);
const FCogAbilityTweak& Tweak = TweaksAsset->Tweaks[TweakIndex]; const FCogAbilityTweak& Tweak = AbilityAsset->Tweaks[TweakIndex];
TArray<AActor*> Actors; TArray<AActor*> Actors;
GetActorsFromTweakCategory(TweaksAsset, TweakCategoryIndex, Actors); FindActorsFromTweakCategory(TweakCategoryIndex, Actors);
for (AActor* Actor : Actors) for (AActor* Actor : Actors)
{ {
ApplyTweakOnActor(Actor, Tweak, Value, TweaksAsset->SetByCallerMagnitudeTag); ApplyTweakOnActor(Actor, Tweak, Value, AbilityAsset->SetByCallerMagnitudeTag);
} }
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::ApplyAllTweaksOnActor(const UCogAbilityDataAsset* TweaksAsset, int32 TweakCategoryIndex, AActor* Actor) void ACogAbilityReplicator::ApplyAllTweaksOnActor(int32 TweakCategoryIndex, AActor* Actor)
{ {
if (TweaksAsset == nullptr) if (AbilityAsset == nullptr)
{ {
return; return;
} }
if (TweaksAsset->TweaksCategories.IsValidIndex(TweakCategoryIndex) == false) if (AbilityAsset->TweaksCategories.IsValidIndex(TweakCategoryIndex) == false)
{ {
return; return;
} }
int32 TweakIndex = 0; int32 TweakIndex = 0;
for (const FCogAbilityTweak& Tweak : TweaksAsset->Tweaks) for (const FCogAbilityTweak& Tweak : AbilityAsset->Tweaks)
{ {
const float Value = GetTweakCurrentValue(TweaksAsset, TweakIndex, TweakCategoryIndex); const float Value = GetTweakCurrentValue(TweakIndex, TweakCategoryIndex);
ApplyTweakOnActor(Actor, Tweak, Value, TweaksAsset->SetByCallerMagnitudeTag); ApplyTweakOnActor(Actor, Tweak, Value, AbilityAsset->SetByCallerMagnitudeTag);
TweakIndex++; TweakIndex++;
} }
} }
@@ -297,9 +330,9 @@ void ACogAbilityReplicator::ApplyTweakOnActor(AActor* Actor, const FCogAbilityTw
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
float ACogAbilityReplicator::GetTweakCurrentValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 TweakCategoryIndex) float ACogAbilityReplicator::GetTweakCurrentValue(int32 TweakIndex, int32 TweakCategoryIndex)
{ {
float* Value = GetTweakCurrentValuePtr(TweaksAsset, TweakIndex, TweakCategoryIndex); float* Value = GetTweakCurrentValuePtr(TweakIndex, TweakCategoryIndex);
if (Value == nullptr) if (Value == nullptr)
{ {
return 0.0f; return 0.0f;
@@ -309,11 +342,16 @@ float ACogAbilityReplicator::GetTweakCurrentValue(const UCogAbilityDataAsset* Tw
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
float* ACogAbilityReplicator::GetTweakCurrentValuePtr(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 TweakCategoryIndex) float* ACogAbilityReplicator::GetTweakCurrentValuePtr(int32 TweakIndex, int32 TweakCategoryIndex)
{ {
TweakCurrentValues.SetNum(TweaksAsset->Tweaks.Num() * TweaksAsset->TweaksCategories.Num()); if (AbilityAsset == nullptr)
{
return nullptr;
}
const int32 Index = TweakIndex + (TweakCategoryIndex * TweaksAsset->Tweaks.Num()); TweakCurrentValues.SetNum(AbilityAsset->Tweaks.Num() * AbilityAsset->TweaksCategories.Num());
const int32 Index = TweakIndex + (TweakCategoryIndex * AbilityAsset->Tweaks.Num());
if (TweakCurrentValues.IsValidIndex(Index) == false) if (TweakCurrentValues.IsValidIndex(Index) == false)
{ {
@@ -324,16 +362,16 @@ float* ACogAbilityReplicator::GetTweakCurrentValuePtr(const UCogAbilityDataAsset
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::SetTweakCurrentValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 TweakCategoryIndex, float Value) void ACogAbilityReplicator::SetTweakCurrentValue(int32 TweakIndex, int32 TweakCategoryIndex, float Value)
{ {
if (TweaksAsset == nullptr) if (AbilityAsset == nullptr)
{ {
return; return;
} }
TweakCurrentValues.SetNum(TweaksAsset->Tweaks.Num() * TweaksAsset->TweaksCategories.Num()); TweakCurrentValues.SetNum(AbilityAsset->Tweaks.Num() * AbilityAsset->TweaksCategories.Num());
const int32 Index = TweakIndex + (TweakCategoryIndex * TweaksAsset->Tweaks.Num()); const int32 Index = TweakIndex + (TweakCategoryIndex * AbilityAsset->Tweaks.Num());
if (TweakCurrentValues.IsValidIndex(TweakIndex) == false) if (TweakCurrentValues.IsValidIndex(TweakIndex) == false)
{ {
return; return;
@@ -344,20 +382,20 @@ void ACogAbilityReplicator::SetTweakCurrentValue(const UCogAbilityDataAsset* Twe
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::SetTweakProfile(const UCogAbilityDataAsset* TweaksAsset, int32 ProfileIndex) void ACogAbilityReplicator::SetTweakProfile(int32 ProfileIndex)
{ {
Server_SetTweakProfile(TweaksAsset, ProfileIndex); Server_SetTweakProfile(ProfileIndex);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::Server_SetTweakProfile_Implementation(const UCogAbilityDataAsset* TweaksAsset, int32 ProfileIndex) void ACogAbilityReplicator::Server_SetTweakProfile_Implementation(int32 ProfileIndex)
{ {
if (TweaksAsset == nullptr) if (AbilityAsset == nullptr)
{ {
return; return;
} }
if (TweaksAsset->TweakProfiles.IsValidIndex(ProfileIndex) == false) if (AbilityAsset->TweakProfiles.IsValidIndex(ProfileIndex) == false)
{ {
ProfileIndex = INDEX_NONE; ProfileIndex = INDEX_NONE;
} }
@@ -367,48 +405,59 @@ void ACogAbilityReplicator::Server_SetTweakProfile_Implementation(const UCogAbil
ResetAllTweaks(); ResetAllTweaks();
if (TweaksAsset->TweakProfiles.IsValidIndex(TweakProfileIndex)) if (AbilityAsset->TweakProfiles.IsValidIndex(TweakProfileIndex))
{ {
const FCogAbilityTweakProfile& TweakProfile = TweaksAsset->TweakProfiles[TweakProfileIndex]; const FCogAbilityTweakProfile& TweakProfile = AbilityAsset->TweakProfiles[TweakProfileIndex];
for (const FCogAbilityTweakProfileValue& ProfileTweak : TweakProfile.Tweaks) for (const FCogAbilityTweakProfileValue& ProfileTweak : TweakProfile.Tweaks)
{ {
const int32 TweakIndex = TweaksAsset->Tweaks.IndexOfByPredicate([ProfileTweak](const FCogAbilityTweak& Tweak) { return ProfileTweak.Effect == Tweak.Effect; }); const int32 TweakIndex = AbilityAsset->Tweaks.IndexOfByPredicate([ProfileTweak](const FCogAbilityTweak& Tweak) { return ProfileTweak.Effect == Tweak.Effect; });
const int32 TweakCategoryIndex = TweaksAsset->TweaksCategories.IndexOfByPredicate([ProfileTweak](const FCogAbilityTweakCategory& TweakCategory) { return ProfileTweak.CategoryId == TweakCategory.Id; }); const int32 TweakCategoryIndex = AbilityAsset->TweaksCategories.IndexOfByPredicate([ProfileTweak](const FCogAbilityTweakCategory& TweakCategory) { return ProfileTweak.CategoryId == TweakCategory.Id; });
if (TweakIndex != INDEX_NONE && TweakCategoryIndex != INDEX_NONE) if (TweakIndex != INDEX_NONE && TweakCategoryIndex != INDEX_NONE)
{ {
SetTweakCurrentValue(TweaksAsset, TweakIndex, TweakCategoryIndex, ProfileTweak.Value); SetTweakCurrentValue(TweakIndex, TweakCategoryIndex, ProfileTweak.Value);
} }
} }
} }
for (int32 TweakCategoryIndex = 0; TweakCategoryIndex < TweaksAsset->TweaksCategories.Num(); ++TweakCategoryIndex) ApplyAllTweaksOnAllActors();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::ApplyAllTweaksOnAllActors()
{
if (AbilityAsset == nullptr)
{
return;
}
for (int32 TweakCategoryIndex = 0; TweakCategoryIndex < AbilityAsset->TweaksCategories.Num(); ++TweakCategoryIndex)
{ {
TArray<AActor*> Actors; TArray<AActor*> Actors;
GetActorsFromTweakCategory(TweaksAsset, TweakCategoryIndex, Actors); FindActorsFromTweakCategory(TweakCategoryIndex, Actors);
for (AActor* Actor : Actors) for (AActor* Actor : Actors)
{ {
ApplyAllTweaksOnActor(TweaksAsset, TweakCategoryIndex, Actor); ApplyAllTweaksOnActor(TweakCategoryIndex, Actor);
} }
} }
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::GetActorsFromTweakCategory(const UCogAbilityDataAsset* TweaksAsset, int32 TweakCategoryIndex, TArray<AActor*>& Actors) void ACogAbilityReplicator::FindActorsFromTweakCategory(int32 TweakCategoryIndex, TArray<AActor*>& Actors)
{ {
if (TweaksAsset == nullptr) if (AbilityAsset == nullptr)
{ {
return; return;
} }
if (TweaksAsset->TweaksCategories.IsValidIndex(TweakCategoryIndex) == false) if (AbilityAsset->TweaksCategories.IsValidIndex(TweakCategoryIndex) == false)
{ {
return; return;
} }
const FCogAbilityTweakCategory& TweakCategory = TweaksAsset->TweaksCategories[TweakCategoryIndex]; const FCogAbilityTweakCategory& TweakCategory = AbilityAsset->TweaksCategories[TweakCategoryIndex];
for (TActorIterator<AActor> It(GetWorld(), TweakCategory.ActorClass); It; ++It) for (TActorIterator<AActor> It(GetWorld(), TweakCategory.ActorClass); It; ++It)
{ {
@@ -424,3 +473,48 @@ void ACogAbilityReplicator::GetActorsFromTweakCategory(const UCogAbilityDataAsse
} }
} }
} }
//--------------------------------------------------------------------------------------------------------------------------
int32 ACogAbilityReplicator::FindTweakCategoryFromActor(AActor* Actor)
{
UAbilitySystemComponent* AbilitySystem = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(Actor, true);
if (AbilitySystem == nullptr)
{
return INDEX_NONE;
}
for (int32 i = 0; i < AbilityAsset->TweaksCategories.Num(); ++i)
{
const FCogAbilityTweakCategory& TweakCategory = AbilityAsset->TweaksCategories[i];
if (IsActorMatchingTweakCategory(Actor, AbilitySystem, TweakCategory))
{
return i;
}
}
return INDEX_NONE;
}
//--------------------------------------------------------------------------------------------------------------------------
bool ACogAbilityReplicator::IsActorMatchingTweakCategory(const AActor* Actor, const UAbilitySystemComponent* ActorAbilitySystem, const FCogAbilityTweakCategory& TweakCategory)
{
if (Actor->GetClass()->IsChildOf(TweakCategory.ActorClass) == false)
{
return false;
}
const bool bHasRequiredTags = ActorAbilitySystem->HasAllMatchingGameplayTags(TweakCategory.RequiredTags);
if (bHasRequiredTags == false)
{
return false;
}
const bool bHasIgnoredTags = ActorAbilitySystem->HasAnyMatchingGameplayTags(TweakCategory.IgnoredTags);
if (bHasIgnoredTags)
{
return false;
}
return true;
}
@@ -6,6 +6,7 @@
#include "CogAbilityHelper.h" #include "CogAbilityHelper.h"
#include "CogAbilityReplicator.h" #include "CogAbilityReplicator.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "imgui.h" #include "imgui.h"
#include "imgui_internal.h" #include "imgui_internal.h"
@@ -25,6 +26,8 @@ void UCogAbilityWindow_Abilities::RenderHelp()
UCogAbilityWindow_Abilities::UCogAbilityWindow_Abilities() UCogAbilityWindow_Abilities::UCogAbilityWindow_Abilities()
{ {
bHasMenu = true; bHasMenu = true;
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -5,6 +5,7 @@
#include "CogAbilityDataAsset.h" #include "CogAbilityDataAsset.h"
#include "CogAbilityHelper.h" #include "CogAbilityHelper.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "AttributeSet.h" #include "AttributeSet.h"
#include "EngineUtils.h" #include "EngineUtils.h"
@@ -26,6 +27,8 @@ void UCogAbilityWindow_Attributes::RenderHelp()
UCogAbilityWindow_Attributes::UCogAbilityWindow_Attributes() UCogAbilityWindow_Attributes::UCogAbilityWindow_Attributes()
{ {
bHasMenu = true; bHasMenu = true;
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -6,6 +6,7 @@
#include "CogCommonAllegianceActorInterface.h" #include "CogCommonAllegianceActorInterface.h"
#include "CogDebugDraw.h" #include "CogDebugDraw.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "EngineUtils.h" #include "EngineUtils.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
@@ -30,6 +31,8 @@ void UCogAbilityWindow_Cheats::RenderHelp()
UCogAbilityWindow_Cheats::UCogAbilityWindow_Cheats() UCogAbilityWindow_Cheats::UCogAbilityWindow_Cheats()
{ {
bHasMenu = true; bHasMenu = true;
SetAsset(FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>());
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -6,6 +6,7 @@
#include "CogAbilityDataAsset.h" #include "CogAbilityDataAsset.h"
#include "CogAbilityHelper.h" #include "CogAbilityHelper.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "EngineUtils.h" #include "EngineUtils.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
@@ -23,6 +24,8 @@ void UCogAbilityWindow_Effects::RenderHelp()
UCogAbilityWindow_Effects::UCogAbilityWindow_Effects() UCogAbilityWindow_Effects::UCogAbilityWindow_Effects()
{ {
bHasMenu = false; bHasMenu = false;
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -4,9 +4,16 @@
#include "AbilitySystemGlobals.h" #include "AbilitySystemGlobals.h"
#include "CogAbilityDataAsset.h" #include "CogAbilityDataAsset.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "imgui_internal.h" #include "imgui_internal.h"
//--------------------------------------------------------------------------------------------------------------------------
UCogAbilityWindow_Pools::UCogAbilityWindow_Pools()
{
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>();
}
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Pools::RenderHelp() void UCogAbilityWindow_Pools::RenderHelp()
{ {
@@ -4,12 +4,15 @@
#include "CogAbilityDataAsset.h" #include "CogAbilityDataAsset.h"
#include "CogAbilityReplicator.h" #include "CogAbilityReplicator.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
UCogAbilityWindow_Tweaks::UCogAbilityWindow_Tweaks() UCogAbilityWindow_Tweaks::UCogAbilityWindow_Tweaks()
{ {
bHasMenu = true; bHasMenu = true;
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogAbilityDataAsset>();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -62,7 +65,7 @@ void UCogAbilityWindow_Tweaks::RenderContent()
bool IsSelected = CurrentTweakProfileIndex == INDEX_NONE; bool IsSelected = CurrentTweakProfileIndex == INDEX_NONE;
if (ImGui::Selectable("None", IsSelected)) if (ImGui::Selectable("None", IsSelected))
{ {
Replicator->SetTweakProfile(Asset.Get(), INDEX_NONE); Replicator->SetTweakProfile(INDEX_NONE);
} }
} }
@@ -73,7 +76,7 @@ void UCogAbilityWindow_Tweaks::RenderContent()
if (ImGui::Selectable(TCHAR_TO_ANSI(*TweakProfile.Name.ToString()), IsSelected)) if (ImGui::Selectable(TCHAR_TO_ANSI(*TweakProfile.Name.ToString()), IsSelected))
{ {
Replicator->SetTweakProfile(Asset.Get(), TweakProfileIndex); Replicator->SetTweakProfile(TweakProfileIndex);
} }
} }
ImGui::EndCombo(); ImGui::EndCombo();
@@ -128,7 +131,7 @@ void UCogAbilityWindow_Tweaks::DrawTweak(ACogAbilityReplicator* Replicator, int3
return; return;
} }
float* Value = Replicator->GetTweakCurrentValuePtr(Asset.Get(), TweakIndex, TweakCategoryIndex); float* Value = Replicator->GetTweakCurrentValuePtr(TweakIndex, TweakCategoryIndex);
if (Value == nullptr) if (Value == nullptr)
{ {
return; return;
@@ -156,6 +159,6 @@ void UCogAbilityWindow_Tweaks::DrawTweak(ACogAbilityReplicator* Replicator, int3
if (bUpdateValue) if (bUpdateValue)
{ {
Replicator->SetTweakValue(Asset.Get(), TweakIndex, TweakCategoryIndex, *Value); Replicator->SetTweakValue(TweakIndex, TweakCategoryIndex, *Value);
} }
} }
@@ -192,6 +192,9 @@ public:
UPROPERTY(Category = "Tweaks", EditAnywhere) UPROPERTY(Category = "Tweaks", EditAnywhere)
FGameplayTag SetByCallerMagnitudeTag; FGameplayTag SetByCallerMagnitudeTag;
UPROPERTY(Category = "Tweaks", EditAnywhere)
TSubclassOf<AActor> ActorRootClass;
UPROPERTY(Category = "Tweaks", EditAnywhere, meta = (TitleProperty = "Name")) UPROPERTY(Category = "Tweaks", EditAnywhere, meta = (TitleProperty = "Name"))
TArray<FCogAbilityTweak> Tweaks; TArray<FCogAbilityTweak> Tweaks;
@@ -9,6 +9,7 @@ class UAbilitySystemComponent;
class UCogAbilityDataAsset; class UCogAbilityDataAsset;
struct FCogAbilityCheat; struct FCogAbilityCheat;
struct FCogAbilityTweak; struct FCogAbilityTweak;
struct FCogAbilityTweakCategory;
struct FGameplayTag; struct FGameplayTag;
UCLASS(NotBlueprintable, NotBlueprintType, notplaceable, noteditinlinenew, hidedropdown, Transient, Config = Cog) UCLASS(NotBlueprintable, NotBlueprintType, notplaceable, noteditinlinenew, hidedropdown, Transient, Config = Cog)
@@ -26,6 +27,8 @@ public:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
APlayerController* GetPlayerController() const { return OwnerPlayerController.Get(); } APlayerController* GetPlayerController() const { return OwnerPlayerController.Get(); }
void ApplyCheat(AActor* CheatInstigator, const TArray<AActor*>& Targets, const FCogAbilityCheat& Cheat); void ApplyCheat(AActor* CheatInstigator, const TArray<AActor*>& Targets, const FCogAbilityCheat& Cheat);
@@ -38,18 +41,21 @@ public:
void ResetAllTweaks(); void ResetAllTweaks();
void SetTweakValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 CategoryIndex, float Value); void SetTweakValue(int32 TweakIndex, int32 CategoryIndex, float Value);
void SetTweakProfile(const UCogAbilityDataAsset* TweaksAsset, int32 ProfileIndex); void SetTweakProfile(int32 ProfileIndex);
int32 GetTweakProfileIndex() const { return TweakProfileIndex; } int32 GetTweakProfileIndex() const { return TweakProfileIndex; }
float GetTweakCurrentValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 CategoryIndex); float GetTweakCurrentValue(int32 TweakIndex, int32 CategoryIndex);
float* GetTweakCurrentValuePtr(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 CategoryIndex); float* GetTweakCurrentValuePtr(int32 TweakIndex, int32 CategoryIndex);
private: private:
UFUNCTION()
void OnAnyActorSpawned(AActor* Actor);
UFUNCTION(Reliable, Server) UFUNCTION(Reliable, Server)
void Server_ApplyCheat(const AActor* CheatInstigator, const TArray<AActor*>& TargetActors, const FCogAbilityCheat& Cheat) const; void Server_ApplyCheat(const AActor* CheatInstigator, const TArray<AActor*>& TargetActors, const FCogAbilityCheat& Cheat) const;
@@ -63,17 +69,24 @@ private:
void Server_ResetAllTweaks(); void Server_ResetAllTweaks();
UFUNCTION(Reliable, Server) UFUNCTION(Reliable, Server)
void Server_SetTweakValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 TweakCategoryIndex, float Value); void Server_SetTweakValue(int32 TweakIndex, int32 TweakCategoryIndex, float Value);
UFUNCTION(Reliable, Server) UFUNCTION(Reliable, Server)
void Server_SetTweakProfile(const UCogAbilityDataAsset* TweaksAsset, int32 ProfileIndex); void Server_SetTweakProfile(int32 ProfileIndex);
void SetTweakCurrentValue(int32 TweakIndex, int32 CategoryIndex, float Value);
void ApplyAllTweaksOnAllActors();
void SetTweakCurrentValue(const UCogAbilityDataAsset* TweaksAsset, int32 TweakIndex, int32 CategoryIndex, float Value);
void ApplyTweakOnActor(AActor* Actor, const FCogAbilityTweak& Tweak, float Value, const FGameplayTag& SetByCallerMagnitudeTag); void ApplyTweakOnActor(AActor* Actor, const FCogAbilityTweak& Tweak, float Value, const FGameplayTag& SetByCallerMagnitudeTag);
void ApplyAllTweaksOnActor(const UCogAbilityDataAsset* TweaksAsset, int32 TweakCategoryIndex, AActor* Actor);
void GetActorsFromTweakCategory(const UCogAbilityDataAsset* TweaksAsset, int32 CategoryIndex, TArray<AActor*>& Actors);
TObjectPtr<APlayerController> OwnerPlayerController; void ApplyAllTweaksOnActor(int32 TweakCategoryIndex, AActor* Actor);
void FindActorsFromTweakCategory(int32 CategoryIndex, TArray<AActor*>& Actors);
int32 FindTweakCategoryFromActor(AActor* Actor);
static bool IsActorMatchingTweakCategory(const AActor* Actor, const UAbilitySystemComponent* ActorAbilitySystem, const FCogAbilityTweakCategory& TweakCategory);
UPROPERTY(Replicated) UPROPERTY(Replicated)
int32 TweakProfileIndex = INDEX_NONE; int32 TweakProfileIndex = INDEX_NONE;
@@ -83,4 +96,11 @@ private:
UPROPERTY(Config) UPROPERTY(Config)
TArray<FString> AppliedCheatsOnLocalPawn; TArray<FString> AppliedCheatsOnLocalPawn;
TObjectPtr<APlayerController> OwnerPlayerController;
FDelegateHandle OnAnyActorSpawnedHandle;
UPROPERTY()
TObjectPtr<const UCogAbilityDataAsset> AbilityAsset = nullptr;
}; };
@@ -19,10 +19,6 @@ public:
UCogAbilityWindow_Abilities(); UCogAbilityWindow_Abilities();
const UCogAbilityDataAsset* GetAsset() const { return Asset.Get(); }
void SetAsset(const UCogAbilityDataAsset* Value) { Asset = Value; }
protected: protected:
virtual void RenderHelp() override; virtual void RenderHelp() override;
@@ -19,10 +19,6 @@ public:
UCogAbilityWindow_Attributes(); UCogAbilityWindow_Attributes();
const UCogAbilityDataAsset* GetAsset() const { return Asset.Get(); }
void SetAsset(const UCogAbilityDataAsset* Value) { Asset = Value; }
protected: protected:
virtual void ResetConfig() override; virtual void ResetConfig() override;
@@ -24,10 +24,6 @@ public:
UCogAbilityWindow_Effects(); UCogAbilityWindow_Effects();
const UCogAbilityDataAsset* GetAsset() const { return Asset.Get(); }
void SetAsset(const UCogAbilityDataAsset* Value) { Asset = Value; }
protected: protected:
virtual void RenderHelp() override; virtual void RenderHelp() override;
@@ -16,9 +16,7 @@ class COGABILITY_API UCogAbilityWindow_Pools : public UCogWindow
public: public:
const UCogAbilityDataAsset* GetAsset() const { return Asset.Get(); } UCogAbilityWindow_Pools();
void SetAsset(const UCogAbilityDataAsset* Value) { Asset = Value; }
protected: protected:
@@ -16,10 +16,6 @@ public:
UCogAbilityWindow_Tweaks(); UCogAbilityWindow_Tweaks();
const UCogAbilityDataAsset* GetAsset() const { return Asset.Get(); }
void SetAsset(const UCogAbilityDataAsset* Value) { Asset = Value; }
protected: protected:
virtual void RenderHelp() override; virtual void RenderHelp() override;
@@ -1,6 +1,7 @@
#include "CogInputWindow_Actions.h" #include "CogInputWindow_Actions.h"
#include "CogInputDataAsset.h" #include "CogInputDataAsset.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "Engine/LocalPlayer.h" #include "Engine/LocalPlayer.h"
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
@@ -23,6 +24,8 @@ void UCogInputWindow_Actions::RenderHelp()
UCogInputWindow_Actions::UCogInputWindow_Actions() UCogInputWindow_Actions::UCogInputWindow_Actions()
{ {
bHasMenu = true; bHasMenu = true;
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogInputDataAsset>();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -2,6 +2,7 @@
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "CogInputDataAsset.h" #include "CogInputDataAsset.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h" #include "CogWindowWidgets.h"
#include "Engine/LocalPlayer.h" #include "Engine/LocalPlayer.h"
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
@@ -11,6 +12,7 @@
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
UCogInputWindow_Gamepad::UCogInputWindow_Gamepad() UCogInputWindow_Gamepad::UCogInputWindow_Gamepad()
{ {
Asset = FCogWindowHelper::GetFirstAssetByClass<UCogInputDataAsset>();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -17,10 +17,6 @@ public:
UCogInputWindow_Actions(); UCogInputWindow_Actions();
const UCogInputDataAsset* GetAsset() const { return Asset.Get(); }
void SetAsset(const UCogInputDataAsset* Value) { Asset = Value; }
protected: protected:
void RenderHelp(); void RenderHelp();
@@ -18,10 +18,6 @@ public:
UCogInputWindow_Gamepad(); UCogInputWindow_Gamepad();
const UCogInputDataAsset* GetAsset() const { return Asset.Get(); }
void SetAsset(const UCogInputDataAsset* Value) { Asset = Value; }
protected: protected:
virtual void ResetConfig() override; virtual void ResetConfig() override;
+11 -47
View File
@@ -1,7 +1,5 @@
#include "CogSampleGameState.h" #include "CogSampleGameState.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "CogSampleAbilitySystemComponent.h" #include "CogSampleAbilitySystemComponent.h"
#include "CogSampleFunctionLibrary_Tag.h" #include "CogSampleFunctionLibrary_Tag.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
@@ -52,25 +50,6 @@
#endif //ENABLE_COG #endif //ENABLE_COG
//--------------------------------------------------------------------------------------------------------------------------
template<typename T>
T* GetFirstAssetByClass()
{
IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();
TArray<FAssetData> Assets;
AssetRegistry.GetAssetsByClass(T::StaticClass()->GetClassPathName(), Assets, true);
if (Assets.Num() == 0)
{
return nullptr;
}
UObject* Asset = Assets[0].GetAsset();
T* CastedAsset = Cast<T>(Asset);
return CastedAsset;
}
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
ACogSampleGameState::ACogSampleGameState(const FObjectInitializer & ObjectInitializer) ACogSampleGameState::ACogSampleGameState(const FObjectInitializer & ObjectInitializer)
: Super(ObjectInitializer) : Super(ObjectInitializer)
@@ -139,10 +118,7 @@ void ACogSampleGameState::InitializeCog()
//--------------------------------------- //---------------------------------------
// Engine // Engine
//--------------------------------------- //---------------------------------------
const UCogEngineDataAsset* EngineAsset = GetFirstAssetByClass<UCogEngineDataAsset>(); CogWindowManager->CreateWindow<UCogEngineWindow_Collisions>("Engine.Collision");
UCogEngineWindow_Collisions* CollisionsWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Collisions>("Engine.Collision");
CollisionsWindow->SetAsset(EngineAsset);
CogWindowManager->CreateWindow<UCogEngineWindow_CommandBindings>("Engine.Command Bindings"); CogWindowManager->CreateWindow<UCogEngineWindow_CommandBindings>("Engine.Command Bindings");
@@ -177,8 +153,7 @@ void ACogSampleGameState::InitializeCog()
CogWindowManager->CreateWindow<UCogEngineWindow_Skeleton>("Engine.Skeleton"); CogWindowManager->CreateWindow<UCogEngineWindow_Skeleton>("Engine.Skeleton");
UCogEngineWindow_Spawns* SpawnWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Spawns>("Engine.Spawns"); CogWindowManager->CreateWindow<UCogEngineWindow_Spawns>("Engine.Spawns");
SpawnWindow->SetAsset(EngineAsset);
UCogEngineWindow_Stats* StatsWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Stats>("Engine.Stats"); UCogEngineWindow_Stats* StatsWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Stats>("Engine.Stats");
@@ -187,44 +162,33 @@ void ACogSampleGameState::InitializeCog()
//--------------------------------------- //---------------------------------------
// Abilities // Abilities
//--------------------------------------- //---------------------------------------
const UCogAbilityDataAsset* AbilityAsset = GetFirstAssetByClass<UCogAbilityDataAsset>(); CogWindowManager->CreateWindow<UCogAbilityWindow_Abilities>("Gameplay.Abilities");
UCogAbilityWindow_Abilities* AbilitiesWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Abilities>("Gameplay.Abilities"); CogWindowManager->CreateWindow<UCogAbilityWindow_Attributes>("Gameplay.Attributes");
AbilitiesWindow->SetAsset(AbilityAsset);
UCogAbilityWindow_Attributes* AttributesWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Attributes>("Gameplay.Attributes"); CogWindowManager->CreateWindow<UCogAbilityWindow_Cheats>("Gameplay.Cheats");
AttributesWindow->SetAsset(AbilityAsset);
UCogAbilityWindow_Cheats* CheatsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Cheats>("Gameplay.Cheats"); CogWindowManager->CreateWindow<UCogAbilityWindow_Effects>("Gameplay.Effects");
CheatsWindow->SetAsset(AbilityAsset);
UCogAbilityWindow_Effects* EffectsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Effects>("Gameplay.Effects"); CogWindowManager->CreateWindow<UCogAbilityWindow_Pools>("Gameplay.Pools");
EffectsWindow->SetAsset(AbilityAsset);
UCogAbilityWindow_Pools* PoolsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Pools>("Gameplay.Pools");
PoolsWindow->SetAsset(AbilityAsset);
CogWindowManager->CreateWindow<UCogAbilityWindow_Tags>("Gameplay.Tags"); CogWindowManager->CreateWindow<UCogAbilityWindow_Tags>("Gameplay.Tags");
UCogAbilityWindow_Tweaks* TweaksWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Tweaks>("Gameplay.Tweaks"); CogWindowManager->CreateWindow<UCogAbilityWindow_Tweaks>("Gameplay.Tweaks");
TweaksWindow->SetAsset(AbilityAsset);
//--------------------------------------- //---------------------------------------
// AI // AI
//--------------------------------------- //---------------------------------------
CogWindowManager->CreateWindow<UCogAIWindow_BehaviorTree>("AI.Behavior Tree"); CogWindowManager->CreateWindow<UCogAIWindow_BehaviorTree>("AI.Behavior Tree");
CogWindowManager->CreateWindow<UCogAIWindow_Blackboard>("AI.Blackboard"); CogWindowManager->CreateWindow<UCogAIWindow_Blackboard>("AI.Blackboard");
//--------------------------------------- //---------------------------------------
// Input // Input
//--------------------------------------- //---------------------------------------
const UCogInputDataAsset* InputAsset = GetFirstAssetByClass<UCogInputDataAsset>(); CogWindowManager->CreateWindow<UCogInputWindow_Actions>("Input.Actions");
UCogInputWindow_Actions* ActionsWindow = CogWindowManager->CreateWindow<UCogInputWindow_Actions>("Input.Actions"); CogWindowManager->CreateWindow<UCogInputWindow_Gamepad>("Input.Gamepad");
ActionsWindow->SetAsset(InputAsset);
UCogInputWindow_Gamepad* GamepadWindow = CogWindowManager->CreateWindow<UCogInputWindow_Gamepad>("Input.Gamepad");
GamepadWindow->SetAsset(InputAsset);
//--------------------------------------- //---------------------------------------
// Main Menu Widget // Main Menu Widget