Working on CommonUI conversion. Need to stop using SetAnchorsInViewport as way to position widgets, so now implementing new thing using GridPanels.
This commit is contained in:
@@ -82,3 +82,6 @@ UIScaleCurve=(EditorCurveData=(Keys=((Time=480.000000,Value=0.444000),(Time=720.
|
||||
+CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")
|
||||
+CollisionChannelRedirects=(OldName="Clickable",NewName="LookAtDetection")
|
||||
|
||||
[/Script/Engine.Engine]
|
||||
GameViewportClientClassName=/Script/CommonUI.CommonGameViewportClient
|
||||
|
||||
|
||||
BIN
Content/Luprex/CIBD.uasset
LFS
Normal file
BIN
Content/Luprex/CIBD.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Luprex/lxGameMode.uasset
LFS
BIN
Content/Luprex/lxGameMode.uasset
LFS
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,6 +6,8 @@
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Components/GridPanel.h"
|
||||
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Luprex Utility"
|
||||
@@ -146,3 +148,64 @@ bool UlxUtilityLibrary::LineTraceThroughPixel(const APlayerController* PlayerCon
|
||||
HitResult.Init();
|
||||
return false;
|
||||
}
|
||||
|
||||
void UlxUtilityLibrary::SetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D UpperLeftXY, FVector2D LowerRightXY)
|
||||
{
|
||||
if ((GridPanel == nullptr) || (GridPanel->ColumnFill.Num() != 3) || (GridPanel->RowFill.Num() != 3))
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("SetPositionOfGridPanelMiddleCell only works on 3x3 GridPanels."));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,4 +85,51 @@ public:
|
||||
FVector2D PixelXY, double MaxDistanceFromCamera,
|
||||
ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn,
|
||||
const TArray<AActor*>& ActorsToIgnore, FHitResult& HitResult);
|
||||
|
||||
// Set Position of GridPanel Middle Cell
|
||||
//
|
||||
// Sometimes, you want to specify the position of a widget, and you
|
||||
// don't want to specify the position in slate units, instead, you
|
||||
// want to specify the position using fractions: ie, (0,0) is the
|
||||
// upper left corner of the screen, and (1,1) is the lower-right corner.
|
||||
//
|
||||
// One way to accomplish this is to put your widget in the middle cell
|
||||
// of a 3x3 GridPanel. Then, you can position it by adjusting the grid
|
||||
// fill rules. This utility routine can do the math necessary to
|
||||
// correctly populate those fill rules.
|
||||
//
|
||||
// This routine must be passed a 3x3 GridPanel. This will reposition
|
||||
// the middle cell. You must specify the upper-left and lower-right
|
||||
// corners of the middle cell as fractions between (0,0) and (1,1).
|
||||
//
|
||||
// Be aware that if the content of a grid cell overflows the amount of
|
||||
// space allocated for it, then the grid will adjust to make room.
|
||||
// But that will mean that the grid is no longer faithful to the
|
||||
// positions specified in its fill rules. One way to ensure that the
|
||||
// grid remains faithful to its fill rules is to put an Overlay
|
||||
// into the GridPanel cell, then put -1000 padding into the
|
||||
// Overlay's GridPanel slot, then put +1000 padding into the Overlay
|
||||
// slot. The two paddings cancel each other out, leaving the item in
|
||||
// the Overlay at the originally-intended position. But if the item
|
||||
// in the overlay overflows, it doesn't cause the Grid to deform.
|
||||
// Instead, the item exceeds the bounds of the grid cell, but it leaves
|
||||
// the grid cell where it belongs.
|
||||
//
|
||||
UFUNCTION(BlueprintCallable, Category="Widget")
|
||||
static void SetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D UpperLeftXY, FVector2D LowerRightXY);
|
||||
|
||||
// Get Position of GridPanel Middle Cell
|
||||
//
|
||||
// The routine must be passed a 3x3 GridPanel. This will return the
|
||||
// position of the middle cell of the gridpanel, expressed on a scale
|
||||
// from (0,0) to (1,1).
|
||||
//
|
||||
// The numbers returned by this routine are based entirely on the
|
||||
// GridPanel fill rules. If an item in the grid is overflowing its
|
||||
// allocated space, causing the grid to deform, then that won't be
|
||||
// reflected in the output of this routine.
|
||||
//
|
||||
UFUNCTION(BlueprintPure, Category="Widget")
|
||||
static void GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D &UpperLeftXY, FVector2D &LowerRightXY);
|
||||
|
||||
};
|
||||
|
||||
@@ -31,7 +31,11 @@ end
|
||||
|
||||
function engio.getlookat()
|
||||
local class = tangible.getclass(tangible.place())
|
||||
if class == nil then return end
|
||||
|
||||
-- if the tangible is not of any class, return empty string.
|
||||
if class == nil then
|
||||
return ""
|
||||
end
|
||||
|
||||
-- if the class has a function 'lookhotkeys', then the correct
|
||||
-- look-at widget is 'hotkeys'. We're going to automatically
|
||||
@@ -47,5 +51,8 @@ function engio.getlookat()
|
||||
if class.getlookat ~= nil then
|
||||
return class.getlookat()
|
||||
end
|
||||
|
||||
-- by default, return the empty string.
|
||||
return ""
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user