Files
UnrealEngineUWP/Engine/Source/Developer/Settings/Private/SettingsContainer.cpp
jason stasik 8322a4f3bc Add visibility controls to settings sections
#rb brooke.hubert
#preflight skip

#ROBOMERGE-AUTHOR: jason.stasik
#ROBOMERGE-SOURCE: CL 19053548 via CL 19059537 via CL 19071223 via CL 19071339 via CL 19072058
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v920-19070459)

[CL 19072234 by jason stasik in ue5-main branch]
2022-02-22 09:23:45 -05:00

135 lines
4.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SettingsContainer.h"
#include "UObject/WeakObjectPtr.h"
#include "Misc/App.h"
/* FSettingsContainer structors
*****************************************************************************/
FSettingsContainer::FSettingsContainer( const FName& InName )
: Name(InName)
{ }
/* FSettingsContainer interface
*****************************************************************************/
ISettingsSectionPtr FSettingsContainer::AddSection( const FName& CategoryName, const FName& SectionName, const FText& InDisplayName, const FText& InDescription, const TWeakObjectPtr<UObject>& SettingsObject )
{
TSharedPtr<FSettingsCategory> Category = Categories.FindRef(CategoryName);
if (!Category.IsValid())
{
DescribeCategory(CategoryName, FText::FromString(FName::NameToDisplayString(CategoryName.ToString(), false)), FText::GetEmpty());
Category = Categories.FindRef(CategoryName);
}
ISettingsSectionRef Section = Category->AddSection(SectionName, InDisplayName, InDescription, SettingsObject);
CategoryModifiedDelegate.Broadcast(CategoryName);
return Section;
}
ISettingsSectionPtr FSettingsContainer::AddSection( const FName& CategoryName, const FName& SectionName, const FText& InDisplayName, const FText& InDescription, const TSharedRef<SWidget>& CustomWidget )
{
TSharedPtr<FSettingsCategory> Category = Categories.FindRef(CategoryName);
if (!Category.IsValid())
{
DescribeCategory(CategoryName, FText::FromString(FName::NameToDisplayString(CategoryName.ToString(), false)), FText::GetEmpty());
Category = Categories.FindRef(CategoryName);
}
ISettingsSectionRef Section = Category->AddSection(SectionName, InDisplayName, InDescription, CustomWidget);
CategoryModifiedDelegate.Broadcast(CategoryName);
return Section;
}
void FSettingsContainer::RemoveSection( const FName& CategoryName, const FName& SectionName )
{
TSharedPtr<FSettingsCategory> Category = Categories.FindRef(CategoryName);
if (Category.IsValid())
{
ISettingsSectionPtr Section = Category->GetSection(SectionName, true);
if (Section.IsValid())
{
Category->RemoveSection(SectionName);
SectionRemovedDelegate.Broadcast(Section.ToSharedRef());
CategoryModifiedDelegate.Broadcast(CategoryName);
}
}
}
/* ISettingsContainer interface
*****************************************************************************/
void FSettingsContainer::Describe( const FText& InDisplayName, const FText& InDescription, const FName& InIconName )
{
Description = InDescription;
DisplayName = InDisplayName;
IconName = InIconName;
}
void FSettingsContainer::DescribeCategory( const FName& CategoryName, const FText& InDisplayName, const FText& InDescription )
{
TSharedPtr<FSettingsCategory>& Category = Categories.FindOrAdd(CategoryName);
if (!Category.IsValid())
{
Category = MakeShareable(new FSettingsCategory(CategoryName));
}
Category->Describe(InDisplayName, InDescription);
CategoryModifiedDelegate.Broadcast(CategoryName);
}
int32 FSettingsContainer::GetCategories( TArray<ISettingsCategoryPtr>& OutCategories ) const
{
OutCategories.Empty(Categories.Num());
static const FName AdvancedCategoryName("Advanced");
const FName GameSpecificCategoryName = FApp::GetProjectName();
TSharedPtr<FSettingsCategory> AdvancedCategory;
TSharedPtr<FSettingsCategory> GameSpecificCategory;
for (TMap<FName, TSharedPtr<FSettingsCategory> >::TConstIterator It(Categories); It; ++It)
{
TSharedPtr<FSettingsCategory> Category = It.Value();
if(Category->GetName() == AdvancedCategoryName)
{
// Store off the advanced category, we'll add it to the bottom of all categories
AdvancedCategory = Category;
}
else if (Category->GetName() == GameSpecificCategoryName)
{
GameSpecificCategory = Category;
}
else
{
OutCategories.Add(It.Value());
}
}
// Always show the game specific category first
if (GameSpecificCategory.IsValid())
{
OutCategories.Insert(GameSpecificCategory, 0);
}
// always show the advanced category last
if (AdvancedCategory.IsValid())
{
OutCategories.Add(AdvancedCategory);
}
return OutCategories.Num();
}