Add SpellOverlay class

This commit is contained in:
2024-12-19 21:44:09 -05:00
parent 686c7d6c6c
commit 75fbfb97ba
8 changed files with 221 additions and 23 deletions
@@ -0,0 +1,62 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SpellOverlay.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
{
// Call the parent implementation
const int32 Layer = Super::NativePaint(Args,
AllottedGeometry,
MyCullingRect,
OutDrawElements,
LayerId,
InWidgetStyle,
bParentEnabled);
if (SpellPoints.Num() < 2)
{
return Layer;
}
TArray<FVector2d> LocalDrawPoints;
for (int32 i = 0; i < SpellPoints.Num(); i++)
{
LocalDrawPoints.Add(AllottedGeometry.LocalToAbsolute(SpellPoints[i]));
}
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;
}
void
USpellOverlay::UpdateSpellPoints(const TArray<FVector2D>& NewSpellPoints)
{
this->SpellPoints = NewSpellPoints;
// Redraw the widget
Invalidate(EInvalidateWidgetReason::Paint);
}