diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d5d08d..375e8b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set(USE_SERIALIZER True) set(USE_INPUT True) set(USE_BULLET True) set(USE_SOL2 True) +set(USE_IMGUI True) set(SFML_MODULES audio graphics) set(CMAKE_TEMPLATE_PATH "../CMakeTemplate") diff --git a/src/defaultkeysmap.h b/src/defaultkeysmap.h index 3e5157d..fc7abbc 100644 --- a/src/defaultkeysmap.h +++ b/src/defaultkeysmap.h @@ -52,6 +52,7 @@ public: { return { {TOGGLE_CONSOLE,input::KEYBOARD}, + {EXIT_GAME,input::KEYBOARD}, {MOVE_CURSOR_LEFT,input::KEYBOARD}, {MOVE_CURSOR_RIGHT,input::KEYBOARD} }; diff --git a/src/engine.cpp b/src/engine.cpp index 22f7318..389fff9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -11,6 +11,7 @@ #include "scene/scenetree.h" #include "sparrowshell/sparrowshell.h" #include "scene/physicsdebugnode.h" +#include "imgui/imgui.h" Engine::Engine() : m_window(nullptr), @@ -81,6 +82,33 @@ void Engine::update() m_input->updateEvents(); checkSpecialInputs(); + // initialize imgui frame + ImGuiIO& io = ImGui::GetIO(); + io.DeltaTime = float(getDeltaTime()) / 1000.; + ImGui::NewFrame(); + + // test gui + { + static bool testGuiOpen = true; + if(testGuiOpen) + { + ImGui::Begin("Test imgui Window", &testGuiOpen); + ImGui::Text("Hello, world!"); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + bool physicsDebugEnabled = (m_physicsDebugNode != nullptr); + if(ImGui::Checkbox("Toggle physics debug", &physicsDebugEnabled)) + { + if(physicsDebugEnabled) + enablePhysicsDebug(); + else + disablePhysicsDebug(); + } + if(ImGui::Button("EXIT GAME")) + stop(); + ImGui::End(); + } + } + // update Physics if(m_world != nullptr) { @@ -214,7 +242,12 @@ void Engine::checkSpecialInputs() else if(action.action == m_toggleShellAction) m_sparrowshell->toggleShell(); else if(action.action == m_exitGameAction) - m_running = false; + { + if(m_sparrowshell->isVisible()) + m_sparrowshell->toggleShell(); + else + m_running = false; + } else if(action.action == m_showMouseAction) toggleMouseVisibility(); }