save cheats state

This commit is contained in:
Arnaud Jamin
2023-10-10 01:12:59 -04:00
parent 0dca669326
commit c9a3013bb9
4 changed files with 70 additions and 15 deletions
@@ -1,6 +1,8 @@
#include "CogAbilityWindow_Cheats.h"
#include "AbilitySystemGlobals.h"
#include "CogAbilityDataAsset_Cheats.h"
#include "CogAbilityReplicator.h"
#include "CogInterfaceAllegianceActor.h"
#include "CogDebugDraw.h"
#include "CogImguiHelper.h"
@@ -23,6 +25,41 @@ void UCogAbilityWindow_Cheats::RenderHelp()
);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::SetCheatsAsset(const UCogAbilityDataAsset_Cheats* Value)
{
CheatsAsset = Value;
if (CheatsAsset == nullptr)
{
return;
}
APawn* LocalPawn = GetLocalPlayerPawn();
if (LocalPawn == nullptr)
{
return;
}
FCogAbilityModule& Module = FCogAbilityModule::Get();
ACogAbilityReplicator* Replicator = Module.GetLocalReplicator();
if (Replicator == nullptr)
{
return;
}
TArray<AActor*> Targets{ LocalPawn };
for (const FString& AppliedCheatName : AppliedCheats)
{
if (const FCogAbilityCheat* Cheat = CheatsAsset->PersistentEffects.FindByPredicate(
[AppliedCheatName](const FCogAbilityCheat& Cheat) { return Cheat.Name == AppliedCheatName; }))
{
Replicator->ApplyCheat(LocalPawn, Targets, *Cheat);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::RenderContent()
{
@@ -39,7 +76,12 @@ void UCogAbilityWindow_Cheats::RenderContent()
return;
}
APawn* LocalPawn = GetLocalPlayerPawn();
APawn* ControlledActor = GetLocalPlayerPawn();
if (SelectedActor == ControlledActor)
{
AppliedCheats.Empty();
}
if (ImGui::BeginTable("Cheats", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize))
{
@@ -53,7 +95,7 @@ void UCogAbilityWindow_Cheats::RenderContent()
for (const FCogAbilityCheat& CheatEffect : CheatsAsset->PersistentEffects)
{
ImGui::PushID(Index);
AddCheat(LocalPawn, SelectedActor, CheatEffect, true);
AddCheat(ControlledActor, SelectedActor, CheatEffect, true);
ImGui::PopID();
Index++;
}
@@ -63,7 +105,7 @@ void UCogAbilityWindow_Cheats::RenderContent()
for (const FCogAbilityCheat& CheatEffect : CheatsAsset->InstantEffects)
{
ImGui::PushID(Index);
AddCheat(LocalPawn, SelectedActor, CheatEffect, false);
AddCheat(ControlledActor, SelectedActor, CheatEffect, false);
ImGui::PopID();
Index++;
}
@@ -73,7 +115,7 @@ void UCogAbilityWindow_Cheats::RenderContent()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::AddCheat(AActor* CheatInstigator, AActor* SelectedActor, const FCogAbilityCheat& Cheat, bool IsPersistent)
void UCogAbilityWindow_Cheats::AddCheat(AActor* ControlledActor, AActor* SelectedActor, const FCogAbilityCheat& Cheat, bool IsPersistent)
{
if (Cheat.Effect == nullptr)
{
@@ -103,14 +145,19 @@ void UCogAbilityWindow_Cheats::AddCheat(AActor* CheatInstigator, AActor* Selecte
bool isEnabled = ACogAbilityReplicator::IsCheatActive(SelectedActor, Cheat);
if (ImGui::Checkbox(TCHAR_TO_ANSI(*Cheat.Name), &isEnabled))
{
RequestCheat(CheatInstigator, SelectedActor, Cheat);
RequestCheat(ControlledActor, SelectedActor, Cheat);
}
if (isEnabled && SelectedActor == ControlledActor)
{
AppliedCheats.Add(Cheat.Name);
}
}
else
{
if (ImGui::Button(TCHAR_TO_ANSI(*Cheat.Name), ImVec2(-1, 0)))
{
RequestCheat(CheatInstigator, SelectedActor, Cheat);
RequestCheat(ControlledActor, SelectedActor, Cheat);
}
}
@@ -132,7 +179,7 @@ void UCogAbilityWindow_Cheats::AddCheat(AActor* CheatInstigator, AActor* Selecte
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::RequestCheat(AActor* CheatInstigator, AActor* SelectedActor, const FCogAbilityCheat& Cheat)
void UCogAbilityWindow_Cheats::RequestCheat(AActor* ControlledActor, AActor* SelectedActor, const FCogAbilityCheat& Cheat)
{
const bool IsShiftDown = (ImGui::GetCurrentContext()->IO.KeyMods & ImGuiMod_Shift) != 0;
const bool IsAltDown = (ImGui::GetCurrentContext()->IO.KeyMods & ImGuiMod_Alt) != 0;
@@ -142,7 +189,7 @@ void UCogAbilityWindow_Cheats::RequestCheat(AActor* CheatInstigator, AActor* Sel
if (IsControlDown)
{
Actors.Add(CheatInstigator);
Actors.Add(ControlledActor);
}
if (IsShiftDown || IsAltDown)
@@ -155,7 +202,7 @@ void UCogAbilityWindow_Cheats::RequestCheat(AActor* CheatInstigator, AActor* Sel
if (ICogInterfacesAllegianceActor* AllegianceInterface = Cast<ICogInterfacesAllegianceActor>(OtherActor))
{
AllegianceInterface->GetAllegianceWithOtherActor(CheatInstigator);
AllegianceInterface->GetAllegianceWithOtherActor(ControlledActor);
}
if ((IsShiftDown && (Allegiance == ECogInterfacesAllegiance::Enemy))
@@ -175,6 +222,6 @@ void UCogAbilityWindow_Cheats::RequestCheat(AActor* CheatInstigator, AActor* Sel
FCogAbilityModule& Module = FCogAbilityModule::Get();
if (ACogAbilityReplicator* Replicator = Module.GetLocalReplicator())
{
Replicator->ApplyCheat(CheatInstigator, Actors, Cheat);
Replicator->ApplyCheat(ControlledActor, Actors, Cheat);
}
}
@@ -11,7 +11,7 @@ struct FCogAbilityCheat;
struct FCogAbilityTweak;
struct FGameplayTag;
UCLASS(NotBlueprintable, NotBlueprintType, notplaceable, noteditinlinenew, hidedropdown, Transient)
UCLASS(NotBlueprintable, NotBlueprintType, notplaceable, noteditinlinenew, hidedropdown, Transient, Config = Cog)
class COGABILITY_API ACogAbilityReplicator : public AActor
{
GENERATED_UCLASS_BODY()
@@ -71,4 +71,7 @@ private:
UPROPERTY(Replicated)
TArray<float> TweakCurrentValues;
UPROPERTY(Config)
TArray<FString> AppliedCheatsOnLocalPawn;
};
@@ -15,7 +15,9 @@ class COGABILITY_API UCogAbilityWindow_Cheats : public UCogWindow
public:
TWeakObjectPtr<UCogAbilityDataAsset_Cheats> CheatsAsset;
const UCogAbilityDataAsset_Cheats* GetCheatsAsset() const { return CheatsAsset.Get(); }
void SetCheatsAsset(const UCogAbilityDataAsset_Cheats* Value);
protected:
@@ -25,10 +27,12 @@ protected:
private:
void AddCheat(AActor* InstigatorActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect, bool IsPersistent);
void AddCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect, bool IsPersistent);
void RequestCheat(AActor* InstigatorActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect);
void RequestCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect);
UPROPERTY(Config)
TArray<FString> AppliedCheats;
TWeakObjectPtr<const UCogAbilityDataAsset_Cheats> CheatsAsset;
};
+2 -1
View File
@@ -188,7 +188,8 @@ void ACogSampleGameState::InitializeCog()
CogWindowManager->CreateWindow<UCogAbilityWindow_Attributes>("Gameplay.Attributes");
UCogAbilityWindow_Cheats* CheatsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Cheats>("Gameplay.Cheats");
CheatsWindow->CheatsAsset = GetFirstAssetByClass<UCogAbilityDataAsset_Cheats>();
CheatsWindow->SetCheatsAsset(GetFirstAssetByClass<UCogAbilityDataAsset_Cheats>());
UCogAbilityWindow_Effects* EffectsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Effects>("Gameplay.Effects");
EffectsWindow->NegativeEffectTag = Tag_Effect_Alignment_Negative;
EffectsWindow->PositiveEffectTag = Tag_Effect_Alignment_Positive;