Rewrite absurd implementation of lxCrosshairWidget to use FAnchors instead
This commit is contained in:
Binary file not shown.
BIN
Content/Luprex/lxGameMode.uasset
LFS
BIN
Content/Luprex/lxGameMode.uasset
LFS
Binary file not shown.
Binary file not shown.
@@ -24,6 +24,7 @@ public class Integration : ModuleRules
|
|||||||
"Kismet",
|
"Kismet",
|
||||||
"KismetWidgets",
|
"KismetWidgets",
|
||||||
"BlueprintGraph",
|
"BlueprintGraph",
|
||||||
|
"UMG",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Uncomment if you are using Slate UI
|
// Uncomment if you are using Slate UI
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "ConsoleOutput.h"
|
#include "ConsoleOutput.h"
|
||||||
#include "Tangible.h"
|
#include "Tangible.h"
|
||||||
#include "TangibleManager.h"
|
#include "TangibleManager.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
|
||||||
#include "CommonTypes.h"
|
#include "CommonTypes.h"
|
||||||
#include "AnimQueue.h"
|
#include "AnimQueue.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -337,11 +339,37 @@ ALuprexGameModeBase *ALuprexGameModeBase::FromContext(const UObject *context) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ALuprexGameModeBase::IsLookAtChanged(UObject *context) {
|
bool ALuprexGameModeBase::IsLookAtChanged(const UObject *context) {
|
||||||
ALuprexGameModeBase *mode = FromContext(context);
|
ALuprexGameModeBase *mode = FromContext(context);
|
||||||
return mode->CurrentLookAt.HitObjectHandle != mode->PreviousLookAt.HitObjectHandle;
|
return mode->CurrentLookAt.HitObjectHandle != mode->PreviousLookAt.HitObjectHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ALuprexGameModeBase::ClearLookAtWidget(const UObject *Context)
|
||||||
|
{
|
||||||
|
ALuprexGameModeBase *mode = FromContext(Context);
|
||||||
|
if (mode->LookAtWidget != nullptr)
|
||||||
|
{
|
||||||
|
mode->LookAtWidget->RemoveFromParent();
|
||||||
|
mode->LookAtWidget = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ALuprexGameModeBase::SetLookAtWidget(const UObject *Context, UUserWidget *Widget, int ZOrder)
|
||||||
|
{
|
||||||
|
ALuprexGameModeBase *Mode = FromContext(Context);
|
||||||
|
if (Mode->LookAtWidget != Widget)
|
||||||
|
{
|
||||||
|
ClearLookAtWidget(Context);
|
||||||
|
}
|
||||||
|
if (Widget != nullptr)
|
||||||
|
{
|
||||||
|
Widget->RemoveFromParent();
|
||||||
|
Widget->AddToViewport(ZOrder);
|
||||||
|
}
|
||||||
|
Mode->LookAtWidget = Widget;
|
||||||
|
}
|
||||||
|
|
||||||
void ALuprexGameModeBase::UpdateLookAt() {
|
void ALuprexGameModeBase::UpdateLookAt() {
|
||||||
// Rotate the variables.
|
// Rotate the variables.
|
||||||
PreviousLookAt = CurrentLookAt;
|
PreviousLookAt = CurrentLookAt;
|
||||||
@@ -361,6 +389,7 @@ void ALuprexGameModeBase::UpdateLookAt() {
|
|||||||
CalculateLookAt(pc);
|
CalculateLookAt(pc);
|
||||||
|
|
||||||
if (IsLookAtChanged(this)) {
|
if (IsLookAtChanged(this)) {
|
||||||
|
ClearLookAtWidget(this);
|
||||||
LookAtChanged();
|
LookAtChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,30 +55,44 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Miscellaneous")
|
UFUNCTION(BlueprintCallable, Category = "Luprex|Miscellaneous")
|
||||||
int64 GetPlayerId();
|
int64 GetPlayerId();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"),Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection")
|
||||||
static void SetLookAt(UObject *context, const FHitResult &hit) { FromContext(context)->CurrentLookAt = hit; }
|
static void SetLookAt(const UObject *Context, const FHitResult &hit) { FromContext(Context)->CurrentLookAt = hit; }
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "context"),Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection")
|
||||||
static const FHitResult &GetLookAt(UObject *context) { return FromContext(context)->CurrentLookAt; }
|
static const FHitResult &GetLookAt(const UObject *Context) { return FromContext(Context)->CurrentLookAt; }
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "context"),Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection")
|
||||||
static const AActor *GetLookAtActor(UObject *context) { return FromContext(context)->CurrentLookAt.GetActor(); }
|
static const AActor *GetLookAtActor(const UObject *Context) { return FromContext(Context)->CurrentLookAt.GetActor(); }
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "context"),Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection")
|
||||||
static const FHitResult &GetPreviousLookAt(UObject *context) { return FromContext(context)->PreviousLookAt; }
|
static const FHitResult &GetPreviousLookAt(const UObject *Context) { return FromContext(Context)->PreviousLookAt; }
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "context"),Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection")
|
||||||
static const AActor *GetPreviousLookAtActor(UObject *context) { return FromContext(context)->PreviousLookAt.GetActor(); }
|
static const AActor *GetPreviousLookAtActor(const UObject *Context) { return FromContext(Context)->PreviousLookAt.GetActor(); }
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "context"),Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection")
|
||||||
static bool IsLookAtChanged(UObject *context);
|
static bool IsLookAtChanged(const UObject *Context);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection")
|
||||||
|
static void SetLookAtWidget(const UObject *Context, UUserWidget *Widget, int ZOrder = 100);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection")
|
||||||
|
static UUserWidget *GetLookAtWidget(const UObject *Context) { return FromContext(Context)->LookAtWidget; }
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection")
|
||||||
|
static void ClearLookAtWidget(const UObject *Context);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Look-At Related Events
|
||||||
|
//
|
||||||
|
|
||||||
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
|
||||||
void CalculateLookAt(APlayerController *PlayerController);
|
void CalculateLookAt(APlayerController *PlayerController);
|
||||||
|
|
||||||
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
|
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
|
||||||
void LookAtChanged();
|
void LookAtChanged();
|
||||||
|
|
||||||
|
|
||||||
// Assemble a lua call. To call into lua:
|
// Assemble a lua call. To call into lua:
|
||||||
//
|
//
|
||||||
// * Use LuaCallBegin
|
// * Use LuaCallBegin
|
||||||
@@ -127,8 +141,8 @@ public:
|
|||||||
// to update luprex sockets and update luprex itself.
|
// to update luprex sockets and update luprex itself.
|
||||||
virtual uint32 Run() override;
|
virtual uint32 Run() override;
|
||||||
|
|
||||||
// Get the current Luprex Game Mode Base, given a context object.
|
// Get the current Luprex Game Mode Base, given a Context object.
|
||||||
static ALuprexGameModeBase *FromContext(const UObject *context);
|
static ALuprexGameModeBase *FromContext(const UObject *Context);
|
||||||
|
|
||||||
// Asset Lookup by Name.
|
// Asset Lookup by Name.
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
@@ -145,6 +159,9 @@ public:
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
FHitResult CurrentLookAt;
|
FHitResult CurrentLookAt;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UUserWidget *LookAtWidget;
|
||||||
|
|
||||||
// The sensitivity level at which a log message triggers a debugger breakpoint.
|
// The sensitivity level at which a log message triggers a debugger breakpoint.
|
||||||
UPROPERTY(EditAnywhere, Category="Debugging Tools")
|
UPROPERTY(EditAnywhere, Category="Debugging Tools")
|
||||||
ElxLogVerbosity BreakToDebuggerLogVerbosity;
|
ElxLogVerbosity BreakToDebuggerLogVerbosity;
|
||||||
|
|||||||
@@ -77,6 +77,34 @@ UEnhancedInputLocalPlayerSubsystem *UlxUtilityLibrary::GetEnhancedInputLocalPlay
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FVector2D UlxUtilityLibrary::PixelToViewportPosition(FVector2D Pixel)
|
||||||
|
{
|
||||||
|
FVector2D ViewportSize;
|
||||||
|
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||||
|
return Pixel / ViewportSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
FVector2D UlxUtilityLibrary::ViewportPositionToPixel(FVector2D Fraction, bool Snap)
|
||||||
|
{
|
||||||
|
FVector2D ViewportSize;
|
||||||
|
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||||
|
FVector2D Pixel = Fraction * ViewportSize;
|
||||||
|
if (Snap)
|
||||||
|
{
|
||||||
|
Pixel.X = FMath::FloorToDouble(Pixel.X) + 0.5;
|
||||||
|
Pixel.Y = FMath::FloorToDouble(Pixel.Y) + 0.5;
|
||||||
|
Pixel.X = FMath::Min(ViewportSize.X - 0.5, FMath::Max(0.5, Pixel.X));
|
||||||
|
Pixel.Y = FMath::Min(ViewportSize.Y - 0.5, FMath::Max(0.5, Pixel.Y));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Pixel.X = FMath::Min(ViewportSize.X, FMath::Max(0.0, Pixel.X));
|
||||||
|
Pixel.Y = FMath::Min(ViewportSize.Y, FMath::Max(0.0, Pixel.Y));
|
||||||
|
}
|
||||||
|
return Pixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool UlxUtilityLibrary::LineTraceThroughPixel(const APlayerController* PlayerController,
|
bool UlxUtilityLibrary::LineTraceThroughPixel(const APlayerController* PlayerController,
|
||||||
FVector2D PixelXY, double MaxDistanceFromCamera,
|
FVector2D PixelXY, double MaxDistanceFromCamera,
|
||||||
ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn,
|
ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn,
|
||||||
|
|||||||
@@ -47,17 +47,35 @@ public:
|
|||||||
// Get the enhanced input local player subsystem from a controller. If the controller
|
// Get the enhanced input local player subsystem from a controller. If the controller
|
||||||
// is not a player controller, or if it is a player controller but it doesn't have an
|
// is not a player controller, or if it is a player controller but it doesn't have an
|
||||||
// enhanced input subsystem, return nullptr.
|
// enhanced input subsystem, return nullptr.
|
||||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Player Controller|Local Player Subsystems")
|
UFUNCTION(BlueprintPure, Category="Player Controller|Local Player Subsystems")
|
||||||
static UEnhancedInputLocalPlayerSubsystem *GetEnhancedInputLocalPlayerSubsystem(AController *Controller);
|
static UEnhancedInputLocalPlayerSubsystem *GetEnhancedInputLocalPlayerSubsystem(AController *Controller);
|
||||||
|
|
||||||
|
// Given a Pixel XY coordinate, convert it to a viewport position.
|
||||||
|
//
|
||||||
|
// The input should be in the range (0.0, 0.0) to (ViewportX, ViewportY).
|
||||||
|
// The output XY will be in the range 0.0 to 1.0. The input
|
||||||
|
// may specify a fraction of a pixel. So the input (0.0, 0.0)
|
||||||
|
// represents the upper-left corner of the upper-left pixel, whereas the
|
||||||
|
// input (0.5, 0.5) represents the center of the upper-left pixel.
|
||||||
|
UFUNCTION(BlueprintPure, meta = (ReturnDisplayName = "Percent XY"), Category="Luprex|Utility")
|
||||||
|
static FVector2D PixelToViewportPosition(FVector2D PixelXY);
|
||||||
|
|
||||||
|
// Given a viewport position, convert it to a Pixel XY coordinate.
|
||||||
|
//
|
||||||
|
// The input X and Y coordinates should be in the range 0 to 1. The output
|
||||||
|
// will be in the range (0,0) to (ViewportX, ViewportY). The output may
|
||||||
|
// specify a fraction of a pixel. If SnapToCenter is true, the output is
|
||||||
|
// rounded to the center of the nearest pixel.
|
||||||
|
UFUNCTION(BlueprintPure, meta = (ReturnDisplayName = "Pixel XY"), Category="Luprex|Utility")
|
||||||
|
static FVector2D ViewportPositionToPixel(FVector2D PercentXY, bool SnapToCenter);
|
||||||
|
|
||||||
// Do a Line Trace from the camera through a specified pixel.
|
// Do a Line Trace from the camera through a specified pixel.
|
||||||
//
|
//
|
||||||
// This can be used when you have a crosshair on the screen and you want to
|
// This can be used when you have a crosshair on the screen and you want to
|
||||||
// determine the object that the crosshairs are pointing at. It can also
|
// determine the object that the crosshairs are pointing at. It can also
|
||||||
// be used to do a line trace through the mouse.
|
// be used to do a line trace through the mouse. Fractional pixels are allowed.
|
||||||
//
|
// Be aware that (0.0, 0.0) is the upper-left corner of the upper-left pixel,
|
||||||
// Fractional pixels are allowed. Therefore, (0.0, 0.0) is the upper-left corner
|
// whereas (0.5, 0.5) is the center of the upper-left pixel.
|
||||||
// of the upper-left pixel, whereas (0.5, 0.5) is the center of the upper-left pixel.
|
|
||||||
//
|
//
|
||||||
UFUNCTION(BlueprintCallable, Category="Collision", meta=(AutoCreateRefTerm="ActorsToIgnore", Keywords="raycast"))
|
UFUNCTION(BlueprintCallable, Category="Collision", meta=(AutoCreateRefTerm="ActorsToIgnore", Keywords="raycast"))
|
||||||
static bool LineTraceThroughPixel(const APlayerController* PlayerController,
|
static bool LineTraceThroughPixel(const APlayerController* PlayerController,
|
||||||
|
|||||||
Reference in New Issue
Block a user