Support not hiding when superceded when embedding; if next item is not embedded this works to overlay

This commit is contained in:
Steve Streeting 2024-07-03 11:59:37 +01:00
parent e13e24643e
commit 46cd0c93c2
3 changed files with 11 additions and 7 deletions

View File

@ -52,12 +52,15 @@ void UMenuBase::RemovedFromStack(UMenuStack* Parent)
PreviousFocusWidget.Reset(); PreviousFocusWidget.Reset();
} }
void UMenuBase::SupercededInStack() void UMenuBase::SupercededInStack(UMenuBase* ByMenu)
{ {
SavePreviousFocus(); SavePreviousFocus();
if (bEmbedInParentContainer) if (bEmbedInParentContainer)
RemoveFromParent(); {
if (bHideWhenSuperceded)
RemoveFromParent();
}
else else
{ {
if (bHideWhenSuperceded) if (bHideWhenSuperceded)
@ -85,7 +88,7 @@ void UMenuBase::EmbedInParent()
void UMenuBase::Open(bool bIsRegain) void UMenuBase::Open(bool bIsRegain)
{ {
if (ParentStack.IsValid() && bEmbedInParentContainer) if (ParentStack.IsValid() && bEmbedInParentContainer && bHideWhenSuperceded)
EmbedInParent(); EmbedInParent();
else else
AddToViewport(); AddToViewport();

View File

@ -204,7 +204,7 @@ void UMenuStack::PushMenuByObject(UMenuBase* NewMenu)
if (Menus.Num() > 0) if (Menus.Num() > 0)
{ {
auto Top = Menus.Last(); auto Top = Menus.Last();
Top->SupercededInStack(); Top->SupercededInStack(NewMenu);
// We keep this allocated, to restore later on back // We keep this allocated, to restore later on back
} }
Menus.Add(NewMenu); Menus.Add(NewMenu);

View File

@ -39,8 +39,9 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Layout") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Layout")
bool bEmbedInParentContainer = true; bool bEmbedInParentContainer = true;
/// Whether to hide this menu when it's superceded by another in the stack. This property is only relevant /// Whether to hide this menu when it's superceded by another in the stack.
/// when bEmbedInParentContainer = false, since only one menu can be embedded at once. /// If you set this to "false" when bEmbedInParentContainer=true, then the superceding menu should have its
/// own bEmbedInParentContainer set to false in order to overlay on top of this one.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
bool bHideWhenSuperceded = true; bool bHideWhenSuperceded = true;
@ -92,7 +93,7 @@ public:
void AddedToStack(UMenuStack* Parent); void AddedToStack(UMenuStack* Parent);
void RemovedFromStack(UMenuStack* Parent); void RemovedFromStack(UMenuStack* Parent);
void SupercededInStack(); void SupercededInStack(UMenuBase* ByMenu);
void RegainedFocusInStack(); void RegainedFocusInStack();
void InputModeChanged(EInputMode OldMode, EInputMode NewMode); void InputModeChanged(EInputMode OldMode, EInputMode NewMode);
}; };