Skip to content

Commit

Permalink
- editor layout default option
Browse files Browse the repository at this point in the history
- save/load editor layout from user profile
  • Loading branch information
kaffeewolf committed Nov 24, 2024
1 parent e1cb458 commit a9e6727
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 21 deletions.
41 changes: 24 additions & 17 deletions code/addons/dynui/imguicontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "io/ioserver.h"
#include "frame/framesubgraph.h"
#include "core/cvar.h"
#include "appgame/gameapplication.h"

#include "frame/default.h"
#if WITH_NEBULA_EDITOR
Expand Down Expand Up @@ -378,22 +379,25 @@ ImguiContext::Create()
*/

#if WITH_NEBULA_EDITOR
FrameScript_editorframe::RegisterSubgraphPipelines_ImGUI_Pass([](const CoreGraphics::PassId pass, uint subpass)
if (App::GameApplication::IsEditorEnabled())
{
CoreGraphics::InputAssemblyKey inputAssembly{ CoreGraphics::PrimitiveTopology::TriangleList, false };
if (state.editorPipeline != CoreGraphics::InvalidPipelineId)
CoreGraphics::DestroyGraphicsPipeline(state.editorPipeline);
state.editorPipeline = CoreGraphics::CreateGraphicsPipeline({ state.prog, pass, subpass, inputAssembly });
});
FrameScript_editorframe::RegisterSubgraphPipelines_ImGUI_Pass([](const CoreGraphics::PassId pass, uint subpass)
{
CoreGraphics::InputAssemblyKey inputAssembly{ CoreGraphics::PrimitiveTopology::TriangleList, false };
if (state.editorPipeline != CoreGraphics::InvalidPipelineId)
CoreGraphics::DestroyGraphicsPipeline(state.editorPipeline);
state.editorPipeline = CoreGraphics::CreateGraphicsPipeline({ state.prog, pass, subpass, inputAssembly });
});

FrameScript_editorframe::RegisterSubgraph_ImGUI_Pass([](const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle<int>& viewport, const IndexT frame, const IndexT bufferIndex)
{
FrameScript_editorframe::RegisterSubgraph_ImGUI_Pass([](const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle<int>& viewport, const IndexT frame, const IndexT bufferIndex)
{
#ifdef NEBULA_NO_DYNUI_ASSERTS
ImguiContext::RecoverImGuiContextErrors();
ImguiContext::RecoverImGuiContextErrors();
#endif
ImGui::Render();
ImguiDrawFunction(cmdBuf, viewport, true);
});
ImGui::Render();
ImguiDrawFunction(cmdBuf, viewport, true);
});
}
#endif

SizeT numBuffers = CoreGraphics::GetNumBufferedFrames();
Expand Down Expand Up @@ -604,13 +608,16 @@ ImguiContext::Create()
io.Fonts->TexID = &state.fontTexture;
io.Fonts->ClearTexData();

// load settings from disk. If we don't do this here we need to
// run an entire frame before being able to create or load settings
if (!IO::IoServer::Instance()->FileExists("imgui.ini"))
if (!App::GameApplication::IsEditorEnabled())
{
ImGui::SaveIniSettingsToDisk("imgui.ini");
// load settings from disk. If we don't do this here we need to
// run an entire frame before being able to create or load settings
if (!IO::IoServer::Instance()->FileExists("imgui.ini"))
{
ImGui::SaveIniSettingsToDisk("imgui.ini");
}
ImGui::LoadIniSettingsFromDisk("imgui.ini");
}
ImGui::LoadIniSettingsFromDisk("imgui.ini");
}

//------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions code/application/appgame/gameapplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace App
{
__ImplementSingleton(App::GameApplication);
IndexT GameApplication::FrameIndex = -1;
bool GameApplication::editorEnabled = false;


using namespace Util;
using namespace Core;
Expand Down Expand Up @@ -87,9 +89,6 @@ GameApplication::Open()
this->coreServer->SetToolDirectory(System::NebulaSettings::ReadString("gscept", "ToolkitShared", "path"));
}
#endif

//n_assert2(System::NebulaSettings::ReadString("gscept", "ToolkitShared", "workdir"), "No working directory defined!");

this->coreServer->SetRootDirectory(root);
this->coreServer->Open();

