Compare commits

...

2 Commits

Author SHA1 Message Date
Steve Streeting
956d6b764c Add AddViewOriginToStreaming to blueprint library 2024-07-24 15:57:47 +01:00
Steve Streeting
b9ab8feb16 Add useful functions for detecting whether a menu is the top of stack 2024-07-24 15:17:28 +01:00
6 changed files with 100 additions and 1 deletions

View File

@ -20,3 +20,20 @@ FStevesBalancedRandomStream UStevesBPL::MakeBalancedRandomStream(int64 Seed)
{
return FStevesBalancedRandomStream(Seed);
}
void UStevesBPL::AddViewOriginToStreaming(const FVector& ViewOrigin,
float ScreenWidth,
float FOV,
float BoostFactor,
bool bOverrideLocation,
float Duration,
AActor* ActorToBoost)
{
IStreamingManager::Get().AddViewInformation(ViewOrigin,
ScreenWidth,
ScreenWidth / FMath::Tan(FMath::DegreesToRadians(FOV * 0.5f)),
BoostFactor,
bOverrideLocation,
Duration,
ActorToBoost);
}

View File

@ -27,6 +27,7 @@ void UMenuBase::AddedToStack(UMenuStack* Parent)
ParentStack = MakeWeakObjectPtr(Parent);
Open(false);
OnAddedToStack(Parent);
}
@ -45,11 +46,22 @@ void UMenuBase::InputModeChanged(EInputMode OldMode, EInputMode NewMode)
}
}
bool UMenuBase::IsTopOfStack() const
{
if (ParentStack.IsValid())
{
return ParentStack->GetTopMenu() == this;
}
return true;
}
void UMenuBase::RemovedFromStack(UMenuStack* Parent)
{
// This works whether embedded or not
RemoveFromParent();
PreviousFocusWidget.Reset();
OnRemovedFromStack(Parent);
}
void UMenuBase::SupercededInStack(UMenuBase* ByMenu)
@ -66,12 +78,13 @@ void UMenuBase::SupercededInStack(UMenuBase* ByMenu)
if (bHideWhenSuperceded)
SetVisibility(ESlateVisibility::Collapsed);
}
OnSupercededInStack(ByMenu);
}
void UMenuBase::RegainedFocusInStack()
{
Open(true);
OnRegainedFocusInStack();
}
void UMenuBase::EmbedInParent()
@ -156,3 +169,19 @@ bool UMenuBase::ValidateClose_Implementation(bool bWasCancel)
// Default always pass
return true;
}
void UMenuBase::OnSupercededInStack_Implementation(UMenuBase* ByMenu)
{
}
void UMenuBase::OnRegainedFocusInStack_Implementation()
{
}
void UMenuBase::OnAddedToStack_Implementation(UMenuStack* Parent)
{
}
void UMenuBase::OnRemovedFromStack_Implementation(UMenuStack* Parent)
{
}

View File

@ -269,6 +269,15 @@ void UMenuStack::RemoveFromParent()
}
UMenuBase* UMenuStack::GetTopMenu() const
{
if (Menus.Num() > 0)
{
return Menus.Top();
}
return nullptr;
}
UMenuStack::UMenuStack()
{
// Default to enabling automatic focus for menus (can still be overridden in serialized properties)

View File

@ -75,4 +75,27 @@ public:
UFUNCTION(BlueprintCallable, Category="StevesUEHelpers|Random")
static FVector BalancedRandomPointInBox(const FStevesBalancedRandomStream& Stream, const FVector& Min, const FVector& Max) { return Stream.RandPointInBox(FBox(Min, Max)); }
/**
* Let the content streaming system know that there is a viewpoint other than a possessed camera that should be taken
* into account when deciding what to stream in. This can be useful when you're using a scene capture component,
* which if it's capturing a scene that isn't close to a player, can result in blurry textures.
* @param ViewOrigin The world space view point
* @param ScreenWidth The width in pixels of the screen being rendered
* @param FOV Horizontal field of view, in degrees
* @param BoostFactor How much to boost the LOD by (1 being normal, higher being higher detail)
* @param bOverrideLocation Whether this is an override location, which forces the streaming system to ignore all other regular locations
* @param Duration How long the streaming system should keep checking this location (in seconds). 0 means just for the next Tick.
* @param ActorToBoost Optional pointer to an actor who's textures should have their streaming priority boosted
*/
UFUNCTION(BlueprintCallable, Category="StevesUEHelpers|Streaming")
static void AddViewOriginToStreaming(const FVector& ViewOrigin,
float ScreenWidth,
float FOV,
float BoostFactor = 1.0f,
bool bOverrideLocation = false,
float Duration = 0.0f,
AActor* ActorToBoost = nullptr);
};

View File

@ -62,6 +62,19 @@ protected:
UFUNCTION(BlueprintNativeEvent)
bool ValidateClose(bool bWasCancel);
/// Called when this menu is superceded by another menu being pushed on to this stack
UFUNCTION(BlueprintNativeEvent)
void OnSupercededInStack(UMenuBase* ByMenu);
/// Called when this menu is superceded by another menu being pushed on to this stack
UFUNCTION(BlueprintNativeEvent)
void OnRegainedFocusInStack();
UFUNCTION(BlueprintNativeEvent)
void OnAddedToStack(UMenuStack* Parent);
UFUNCTION(BlueprintNativeEvent)
void OnRemovedFromStack(UMenuStack* Parent);
public:
/**
@ -96,4 +109,9 @@ public:
void SupercededInStack(UMenuBase* ByMenu);
void RegainedFocusInStack();
void InputModeChanged(EInputMode OldMode, EInputMode NewMode);
/// Return whether this menu is currently at the top of the menu stack
/// Note: if this menu is not owned by a stack, will always return true
UFUNCTION(BlueprintCallable)
bool IsTopOfStack() const;
};

View File

@ -139,6 +139,9 @@ public:
virtual void PopMenuIfTop(UMenuBase* UiMenuBase, bool bWasCancel);
virtual void RemoveFromParent() override;
/// Return the menu which is currently top of the stack
UFUNCTION(BlueprintCallable)
UMenuBase* GetTopMenu() const;
UMenuStack();