mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 00:01:37 -07:00
CogEngine: Add Levels window to load a specific level
CogSample: fix server target not excluding cog
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
#include "CogEngineWindow_Levels.h"
|
||||
|
||||
#include "CogImguiHelper.h"
|
||||
#include "CogWindowWidgets.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::RenderHelp()
|
||||
{
|
||||
ImGui::Text("This window can be used to load levels.");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::Initialize()
|
||||
{
|
||||
Super::Initialize();
|
||||
|
||||
bHasMenu = true;
|
||||
Config = GetConfig<UCogEngineWindowConfig_LevelLoader>();
|
||||
GetAllLevels(UnsortedLevels);
|
||||
|
||||
RefreshSorting();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::GetAllLevels(TArray<FAssetData>& OutLevels)
|
||||
{
|
||||
const FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
|
||||
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
|
||||
|
||||
AssetRegistry.SearchAllAssets(true);
|
||||
|
||||
FARFilter AssetFilter;
|
||||
AssetFilter.ClassPaths.Add(UWorld::StaticClass()->GetClassPathName());
|
||||
AssetFilter.bRecursiveClasses = true;
|
||||
|
||||
AssetRegistry.GetAssets(AssetFilter, OutLevels);
|
||||
|
||||
RefreshSorting();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::RefreshSorting()
|
||||
{
|
||||
Levels = UnsortedLevels;
|
||||
|
||||
if (Config->SortByName)
|
||||
{
|
||||
if (Config->ShowPath)
|
||||
{
|
||||
Levels.Sort([](const FAssetData& InA, const FAssetData& InB) { return InA.PackagePath.Compare(InB.PackagePath) < 0; });
|
||||
}
|
||||
else
|
||||
{
|
||||
Levels.Sort([](const FAssetData& InA, const FAssetData& InB) { return InA.AssetName.Compare(InB.AssetName) < 0; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::RenderMenu()
|
||||
{
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("Options"))
|
||||
{
|
||||
if (ImGui::Checkbox("Sort by Name", &Config->SortByName))
|
||||
{
|
||||
RefreshSorting();
|
||||
}
|
||||
|
||||
if (ImGui::Checkbox("Show Path", &Config->ShowPath))
|
||||
{
|
||||
RefreshSorting();
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
FCogWindowWidgets::SearchBar("##Filter", Filter);
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::RenderContent()
|
||||
{
|
||||
Super::RenderContent();
|
||||
|
||||
RenderMenu();
|
||||
|
||||
const float FooterHeight = ImGui::GetFrameHeightWithSpacing();
|
||||
const ImVec2 Size = IsWindowRenderedInMainMenu()
|
||||
? ImVec2(0.f, ImGui::GetFontSize() * 10 - FooterHeight)
|
||||
: ImVec2(0.f, ImGui::GetContentRegionAvail().y - FooterHeight);
|
||||
|
||||
const bool Visible = ImGui::BeginChild("Levels", Size, 0, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
|
||||
if (Visible)
|
||||
{
|
||||
for (int32 i = 0; i < Levels.Num(); i++)
|
||||
{
|
||||
ImGui::PushID(i);
|
||||
|
||||
const FAssetData& Asset = Levels[i];
|
||||
RenderLevel(i, Asset);
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
const bool CanLoad = Levels.IsValidIndex(SelectedIndex);
|
||||
if (CanLoad == false)
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
if (ImGui::Button("Load", ImVec2(-1, 0)))
|
||||
{
|
||||
if (Levels.IsValidIndex(SelectedIndex))
|
||||
{
|
||||
LoadLevel(Levels[SelectedIndex]);
|
||||
}
|
||||
}
|
||||
if (CanLoad == false)
|
||||
{
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::RenderLevel(int32 InIndex, const FAssetData& InAsset)
|
||||
{
|
||||
FString Label;
|
||||
if (Config->ShowPath)
|
||||
{
|
||||
Label = InAsset.PackageName.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Label = InAsset.AssetName.ToString();
|
||||
}
|
||||
|
||||
const auto LabelStr = StringCast<ANSICHAR>(*Label);
|
||||
if (Filter.PassFilter(LabelStr.Get()) == false)
|
||||
{ return; }
|
||||
|
||||
if (ImGui::Selectable(LabelStr.Get(), SelectedIndex == InIndex, ImGuiSelectableFlags_AllowDoubleClick))
|
||||
{
|
||||
SelectedIndex = InIndex;
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
LoadLevel(InAsset);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SetItemTooltip(StringCast<ANSICHAR>(*InAsset.PackagePath.ToString()).Get());
|
||||
|
||||
RenderLevelContextMenu(InIndex, InAsset);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::LoadLevel(const FAssetData& InAsset)
|
||||
{
|
||||
APlayerController* LocalPlayerController = GetLocalPlayerController();
|
||||
if (LocalPlayerController == nullptr)
|
||||
{ return; }
|
||||
|
||||
LocalPlayerController->ConsoleCommand(FString::Printf(TEXT("Travel %s"), *InAsset.PackageName.ToString()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Levels::RenderLevelContextMenu(int Index, const FAssetData& Asset)
|
||||
{
|
||||
if (ImGui::BeginPopupContextItem())
|
||||
{
|
||||
FCogWindowWidgets::BrowseToAssetButton(Asset);
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,6 @@
|
||||
#include "CogImguiHelper.h"
|
||||
#include "CogWindowWidgets.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Spawns::Initialize()
|
||||
{
|
||||
Super::Initialize();
|
||||
|
||||
Asset = GetAsset<UCogEngineDataAsset>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Spawns::RenderHelp()
|
||||
{
|
||||
@@ -23,6 +15,14 @@ void FCogEngineWindow_Spawns::RenderHelp()
|
||||
);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Spawns::Initialize()
|
||||
{
|
||||
Super::Initialize();
|
||||
|
||||
Asset = GetAsset<UCogEngineDataAsset>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Spawns::RenderContent()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CogWindow.h"
|
||||
#include "CogEngineWindow_Levels.generated.h"
|
||||
|
||||
class UCogEngineWindowConfig_LevelLoader;
|
||||
|
||||
class COGENGINE_API FCogEngineWindow_Levels : public FCogWindow
|
||||
{
|
||||
typedef FCogWindow Super;
|
||||
|
||||
public:
|
||||
|
||||
virtual void Initialize() override;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void RenderHelp() override;
|
||||
|
||||
virtual void RenderContent() override;
|
||||
|
||||
virtual void RenderMenu();
|
||||
|
||||
virtual void RenderLevel(int32 InIndex, const FAssetData& InAsset);
|
||||
|
||||
virtual void RenderLevelContextMenu(int Index, const FAssetData& Asset);
|
||||
|
||||
virtual void GetAllLevels(TArray<FAssetData>& OutLevels);
|
||||
void RefreshSorting();
|
||||
|
||||
virtual void LoadLevel(const FAssetData& InAsset);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
TArray<FAssetData> Levels;
|
||||
|
||||
TArray<FAssetData> UnsortedLevels;
|
||||
|
||||
int32 SelectedIndex = -1;
|
||||
|
||||
TObjectPtr<UCogEngineWindowConfig_LevelLoader> Config = nullptr;
|
||||
|
||||
ImGuiTextFilter Filter;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
UCLASS(Config = Cog)
|
||||
class UCogEngineWindowConfig_LevelLoader : public UCogCommonConfig
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
virtual void Reset() override
|
||||
{
|
||||
UCogCommonConfig::Reset();
|
||||
|
||||
SortByName = true;
|
||||
ShowPath = false;
|
||||
}
|
||||
|
||||
UPROPERTY(Config)
|
||||
bool SortByName = true;
|
||||
|
||||
UPROPERTY(Config)
|
||||
bool ShowPath = false;
|
||||
};
|
||||
@@ -1236,6 +1236,24 @@ bool FCogWindowWidgets::BrowseToAssetButton(const UObject* InAsset, const ImVec2
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::BrowseToAssetButton(const FAssetData& InAssetData, const ImVec2& InSize)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
|
||||
const bool result = ImGui::Button("Browse To Asset", InSize);
|
||||
if (result)
|
||||
{
|
||||
IAssetTools::Get().SyncBrowserToAssets({ InAssetData });
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWindowWidgets::BrowseToObjectAssetButton(const UObject* InObject, const ImVec2& InSize)
|
||||
{
|
||||
|
||||
@@ -133,6 +133,8 @@ public:
|
||||
static void MenuItemShortcut(const char* Id, const FString& Text);
|
||||
|
||||
static bool BrowseToAssetButton(const UObject* InAsset, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
static bool BrowseToAssetButton(const FAssetData& InAssetData, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
static bool BrowseToObjectAssetButton(const UObject* InObject, const ImVec2& InSize = ImVec2(0, 0));
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "CogEngineWindow_DebugSettings.h"
|
||||
#include "CogEngineWindow_ImGui.h"
|
||||
#include "CogEngineWindow_Inspector.h"
|
||||
#include "CogEngineWindow_Levels.h"
|
||||
#include "CogEngineWindow_LogCategories.h"
|
||||
#include "CogEngineWindow_Metrics.h"
|
||||
#include "CogEngineWindow_NetImgui.h"
|
||||
@@ -69,6 +70,8 @@ void Cog::AddAllWindows(UCogWindowManager& CogWindowManager)
|
||||
}
|
||||
});
|
||||
|
||||
CogWindowManager.AddWindow<FCogEngineWindow_Levels>("Engine.Levels");
|
||||
|
||||
CogWindowManager.AddWindow<FCogEngineWindow_LogCategories>("Engine.Log Categories");
|
||||
|
||||
CogWindowManager.AddWindow<FCogEngineWindow_Metrics>("Engine.Metrics");
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CogSample : ModuleRules
|
||||
"Niagara",
|
||||
});
|
||||
|
||||
if (Target.Configuration != UnrealTargetConfiguration.Shipping)
|
||||
if (Target.Configuration != UnrealTargetConfiguration.Shipping && Target.Type != TargetRules.TargetType.Server)
|
||||
{
|
||||
PublicDependencyModuleNames.AddRange(new string[]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user