diff options
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/game.cpp b/src/game.cpp index cfb6d7c..a48cbfe 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,8 +1,15 @@ #include "game.hpp" +#include "imgui.h" GameSettings pkeSettings{}; +const uint64_t consoleBufferCount = 30; +const uint64_t consoleLineLength = 128; + +char consoleBuffer[consoleBufferCount][consoleLineLength]; +long consoleBufferIndex = 0; + void GameTick(double delta) { /* * ECS_Tick() gets called first because it updates the public @@ -10,3 +17,47 @@ void GameTick(double delta) { */ ECS_Tick(delta); } + +void RecordImGuiConsole(bool *pOpen) { + static bool scrollToBottom = true; + if (!ImGui::Begin("Console", pOpen)) { + ImGui::End(); + return; + } + ImVec2 region = ImGui::GetContentRegionAvail(); + region.y -= 27; + if (ImGui::BeginListBox("##ConsoleHistory", region)) { + for (long i = consoleBufferIndex + 1; i < consoleBufferCount; ++i) { + ImGui::Text("%s", consoleBuffer[i]); + } + for (long i = 0; i < consoleBufferIndex; ++i) { + ImGui::Text("%s", consoleBuffer[i]); + } + if (scrollToBottom) ImGui::SetScrollHereY(1); + scrollToBottom = false; + ImGui::EndListBox(); + } + ImGui::Separator(); + if (ImGui::InputText("##ConsoleInput", consoleBuffer[consoleBufferIndex], consoleLineLength, ImGuiInputTextFlags_EnterReturnsTrue)) { + // TODO parse and execute. + scrollToBottom = true; + consoleBufferIndex = (consoleBufferIndex + 1) % consoleBufferCount; + memset(consoleBuffer[consoleBufferIndex], '\0', consoleLineLength); + } + auto flags = (ImGuiFocusedFlags_ChildWindows); + if (ImGui::IsWindowFocused(flags) && !ImGui::IsAnyItemFocused() && !ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsMouseClicked(ImGuiMouseButton_Left, true)) { + ImGui::SetKeyboardFocusHere(-1); + } + ImGui::End(); +} + +void RecordImGuiEditor() { + RecordImGuiConsole(&pkeSettings.isShowingEditor); +} + +void GameInit() { + for (long i = 0; i < consoleBufferCount; ++i) { + memset(consoleBuffer[i], '\0', consoleLineLength); + } + RegisterCallback("RenderImGui", RecordImGuiEditor); +} |
