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