Expand Down Expand Up @@ -195,7 +194,7 @@ GameApplication::Close()
this->gameContentServer = nullptr;

this->resourceServer->Close();
this->resourceServer = nullptr;
this->resourceServer = nullptr;

#if __NEBULA_HTTP__
this->debugInterface->Close();
Expand Down Expand Up @@ -311,6 +310,7 @@ GameApplication::SetupAppFromCmdLineArgs()
{
this->SetAppTitle(args.GetString("-appname"));
}
editorEnabled = args.GetBoolFlag("-editor");
}

} // namespace App
13 changes: 13 additions & 0 deletions code/application/appgame/gameapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class GameApplication : public Application
virtual void StepFrame();

static IndexT FrameIndex;
///
static bool IsEditorEnabled();

protected:
/// setup game features
Expand All @@ -62,6 +64,8 @@ class GameApplication : public Application
Ptr<IO::IoInterface> ioInterface;
Ptr<BaseGameFeature::BaseGameFeatureUnit> baseGameFeature;

static bool editorEnabled;


#if __NEBULA_HTTP__
Ptr<Debug::DebugInterface> debugInterface;
Expand Down Expand Up @@ -97,5 +101,14 @@ class GameApplication : public Application
GameAppExitHandler exitHandler;
};

//------------------------------------------------------------------------------
/**
*/
inline
bool GameApplication::IsEditorEnabled()
{
return editorEnabled;
}

} // namespace App
//------------------------------------------------------------------------------
164 changes: 164 additions & 0 deletions syswork/data/editor/defaultui.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
[Window][DockSpaceViewport_11111111]
Pos=0,29
Size=1920,1507
Collapsed=0

