diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp index 962a5de..e0a9250 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp @@ -638,6 +638,90 @@ void FCogDebugDraw::Skeleton(const FLogCategoryBase& LogCategory, const USkeleta } } +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDraw::LineTrace(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FVector& Start, const FVector& End, const bool HasHits, TArray& HitResults, const FCogDebugDrawLineTraceParams& Settings) +{ + if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false) + { return; } + + const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (World == nullptr) + { return; } + + Settings.Persistent = FCogDebug::GetDebugPersistent(Settings.Persistent); + FCogDebugDrawHelper::DrawLineTrace(World, Start, End, HasHits, HitResults, Settings); + + ReplicateShape(WorldContextObject, + FCogDebugShape::MakeArrow(Start, + End, + FCogDebug::Settings.ArrowSize, + HasHits + ? Settings.HitColor + : Settings.NoHitColor, + FCogDebug::Settings.Thickness, + Settings.Persistent, + Settings.DepthPriority)); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDraw::Sweep(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Start, const FVector& End, const FQuat& Rotation, const bool HasHits, TArray& HitResults, const FCogDebugDrawSweepParams& Settings) +{ + if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false) + { return; } + + const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (World == nullptr) + { return; } + + FCogDebugDrawHelper::DrawSweep(World, Shape, Start, End, Rotation, HasHits, HitResults, Settings); + + const FColor Color = HasHits + ? Settings.HitColor + : Settings.NoHitColor; + ReplicateShape(WorldContextObject, + FCogDebugShape::MakeCollisionShape(Shape, + Start, + Rotation, + Shape.GetExtent(), + Color, + FCogDebug::Settings.Thickness, + Settings.Persistent, + Settings.DepthPriority)); + ReplicateShape(WorldContextObject, + FCogDebugShape::MakeArrow(Start, + End, + FCogDebug::Settings.ArrowSize, + Color, + FCogDebug::Settings.Thickness, + Settings.Persistent, + Settings.DepthPriority)); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDraw::Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray& OverlapResults, const FCogDebugDrawOverlapParams& Settings) +{ + if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false) + { return; } + + const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (World == nullptr) + { return; } + + FCogDebugDrawHelper::DrawOverlap(World, Shape, Location, Rotation, OverlapResults, Settings); + + const FColor Color = OverlapResults.Num() > 0 + ? Settings.HitColor + : Settings.NoHitColor; + ReplicateShape(WorldContextObject, + FCogDebugShape::MakeCollisionShape(Shape, + Location, + Rotation, + Shape.GetExtent(), + Color, + FCogDebug::Settings.Thickness, + Settings.Persistent, + Settings.DepthPriority)); +} //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugDraw::ReplicateShape(const UObject* WorldContextObject, const FCogDebugShape& Shape) diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp index a1ec759..768bafb 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp @@ -596,6 +596,22 @@ FCogDebugShape FCogDebugShape::MakePolygon(const TArray& Verts, const F return NewElement; } +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugShape FCogDebugShape::MakeCollisionShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Extent, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) +{ + switch (Shape.ShapeType) + { + case ECollisionShape::Box: + return MakeBox(Location, Rotation.Rotator(), Extent, Color, Thickness, bPersistent, DepthPriority); + case ECollisionShape::Capsule: + return MakeCapsule(Location, Rotation, Extent.X, Extent.Z, Color, Thickness, bPersistent, DepthPriority); + + default: + case ECollisionShape::Sphere: + return MakeCapsule(Location, Rotation, Extent.X, 0.0f, Color, Thickness, bPersistent, DepthPriority); + } +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugShape::DrawPolygon(const UWorld* World) const { diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugDraw.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugDraw.h index 351ca87..2be83f8 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugDraw.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugDraw.h @@ -5,6 +5,9 @@ class USkeletalMeshComponent; struct FCogDebugShape; +struct FCollisionShape; +struct FHitResult; +struct FOverlapResult; #if ENABLE_COG @@ -52,6 +55,12 @@ struct COGDEBUG_API FCogDebugDraw static void Skeleton(const FLogCategoryBase& LogCategory, const USkeletalMeshComponent* Skeleton, const FColor& Color, bool DrawSecondaryBones = false, const uint8 DepthPriority = 1); + static void LineTrace(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FVector& Start, const FVector& End, const bool HasHits, TArray& HitResults, const FCogDebugDrawLineTraceParams& Settings); + + static void Sweep(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Start, const FVector& End, const FQuat& Rotation, const bool HasHits, TArray& HitResults, const FCogDebugDrawSweepParams& Settings); + + static void Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray& OverlapResults, const FCogDebugDrawOverlapParams& Settings); + static void ReplicateShape(const UObject* WorldContextObject, const FCogDebugShape& Shape); }; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h index 710a66e..bac57e4 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h @@ -19,7 +19,7 @@ struct FCogDebugDrawOverlapParams bool DrawHitPrimitiveActorsName = false; bool HitPrimitiveActorsNameShadow = true; float HitPrimitiveActorsNameSize = 1.0f; - bool Persistent = false; + mutable bool Persistent = false; float LifeTime = 0.0f; uint8 DepthPriority = 0; float Thickness = 0.0f; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugShape.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugShape.h index bb2742d..de3a1aa 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugShape.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugShape.h @@ -4,6 +4,8 @@ DECLARE_LOG_CATEGORY_EXTERN(LogCogServerVLOG, Verbose, All); +struct FCollisionShape; + enum class ECogDebugShape : uint8 { Invalid, @@ -59,6 +61,7 @@ struct COGDEBUG_API FCogDebugShape static FCogDebugShape MakeCapsule(const FVector& Center, const FQuat& Rotation, const float Radius, const float HalfHeight, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority); static FCogDebugShape MakeFlatCapsule(const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority); static FCogDebugShape MakePolygon(const TArray& Verts, const FColor& Color, const bool bPersistent, const uint8 DepthPriority); + static FCogDebugShape MakeCollisionShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Extent, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority); void DrawPoint(const UWorld* World) const; void DrawSegment(const UWorld* World) const; diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp index e1461a5..7c79cfd 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp @@ -139,6 +139,16 @@ void FCogWindow::SetSelection(AActor* NewSelection) } //-------------------------------------------------------------------------------------------------------------------------- + +void FCogWindow::SetIsVisible(const bool Value) +{ + if (bIsVisible == Value) + { return; } + + bIsVisible = Value; + OnWindowVisibilityChanged(Value); +} + APawn* FCogWindow::GetLocalPlayerPawn() const { const APlayerController* LocalPlayerController = GetLocalPlayerController(); diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindow.h b/Plugins/Cog/Source/CogWindow/Public/CogWindow.h index fda5de3..885ec73 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindow.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindow.h @@ -59,7 +59,7 @@ public: bool GetIsVisible() const { return bIsVisible; } - void SetIsVisible(bool Value) { bIsVisible = Value; } + void SetIsVisible(bool Value); bool HasWidget() const { return bHasWidget; } @@ -103,6 +103,8 @@ protected: virtual bool CheckEditorVisibility(); + virtual void OnWindowVisibilityChanged(bool NewVisibility) { } + virtual void OnSelectionChanged(AActor* OldSelection, AActor* NewSelection) {} APawn* GetLocalPlayerPawn() const;