mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Fix #6: Change InputImage update delay to a tickable
Previously used a timer but timers cannot run while game is paused, and UI images should update regardless.
This commit is contained in:
parent
997eddce01
commit
600603ce92
@ -107,15 +107,50 @@ void UInputImage::UpdateImage()
|
|||||||
SetBrushFromAtlasInterface(Sprite, true);
|
SetBrushFromAtlasInterface(Sprite, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DelayedUpdateImageTimer.Invalidate();
|
bIsDirty = false;
|
||||||
|
DelayUpdate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UInputImage::MarkImageDirty()
|
void UInputImage::MarkImageDirty()
|
||||||
{
|
{
|
||||||
if (!DelayedUpdateImageTimer.IsValid())
|
bIsDirty = true;
|
||||||
{
|
DelayUpdate = 0.5f;
|
||||||
// Delayed update
|
|
||||||
GetWorld()->GetTimerManager().SetTimer(DelayedUpdateImageTimer, this, &UInputImage::UpdateImage, 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tickables
|
||||||
|
// We need a tick rather than FTimer because timers won't run when game is paused, and UIs are useful while paused!
|
||||||
|
ETickableTickType UInputImage::GetTickableTickType() const
|
||||||
|
{
|
||||||
|
return ETickableTickType::Conditional;
|
||||||
|
}
|
||||||
|
bool UInputImage::IsTickableWhenPaused() const
|
||||||
|
{
|
||||||
|
// UIs need to update while game is paused
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool UInputImage::IsTickableInEditor() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UInputImage::IsTickable() const
|
||||||
|
{
|
||||||
|
// Only need to tick while dirty
|
||||||
|
return bIsDirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UInputImage::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
DelayUpdate -= DeltaTime;
|
||||||
|
if (DelayUpdate <= 0)
|
||||||
|
{
|
||||||
|
UpdateImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TStatId UInputImage::GetStatId() const
|
||||||
|
{
|
||||||
|
RETURN_QUICK_DECLARE_CYCLE_STAT( UInputImage, STATGROUP_Tickables );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tickables
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
/// A special widget containing an image which populates itself based on an input action / axis and can dynamically
|
/// A special widget containing an image which populates itself based on an input action / axis and can dynamically
|
||||||
/// change based on the active input method.
|
/// change based on the active input method.
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class STEVESUEHELPERS_API UInputImage : public UImage
|
class STEVESUEHELPERS_API UInputImage : public UImage, public FTickableGameObject
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
@ -39,9 +39,13 @@ protected:
|
|||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
UUiTheme* CustomTheme;
|
UUiTheme* CustomTheme;
|
||||||
|
|
||||||
bool bSubbedToInputEvents = false;
|
UPROPERTY(EditAnywhere)
|
||||||
|
bool bUpdateWhilePaused = true;
|
||||||
|
|
||||||
|
bool bSubbedToInputEvents = false;
|
||||||
|
bool bIsDirty = true;
|
||||||
|
float DelayUpdate = 0;
|
||||||
|
|
||||||
FTimerHandle DelayedUpdateImageTimer;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Tell this image to display the bound action for the current input method
|
/// Tell this image to display the bound action for the current input method
|
||||||
@ -76,6 +80,16 @@ public:
|
|||||||
virtual void BeginDestroy() override;
|
virtual void BeginDestroy() override;
|
||||||
|
|
||||||
virtual void SetVisibility(ESlateVisibility InVisibility) override;
|
virtual void SetVisibility(ESlateVisibility InVisibility) override;
|
||||||
|
|
||||||
|
// FTickableGameObject begin
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
virtual TStatId GetStatId() const override;
|
||||||
|
virtual bool IsTickableWhenPaused() const override;
|
||||||
|
virtual bool IsTickableInEditor() const override;
|
||||||
|
virtual bool IsTickable() const override;
|
||||||
|
virtual ETickableTickType GetTickableTickType() const override;
|
||||||
|
// FTickableGameObject end
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user