Files
UnrealEngineUWP/Engine/Source/Editor/CommonMenuExtensions/Private/ShowFlagMenuCommands.cpp
krzysztof narkowicz 02819f2a85 Refactored Lumen visualization views and show flag in order to improve user experience. All Lumen visualization modes and show flags were moved into Lumen submenus for easier discovery. View modes were made exclusive (only one may be active at a time). Additonally exposed new view modes and show flags in order to easier debug and understand Lumen.
Lit->Lumen
Added Lit->Lumen submenu with 4 view modes - Lumen Scene, Lumen Reflection View, Lumen Surface Cache and Overview:
* Lumen Scene - same as ShowFlags->VisualizeLumenScene. Visualizes Lumen scene representation in highest possible quality, with highest possible view distance
* Lumen Reflection View - Lumen Scene, but with current reflections settings. Basically represents how things look in the reflections
* Lumen Surface Cache - visualizes surface cache and marks with pink missing surface cache coverage
* Overview - 3 Lumen view mode tiles, overlaid on top of normal view

Show->Lumen
Added Show->Lumen submenu with 6 flags, which allow to disable specific trace types (screen space, detail, global, far field), disable secondary bounces (radiosity) and disable Screen Space Directional Occlusion.

Show->Visualize
Removed �Lumen Scene� (replaced by Lit->Lumen->Lumen Scene view mode) and �Lumen Global Illumination� (replaced by r.Lumen.Visualize.IndirectDiffuse) from

Advanced visualization modes are accessible through r.Lumen.Visualize.Mode, which overrides current Lit->Lumen-> settings.

Misc changes:
* Renamed VisualizeLumenScene* to LumenVisualize*
* Moved shared visualize parameters to LumenVisualize.h
* Lumen HWRT visualize now uses same ray footprint as SWRT visualize
* Replaced HALF_WORLD_MAX with Lumen::MaxTracingEndDistanceFromCamera and Lumen::MaxTraceDistance in preparation for the LWC WORLD_MAX changes

#rb Patrick.Kelly, Daniel.Wright
#preflight 61e73339b56c33b8ecf753b2

#ROBOMERGE-AUTHOR: krzysztof.narkowicz
#ROBOMERGE-SOURCE: CL 18658215 in //UE5/Release-5.0/... via CL 18658227 via CL 18658249
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v900-18638592)

[CL 18658268 by krzysztof narkowicz in ue5-main branch]
2022-01-19 10:11:35 -05:00

237 lines
10 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ShowFlagMenuCommands.h"
#include "EditorShowFlags.h"
#include "EditorStyleSet.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "ToolMenus.h"
#define LOCTEXT_NAMESPACE "ShowFlagMenuCommands"
namespace
{
inline FText GetLocalizedShowFlagName(const FShowFlagData& Flag)
{
FFormatNamedArguments Args;
Args.Add(TEXT("ShowFlagName"), Flag.DisplayName);
switch (Flag.Group)
{
case SFG_Visualize:
{
return FText::Format(LOCTEXT("VisualizeFlagLabel", "Visualize {ShowFlagName}"), Args);
}
default:
{
return FText::Format(LOCTEXT("ShowFlagLabel", "Show {ShowFlagName}"), Args);
}
}
}
}
FShowFlagMenuCommands::FShowFlagMenuCommands()
: TCommands<FShowFlagMenuCommands>
(
TEXT("ShowFlagsMenu"), // Context name for fast lookup
NSLOCTEXT("Contexts", "ShowFlagsMenu", "Show Flags Menu"), // Localized context name for displaying
NAME_None, // Parent context name.
FEditorStyle::GetStyleSetName() // Icon Style Set
),
ShowFlagCommands(),
bCommandsInitialised(false)
{
}
void FShowFlagMenuCommands::UpdateCustomShowFlags() const
{
if (GetShowFlagMenuItems().Num() != ShowFlagCommands.Num())
{
const_cast<FShowFlagMenuCommands*>(this)->CreateShowFlagCommands();
}
}
void FShowFlagMenuCommands::BuildShowFlagsMenu(UToolMenu* Menu, const FShowFlagFilter& Filter) const
{
check(bCommandsInitialised);
UpdateCustomShowFlags();
const FShowFlagFilter::FGroupedShowFlagIndices& FlagIndices = Filter.GetFilteredIndices();
if ( FlagIndices.TotalIndices() < 1 )
{
return;
}
CreateCommonShowFlagMenuItems(Menu, Filter);
{
FToolMenuSection& Section = Menu->AddSection("LevelViewportShowFlags", LOCTEXT("AllShowFlagHeader", "All Show Flags"));
CreateSubMenuIfRequired(Section, Filter, SFG_PostProcess, "SFG_PostProcess", LOCTEXT("PostProcessShowFlagsMenu", "Post Processing"), LOCTEXT("PostProcessShowFlagsMenu_ToolTip", "Post process show flags"), "ShowFlagsMenu.SubMenu.PostProcessing");
CreateSubMenuIfRequired(Section, Filter, SFG_LightTypes, "SFG_LightTypes", LOCTEXT("LightTypesShowFlagsMenu", "Light Types"), LOCTEXT("LightTypesShowFlagsMenu_ToolTip", "Light Types show flags"), "ShowFlagsMenu.SubMenu.LightTypes");
CreateSubMenuIfRequired(Section, Filter, SFG_LightingComponents, "SFG_LightingComponents", LOCTEXT("LightingComponentsShowFlagsMenu", "Lighting Components"), LOCTEXT("LightingComponentsShowFlagsMenu_ToolTip", "Lighting Components show flags"), "ShowFlagsMenu.SubMenu.LightingComponents");
CreateSubMenuIfRequired(Section, Filter, SFG_LightingFeatures, "SFG_LightingFeatures", LOCTEXT("LightingFeaturesShowFlagsMenu", "Lighting Features"), LOCTEXT("LightingFeaturesShowFlagsMenu_ToolTip", "Lighting Features show flags"), "ShowFlagsMenu.SubMenu.LightingFeatures");
CreateSubMenuIfRequired(Section, Filter, SFG_Lumen, "SFG_Lumen", LOCTEXT("LumenShowFlagsMenu", "Lumen"), LOCTEXT("LumenShowFlagsMenu_ToolTip", "Lumen show flags"), "ShowFlagsMenu.SubMenu.Lumen");
CreateSubMenuIfRequired(Section, Filter, SFG_Developer, "SFG_Developer", LOCTEXT("DeveloperShowFlagsMenu", "Developer"), LOCTEXT("DeveloperShowFlagsMenu_ToolTip", "Developer show flags"), "ShowFlagsMenu.SubMenu.Developer");
CreateSubMenuIfRequired(Section, Filter, SFG_Visualize, "SFG_Visualize", LOCTEXT("VisualizeShowFlagsMenu", "Visualize"), LOCTEXT("VisualizeShowFlagsMenu_ToolTip", "Visualize show flags"), "ShowFlagsMenu.SubMenu.Visualize");
CreateSubMenuIfRequired(Section, Filter, SFG_Advanced, "SFG_Advanced", LOCTEXT("AdvancedShowFlagsMenu", "Advanced"), LOCTEXT("AdvancedShowFlagsMenu_ToolTip", "Advanced show flags"), "ShowFlagsMenu.SubMenu.Advanced");
CreateSubMenuIfRequired(Section, Filter, SFG_Custom, "SFG_Custom", LOCTEXT("CustomShowFlagsMenu", "Custom"), LOCTEXT("CustomShowFlagsMenu_ToolTip", "Custom show flags"), NAME_None);
}
}
void FShowFlagMenuCommands::CreateCommonShowFlagMenuItems(UToolMenu* Menu, const FShowFlagFilter& Filter) const
{
const FShowFlagFilter::FGroupedShowFlagIndices& GroupedFlagIndices = Filter.GetFilteredIndices();
const TArray<uint32>& FlagIndices = GroupedFlagIndices[SFG_Normal];
if (FlagIndices.Num() < 1)
{
return;
}
{
FToolMenuSection& Section = Menu->AddSection("ShowFlagsMenuSectionCommon", LOCTEXT("CommonShowFlagHeader", "Common Show Flags"));
for (int32 ArrayIndex = 0; ArrayIndex < FlagIndices.Num(); ++ArrayIndex)
{
const uint32 FlagIndex = FlagIndices[ArrayIndex];
const FShowFlagCommand& ShowFlagCommand = ShowFlagCommands[FlagIndex];
ensure(Section.FindEntry(ShowFlagCommand.ShowMenuItem->GetCommandName()) == nullptr);
Section.AddMenuEntry(*FString::Printf(TEXT("Common_%s"), *ShowFlagCommand.ShowMenuItem->GetCommandName().ToString()), ShowFlagCommand.ShowMenuItem, ShowFlagCommand.LabelOverride);
}
}
}
void FShowFlagMenuCommands::CreateSubMenuIfRequired(FToolMenuSection& Section, const FShowFlagFilter& Filter, EShowFlagGroup Group, const FName SubMenuName, const FText& MenuLabel, const FText& ToolTip, const FName IconName) const
{
const FShowFlagFilter::FGroupedShowFlagIndices& GroupedFlagIndices = Filter.GetFilteredIndices();
const TArray<uint32>& FlagIndices = GroupedFlagIndices[Group];
if ( FlagIndices.Num() < 1 )
{
return;
}
Section.AddSubMenu(SubMenuName, MenuLabel, ToolTip, FNewToolMenuDelegate::CreateStatic(&FShowFlagMenuCommands::StaticCreateShowFlagsSubMenu, FlagIndices, 0), false, FSlateIcon(FAppStyle::Get().GetStyleSetName(), IconName));
}
void FShowFlagMenuCommands::CreateShowFlagsSubMenu(UToolMenu* Menu, TArray<uint32> FlagIndices, int32 EntryOffset) const
{
// Generate entries for the standard show flags.
// Assumption: the first 'n' entries types like 'Show All' and 'Hide All' buttons, so insert a separator after them.
FToolMenuSection& Section = Menu->AddSection("Section");
for (int32 ArrayIndex = 0; ArrayIndex < FlagIndices.Num(); ++ArrayIndex)
{
const uint32 FlagIndex = FlagIndices[ArrayIndex];
const FShowFlagCommand& ShowFlagCommand = ShowFlagCommands[FlagIndex];
ensure(Section.FindEntry(ShowFlagCommand.ShowMenuItem->GetCommandName()) == nullptr);
FFormatNamedArguments Args;
Args.Add(TEXT("ShowFlagDefault"), FText::AsCultureInvariant("ShowFlag." + FEngineShowFlags::FindNameByIndex(ShowFlagCommand.FlagIndex) + " 2"));
FText OverrideEnabledWarning = FEngineShowFlags::IsForceFlagSet(ShowFlagCommand.FlagIndex)
? FText::GetEmpty()
: FText::Format(LOCTEXT("ShowFlagOverrideWarning", "ShowFlag override on. Set to default in console to use Editor UI (Set: \"{ShowFlagDefault}\")."), Args);
Section.AddMenuEntry(ShowFlagCommand.ShowMenuItem->GetCommandName(), ShowFlagCommand.ShowMenuItem, ShowFlagCommand.LabelOverride, OverrideEnabledWarning);
if (ArrayIndex == EntryOffset - 1)
{
Section.AddSeparator(NAME_None);
}
}
}
void FShowFlagMenuCommands::RegisterCommands()
{
CreateShowFlagCommands();
bCommandsInitialised = true;
}
void FShowFlagMenuCommands::CreateShowFlagCommands()
{
TBitArray<> ExistingCommands;
int32 MaxIndex = 0;
for (const FShowFlagCommand& Command : ShowFlagCommands)
{
MaxIndex = FMath::Max(MaxIndex, (int32)Command.FlagIndex);
}
ExistingCommands.Init(false, MaxIndex + 1);
for (const FShowFlagCommand& Command : ShowFlagCommands)
{
ExistingCommands[Command.FlagIndex] = true;
}
const TArray<FShowFlagData>& AllShowFlags = GetShowFlagMenuItems();
for (int32 ShowFlagIndex = 0; ShowFlagIndex < AllShowFlags.Num(); ++ShowFlagIndex)
{
const FShowFlagData& ShowFlag = AllShowFlags[ShowFlagIndex];
if ((int32)ShowFlag.EngineShowFlagIndex < ExistingCommands.Num() && ExistingCommands[ShowFlag.EngineShowFlagIndex])
{
continue;
}
const FText LocalizedName = GetLocalizedShowFlagName(ShowFlag);
//@todo Slate: The show flags system does not support descriptions currently
const FText ShowFlagDesc;
TSharedPtr<FUICommandInfo> ShowFlagCommand = FUICommandInfoDecl(this->AsShared(), ShowFlag.ShowFlagName, LocalizedName, ShowFlagDesc)
.UserInterfaceType(EUserInterfaceActionType::ToggleButton)
.DefaultChord(ShowFlag.InputChord)
.Icon(GetShowFlagIcon(ShowFlag));
ShowFlagCommands.Add(FShowFlagCommand(static_cast<FEngineShowFlags::EShowFlag>(ShowFlag.EngineShowFlagIndex), ShowFlagCommand, ShowFlag.DisplayName));
}
}
void FShowFlagMenuCommands::StaticCreateShowFlagsSubMenu(UToolMenu* Menu, TArray<uint32> FlagIndices, int32 EntryOffset)
{
FShowFlagMenuCommands::Get().CreateShowFlagsSubMenu(Menu, FlagIndices, EntryOffset);
}
FSlateIcon FShowFlagMenuCommands::GetShowFlagIcon(const FShowFlagData& Flag) const
{
return Flag.Group == EShowFlagGroup::SFG_Normal
? FSlateIcon(FEditorStyle::GetStyleSetName(), FEditorStyle::Join(GetContextName(), TCHAR_TO_ANSI(*FString::Printf(TEXT(".%s"), *Flag.ShowFlagName.ToString()))))
: FSlateIcon();
}
void FShowFlagMenuCommands::BindCommands(FUICommandList& CommandList, const TSharedPtr<FEditorViewportClient>& Client) const
{
check(bCommandsInitialised);
check(Client.IsValid());
UpdateCustomShowFlags();
for (int32 ArrayIndex = 0; ArrayIndex < ShowFlagCommands.Num(); ++ArrayIndex)
{
const FShowFlagCommand& ShowFlagCommand = ShowFlagCommands[ArrayIndex];
CommandList.MapAction(ShowFlagCommand.ShowMenuItem,
FExecuteAction::CreateStatic<const TSharedPtr<FEditorViewportClient>&>(&FShowFlagMenuCommands::ToggleShowFlag, Client, ShowFlagCommand.FlagIndex),
FCanExecuteAction::CreateStatic(&FEngineShowFlags::IsForceFlagSet, static_cast<uint32>(ShowFlagCommand.FlagIndex)),
FIsActionChecked::CreateStatic<const TSharedPtr<FEditorViewportClient>&>(&FShowFlagMenuCommands::IsShowFlagEnabled, Client, ShowFlagCommand.FlagIndex));
}
}
void FShowFlagMenuCommands::ToggleShowFlag(const TSharedPtr<FEditorViewportClient>& Client, FEngineShowFlags::EShowFlag EngineShowFlagIndex)
{
check(Client.IsValid());
Client->HandleToggleShowFlag(EngineShowFlagIndex);
}
bool FShowFlagMenuCommands::IsShowFlagEnabled(const TSharedPtr<FEditorViewportClient>& Client, FEngineShowFlags::EShowFlag EngineShowFlagIndex)
{
check(Client.IsValid());
return Client->HandleIsShowFlagEnabled(EngineShowFlagIndex);
}
#undef LOCTEXT_NAMESPACE