Lots of work on the lua read-eval-print loop

This commit is contained in:
2026-05-21 18:41:09 -04:00
parent f7983b1f02
commit 2bfa3024f1
15 changed files with 70 additions and 120 deletions

View File

@@ -10,6 +10,8 @@
#include "Kismet/GameplayStatics.h"
#include "Blueprint/UserWidget.h"
#include "Components/GridPanel.h"
#include "Components/CanvasPanelSlot.h"
#include "Components/Widget.h"
#include "InputMappingContext.h"
#include "EnhancedInputComponent.h"
#include "Animation/AnimSequenceBase.h"
@@ -156,65 +158,28 @@ bool UlxUtilityLibrary::LineTraceThroughPixel(const APlayerController* PlayerCon
return false;
}
void UlxUtilityLibrary::SetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D UpperLeftXY, FVector2D LowerRightXY)
void UlxUtilityLibrary::ConfigureCanvasPanelSlot(UObject *Target, FAnchors Anchors, FVector2D Position, FVector2D Size, FVector2D Alignment, bool SizeToContent)
{
if ((GridPanel == nullptr) || (GridPanel->ColumnFill.Num() != 3) || (GridPanel->RowFill.Num() != 3))
UCanvasPanelSlot *CanvasSlot = Cast<UCanvasPanelSlot>(Target);
if (CanvasSlot == nullptr)
{
UE_LOG(LogBlueprint, Error, TEXT("SetPositionOfGridPanelMiddleCell only works on 3x3 GridPanels."));
UWidget *Widget = Cast<UWidget>(Target);
if (Widget != nullptr)
{
CanvasSlot = Cast<UCanvasPanelSlot>(Widget->Slot);
}
}
if (CanvasSlot == nullptr)
{
UE_LOG(LogBlueprint, Error, TEXT("ConfigureCanvasPanelSlot: object is not a CanvasPanelSlot, and is not a Widget in a CanvasPanel."));
return;
}
if ((LowerRightXY.X < UpperLeftXY.X) || (LowerRightXY.Y < UpperLeftXY.Y))
{
UE_LOG(LogBlueprint, Error, TEXT("LowerRightXY must be greater than or equal to UpperLeftXY"));
return;
}
UpperLeftXY.X = FMath::Clamp(UpperLeftXY.X, 0.0f, 1.0f);
UpperLeftXY.Y = FMath::Clamp(UpperLeftXY.Y, 0.0f, 1.0f);
LowerRightXY.X = FMath::Clamp(LowerRightXY.X, 0.0f, 1.0f);
LowerRightXY.Y = FMath::Clamp(LowerRightXY.Y, 0.0f, 1.0f);
GridPanel->SetRowFill(0, UpperLeftXY.Y);
GridPanel->SetRowFill(1, LowerRightXY.Y - UpperLeftXY.Y);
GridPanel->SetRowFill(2, 1.0 - LowerRightXY.Y);
GridPanel->SetColumnFill(0, UpperLeftXY.X);
GridPanel->SetColumnFill(1, LowerRightXY.X - UpperLeftXY.X);
GridPanel->SetColumnFill(2, 1.0 - LowerRightXY.X);
}
void UlxUtilityLibrary::GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D &UpperLeftXY, FVector2D &LowerRightXY)
{
TArray<float> &Col = GridPanel->ColumnFill;
TArray<float> &Row = GridPanel->RowFill;
// Set default return value for error situations.
UpperLeftXY.X = 0.0;
LowerRightXY.X = 1.0;
UpperLeftXY.Y = 0.0;
LowerRightXY.Y = 1.0;
if ((GridPanel == nullptr) || (Row.Num() != 3) || (Col.Num() != 3))
{
UE_LOG(LogBlueprint, Error, TEXT("SetPositionOfGridPanelMiddleCell only works on 3x3 GridPanels."));
return;
}
double TotalX = Col[0] + Col[1] + Col[2];
double TotalY = Row[0] + Row[1] + Row[2];
if (TotalX > 0)
{
UpperLeftXY.X = Col[0] / TotalX;
LowerRightXY.X = (Col[0] + Col[1]) / TotalX;
}
if (TotalY > 0)
{
UpperLeftXY.Y = Row[0] / TotalY;
LowerRightXY.Y = (Row[0] + Row[1]) / TotalY;
}
CanvasSlot->SetAnchors(Anchors);
CanvasSlot->SetAlignment(Alignment);
CanvasSlot->SetPosition(Position);
CanvasSlot->SetSize(Size);
CanvasSlot->SetAutoSize(SizeToContent);
}
ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByMappingContext(const FKey &Key, const UInputMappingContext *MappingContext)