mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Oops forgot new files
This commit is contained in:
parent
5af66f2243
commit
c964c990c0
75
Source/StevesUEHelpers/Private/StevesUI/MenuSystem.cpp
Normal file
75
Source/StevesUEHelpers/Private/StevesUI/MenuSystem.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include "StevesUI/MenuSystem.h"
|
||||
#include "StevesUI/MenuStack.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogMenuSystem)
|
||||
|
||||
TWeakObjectPtr<UMenuStack> FMenuSystem::GetHighestFocusPriority()
|
||||
{
|
||||
int Highest = -999;
|
||||
TWeakObjectPtr<UMenuStack> Ret;
|
||||
|
||||
for (auto && S : ActiveMenuStacks)
|
||||
{
|
||||
if (S.IsValid() && S->IsRequestingFocus() && S->FocusPriority > Highest)
|
||||
{
|
||||
Highest = S->FocusPriority;
|
||||
Ret = S;
|
||||
}
|
||||
}
|
||||
|
||||
return Ret;
|
||||
}
|
||||
|
||||
void FMenuSystem::MenuStackOpened(UMenuStack* Stack)
|
||||
{
|
||||
UE_LOG(LogMenuSystem, Display, TEXT("MenuStack %s opened"), *Stack->GetName());
|
||||
// check to make sure we never dupe, shouldn't normally be a problem
|
||||
// but let's just be safe, there will never be that many
|
||||
bool bPresent = false;
|
||||
for (auto && S : ActiveMenuStacks)
|
||||
{
|
||||
if (S.Get() == Stack)
|
||||
{
|
||||
bPresent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bPresent)
|
||||
ActiveMenuStacks.Add(Stack);
|
||||
|
||||
if (Stack->IsRequestingFocus())
|
||||
{
|
||||
auto Highest = GetHighestFocusPriority();
|
||||
if (!Highest.IsValid() || Highest->FocusPriority <= Stack->FocusPriority)
|
||||
{
|
||||
// give new stack the focus if it's equal or higher priority than anything else
|
||||
UE_LOG(LogMenuSystem, Display, TEXT("Giving focus to MenuStack %s"), *Stack->GetName());
|
||||
Stack->TakeFocusIfDesired();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FMenuSystem::MenuStackClosed(UMenuStack* Stack)
|
||||
{
|
||||
UE_LOG(LogMenuSystem, Display, TEXT("MenuStack %s closed"), *Stack->GetName());
|
||||
|
||||
for (int i = 0; i < ActiveMenuStacks.Num(); ++i)
|
||||
{
|
||||
if (ActiveMenuStacks[i].Get() == Stack)
|
||||
{
|
||||
ActiveMenuStacks.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if the menu closing had focus, give it to the highest remaining stack
|
||||
if (Stack->HasFocusedDescendants())
|
||||
{
|
||||
auto Highest = GetHighestFocusPriority();
|
||||
if (Highest.IsValid())
|
||||
{
|
||||
UE_LOG(LogMenuSystem, Display, TEXT("Giving focus to MenuStack %s"), *Highest->GetName());
|
||||
Highest->TakeFocusIfDesired();
|
||||
}
|
||||
}
|
||||
}
|
17
Source/StevesUEHelpers/Public/StevesUI/MenuSystem.h
Normal file
17
Source/StevesUEHelpers/Public/StevesUI/MenuSystem.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogMenuSystem, Log, All)
|
||||
|
||||
class FMenuSystem
|
||||
{
|
||||
protected:
|
||||
TArray<TWeakObjectPtr<class UMenuStack>> ActiveMenuStacks;
|
||||
|
||||
TWeakObjectPtr<UMenuStack> GetHighestFocusPriority();
|
||||
public:
|
||||
void MenuStackOpened(UMenuStack* Stack);
|
||||
void MenuStackClosed(UMenuStack* Stack);
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user