mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Give menus the option to veto closure
This commit is contained in:
parent
4f25ffed56
commit
b601b16764
@ -94,6 +94,7 @@ void UMenuBase::Open(bool bIsRegain)
|
||||
auto PC = GetOwningPlayer();
|
||||
switch (InputModeSetting)
|
||||
{
|
||||
default:
|
||||
case EInputModeChange::DoNotChange:
|
||||
break;
|
||||
case EInputModeChange::UIOnly:
|
||||
@ -109,6 +110,7 @@ void UMenuBase::Open(bool bIsRegain)
|
||||
|
||||
switch (MousePointerVisibility)
|
||||
{
|
||||
default:
|
||||
case EMousePointerVisibilityChange::DoNotChange:
|
||||
break;
|
||||
case EMousePointerVisibilityChange::Visible:
|
||||
@ -121,6 +123,7 @@ void UMenuBase::Open(bool bIsRegain)
|
||||
|
||||
switch (GamePauseSetting)
|
||||
{
|
||||
default:
|
||||
case EGamePauseChange::DoNotChange:
|
||||
break;
|
||||
case EGamePauseChange::Paused:
|
||||
@ -134,3 +137,19 @@ void UMenuBase::Open(bool bIsRegain)
|
||||
TakeFocusIfDesired();
|
||||
|
||||
}
|
||||
|
||||
bool UMenuBase::RequestClose(bool bWasCancel)
|
||||
{
|
||||
if (ValidateClose(bWasCancel))
|
||||
{
|
||||
Close(bWasCancel);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UMenuBase::ValidateClose_Implementation(bool bWasCancel)
|
||||
{
|
||||
// Default always pass
|
||||
return true;
|
||||
}
|
||||
|
@ -149,7 +149,12 @@ bool UMenuStack::HandleKeyDownEvent(const FKeyEvent& InKeyEvent)
|
||||
if (BackKeys.Contains(Key))
|
||||
{
|
||||
// This is "Back"
|
||||
PopMenu(true);
|
||||
// Request close but allow veto
|
||||
if (Menus.Num() > 0)
|
||||
{
|
||||
auto Top = Menus.Last();
|
||||
Top->RequestClose(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (InstantCloseKeys.Contains(Key))
|
||||
|
@ -59,6 +59,8 @@ protected:
|
||||
|
||||
virtual void EmbedInParent();
|
||||
|
||||
UFUNCTION(BlueprintNativeEvent)
|
||||
bool ValidateClose(bool bWasCancel);
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -70,12 +72,21 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void Open(bool bIsRegainedFocus = false);
|
||||
/**
|
||||
* @brief Close this menu.
|
||||
* @brief Request this menu to close. The menu can veto this request.
|
||||
* @param bWasCancel Set this to true if the reason for closure was a cancellation action
|
||||
* @return True if the request was approved
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable)
|
||||
bool RequestClose(bool bWasCancel);
|
||||
/**
|
||||
* @brief Close this menu. This ALWAYS closes the menu, if you want it to be able to veto it, call RequestClose
|
||||
* @param bWasCancel Set this to true if the reason for closure was a cancellation action
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void Close(bool bWasCancel);
|
||||
|
||||
|
||||
|
||||
TWeakObjectPtr<UMenuStack> GetParentStack() const { return ParentStack; }
|
||||
virtual bool IsRequestingFocus_Implementation() const override { return bRequestFocus; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user