[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0

[Window][###Outline]
Pos=1435,29
Size=485,848
Collapsed=0
DockId=0x0000000B,0

[Window][###History]
Pos=0,1133
Size=615,403
Collapsed=0
DockId=0x00000003,0

[Window][###Style Editor]
Pos=1435,879
Size=485,657
Collapsed=0
DockId=0x0000000C,0

[Window][###Toolbar]
Pos=0,29
Size=1433,81
Collapsed=0
DockId=0x00000005,0

[Window][###Environment]
Pos=617,1133
Size=816,403
Collapsed=0
DockId=0x00000004,0

[Window][###Scene View]
Pos=0,112
Size=1433,1019
Collapsed=0
DockId=0x0000000A,0

[Window][###Inspector]
Pos=1435,879
Size=485,657
Collapsed=0
DockId=0x0000000C,1

[Window][###Asset Browser]
Pos=0,1133
Size=524,403
Collapsed=0
DockId=0x00000008,0

[Window][###Asset Editor]
Pos=0,1133
Size=615,403
Collapsed=0
DockId=0x00000003,1

[Window][###Resource Browser]
Pos=0,112
Size=1433,1019
Collapsed=0
DockId=0x0000000A,1

[Window][###Profiler]
Pos=0,112
Size=1433,1019
Collapsed=0
DockId=0x0000000A,2

[Window][###Physics]
Pos=1892,1508
Size=709,402
Collapsed=0

[Window][###Console]
Pos=0,1133
Size=615,403
Collapsed=0
DockId=0x00000003,1

[Window][###testwindow]
Pos=60,60
Size=574,412
Collapsed=0

[Window][testwindow]
Pos=332,1159
Size=1087,377
Collapsed=0
DockId=0x00000003,5

[Window][###Settings]
Pos=617,1133
Size=816,403
Collapsed=0
DockId=0x00000004,1

[Table][0x71AC9337,2]
Column 0 Weight=1.0057
Column 1 Weight=0.9943

[Table][0x10A3CED7,4]
Column 0 Weight=2.2383
Column 1 Weight=0.3598 Sort=0v
Column 2 Weight=0.3879
Column 3 Weight=1.0140

[Table][0x57A4DCA6,2]
RefScale=21
Column 0 Width=69
Column 1 Weight=1.0000

[Table][0xBC9367A5,2]
RefScale=21
Column 0 Width=99
Column 1 Weight=1.0000

[Table][0x53510C9B,2]
RefScale=21
Column 0 Width=44
Column 1 Weight=1.0000

[Table][0x39B5DD78,2]
RefScale=21
Column 0 Width=12
Column 1 Weight=1.0000

[Table][0x34ABAD3F,2]
RefScale=21
Column 0 Width=90
Column 1 Weight=1.0000

[Table][0xDF9C163C,2]
RefScale=21
Column 0 Width=118
Column 1 Weight=1.0000

[Table][0xDB69C601,2]
RefScale=21
Column 0 Width=118
Column 1 Weight=1.0000

[Docking][Data]
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,29 Size=1920,1507 Split=X
DockNode ID=0x00000001 Parent=0x8B93E3BD SizeRef=1433,1507 Split=Y
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1419,81 Selected=0x19A1EAF5
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=1419,1424 Split=Y
DockNode ID=0x0000000A Parent=0x00000006 SizeRef=1087,1019 CentralNode=1 Selected=0xCA8839C9
DockNode ID=0x00000007 Parent=0x00000006 SizeRef=1087,403 Split=X Selected=0x5ABBAD4F
DockNode ID=0x00000008 Parent=0x00000007 SizeRef=1145,269 Selected=0x2E013A47
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=1982,269 Split=X Selected=0x230535F5
DockNode ID=0x00000003 Parent=0x00000009 SizeRef=615,513 Selected=0x230535F5
DockNode ID=0x00000004 Parent=0x00000009 SizeRef=816,513 Selected=0xDE7DD914
DockNode ID=0x00000002 Parent=0x8B93E3BD SizeRef=485,1507 Split=Y Selected=0x6222C848
DockNode ID=0x0000000B Parent=0x00000002 SizeRef=345,1147 Selected=0xABFEC94A
DockNode ID=0x0000000C Parent=0x00000002 SizeRef=345,888 Selected=0x128659EE

38 changes: 38 additions & 0 deletions toolkit/editor/editor/ui/uimanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "editor/commandmanager.h"
#include "dynui/imguicontext.h"
#include "io/filedialog.h"
#include "io/filestream.h"
#include "window.h"
#include "editor/tools/selectiontool.h"
#include "editor/cmds.h"
Expand All @@ -40,6 +41,7 @@ namespace Editor
__ImplementClass(Editor::UIManager, 'UiMa', Game::Manager);

static Ptr<Presentation::WindowServer> windowServer;
const char* UIManager::editorUIPath = "user:nebula/editor/editorui.ini";

namespace UI
{
Expand Down Expand Up @@ -168,6 +170,24 @@ UIManager::OnActivate()
swapInfo.swapSource = FrameScript_editorframe::Export_EditorBuffer.tex;
Graphics::GraphicsServer::Instance()->SetSwapInfo(swapInfo);
});
IO::URI userEditorIni = IO::URI(editorUIPath);
Util::String path = userEditorIni.LocalPath();
if (!IO::IoServer::Instance()->FileExists(userEditorIni))
{
const Util::String defaultIni = "tool:syswork/data/editor/defaultui.ini";
IO::IoServer::Instance()->CreateDirectory("user:nebula/editor/");
if (IO::IoServer::Instance()->FileExists(defaultIni))
{
IO::IoServer::Instance()->CopyFile(defaultIni, userEditorIni);
}
else
{
// Fallback

ImGui::SaveIniSettingsToDisk(path.c_str());
}
}

}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -197,7 +217,25 @@ UIManager::OnBeginFrame()
void
UIManager::OnFrame()
{
if (this->delayedImguiLoad)
{
this->delayedImguiLoad = false;
IO::URI userEditorIni = IO::URI(editorUIPath);
Util::String path = userEditorIni.LocalPath();
if (IO::IoServer::Instance()->FileExists(userEditorIni))
{
ImGui::LoadIniSettingsFromDisk(path.c_str());
}
}

}
//------------------------------------------------------------------------------
/**
*/
const Util::String
UIManager::GetEditorUIIniPath()
{
return editorUIPath;
}

} // namespace Editor
5 changes: 5 additions & 0 deletions toolkit/editor/editor/ui/uimanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class UIManager : public Game::Manager
void OnDeactivate() override;
void OnBeginFrame() override;
void OnFrame() override;
static const Util::String GetEditorUIIniPath();
private:
/// fugly
bool delayedImguiLoad = true;
static const char* editorUIPath;
};

namespace UI
Expand Down
Loading

0 comments on commit a9e6727

Please sign in to comment.