Fix spell drawing

This commit is contained in:
2025-01-04 03:14:05 -05:00
parent fbffa6ae71
commit 1f0533daf1
4 changed files with 138 additions and 76 deletions
@@ -2,61 +2,69 @@
#include "SpellOverlay.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Rendering/DrawElements.h"
int32
USpellOverlay::NativePaint(const FPaintArgs& Args,
const FGeometry& AllottedGeometry,
const FSlateRect& MyCullingRect,
FSlateWindowElementList& OutDrawElements,
int32 LayerId,
const FWidgetStyle& InWidgetStyle,
bool bParentEnabled) const
const FGeometry& AllottedGeometry,
const FSlateRect& MyCullingRect,
FSlateWindowElementList& OutDrawElements,
const int32 LayerId,
const FWidgetStyle& InWidgetStyle,
const bool bParentEnabled) const
{
// Call the parent implementation
const int32 Layer = Super::NativePaint(Args,
AllottedGeometry,
MyCullingRect,
OutDrawElements,
LayerId,
InWidgetStyle,
bParentEnabled);
Super::NativePaint(
Args,
AllottedGeometry,
MyCullingRect,
OutDrawElements,
LayerId,
InWidgetStyle,
bParentEnabled
);
if (SpellPoints.Num() < 2)
{
return Layer;
}
FPaintContext Context(
AllottedGeometry,
MyCullingRect,
OutDrawElements,
LayerId,
InWidgetStyle,
bParentEnabled
);
TArray<FVector2d> LocalDrawPoints;
for (int32 i = 0; i < SpellPoints.Num(); i++)
{
LocalDrawPoints.Add(AllottedGeometry.LocalToAbsolute(SpellPoints[i]));
}
UWidgetBlueprintLibrary::DrawLines(
Context, SpellPoints,
this->SpellLineColor,
this->bAntiAlias,
this->SpellLineThickness
);
for (int32 i = 0; i < LocalDrawPoints.Num() - 1; ++i)
{
const FVector2D& StartPoint = LocalDrawPoints[i];
const FVector2D& EndPoint = LocalDrawPoints[i + 1];
FSlateDrawElement::MakeLines(
OutDrawElements,
Layer + 1,
AllottedGeometry.ToPaintGeometry(),
{StartPoint, EndPoint},
ESlateDrawEffect::None,
SpellLineColor,
bAntiAlias,
SpellLineThickness
);
}
return Layer + 1;
return LayerId + 1;
}
void
USpellOverlay::UpdateSpellPoints(const TArray<FVector2D>& NewSpellPoints)
SIZE_T USpellOverlay::GetNumPoints() const
{
this->SpellPoints = NewSpellPoints;
// Redraw the widget
Invalidate(EInvalidateWidgetReason::Paint);
return this->SpellPoints.Num();
}
const FVector2D& USpellOverlay::GetLastPoint()
{
return this->SpellPoints.Last();
}
const FVector2D& USpellOverlay::GetLastPoint(const FVector2D& CurrPoint)
{
return this->SpellPoints.Num() > 0 ? this->SpellPoints.Last() : CurrPoint;
}
void USpellOverlay::AddPoint(const FVector2D& Point)
{
this->SpellPoints.Add(Point);
}
void USpellOverlay::Clear()
{
this->SpellPoints.Empty();
}