mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 00:01:37 -07:00
Fix saving of cog window visible state
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include "CogWidgets.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "GameFramework/PlayerInput.h"
|
||||
#include "HAL/IConsoleManager.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "Misc/CoreMisc.h"
|
||||
#include "NetImgui_Api.h"
|
||||
@@ -43,6 +42,12 @@ TStatId UCogSubsystem::GetStatId() const
|
||||
RETURN_QUICK_DECLARE_CYCLE_STAT(UCogSubsystemBase, STATGROUP_Tickables);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogSubsystem::PostInitialize()
|
||||
{
|
||||
Super::PostInitialize();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogSubsystem::Deinitialize()
|
||||
{
|
||||
@@ -54,7 +59,7 @@ void UCogSubsystem::Deinitialize()
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogSubsystem::TryInitialize(UWorld& World)
|
||||
{
|
||||
if (IsInitialized)
|
||||
if (bIsInitialized)
|
||||
{ return; }
|
||||
|
||||
FWorldContext* WorldContext = GEngine->GetWorldContextFromWorld(&World);
|
||||
@@ -64,6 +69,8 @@ void UCogSubsystem::TryInitialize(UWorld& World)
|
||||
if (WorldContext->GameViewport == nullptr && IsRunningDedicatedServer() == false)
|
||||
{ return; }
|
||||
|
||||
UE_LOG(LogCogImGui, Verbose, TEXT("UCogSubsystem::TryInitialize | World:%s %p"), *World.GetName(), &World);
|
||||
|
||||
Context.Initialize(WorldContext->GameViewport.Get());
|
||||
|
||||
FCogImGuiContextScope ImGuiContextScope(Context);
|
||||
@@ -161,7 +168,7 @@ void UCogSubsystem::TryInitialize(UWorld& World)
|
||||
}));
|
||||
|
||||
|
||||
IsInitialized = true;
|
||||
bIsInitialized = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -169,11 +176,10 @@ void UCogSubsystem::Shutdown()
|
||||
{
|
||||
FCogImGuiContextScope ImGuiContextScope(Context);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Destroy ImGui before destroying the windows to make sure
|
||||
// imgui serialize their visibility state in imgui.ini
|
||||
// It also save the Cog Settings, so they are saved regularly.
|
||||
//------------------------------------------------------------------
|
||||
if (bIsInitialized)
|
||||
{
|
||||
Context.SaveSettings();
|
||||
}
|
||||
|
||||
for (FCogWindow* Window : Windows)
|
||||
{
|
||||
@@ -182,7 +188,7 @@ void UCogSubsystem::Shutdown()
|
||||
}
|
||||
Windows.Empty();
|
||||
|
||||
if (IsInitialized)
|
||||
if (bIsInitialized)
|
||||
{
|
||||
Context.Shutdown();
|
||||
}
|
||||
@@ -233,8 +239,8 @@ void UCogSubsystem::Tick(float InDeltaTime)
|
||||
|
||||
if (World == nullptr)
|
||||
{ return; }
|
||||
|
||||
if (IsInitialized == false)
|
||||
|
||||
if (bIsInitialized == false)
|
||||
{
|
||||
TryInitialize(*World);
|
||||
return;
|
||||
@@ -538,7 +544,7 @@ UCogSubsystem::FMenu* UCogSubsystem::AddMenu(const FString& Name)
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogSubsystem::RenderMainMenu()
|
||||
{
|
||||
IsRenderingInMainMenu = true;
|
||||
bIsRenderingInMainMenu = true;
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
// Prevent having a small gap on the right of the main menu, where some widgets are displayed
|
||||
@@ -588,7 +594,7 @@ void UCogSubsystem::RenderMainMenu()
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
IsRenderingInMainMenu = false;
|
||||
bIsRenderingInMainMenu = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -32,10 +32,14 @@ public:
|
||||
|
||||
virtual TStatId GetStatId() const override;
|
||||
|
||||
virtual void PostInitialize() override;
|
||||
|
||||
virtual void Deinitialize() override;
|
||||
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
virtual void Activate();
|
||||
|
||||
virtual void AddWindow(FCogWindow* Window, const FString& Name);
|
||||
|
||||
template<class T>
|
||||
@@ -82,7 +86,7 @@ public:
|
||||
|
||||
FCogImguiContext& GetContext() { return Context; }
|
||||
|
||||
bool IsRenderingMainMenu() const { return IsRenderingInMainMenu; }
|
||||
bool IsRenderingMainMenu() const { return bIsRenderingInMainMenu; }
|
||||
|
||||
static void AddCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key);
|
||||
|
||||
@@ -215,12 +219,11 @@ protected:
|
||||
bool bIsInputEnabledBeforeEnteringSelectionMode = false;
|
||||
|
||||
bool bEnable = false;
|
||||
|
||||
bool bIsSelectionModeActive = false;
|
||||
|
||||
bool IsInitialized = false;
|
||||
bool bIsInitialized = false;
|
||||
|
||||
bool IsRenderingInMainMenu = false;
|
||||
bool bIsRenderingInMainMenu = false;
|
||||
|
||||
int32 NumExecBindingsChecked = 0;
|
||||
|
||||
|
||||
@@ -202,11 +202,21 @@ void FCogImguiContext::Shutdown()
|
||||
|
||||
if (Context)
|
||||
{
|
||||
Context->IO.IniFilename = nullptr;
|
||||
ImGui::DestroyContext(Context);
|
||||
Context = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiContext::SaveSettings() const
|
||||
{
|
||||
if (Context && Context->SettingsLoaded && Context->IO.IniFilename != nullptr)
|
||||
{
|
||||
ImGui::SaveIniSettingsToDisk(Context->IO.IniFilename);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiContext::OnImGuiWidgetFocusLost()
|
||||
{
|
||||
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
|
||||
void Shutdown();
|
||||
|
||||
void SaveSettings() const;
|
||||
|
||||
bool GetEnableInput() const { return bEnableInput; }
|
||||
|
||||
void SetEnableInput(bool InValue);
|
||||
|
||||
Reference in New Issue
Block a user