33#if defined(TOAD_EDITOR) || !defined(NDEBUG)
44#define IMGUI_DEFINE_MATH_OPERATORS
55#include " imgui/imgui.h"
6+ #include " implot/implot.h"
67#include " imgui-SFML.h"
78#endif
89
1718#include " engine/systems/Time.h"
1819#include " engine/systems/Timer.h"
1920#include " utils/Wrappers.h"
21+ #include " Engine.h"
2022
2123namespace Toad
2224{
@@ -35,8 +37,6 @@ static std::unique_ptr<filewatch::FileWatch<TFILEWATCH_STRTYPE>> dll_file_watch
3537static Camera editor_cam{ " EditorCamera" };
3638// multiple windows
3739
38- static DllHandle curr_dll{};
39-
4040static std::filesystem::path current_path;
4141static std::filesystem::path project_path;
4242
@@ -45,6 +45,10 @@ static std::unique_ptr<sf::RenderTexture> window_texture = nullptr;
4545
4646static Camera* interacting_camera = nullptr ;
4747
48+ #if defined(TOAD_EDITOR) || !defined(NDEBUG)
49+ static UICtx ui_ctx;
50+ #endif
51+
4852void Render (AppWindow& window);
4953void CleanUp ();
5054
@@ -234,10 +238,20 @@ bool Init()
234238
235239 // #TODO: change to a .ini or .json
236240 ::AppSettings gsettings;
241+
242+ DllHandle curr_dll = ScriptManager::GetDLLHandle ();
243+
244+ LOGDEBUGF (" curr_dll: {}" , (void *)(curr_dll));
245+
237246 if (curr_dll != nullptr )
238247 {
239248 auto get_game_settings = reinterpret_cast <get_game_settings_t *>(DLibGetAddress (curr_dll, " get_game_settings" ));
240- gsettings = get_game_settings ();
249+ LOGDEBUGF (" DLGetError: {}" , DLGetError ());
250+ LOGDEBUGF (" get_game_settings: {}" , (void *)(get_game_settings));
251+ if (!get_game_settings)
252+ LOGERROR (" Couldn't get game settings" );
253+ else
254+ gsettings = get_game_settings ();
241255 }
242256
243257#ifdef TOAD_EDITOR
@@ -249,6 +263,8 @@ bool Init()
249263#endif
250264 AppWindow& window = GetWindow ();
251265
266+ LOGDEBUGF (" Creating window ({})" , gsettings.window_name );
267+
252268 if (!window.Create (gsettings.window_width , gsettings.window_height , gsettings.frame_limit , gsettings.style , gsettings.window_name ))
253269 return false ;
254270 // window.Create({ (uint32_t)gsettings.window_width, (uint32_t)gsettings.window_height }, "abc", gsettings.style);
@@ -272,6 +288,11 @@ bool Init()
272288 StartGameSession ();
273289#endif
274290
291+ #if defined(TOAD_EDITOR) || !defined(NDEBUG)
292+ ui_ctx.imgui_ctx = ImGui::GetCurrentContext ();
293+ ui_ctx.implot_ctx = ImPlot::GetCurrentContext ();
294+ #endif
295+
275296 return true ;
276297}
277298
@@ -359,21 +380,20 @@ void Render(AppWindow& window)
359380
360381 for (auto & obj : Scene::current_scene.objects_all )
361382 for (auto & [name, script] : obj->GetAttachedScripts ())
362- script->OnImGui (obj.get (), ImGui::GetCurrentContext () );
383+ script->OnImGui (obj.get (), ui_ctx );
363384
364385 ImGui::SFML::Render (window);
365386#else
366- #if defined(TOAD_EDITOR) || !defined(NDEBUG)
367387 Scene::current_scene.Render (window);
368388 DrawingCanvas::ClearDrawBuffers ();
369389
390+ #if defined(TOAD_EDITOR) || !defined(NDEBUG)
370391 for (auto & obj : Scene::current_scene.objects_all )
371392 for (auto & [name, script] : obj->GetAttachedScripts ())
372- script->OnImGui (obj.get (), ImGui::GetCurrentContext () );
393+ script->OnImGui (obj.get (), ui_ctx );
373394
374395 ImGui::SFML::Render (window);
375396#endif
376- Scene::current_scene.Render (window);
377397
378398 if (cam != nullptr )
379399 {
@@ -539,6 +559,7 @@ void CleanUp()
539559#if defined(TOAD_EDITOR) || !defined(NDEBUG)
540560 LOGDEBUG (" shutting down imgui" );
541561 ImGui::SFML::Shutdown ();
562+ ImPlot::DestroyContext ();
542563#endif
543564
544565 LOGDEBUG (" closing window" );
@@ -552,4 +573,9 @@ Camera& GetEditorCamera()
552573 return editor_cam;
553574}
554575
576+ const UICtx& GetUIContext ()
577+ {
578+ return ui_ctx;
555579}
580+
581+ } // namespace Toad
0 commit comments