mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Add a minimum time before "Close All" button is accepted on a menu
This is to avoid insta-close on some controllers when the same button is mapped to open menu and close
This commit is contained in:
parent
fc958d2ca0
commit
2d50eadfdf
@ -6,7 +6,6 @@
|
|||||||
#include "StevesUI/MenuBase.h"
|
#include "StevesUI/MenuBase.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
|
||||||
void UMenuStack::NativeConstruct()
|
void UMenuStack::NativeConstruct()
|
||||||
{
|
{
|
||||||
Super::NativeConstruct();
|
Super::NativeConstruct();
|
||||||
@ -156,8 +155,15 @@ bool UMenuStack::HandleKeyDownEvent(const FKeyEvent& InKeyEvent)
|
|||||||
else if (InstantCloseKeys.Contains(Key))
|
else if (InstantCloseKeys.Contains(Key))
|
||||||
{
|
{
|
||||||
// Shortcut to exit all menus
|
// Shortcut to exit all menus
|
||||||
CloseAll(true);
|
// Make sure we're open long enough
|
||||||
return true;
|
FDateTime CurrTime = FDateTime::Now();
|
||||||
|
FTimespan Diff = CurrTime - TimeFirstOpen;
|
||||||
|
if (Diff.GetTicks() > (int64)(MinTimeOpen * ETimespan::TicksPerSecond))
|
||||||
|
{
|
||||||
|
CloseAll(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -236,7 +242,8 @@ void UMenuStack::PopMenuIfTop(UMenuBase* UiMenuBase, bool bWasCancel)
|
|||||||
|
|
||||||
void UMenuStack::FirstMenuOpened()
|
void UMenuStack::FirstMenuOpened()
|
||||||
{
|
{
|
||||||
// Nothing to do now but keep for future use
|
// Don't use world time (even real time) since map can change while open
|
||||||
|
TimeFirstOpen = FDateTime::Now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UMenuStack::RemoveFromParent()
|
void UMenuStack::RemoveFromParent()
|
||||||
|
@ -52,6 +52,8 @@ protected:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void InputModeChanged(int PlayerIndex, EInputMode NewMode);
|
void InputModeChanged(int PlayerIndex, EInputMode NewMode);
|
||||||
|
|
||||||
|
FDateTime TimeFirstOpen;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Input keys which go back a level in the menu stack (default Esc and B gamepad button)
|
/// Input keys which go back a level in the menu stack (default Esc and B gamepad button)
|
||||||
/// Clear this list if you don't want this behaviour
|
/// Clear this list if you don't want this behaviour
|
||||||
@ -98,6 +100,10 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
EGamePauseChange GamePauseSettingOnClose = EGamePauseChange::DoNotChange;
|
EGamePauseChange GamePauseSettingOnClose = EGamePauseChange::DoNotChange;
|
||||||
|
|
||||||
|
/// Minimum amount of time a menu should be open before responding to instant close key (prevent fast close because of leaked input)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Behaviour")
|
||||||
|
float MinTimeOpen = 0.5f;
|
||||||
|
|
||||||
/// Push a new menu level by class. This will instantiate the new menu, display it, and inform the previous menu that it's
|
/// Push a new menu level by class. This will instantiate the new menu, display it, and inform the previous menu that it's
|
||||||
/// been superceded. Use the returned instance if you want to cache it
|
/// been superceded. Use the returned instance if you want to cache it
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
@ -131,4 +137,6 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
UMenuStack();
|
UMenuStack();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user