add remove ability

This commit is contained in:
Arnaud Jamin
2023-10-10 11:26:37 -04:00
parent 2d5e764e19
commit 91a18306e4
14 changed files with 122 additions and 61 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -133,7 +133,7 @@ bool ACogAbilityReplicator::IsCheatActive(const AActor* EffectTarget, const FCog
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::GiveAbility(AActor* Target, TSubclassOf<UGameplayAbility> AbilityClass)
void ACogAbilityReplicator::GiveAbility(AActor* Target, TSubclassOf<UGameplayAbility> AbilityClass) const
{
Server_GiveAbility(Target, AbilityClass);
}
@@ -148,12 +148,12 @@ void ACogAbilityReplicator::Server_GiveAbility_Implementation(AActor* TargetActo
return;
}
if (IsValid(AbilityClass) == false)
if (AbilitySystem->IsOwnerActorAuthoritative() == false)
{
return;
}
if (AbilitySystem->IsOwnerActorAuthoritative() == false)
if (IsValid(AbilityClass) == false)
{
return;
}
@@ -162,6 +162,35 @@ void ACogAbilityReplicator::Server_GiveAbility_Implementation(AActor* TargetActo
AbilitySystem->GiveAbility(Spec);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::RemoveAbility(AActor* TargetActor, const FGameplayAbilitySpecHandle& Handle) const
{
Server_RemoveAbility(TargetActor, Handle);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::Server_RemoveAbility_Implementation(AActor* TargetActor, const FGameplayAbilitySpecHandle& Handle) const
{
UAbilitySystemComponent* AbilitySystem = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(TargetActor, true);
if (AbilitySystem == nullptr)
{
return;
}
if (AbilitySystem->IsOwnerActorAuthoritative() == false)
{
return;
}
if (Handle.IsValid() == false)
{
return;
}
AbilitySystem->SetRemoveAbilityOnEnd(Handle);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::ResetAllTweaks()
{
@@ -68,7 +68,7 @@ void UCogAbilityWindow_Abilities::RenderOpenAbilities()
bool Open = true;
if (ImGui::Begin(TCHAR_TO_ANSI(*GetAbilityName(Ability)), &Open))
{
RenderAbilityInfo(*Spec);
RenderAbilityInfo(*AbilitySystemComponent, *Spec);
ImGui::End();
}
@@ -98,18 +98,6 @@ void UCogAbilityWindow_Abilities::RenderContent()
RenderAbiltiesMenu(Selection);
//TArray<FGameplayAbilitySpec>& Abilities = AbilitySystemComponent->GetActivatableAbilities();
//static int FocusedAbilityIndex = INDEX_NONE;
//if (FocusedAbilityIndex != INDEX_NONE && FocusedAbilityIndex < Abilities.Num())
//{
// RenderAbilityInfo(Abilities[FocusedAbilityIndex]);
// if (ImGui::Button("Close", ImVec2(-1, 0)))
// {
// FocusedAbilityIndex = INDEX_NONE;
// }
// ImGui::Spacing();
//}
RenderAbilitiesTable(*AbilitySystemComponent);
}
@@ -215,7 +203,7 @@ void UCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent&
if (ImGui::IsItemHovered())
{
FCogWindowWidgets::BeginTableTooltip();
RenderAbilityInfo(Spec);
RenderAbilityInfo(AbilitySystemComponent, Spec);
FCogWindowWidgets::EndTableTooltip();
}
@@ -291,11 +279,10 @@ void UCogAbilityWindow_Abilities::RenderAbilityContextMenu(UAbilitySystemCompone
ImGui::CloseCurrentPopup();
}
//if (ImGui::Button("Open Properties"))
//{
// GetOwner()->GetPropertyGrid()->Open(BaseAbility);
// ImGui::CloseCurrentPopup();
//}
if (ImGui::Button("Remove"))
{
AbilityHandleToRemove = Spec.Handle;
}
ImGui::EndPopup();
}
@@ -326,7 +313,7 @@ FString UCogAbilityWindow_Abilities::GetAbilityName(const UGameplayAbility* Abil
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Abilities::RenderAbilityInfo(FGameplayAbilitySpec& Spec)
void UCogAbilityWindow_Abilities::RenderAbilityInfo(const UAbilitySystemComponent& AbilitySystemComponent, FGameplayAbilitySpec& Spec)
{
UGameplayAbility* Ability = Spec.GetPrimaryInstance();
if (Ability == nullptr)
@@ -334,6 +321,11 @@ void UCogAbilityWindow_Abilities::RenderAbilityInfo(FGameplayAbilitySpec& Spec)
Ability = Spec.Ability;
}
if (Ability == nullptr)
{
return;
}
if (ImGui::BeginTable("Ability", 2, ImGuiTableFlags_Borders))
{
const ImVec4 TextColor(1.0f, 1.0f, 1.0f, 0.5f);
@@ -377,6 +369,15 @@ void UCogAbilityWindow_Abilities::RenderAbilityInfo(FGameplayAbilitySpec& Spec)
ImGui::TableNextColumn();
ImGui::Text("%u", Spec.ActiveCount);
//------------------------
// Cooldown
//------------------------
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextColored(TextColor, "Cooldown");
ImGui::TableNextColumn();
RenderAbilityCooldown(AbilitySystemComponent, *Ability);
//------------------------
// Handle
//------------------------
@@ -425,6 +426,20 @@ void UCogAbilityWindow_Abilities::GameTick(float DeltaTime)
ProcessAbilityActivation(AbilityHandleToActivate);
AbilityHandleToActivate = FGameplayAbilitySpecHandle();
}
if (AbilityHandleToRemove.IsValid())
{
if (AActor* Selection = GetSelection())
{
FCogAbilityModule& Module = FCogAbilityModule::Get();
if (ACogAbilityReplicator* Replicator = Module.GetLocalReplicator())
{
Replicator->RemoveAbility(Selection, AbilityHandleToRemove);
}
}
AbilityHandleToRemove = FGameplayAbilitySpecHandle();
}
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -295,14 +295,10 @@ FString UCogAbilityWindow_Effects::GetEffectName(const UGameplayEffect& Effect)
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Effects::RenderRemainingTime(const UAbilitySystemComponent& AbilitySystemComponent, const FActiveGameplayEffect& ActiveEffect)
{
float StartTime = ActiveEffect.StartWorldTime;
float Duration = ActiveEffect.GetDuration();
const float StartTime = ActiveEffect.StartWorldTime;
const float Duration = ActiveEffect.GetDuration();
if (Duration <= 0)
{
ImGui::Text("NA");
}
else
if (Duration >= 0)
{
UWorld* World = AbilitySystemComponent.GetWorld();
const float RemainingTime = StartTime + Duration - World->GetTimeSeconds();
@@ -28,7 +28,9 @@ public:
static bool IsCheatActive(const AActor* EffectTarget, const FCogAbilityCheat& Cheat);
void GiveAbility(AActor* TargetActor, TSubclassOf<UGameplayAbility> AbilityClass);
void GiveAbility(AActor* TargetActor, TSubclassOf<UGameplayAbility> AbilityClass) const;
void RemoveAbility(AActor* TargetActor, const FGameplayAbilitySpecHandle& Handle) const;
void ResetAllTweaks();
@@ -50,6 +52,9 @@ private:
UFUNCTION(Reliable, Server)
void Server_GiveAbility(AActor* TargetActor, TSubclassOf<UGameplayAbility> AbilityClass) const;
UFUNCTION(Reliable, Server)
void Server_RemoveAbility(AActor* TargetActor, const FGameplayAbilitySpecHandle& Handle) const;
UFUNCTION(Reliable, Server)
void Server_ResetAllTweaks();
@@ -41,7 +41,7 @@ protected:
virtual void RenderOpenAbilities();
virtual void RenderAbilityInfo(FGameplayAbilitySpec& Spec);
virtual void RenderAbilityInfo(const UAbilitySystemComponent& AbilitySystemComponent, FGameplayAbilitySpec& Spec);
virtual void ProcessAbilityActivation(FGameplayAbilitySpecHandle Handle);
@@ -57,5 +57,7 @@ private:
FGameplayAbilitySpecHandle AbilityHandleToActivate;
FGameplayAbilitySpecHandle AbilityHandleToRemove;
TArray<FGameplayAbilitySpecHandle> OpenedAbilities;
};
@@ -7,7 +7,7 @@
void UCogEngineWindow_DebugSettings::RenderHelp()
{
ImGui::Text(
"This window can be used to setup how the debug display is drawn. "
"This window can be used to tweak how the debug display is drawn. "
"Check each item for more info. "
);
}
@@ -6,32 +6,6 @@
char ImGuiTextBuffer::EmptyString[1] = { 0 };
//--------------------------------------------------------------------------------------------------------------------------
// FCogLogOutputDevice
//--------------------------------------------------------------------------------------------------------------------------
UCogLogOutputDevice::UCogLogOutputDevice()
{
GLog->AddOutputDevice(this);
}
//--------------------------------------------------------------------------------------------------------------------------
UCogLogOutputDevice::~UCogLogOutputDevice()
{
if (GLog != nullptr)
{
GLog->RemoveOutputDevice(this);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogLogOutputDevice::Serialize(const TCHAR* Message, ELogVerbosity::Type Verbosity, const class FName& Category)
{
if (OutputLog != nullptr)
{
OutputLog->AddLog(Message, Verbosity, Category);
}
}
//--------------------------------------------------------------------------------------------------------------------------
// FCogWindow_Log
//--------------------------------------------------------------------------------------------------------------------------
@@ -302,3 +276,29 @@ void UCogEngineWindow_OutputLog::RenderContent()
ImGui::EndChild();
}
}
//--------------------------------------------------------------------------------------------------------------------------
// FCogLogOutputDevice
//--------------------------------------------------------------------------------------------------------------------------
UCogLogOutputDevice::UCogLogOutputDevice()
{
GLog->AddOutputDevice(this);
}
//--------------------------------------------------------------------------------------------------------------------------
UCogLogOutputDevice::~UCogLogOutputDevice()
{
if (GLog != nullptr)
{
GLog->RemoveOutputDevice(this);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogLogOutputDevice::Serialize(const TCHAR* Message, ELogVerbosity::Type Verbosity, const class FName& Category)
{
if (OutputLog != nullptr)
{
OutputLog->AddLog(Message, Verbosity, Category);
}
}
@@ -11,6 +11,17 @@ UCogEngineWindow_Skeleton::UCogEngineWindow_Skeleton()
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Skeleton::RenderHelp()
{
ImGui::Text(
"This window display the bone hierarchy and the skeleton debug draw of the selected actor if it has a Skeletal Mesh. "
"Mouse over a bone to highlight it. "
"Right click a bone to access more debug display. "
"Use the [Ctrl] key to toggle the bone debug draw recursively. "
);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Skeleton::OnSelectionChanged(AActor* OldSelection, AActor* NewSelection)
{
@@ -31,11 +31,14 @@ class COGENGINE_API UCogEngineWindow_Skeleton : public UCogWindow
public:
UCogEngineWindow_Skeleton();
virtual void RenderContent() override;
virtual void RenderTick(float DeltaTime) override;
virtual void RenderHelp() override;
protected:
virtual void RenderContent() override;
virtual void RenderTick(float DeltaTime) override;
virtual void OnSelectionChanged(AActor* OldSelection, AActor* NewSelection) override;
private: