Skip to content

Commit

Permalink
reorganize subsystem categories for future improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aquanox committed Aug 5, 2022
1 parent b74eaa7 commit b98822d
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022, Aquanox.

#include "Model/Category/SubsystemBrowserCategory_Editor.h"
#include "EditorSubsystem.h"

FSubsystemCategory_Editor::FSubsystemCategory_Editor()
{
Name = TEXT("EditorSubsystemCategory");
Label = NSLOCTEXT("SubsystemBrowser", "SubsystemBrowser_Editor", "Editor Subsystems");
SortOrder = 200;
}

void FSubsystemCategory_Editor::Select(UWorld* InContext, TArray<UObject*>& OutData) const
{
if (GEditor)
{
return OutData.Append(GEditor->GetEditorSubsystemArray<UEditorSubsystem>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2022, Aquanox.

#pragma once

#include "Model/SubsystemBrowserCategory.h"

struct FSubsystemCategory_Editor : public FSubsystemCategory
{
FSubsystemCategory_Editor();
virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022, Aquanox.

#include "Model/Category/SubsystemBrowserCategory_Engine.h"
#include "Subsystems/EngineSubsystem.h"

FSubsystemCategory_Engine::FSubsystemCategory_Engine()
{
Name = TEXT("EngineSubsystemCategory");
Label = NSLOCTEXT("SubsystemBrowser", "SubsystemBrowser_Engine", "Engine Subsystems");
SortOrder = 100;
}

void FSubsystemCategory_Engine::Select(UWorld* InContext, TArray<UObject*>& OutData) const
{
if (GEngine)
{
return OutData.Append(GEngine->GetEngineSubsystemArray<UEngineSubsystem>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2022, Aquanox.

#pragma once

#include "Model/SubsystemBrowserCategory.h"

struct FSubsystemCategory_Engine : public FSubsystemCategory
{
FSubsystemCategory_Engine();

virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022, Aquanox.

#include "Model/Category/SubsystemBrowserCategory_GameInstance.h"
#include "Subsystems/GameInstanceSubsystem.h"

FSubsystemCategory_GameInstance::FSubsystemCategory_GameInstance()
{
Name = TEXT("GameInstanceCategory");
Label = NSLOCTEXT("SubsystemBrowser", "SubsystemBrowser_GameInstance", "Game Instance Subsystems");
SortOrder = 300;
}

void FSubsystemCategory_GameInstance::Select(UWorld* InContext, TArray<UObject*>& OutData) const
{
if (IsValid(InContext) && InContext->GetGameInstance())
{
OutData.Append(InContext->GetGameInstance()->GetSubsystemArray<UGameInstanceSubsystem>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2022, Aquanox.

#pragma once
#include "Model/SubsystemBrowserCategory.h"

struct FSubsystemCategory_GameInstance : public FSubsystemCategory
{
FSubsystemCategory_GameInstance();
virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022, Aquanox.

#include "Model/Category/SubsystemBrowserCategory_Player.h"
#include "Subsystems/LocalPlayerSubsystem.h"
#include "Engine/LocalPlayer.h"

FSubsystemCategory_Player::FSubsystemCategory_Player()
{
Name = TEXT("PlayerCategory");
Label = NSLOCTEXT("SubsystemBrowser", "SubsystemBrowser_Player", "Player Subsystems");
SortOrder = 500;
}

void FSubsystemCategory_Player::Select(UWorld* InContext, TArray<UObject*>& OutData) const
{
if (IsValid(InContext) && InContext->GetGameInstance())
{
for (ULocalPlayer* const LocalPlayer : InContext->GetGameInstance()->GetLocalPlayers())
{
OutData.Append(LocalPlayer->GetSubsystemArray<ULocalPlayerSubsystem>());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2022, Aquanox.

#pragma once
#include "Model/SubsystemBrowserCategory.h"

struct FSubsystemCategory_Player: public FSubsystemCategory
{
FSubsystemCategory_Player();
virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022, Aquanox.

#include "Model/Category/SubsystemBrowserCategory_World.h"
#include "Subsystems/WorldSubsystem.h"

FSubsystemCategory_World::FSubsystemCategory_World()
{
Name = TEXT("WorldSubsystemCategory");
Label = NSLOCTEXT("SubsystemBrowser", "SubsystemBrowser_World", "World Subsystems");
SortOrder = 400;
}

void FSubsystemCategory_World::Select(UWorld* InContext, TArray<UObject*>& OutData) const
{
if (IsValid(InContext))
{
OutData.Append(InContext->GetSubsystemArray<UWorldSubsystem>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2022, Aquanox.

#pragma once

#include "Model/SubsystemBrowserCategory.h"

struct FSubsystemCategory_World : public FSubsystemCategory
{
FSubsystemCategory_World();
virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const override;
};
103 changes: 2 additions & 101 deletions Source/SubsystemBrowser/Model/SubsystemBrowserCategory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,10 @@

#include "Model/SubsystemBrowserCategory.h"

#include "SubsystemBrowserModule.h"
#include "SubsystemBrowserFlags.h"
#include "Subsystems/EngineSubsystem.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "Subsystems/WorldSubsystem.h"
#include "Subsystems/LocalPlayerSubsystem.h"
#include "Engine/LocalPlayer.h"
#include "EditorSubsystem.h"

#define LOCTEXT_NAMESPACE "SubsystemBrowser"

namespace SubsystemCategoryHelpers
{
void SelectEngineSubsystems(UWorld* InContext, TArray<UObject*>& OutData);
void SelectEditorSubsystems(UWorld* InContext, TArray<UObject*>& OutData);
void SelectGameInstanceSubsystems(UWorld* InContext, TArray<UObject*>& OutData);
void SelectWorldSubsystems(UWorld* InContext, TArray<UObject*>& OutData);
void SelectPlayerSubsystems(UWorld* InContext, TArray<UObject*>& OutData);
}

void FSubsystemBrowserModule::RegisterDefaultCategories()
{
auto CategoryEngine = MakeShared<FSimpleSubsystemCategory>();
CategoryEngine->Name = TEXT("EngineSubsystemCategory");
CategoryEngine->Label = LOCTEXT("SubsystemBrowser_Engine", "Engine Subsystems");
CategoryEngine->Selector = FEnumSubsystemsDelegate::CreateStatic(&SubsystemCategoryHelpers::SelectEngineSubsystems);
CategoryEngine->SortOrder = 100;
RegisterCategory(CategoryEngine);

auto CategoryEditor = MakeShared<FSimpleSubsystemCategory>();
CategoryEditor->Name = TEXT("EditorSubsystemCategory");
CategoryEditor->Label = LOCTEXT("SubsystemBrowser_Editor", "Editor Subsystems");
CategoryEditor->Selector = FEnumSubsystemsDelegate::CreateStatic(&SubsystemCategoryHelpers::SelectEditorSubsystems);
CategoryEditor->SortOrder = 200;
RegisterCategory(CategoryEditor);

auto CategoryGameInstance = MakeShared<FSimpleSubsystemCategory>();
CategoryGameInstance->Name = TEXT("GameInstanceCategory");
CategoryGameInstance->Label = LOCTEXT("SubsystemBrowser_GameInstance", "Game Instance Subsystems");
CategoryGameInstance->Selector = FEnumSubsystemsDelegate::CreateStatic(&SubsystemCategoryHelpers::SelectGameInstanceSubsystems);
CategoryGameInstance->SortOrder = 300;
RegisterCategory(CategoryGameInstance);

auto CategoryWorld = MakeShared<FSimpleSubsystemCategory>();
CategoryWorld->Name = TEXT("WorldSubsystemCategory");
CategoryWorld->Label = LOCTEXT("SubsystemBrowser_World", "World Subsystems");
CategoryWorld->Selector = FEnumSubsystemsDelegate::CreateStatic(&SubsystemCategoryHelpers::SelectWorldSubsystems);
CategoryWorld->SortOrder = 400;
RegisterCategory(CategoryWorld);

auto CategoryPlayer = MakeShared<FSimpleSubsystemCategory>();
CategoryPlayer->Name = TEXT("PlayerCategory");
CategoryPlayer->Label = LOCTEXT("SubsystemBrowser_Player", "Player Subsystems");
CategoryPlayer->Selector = FEnumSubsystemsDelegate::CreateStatic(&SubsystemCategoryHelpers::SelectPlayerSubsystems);
CategoryPlayer->SortOrder = 500;
RegisterCategory(CategoryPlayer);
}

void SubsystemCategoryHelpers::SelectEngineSubsystems(UWorld* CurrentWorld, TArray<UObject*>& OutData)
{
if (GEngine)
{
OutData.Append(GEngine->GetEngineSubsystemArray<UEngineSubsystem>());
}
}

void SubsystemCategoryHelpers::SelectEditorSubsystems(UWorld* CurrentWorld, TArray<UObject*>& OutData)
{
if (GEditor)
{
OutData.Append(GEditor->GetEditorSubsystemArray<UEditorSubsystem>());
}
}

void SubsystemCategoryHelpers::SelectGameInstanceSubsystems(UWorld* CurrentWorld, TArray<UObject*>& OutData)
{
if (IsValid(CurrentWorld) && CurrentWorld->GetGameInstance())
{
OutData.Append(CurrentWorld->GetGameInstance()->GetSubsystemArray<UGameInstanceSubsystem>());
}
}

void SubsystemCategoryHelpers::SelectWorldSubsystems(UWorld* CurrentWorld, TArray<UObject*>& OutData)
{
if (IsValid(CurrentWorld))
{
OutData.Append(CurrentWorld->GetSubsystemArray<UWorldSubsystem>());
}
}

void SubsystemCategoryHelpers::SelectPlayerSubsystems(UWorld* CurrentWorld, TArray<UObject*>& OutData)
{
if (IsValid(CurrentWorld) && CurrentWorld->GetGameInstance())
{
for (ULocalPlayer* const LocalPlayer : CurrentWorld->GetGameInstance()->GetLocalPlayers())
{
OutData.Append(LocalPlayer->GetSubsystemArray<ULocalPlayerSubsystem>());
}
}
}

FSubsystemCategory::FSubsystemCategory(const FName& Name, const FText& Label, int32 SortOrder)
: Name(Name), Label(Label), SortOrder(SortOrder)
{
Expand All @@ -114,11 +17,9 @@ FSimpleSubsystemCategory::FSimpleSubsystemCategory(const FName& Name, const FTex
ensure(Selector.IsBound());
}

TArray<UObject*> FSimpleSubsystemCategory::Select(UWorld* InContext) const
void FSimpleSubsystemCategory::Select(UWorld* InContext, TArray<UObject*>& OutData) const
{
TArray<UObject*> OutResult;
Selector.Execute(InContext, OutResult);
return OutResult;
Selector.Execute(InContext, OutData);
}

#undef LOCTEXT_NAMESPACE
Expand Down
6 changes: 4 additions & 2 deletions Source/SubsystemBrowser/Model/SubsystemBrowserCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ struct SUBSYSTEMBROWSER_API FSubsystemCategory : public TSharedFromThis<FSubsyst
const FText& GetDisplayName() const { return Label; }
int32 GetSortOrder() const { return SortOrder; }

virtual bool IsVisibleByDefault() const { return true; }

/* Select subsystems for the respected category */
virtual TArray<UObject*> Select(UWorld* InContext) const = 0;
virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const = 0;
};

using SubsystemCategoryPtr = TSharedPtr<FSubsystemCategory>;
Expand All @@ -46,5 +48,5 @@ struct SUBSYSTEMBROWSER_API FSimpleSubsystemCategory : public FSubsystemCategory
FSimpleSubsystemCategory() = default;
FSimpleSubsystemCategory(const FName& Name, const FText& Label, const FEnumSubsystemsDelegate& Selector, int32 SortOrder);

virtual TArray<UObject*> Select(UWorld* InContext) const override;
virtual void Select(UWorld* InContext, TArray<UObject*>& OutData) const override;
};
2 changes: 1 addition & 1 deletion Source/SubsystemBrowser/Model/SubsystemBrowserColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ void RegisterCustomColumns()
Module.RegisterDynamicColumn(MakeShared<FSubsystemDynamicColumn_Tick>());
}

#endif
#endif
7 changes: 7 additions & 0 deletions Source/SubsystemBrowser/Model/SubsystemBrowserDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ FSubsystemTreeCategoryItem::FSubsystemTreeCategoryItem(TSharedRef<FSubsystemMode
Model = InModel;
}

TArray<UObject*> FSubsystemTreeCategoryItem::Select(UWorld* InContext) const
{
TArray<UObject*> Result;
Data->Select(InContext,Result);
return Result;
}

FSubsystemTreeSubsystemItem::FSubsystemTreeSubsystemItem(TSharedRef<FSubsystemModel> InModel, TSharedPtr<ISubsystemTreeItem> InParent, UObject* Instance)
{
Model = InModel;
Expand Down
2 changes: 1 addition & 1 deletion Source/SubsystemBrowser/Model/SubsystemBrowserDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct SUBSYSTEMBROWSER_API FSubsystemTreeCategoryItem final : public ISubsystem
virtual bool CanHaveChildren() const override { return true; }
virtual FSubsystemTreeCategoryItem* GetAsCategoryDescriptor() const override { return const_cast<FSubsystemTreeCategoryItem*>(this); }

TArray<UObject*> Select(UWorld* InContext) const { return Data->Select(InContext); }
TArray<UObject*> Select(UWorld* InContext) const;
};

/**
Expand Down
16 changes: 16 additions & 0 deletions Source/SubsystemBrowser/SubsystemBrowserModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include "Model/Column/SubsystemBrowserColumn_Config.h"
#include "Model/Column/SubsystemBrowserColumn_Module.h"
#include "Model/Column/SubsystemBrowserColumn_Plugin.h"
#include "Model/Category/SubsystemBrowserCategory_Editor.h"
#include "Model/Category/SubsystemBrowserCategory_Engine.h"
#include "Model/Category/SubsystemBrowserCategory_GameInstance.h"
#include "Model/Category/SubsystemBrowserCategory_Player.h"
#include "Model/Category/SubsystemBrowserCategory_World.h"
#include "UI/SubsystemBrowserPanel.h"
#include "ISettingsModule.h"
#include "ISettingsSection.h"
Expand Down Expand Up @@ -46,6 +51,7 @@ void FSubsystemBrowserModule::StartupModule()
SettingsObject
);
SettingsSection->OnSelect().BindUObject(SettingsObject, &USubsystemBrowserSettings::OnSettingsSelected);
//SettingsSection->OnResetDefaults().BindUObject(SettingsObject, &USubsystemBrowserSettings::OnSettingsReset);

FLevelEditorModule& LevelEditorModule = FModuleManager::GetModuleChecked<FLevelEditorModule>(TEXT("LevelEditor"));
LevelEditorModule.OnTabManagerChanged().AddLambda([ &LevelEditorModule ]()
Expand Down Expand Up @@ -126,6 +132,16 @@ const TArray<SubsystemCategoryPtr>& FSubsystemBrowserModule::GetCategories() con
return Categories;
}

void FSubsystemBrowserModule::RegisterDefaultCategories()
{
RegisterCategory<FSubsystemCategory_Engine>();
RegisterCategory<FSubsystemCategory_Editor>();
RegisterCategory<FSubsystemCategory_GameInstance>();
RegisterCategory<FSubsystemCategory_World>();
// RegisterCategory<FSubsystemCategory_Game>();
RegisterCategory<FSubsystemCategory_Player>();
}

const TArray<SubsystemColumnPtr>& FSubsystemBrowserModule::GetDynamicColumns() const
{
return DynamicColumns;
Expand Down
8 changes: 7 additions & 1 deletion Source/SubsystemBrowser/SubsystemBrowserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ bool USubsystemBrowserSettings::OnSettingsModified()
return true;
}

bool USubsystemBrowserSettings::OnSettingsReset()
{
UE_LOG(LogSubsystemBrowser, Log, TEXT("Browser settings being reset"));
return true;
}

// Sync category settings with categories we have in module
void USubsystemBrowserSettings::SyncCategorySettings()
{
Expand All @@ -36,7 +42,7 @@ void USubsystemBrowserSettings::SyncCategorySettings()
{
if (!CurrentSettings.Contains(Category->Name))
{
CurrentSettings.Emplace(Category->Name, true);
CurrentSettings.Emplace(Category->Name, Category->IsVisibleByDefault());
}
}

Expand Down
Loading

0 comments on commit b98822d

Please sign in to comment.