diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5eb1e1a --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +assets/fonts/*.otf filter=lfs diff=lfs merge=lfs -text diff --git a/.gitmodules b/.gitmodules index e5a0c8e..153f048 100644 --- a/.gitmodules +++ b/.gitmodules @@ -26,3 +26,7 @@ path = external/theora url = https://github.com/xiph/theora.git shallow = true +[submodule "external/imgui"] + path = external/imgui + url = https://github.com/ocornut/imgui.git + shallow = true diff --git a/CMakeLists.txt b/CMakeLists.txt index 3418008..0f64225 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,13 +65,34 @@ target_include_directories(theora SYSTEM PUBLIC external/theora/include) target_link_libraries(theora PUBLIC ogg) target_compile_options(theora PRIVATE -w) +# The developer overlay (src/ui/overlay/) in place of the drop-down console, on Dear ImGui's docking branch: its core, +# the std::string widgets and the SDL3 and OpenGL 3 backends, static. OFF builds the game without either. +option(ISAAC_OVERLAY "Build the developer overlay in place of the drop-down console" ON) +if(ISAAC_OVERLAY) + set(IMGUI_SOURCES imgui imgui_draw imgui_tables imgui_widgets misc/cpp/imgui_stdlib backends/imgui_impl_sdl3 + backends/imgui_impl_opengl3) + list(TRANSFORM IMGUI_SOURCES PREPEND external/imgui/) + list(TRANSFORM IMGUI_SOURCES APPEND .cpp) + add_library(imgui STATIC ${IMGUI_SOURCES}) + target_include_directories(imgui SYSTEM PUBLIC external/imgui external/imgui/backends external/imgui/misc/cpp) + target_link_libraries(imgui PRIVATE SDL3::SDL3-static ${CMAKE_DL_LIBS}) + target_compile_options(imgui PRIVATE -w) +endif() + # The curated game: every .cpp under src/, sorted into subsystem folders and including each other by path from src/, # written on top of the declarations generated-src/classes.h holds for every class. # generated-src/'s own bodies stay out until they compile (scripts/source_tree.py --check reports how many do). # generated-src/stubs.cpp defines everything not curated yet as a stub that stops the game where it is reached, so the # executable always links and runs exactly as far as src/ goes. file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp) +if(NOT ISAAC_OVERLAY) + list(FILTER SOURCES EXCLUDE REGEX "/src/ui/overlay/") +endif() add_executable(isaac ${SOURCES} generated-src/stubs.cpp) target_include_directories(isaac PRIVATE src) target_include_directories(isaac SYSTEM PRIVATE generated-src external/stb) target_link_libraries(isaac PRIVATE SDL3::SDL3-static lua simdjson theora vorbis ogg) +if(ISAAC_OVERLAY) + target_compile_definitions(isaac PRIVATE ISAAC_OVERLAY) + target_link_libraries(isaac PRIVATE imgui) +endif() diff --git a/README.md b/README.md index 25440c9..e00ec22 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ scripts/ decompile.sh (print decompiled C for a function, by name regex or fields), build.sh (rebuild everything from the exe after a game update), and the Ghidra Java scripts and Python helpers they use tools/ gitignored local tools: the resource importer and the test harness (tools/harness/) -external/ static submodules: SDL3, Lua 5.3, simdjson, Ogg, Vorbis, Theora, stb +external/ static submodules: SDL3, Lua 5.3, simdjson, Ogg, Vorbis, Theora, stb, Dear ImGui (docking) +assets/ files the repository ships itself (git-lfs): the overlay's fonts, with their licences repentogon/ shallow clone of TeamREPENTOGON/REPENTOGON (libzhl/functions/*.zhl = sigs, structs, enums) bin/ private copy of the exe (analysis input; also used to read constants) jdk/ ghidra_12.2_PUBLIC/ Temurin 21 (system java is 8, too old) and Ghidra @@ -81,6 +82,8 @@ entity/ Entity and its list, factory, config, collision, combat weapon/ weapons, tears, lasers, knives, bombs, projectiles ui/ HUDs, popups, pause screen, cutscenes, console menu/ every menu screen (ui/menu/character, ui/menu/mods ...) + overlay/ the developer overlay (CMake option ISAAC_OVERLAY, on by default): ` shows it in place of the console, + with the Console, Game Options, Mods and Debug windows on Dear ImGui lua/ the Lua engine, API bindings and callbacks online/ online-only code, kept as offline stubs ``` @@ -88,6 +91,7 @@ online/ online-only code, kept as offline stubs ### Test harness Flags on the game binary (`src/engine/harness.cpp`), deterministic: the same input file always gives the same run. +The first three leave the developer overlay out, so the console behaves as the original's. ``` --headless no window, GL context or audio, no frame pacing (about 7,900 frames per second) diff --git a/assets/fonts/Font Awesome 6 Free-Solid-900.otf b/assets/fonts/Font Awesome 6 Free-Solid-900.otf new file mode 100644 index 0000000..12ca6fb --- /dev/null +++ b/assets/fonts/Font Awesome 6 Free-Solid-900.otf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4b9897329b143d012b9a54c7368d0fcae83eb76918f4b43aaad82f2eb7e7012 +size 1025256 diff --git a/assets/fonts/LICENSES.txt b/assets/fonts/LICENSES.txt new file mode 100644 index 0000000..b8e07d4 --- /dev/null +++ b/assets/fonts/LICENSES.txt @@ -0,0 +1,112 @@ +Fonts used by the developer overlay (src/ui/overlay/), copied from isaac-classic's resources/fonts/. + +unifont-15.1.04.otf (GNU Unifont 15.1.04) +Copyright (C) 1998-2023 Roman Czyborra, Paul Hardy, Qianqian Fang, Andrew Miller, Johnnie Weaver, David Corbett, +Nils Moskopp, Rebecca Bettencourt, Minseo Lee, Ho-Seok Ee, et al. +Dual license: the SIL Open Font License version 1.1 (below), and the GNU General Public License version 2 or later +with the GNU Font Embedding Exception: + As a special exception, if you create a document which uses this font, and embed this font or unaltered portions + of this font into the document, this font does not by itself cause the resulting document to be covered by the + GNU General Public License. This exception does not however invalidate any other reasons why the document might + be covered by the GNU General Public License. If you modify this font, you may extend this exception to your + version of the font, but you are not obligated to do so. If you do not wish to do so, delete this exception + statement from your version. +https://unifoundry.com/unifont/ https://gnu.org/licenses/gpl.html https://scripts.sil.org/OFL + +Font Awesome 6 Free-Solid-900.otf (Font Awesome Free 6) +Copyright (c) Fonticons, Inc. (https://fontawesome.com) +The font is licensed under the SIL Open Font License version 1.1 (below). Font Awesome Free's icons are CC BY 4.0 +and its code MIT: https://fontawesome.com/license/free + +----------------------------------------------------------------------------------------------------------------------- + +The SIL Open Font License version 1.1 is copied below, and is also +available with a FAQ at http://scripts.sil.org/OFL. + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/unifont-15.1.04.otf b/assets/fonts/unifont-15.1.04.otf new file mode 100644 index 0000000..e23bf36 --- /dev/null +++ b/assets/fonts/unifont-15.1.04.otf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27c83ca235c3ab99d5d35df35d78b5ac4018421a4287b1b4ea657b2299996d38 +size 5105244 diff --git a/external/imgui b/external/imgui new file mode 160000 index 0000000..9b4eb24 --- /dev/null +++ b/external/imgui @@ -0,0 +1 @@ +Subproject commit 9b4eb24cee2071e61dc1f9ef3e5228097cdde720 diff --git a/src/engine/data.cpp b/src/engine/data.cpp index da0b45e..e56ea4d 100644 --- a/src/engine/data.cpp +++ b/src/engine/data.cpp @@ -14,6 +14,9 @@ constexpr std::string_view LANGUAGE_FOLDER = "lang/"; constexpr std::string_view MODS_FROM_RESOURCES = "../mods/"; constexpr std::string_view PARENT_FOLDER = "../"; constexpr std::string_view MODS_FOLDER = "mods/"; +// The game's own folder name, which the exe writes in front of some paths ("resources/gfx/1000.034_Fart.anm2"). +constexpr std::string_view GAME_RESOURCES_FOLDER = "resources/"; +constexpr std::string_view ASSETS_FOLDER = "assets"; std::string dataDirectory = "resources/"; std::string languageDirectory; @@ -26,12 +29,13 @@ static std::string path_normalize(std::string_view path) std::string_view mods = platform.modsDirectory; bool isModsPath = !mods.empty() && path.starts_with(mods); if (isModsPath) path.remove_prefix(mods.size()); + else if (path.starts_with(dataDirectory)) path.remove_prefix(dataDirectory.size()); std::string normalized(path); for (char& letter : normalized) letter = letter == '\\' ? '/' : (char)std::tolower((unsigned char)letter); if (isModsPath) normalized.insert(0, MODS_FOLDER); else if (normalized.starts_with(MODS_FROM_RESOURCES)) normalized.erase(0, PARENT_FOLDER.size()); - else if (normalized.starts_with(dataDirectory)) normalized.erase(0, dataDirectory.size()); + else if (normalized.starts_with(GAME_RESOURCES_FOLDER)) normalized.erase(0, GAME_RESOURCES_FOLDER.size()); return normalized; } @@ -54,6 +58,12 @@ std::string resource_path(std::string_view path) return mount_resolve(path_normalize(path)); } +// Where a file the repository ships itself lives: in assets/, beside the resources folder. +std::string asset_path(std::string_view path) +{ + return (std::filesystem::path(dataDirectory).parent_path().parent_path() / ASSETS_FOLDER / path).string(); +} + // Where a converted XML document lives: its game path with ".json" appended. std::string data_path(std::string_view path) { diff --git a/src/engine/data.h b/src/engine/data.h index a2e2ab2..1b29913 100644 --- a/src/engine/data.h +++ b/src/engine/data.h @@ -23,6 +23,7 @@ using DataNode = simdjson::dom::element; void data_load(Data& data, std::string_view path); std::string data_path(std::string_view path); std::string resource_path(std::string_view path); +std::string asset_path(std::string_view path); void reload_resource_paths(); std::string_view node_tag(DataNode node); diff --git a/src/engine/harness.cpp b/src/engine/harness.cpp index 50043bf..071b03a 100644 --- a/src/engine/harness.cpp +++ b/src/engine/harness.cpp @@ -174,10 +174,15 @@ void Harness::text_add(uint32_t character) if (!isReplaying) text.push_back(character); } -// The mouse as the game reads it: SDL's, or the harness's while it owns the input. +// The mouse as the game reads it: SDL's (no button while the overlay captures the input), or the harness's while it +// owns the input. SDL_MouseButtonFlags Harness::mouse_get(float* x, float* y) { - if (!isActive) return SDL_GetMouseState(x, y); + if (!isActive) + { + SDL_MouseButtonFlags buttons = SDL_GetMouseState(x, y); + return platform.isInputCaptured ? 0 : buttons; + } if (x) *x = mouse.x; if (y) *y = mouse.y; return mouseButtons; diff --git a/src/engine/kage_input.cpp b/src/engine/kage_input.cpp index db62997..f822386 100644 --- a/src/engine/kage_input.cpp +++ b/src/engine/kage_input.cpp @@ -95,7 +95,7 @@ constexpr ScancodeRun SCANCODE_RUNS[] = { Manager manager; // The GLFW key at a key's physical position, -1 for none. -static int key_from_scancode(SDL_Scancode scancode) +int key_from_scancode(SDL_Scancode scancode) { for (auto [code, key] : SCANCODE_KEYS) if (code == scancode) return key; @@ -104,6 +104,14 @@ static int key_from_scancode(SDL_Scancode scancode) return BUTTON_NONE; } +// The button a standard gamepad button is, -1 for the ones the game has no slot for. +int button_from_gamepad(SDL_GamepadButton button) +{ + auto found = std::ranges::find(SDL_BUTTONS, button); + return button == SDL_GAMEPAD_BUTTON_INVALID || found == std::end(SDL_BUTTONS) ? BUTTON_NONE + : (int)(found - SDL_BUTTONS); +} + // The slot a gamepad button or stick direction keeps its value in, -1 for none. static int gamepad_slot_get(int button) { @@ -257,12 +265,14 @@ void Manager::Shutdown() } // (00a21cb0, 00a1fc00) Takes the window's events, then starts every device's frame, which the harness may replay or -// record. +// record. While the overlay captures the input, every device reads as let go. void Manager::update_devices() { platform.events_poll(); for (auto& device : devices) device->update(); harness.input_update(*this); + if (platform.isInputCaptured) + for (auto& device : devices) std::ranges::fill(device->current, 0); } // 00a20020 The number of devices. diff --git a/src/engine/kage_input.h b/src/engine/kage_input.h index df0931c..3a650ae 100644 --- a/src/engine/kage_input.h +++ b/src/engine/kage_input.h @@ -140,4 +140,7 @@ public: }; extern Manager manager; + +int key_from_scancode(SDL_Scancode scancode); +int button_from_gamepad(SDL_GamepadButton button); } diff --git a/src/engine/platform.cpp b/src/engine/platform.cpp index 5824546..d8d433e 100644 --- a/src/engine/platform.cpp +++ b/src/engine/platform.cpp @@ -7,6 +7,9 @@ #include "engine/kage_sound.h" #include "game/manager.h" #include "game/options_config.h" +#ifdef ISAAC_OVERLAY +#include "ui/overlay/overlay.h" +#endif #include #include #include @@ -259,10 +262,13 @@ void Platform::engine_init() } // 00a71770 Shuts KAGE down: input, sound and graphics, then the framebuffer and the window, and SDL with its threads, -// so none still runs while the process exits. +// so none still runs while the process exits. The overlay goes first, while its GL context is still there. // Its EOS release, log closing, compressor, multiplayer threads, video manager and heaps have nothing here to free. void Platform::engine_shutdown() { +#ifdef ISAAC_OVERLAY + overlay.unload(); +#endif KAGE::Input::manager.Shutdown(); KAGE::Sound::manager.Shutdown(); KAGE::Graphics::manager.Shutdown(); @@ -277,8 +283,8 @@ void Platform::engine_shutdown() SDL_Quit(); } -// Opens the window at its default size with its GL context and shows it, as Graphics::Manager::Init began. A headless -// run has only SDL's events. +// Opens the window at its default size with its GL context and shows it, as Graphics::Manager::Init began, then loads +// the overlay on that context outside the harness. A headless run has only SDL's events. bool Platform::window_open() { if (!SDL_Init(harness.isHeadless ? SDL_INIT_EVENTS : SDL_INIT_VIDEO)) @@ -289,12 +295,18 @@ bool Platform::window_open() if (!window_create()) return false; SDL_ShowWindow(window); SDL_RaiseWindow(window); +#ifdef ISAAC_OVERLAY + if (!harness.isActive) overlay.load(); +#endif return true; } -// Shows the finished frame, as glfwSwapBuffers, after the harness's screenshot of it. +// Shows the finished frame, as glfwSwapBuffers, after the overlay over it and the harness's screenshot. void Platform::window_swap() { +#ifdef ISAAC_OVERLAY + overlay.render(); +#endif harness.screenshot_save(); SDL_GL_SwapWindow(window); } @@ -468,7 +480,8 @@ void Platform::fullscreen_set(FullscreenMode mode) // Takes the window's events as GLFW's callbacks did: closing asks the game to quit, a new size (00a19bf0), position // (00a19ca0) or focus (00a19d40) goes to its listeners and resets what depends on it, each typed character goes to // the text listeners, keys and gamepads go to input. -// Under the harness focus changes are left out and typed characters reach the game through it. +// Under the harness focus changes are left out and typed characters reach the game through it. The overlay sees each +// event first and keeps the ones it captures. // Win32's topmost-while-focused fullscreen window has no SDL counterpart. void Platform::events_poll() { @@ -476,6 +489,9 @@ void Platform::events_poll() while (SDL_PollEvent(&event)) { +#ifdef ISAAC_OVERLAY + if (overlay.is_event_captured(event)) continue; +#endif switch (event.type) { case SDL_EVENT_QUIT: diff --git a/src/engine/platform.h b/src/engine/platform.h index 204aa4a..b286fb1 100644 --- a/src/engine/platform.h +++ b/src/engine/platform.h @@ -64,6 +64,7 @@ enum RenderbufferMode // under them, with the folders the game saves into and the 60 Hz frame pacing. // Listeners get the window's new size, position or focus, as the game registers them in IsaacStartup, and each // character typed while text input is on, as GLFW's char callback did. +// While isInputCaptured (the developer overlay shows), the game reads no key, button or mouse button. class Platform { public: @@ -86,6 +87,7 @@ public: unsigned int framebuffer = 0; bool isEngineInitialized = false; bool isFullscreen = false; + bool isInputCaptured = false; bool isQuitRequested = false; bool isViewportOffset = false; bool isVsync = true; diff --git a/src/game/options_config.cpp b/src/game/options_config.cpp index 632ff1f..5c9d18d 100644 --- a/src/game/options_config.cpp +++ b/src/game/options_config.cpp @@ -132,62 +132,6 @@ static void line_write(std::string& text, const char* key, int value) text.append(line, std::snprintf(line, sizeof(line), "%s=%d\r\n", key, value)); } -// Calls visit with each option options.ini holds under its own key, in the order Save writes them. -template static void options_visit(OptionsConfig& options, Visit visit) -{ - visit("SFXVolume", options.sfxVolume); - visit("MapOpacity", options.mapOpacity); - visit("Fullscreen", options.isFullscreen); - visit("Filter", options.isFilterEnabled); - visit("Exposure", options.exposure); - visit("Gamma", options.gamma); - visit("ControllerHotplug", options.isControllerHotplugEnabled); - visit("PopUps", options.popupsMode); - visit("CameraStyle", options.cameraStyle); - visit("ShowRecentItems", options.historyHudMode); - visit("HudOffset", options.hudOffset); - visit("TryImportSave", options.isTryImportSave); - visit("FoundHUD", options.isFoundHudEnabled); - visit("EnableMods", options.isModsEnabled); - visit("RumbleEnabled", options.isRumbleEnabled); - visit("ChargeBars", options.isChargeBarsEnabled); - visit("BulletVisibility", options.isBulletVisibilityEnabled); - visit("TouchMode", options.touchMode); - visit("AimLock", options.isAimLockEnabled); - visit("JacobEsauControls", options.jacobEsauControls); - visit("AscentVoiceOver", options.isAscentVoiceover); - visit("OnlineHud", options.onlineHud); - visit("StreamerMode", options.isStreamerMode); - visit("OnlinePlayerVolume", options.onlinePlayerVolume); - visit("OnlinePlayerOpacity", options.onlinePlayerOpacity); - visit("OnlineChatEnabled", options.isOnlineChatEnabled); - visit("OnlineChatFilterEnabled", options.isOnlineFilterEnabled); - visit("MultiplayerColorSet", options.onlineColorSet); - visit("OnlineInputDelay", options.onlineInputDelay); - visit("ItemInfoDisplayEnabled", options.isItemInfoDisplayEnabled); - visit("AcceptedPublicBeta_v1.9.7.17", options.isPublicBetaAccepted); - visit("AcceptedDataCollectionDisclaimer", options.isDataCollectionDisclaimerAccepted); - visit("EnableDebugConsole", options.isDebugConsoleEnabled); - visit("MaxScale", options.maxScale); - visit("MaxRenderScale", options.maxRenderScale); - visit("VSync", options.isVsyncEnabled); - visit("PauseOnFocusLost", options.isPauseOnFocusLostEnabled); - visit("SteamCloud", options.isSteamCloudEnabled); - visit("MouseControl", options.isMouseControlEnabled); - visit("BossHpOnBottom", options.isBossHpOnBottom); - visit("AnnouncerVoiceMode", options.announcerVoiceMode); - visit("ConsoleFont", options.consoleFont); - visit("FadedConsoleDisplay", options.isFadedConsoleDisplayEnabled); - visit("SaveCommandHistory", options.isSaveCommandHistoryEnabled); - visit("WindowWidth", options.windowWidth); - visit("WindowHeight", options.windowHeight); - visit("WindowPosX", options.windowPosX); - visit("WindowPosY", options.windowPosY); - visit("UseExclusiveFullscreen", options.isExclusiveFullscreen); - visit("EnableEpicOverlay", options.isEpicOverlayEnabled); - visit("EosCrossplay", options.eosCrossplay); -} - // Where options.ini lives on Linux: in the save folder SDL keeps under the user's data directory. std::string options_path() { diff --git a/src/game/options_config.h b/src/game/options_config.h index b409caf..6d336bb 100644 --- a/src/game/options_config.h +++ b/src/game/options_config.h @@ -148,6 +148,62 @@ struct OptionsConfig void vsync_set(bool isEnabled); }; +// Calls visit with each option options.ini holds under its own key, in the order Save writes them. +template void options_visit(OptionsConfig& options, Visit visit) +{ + visit("SFXVolume", options.sfxVolume); + visit("MapOpacity", options.mapOpacity); + visit("Fullscreen", options.isFullscreen); + visit("Filter", options.isFilterEnabled); + visit("Exposure", options.exposure); + visit("Gamma", options.gamma); + visit("ControllerHotplug", options.isControllerHotplugEnabled); + visit("PopUps", options.popupsMode); + visit("CameraStyle", options.cameraStyle); + visit("ShowRecentItems", options.historyHudMode); + visit("HudOffset", options.hudOffset); + visit("TryImportSave", options.isTryImportSave); + visit("FoundHUD", options.isFoundHudEnabled); + visit("EnableMods", options.isModsEnabled); + visit("RumbleEnabled", options.isRumbleEnabled); + visit("ChargeBars", options.isChargeBarsEnabled); + visit("BulletVisibility", options.isBulletVisibilityEnabled); + visit("TouchMode", options.touchMode); + visit("AimLock", options.isAimLockEnabled); + visit("JacobEsauControls", options.jacobEsauControls); + visit("AscentVoiceOver", options.isAscentVoiceover); + visit("OnlineHud", options.onlineHud); + visit("StreamerMode", options.isStreamerMode); + visit("OnlinePlayerVolume", options.onlinePlayerVolume); + visit("OnlinePlayerOpacity", options.onlinePlayerOpacity); + visit("OnlineChatEnabled", options.isOnlineChatEnabled); + visit("OnlineChatFilterEnabled", options.isOnlineFilterEnabled); + visit("MultiplayerColorSet", options.onlineColorSet); + visit("OnlineInputDelay", options.onlineInputDelay); + visit("ItemInfoDisplayEnabled", options.isItemInfoDisplayEnabled); + visit("AcceptedPublicBeta_v1.9.7.17", options.isPublicBetaAccepted); + visit("AcceptedDataCollectionDisclaimer", options.isDataCollectionDisclaimerAccepted); + visit("EnableDebugConsole", options.isDebugConsoleEnabled); + visit("MaxScale", options.maxScale); + visit("MaxRenderScale", options.maxRenderScale); + visit("VSync", options.isVsyncEnabled); + visit("PauseOnFocusLost", options.isPauseOnFocusLostEnabled); + visit("SteamCloud", options.isSteamCloudEnabled); + visit("MouseControl", options.isMouseControlEnabled); + visit("BossHpOnBottom", options.isBossHpOnBottom); + visit("AnnouncerVoiceMode", options.announcerVoiceMode); + visit("ConsoleFont", options.consoleFont); + visit("FadedConsoleDisplay", options.isFadedConsoleDisplayEnabled); + visit("SaveCommandHistory", options.isSaveCommandHistoryEnabled); + visit("WindowWidth", options.windowWidth); + visit("WindowHeight", options.windowHeight); + visit("WindowPosX", options.windowPosX); + visit("WindowPosY", options.windowPosY); + visit("UseExclusiveFullscreen", options.isExclusiveFullscreen); + visit("EnableEpicOverlay", options.isEpicOverlayEnabled); + visit("EosCrossplay", options.eosCrossplay); +} + std::string options_path(); KeyValueMap keyvalue_map_parse(std::string_view text); diff --git a/src/ui/console.cpp b/src/ui/console.cpp index a232c63..36d9532 100644 --- a/src/ui/console.cpp +++ b/src/ui/console.cpp @@ -15,6 +15,9 @@ #include "engine/render_passes.h" #include "level/room.h" #include "level/room_config.h" +#ifdef ISAAC_OVERLAY +#include "ui/overlay/overlay.h" +#endif #include #include #include @@ -56,7 +59,8 @@ constexpr uint32_t INPUT_COLOR = 0xffadff2f; constexpr uint32_t CURSOR_EDGE_COLOR = 0xff000000; // The suggestions: the commands offered for the first word (0x00c5cab8 and the six FillOmnicomplete adds), and the -// lists offered after gridspawn, debug, curse and combo. The original lost a comma after the fireplace. +// lists offered after gridspawn and combo (console.h has debug's and curse's). The original lost a comma after the +// fireplace. constexpr std::string_view SUGGESTED_COMMANDS[] = { "spawn", "goto", "stage", "gridspawn", "debug", "giveitem", "remove", "costumetest", "time", "restart", "listcollectibles", "repeat", "clearseeds", "seed", "challenge", "combo", "cutscene", "clearcache", "macro", @@ -68,12 +72,6 @@ constexpr std::string_view GRID_SUGGESTIONS[] = { "1490:Red Poop", "1500:Brown Poop", "1900:Block", "1930:Spikes", "1931:On/Off Spikes", "1940:Spider Web", "3000:Pit", "4000:Lock", "4500:Pressure Plate", "4500.1:Reward Plate", "5000:Devil Statue", "5001:Angel Statue", "9000:Trap Door", "9100:Staircase", "10000:Gravity"}; -constexpr std::string_view DEBUG_FLAG_SUGGESTIONS[] = { - "1:Entity Positions", "2:Grid", "3:Infinite HP", "4:High Damage", "5:Show Room Info", "6:Show Hitspheres", - "7:Show Damage Values", "8:Infinite Item Charges", "9:High Luck", "10:Quick Kill", "11:Grid Info", - "12:Player Item Info", "13:Show Grid Collision Points", "14:Show Lua Memory Usage"}; -constexpr std::string_view CURSE_SUGGESTIONS[] = {"0:None", "1:Darkness", "2:Labyrinth", "4:Lost", "8:Unknown", - "16:Cursed", "32:Maze", "64:Blind", "128:Giant"}; constexpr std::string_view COMBO_POOL_SUGGESTIONS[] = { "0:Treasure", "1:Shop", "2:Boss", "3:Devil", "4:Angel", "5:Secret", "6:Library", "7:Challenge", "8:Golden_Chest", "9:Red_Chest", "10:Beggar", "11:Demon_Beggar", "12:Curse", "13:Key_Master", "14:Boss_Rush", "15:Dungeon"}; @@ -491,6 +489,23 @@ static void text_input_start() isStarted = true; } +#ifdef ISAAC_OVERLAY +// With the overlay in place of the panel, whatever the options allow: a mod's console input shows it, and the console +// opens and closes with it, so a run pauses and the hotkeys rest while it shows, as they do for the panel. +static void overlay_follow(Console& console) +{ + if (console.state == CONSOLE_CLOSED && !overlay.is_visible() && is_open_pressed()) overlay.visible_set(true); + if (console.state == CONSOLE_CLOSED && overlay.is_visible()) + { + console.state = CONSOLE_OPENING; + console.animationFrame = 0; + console.scroll = console.scroll_min_get(); + g_manager->isHotkeysEnabled = false; + } + else if (console.state == CONSOLE_OPEN && !overlay.is_visible()) console.Close(); +} +#endif + // 00686ad0 Whether a key acts this frame: when pressed, then every other frame once held for 20 frames. bool Console::is_key_repeated(int key) { @@ -511,6 +526,9 @@ bool Console::is_key_repeated(int key) // Windows fix SDL does not need. void Console::Update() { +#ifdef ISAAC_OVERLAY + if (overlay.is_ready()) return overlay_follow(*this); +#endif if (state == CONSOLE_CLOSED) { if (!is_console_allowed() || !is_open_pressed()) return; @@ -890,9 +908,9 @@ static void argument_suggestions_add(SuggestionQuery& query, bool isSecondWord) else if (command == "metro") item_suggestions_add(query, SUGGEST_COLLECTIBLES); } -// 00686da0 Fills the suggestions for what the input is being typed into: the commands for the first word, then what -// each command takes, laid out on the six rows as many as fit the screen's width. -void Console::FillOmnicomplete() +// The suggestions for what the input is being typed into: the commands for the first word, then what each command +// takes. +std::vector omnicomplete_get(std::string_view input) { SuggestionQuery query{.words = text_split(input, ' ')}; size_t wordCount = query.words.size() + (input.empty() || input.back() == ' ' ? 1 : 0); @@ -905,8 +923,14 @@ void Console::FillOmnicomplete() if (is_word_prefix(query.words, 0, command)) suggestion_add(query, command); } else if (wordCount >= 2) argument_suggestions_add(query, wordCount == 2); + return text_split(query.found, '#'); +} - std::vector entries = text_split(query.found, '#'); +// 00686da0 Fills the suggestions for what the input is being typed into, laid out on the six rows as many as fit the +// screen's width. +void Console::FillOmnicomplete() +{ + std::vector entries = omnicomplete_get(input); Font& font = *console_text_get().font; size_t next = 0; for (std::string& row : suggestions) @@ -941,7 +965,8 @@ void Console::Close() } // 0068c2e0 Draws the console: with the faded display on, the newest lines while it is not fully open, then the panel -// down to its height with the suggestions, the input with its blinking cursor, and the output above. +// down to its height with the suggestions, the input with its blinking cursor, and the output above. The overlay +// shows in place of the panel. void Console::Render() { ConsoleText text = console_text_get(); @@ -953,6 +978,9 @@ void Console::Render() RenderHistory(text, vector_make(TEXT_X, top), std::clamp(1 - height / maxHeight, 0.0f, 1.0f), HISTORY_FADED); } if (state == CONSOLE_CLOSED) return; +#ifdef ISAAC_OVERLAY + if (overlay.is_ready()) return; +#endif rect_render(vector_make(0, 0), vector_make(g_screenWidth, height), kcolor_make(0, 0, 0, PANEL_ALPHA)); rect_render(vector_make(0, height - EDGE_HEIGHT), vector_make(g_screenWidth, height), diff --git a/src/ui/console.h b/src/ui/console.h index 0914a75..ad73f21 100644 --- a/src/ui/console.h +++ b/src/ui/console.h @@ -68,6 +68,15 @@ inline constexpr DeliriousBoss DELIRIOUS_BOSSES[DELIRIOUS_BOSS_COUNT] = { {410, 0, 100, 1}, {401, 0, 100, 1}, {79, 1, 100, 1}, {71, 1, 25, 1}, {263, 0, 100, 1}, {260, 0, 100, 1}, {101, 1, 100, 1}, {237, 2, 100, 1}, {65, 0, 100, 1}, {100, 0, 100, 1}, {100, 1, 100, 1}}; +// What the debug and curse commands take, with the names the console suggests them by. +inline constexpr std::string_view DEBUG_FLAG_SUGGESTIONS[] = { + "1:Entity Positions", "2:Grid", "3:Infinite HP", "4:High Damage", "5:Show Room Info", "6:Show Hitspheres", + "7:Show Damage Values", "8:Infinite Item Charges", "9:High Luck", "10:Quick Kill", "11:Grid Info", + "12:Player Item Info", "13:Show Grid Collision Points", "14:Show Lua Memory Usage"}; +inline constexpr std::string_view CURSE_SUGGESTIONS[] = {"0:None", "1:Darkness", "2:Labyrinth", "4:Lost", + "8:Unknown", "16:Cursed", "32:Maze", "64:Blind", + "128:Giant"}; + // The collectible the metro command makes the Metronome become, 0 for a random one (0x00c7166c). extern int g_metronomeItem; @@ -138,6 +147,7 @@ struct Console bool update_state(); void Update(); void Close(); + void input_submit(); void FillOmnicomplete(); void Render(); @@ -157,9 +167,11 @@ private: void input_update(); void input_erase(size_t position); bool is_input_pasted(); - void input_submit(); }; ConsoleText console_text_get(); std::vector text_split(std::string_view text, char delimiter); std::string lua_code_run(std::string_view code); +std::vector omnicomplete_get(std::string_view input); +std::vector command_names_get(); +std::vector macro_names_get(); diff --git a/src/ui/console_commands.cpp b/src/ui/console_commands.cpp index ee4cd82..870c564 100644 --- a/src/ui/console_commands.cpp +++ b/src/ui/console_commands.cpp @@ -1051,6 +1051,24 @@ const std::pair COMMANDS[] = { {"clear", clear_run}, {"fix_rng_history_log", fix_rng_history_log_run}}; +// The commands' names, as RunCommand knows them. +std::vector command_names_get() +{ + std::vector names; + + for (auto [name, run] : COMMANDS) names.push_back(name); + return names; +} + +// The fixed macros' names. +std::vector macro_names_get() +{ + std::vector names; + + for (const ConsoleMacro& macro : MACROS) names.push_back(macro.name); + return names; +} + // 0068cdc0 Runs a command for a player, the first by default. Its words are split at spaces and the first picks the // command. The output goes into output when given, as Isaac.ExecuteCommand captures it, else to the console. void Console::RunCommand(std::string_view text, std::string* output, Entity_Player* player) diff --git a/src/ui/menu/key_config.cpp b/src/ui/menu/key_config.cpp index 6f12788..0c50d97 100644 --- a/src/ui/menu/key_config.cpp +++ b/src/ui/menu/key_config.cpp @@ -27,13 +27,6 @@ constexpr float COLUMN_WIDTH = 100; constexpr float RESET_CURSOR_X = 75; constexpr float RESET_CURSOR_Y = 390; -// A row of the menu: the action it binds and the string table key of its label. -struct KeyConfigRow -{ - int action; - const char* label; -}; - // How a kind of device lays the menu out: its rows, their height, and how the view scrolls past the third row // until the last scrolled row, then rests at the bottom. struct KeyConfigLayout @@ -107,6 +100,34 @@ static bool is_row_unbound(const KAGE::Input::InputDevice& device, const KeyConf return binding[SLOT_PRIMARY] == KAGE::Input::BUTTON_NONE && binding[SLOT_SECONDARY] == KAGE::Input::BUTTON_NONE; } +// The rows a device binds in the menu. +std::span key_config_rows_get(const KAGE::Input::InputDevice& device) +{ + return layout_get(device).rows; +} + +// Binds a button or key to one slot of an action in the device's config, taking it off every other row that had it. +void key_config_bind(const KAGE::Input::InputDevice& device, int action, int slot, int button) +{ + InputConfig& config = config_get(device); + + for (const KeyConfigRow& row : layout_get(device).rows) + for (int& bound : config.actions[row.action]) + if (bound == button) bound = KAGE::Input::BUTTON_NONE; + config.actions[action][slot] = button; +} + +// Puts every binding of the device's config back to the defaults for its kind. +void key_config_reset(const KAGE::Input::InputDevice& device) +{ + InputConfig& config = config_get(device); + const std::vector& defaults = + device.type == KAGE::Input::DEVICE_KEYBOARD ? platform.bindings.keyboard : platform.bindings.controller; + + for (size_t action = 0; action < config.actions.size() && action < defaults.size(); action++) + config.actions[action] = {defaults[action][SLOT_PRIMARY], defaults[action][SLOT_SECONDARY]}; +} + // Loads the menu, playing, on the first row with the view at its top, at its place on the menu sheet. Inlined in // MenuManager::Init. void Menu_KeyConfig::Init(Vector menuPosition) @@ -162,14 +183,7 @@ void Menu_KeyConfig::browse_update(KAGE::Input::InputDevice& device) if (is_menu_triggered(device, ACTION_MENU_CONFIRM)) { if (selectedElement != RESET_ROW) state = KEY_CONFIG_BINDING; - else - { - InputConfig& config = config_get(device); - const std::vector& defaults = - device.type == KAGE::Input::DEVICE_KEYBOARD ? platform.bindings.keyboard : platform.bindings.controller; - for (size_t action = 0; action < config.actions.size() && action < defaults.size(); action++) - config.actions[action] = {defaults[action][SLOT_PRIMARY], defaults[action][SLOT_SECONDARY]}; - } + else key_config_reset(device); } else if (is_menu_triggered(device, ACTION_MENU_BACK)) { @@ -192,12 +206,8 @@ void Menu_KeyConfig::binding_update(KAGE::Input::InputDevice& device) int button = device.button_triggered_get(); if (button == KAGE::Input::BUTTON_NONE || button == KAGE::Input::BUTTON_START) return; - InputConfig& config = config_get(device); state = KEY_CONFIG_BROWSING; - for (const KeyConfigRow& row : layout_get(device).rows) - for (int& slot : config.actions[row.action]) - if (slot == button) slot = KAGE::Input::BUTTON_NONE; - config.actions[ROWS[selectedElement].action][selectedColumn] = button; + key_config_bind(device, ROWS[selectedElement].action, selectedColumn, button); } // Moves to the next or previous row, the reset row after the last, wrapping, and scrolls the view to keep the row diff --git a/src/ui/menu/key_config.h b/src/ui/menu/key_config.h index c3313f0..c6df538 100644 --- a/src/ui/menu/key_config.h +++ b/src/ui/menu/key_config.h @@ -2,6 +2,7 @@ #include "engine/anm2.h" #include "engine/kage_input.h" +#include // Whether the key config menu moves between its rows or waits for the key to bind to the selected one. enum KeyConfigState : int @@ -10,6 +11,13 @@ enum KeyConfigState : int KEY_CONFIG_BINDING }; +// A row of the menu: the action it binds and the string table key of its label. +struct KeyConfigRow +{ + int action; + const char* label; +}; + // The key config menu (Menu_KeyConfig): the bindings of the device picked in the controller select, two columns of // keys for each action and a reset row, edited in that device's KeyConfigs entry and saved on leaving. // The raw joystick layouts (008da030, 008da510) are dropped, since SDL3 opens every gamepad with the standard mapping. @@ -34,3 +42,7 @@ private: void binding_update(KAGE::Input::InputDevice& device); void row_move(int step, const KAGE::Input::InputDevice& device); }; + +std::span key_config_rows_get(const KAGE::Input::InputDevice& device); +void key_config_bind(const KAGE::Input::InputDevice& device, int action, int slot, int button); +void key_config_reset(const KAGE::Input::InputDevice& device); diff --git a/src/ui/overlay/console.cpp b/src/ui/overlay/console.cpp new file mode 100644 index 0000000..5b9a9a6 --- /dev/null +++ b/src/ui/overlay/console.cpp @@ -0,0 +1,327 @@ +#include "ui/overlay/overlay.h" +#include "entity/config.h" +#include "game/game.h" +#include "game/manager.h" +#include "game/mod_manager.h" +#include "game/sfx_manager.h" +#include "ui/console.h" +#include +#include +#include +#include +#include +#include + +constexpr int MAX_SUGGESTIONS = 8; +constexpr int NO_MATCH = INT_MAX; +constexpr int RED_SHIFT = 16; +constexpr int GREEN_SHIFT = 8; +constexpr uint32_t CHANNEL_MASK = 0xff; +constexpr const char* SUGGESTIONS_WINDOW = "##suggestions"; +// Where a match starts a word, ranking it above one inside a word. +constexpr std::string_view WORD_STARTS = " _-."; +// The commands whose argument is a room path, completed a dotted part at a time. +constexpr std::string_view ROOM_COMMANDS[] = {"goto", "forceroom"}; +// The variant range goto suggests for d is a hint, not a word. +constexpr std::string_view RANGE = ".."; + +static std::string text_lower(std::string_view text) +{ + std::string lower(text); + std::ranges::transform(lower, lower.begin(), [](unsigned char c) { return (char)std::tolower(c); }); + return lower; +} + +// Whether commands can run: in a run, where the console lives. +static bool is_run_live() +{ + return g_game && g_manager->state == MANAGER_STATE_GAME; +} + +// 0 for a prefix match, 1 for a match at a word start, 2 for one anywhere, NO_MATCH for none, ignoring case. +static int match_rank(std::string_view word, std::string_view typed) +{ + std::string lower = text_lower(word); + std::string key = text_lower(typed); + size_t at = lower.find(key); + if (at == 0 || at == std::string::npos) return at == 0 ? 0 : NO_MATCH; + + for (; at != std::string::npos; at = lower.find(key, at + 1)) + if (WORD_STARTS.find(lower[at - 1]) != std::string_view::npos) return 1; + return 2; +} + +// The words the overlay completes where the original console suggests none, from the game's own data: the sounds for +// playsfx, the challenges, the characters for restart and addplayer, the macros and the mods' folders for luamod. +static void extra_entries_add(std::string_view command, std::vector& entries) +{ + auto named_add = [&](size_t id, std::string_view name) { + if (!name.empty()) entries.push_back(std::to_string(id) + ":" + std::string(name)); + }; + std::vector& sounds = g_manager->sfxManager.sounds; + std::vector& challenges = g_manager->challengeParams; + std::vector& players = g_manager->entityConfig.players; + + if (command == "playsfx") + for (size_t id = 0; id < sounds.size(); id++) named_add(id, sounds[id].name); + else if (command == "challenge") + for (size_t id = 1; id < challenges.size(); id++) named_add(id, challenges[id].name); + else if (command == "restart" || command == "addplayer") + for (size_t id = 0; id < players.size(); id++) named_add(id, players[id].name); + else if (command == "macro" || command == "m") + for (std::string_view name : macro_names_get()) entries.emplace_back(name); + else if (command == "luamod") + for (auto& mod : g_manager->modManager.mods) entries.push_back(mod->directory); +} + +// The completions of the input, found again when it changes: the command table's names for the first word, then +// what the original console suggests for the command's argument, with the overlay's own words where it suggests none. +// Each "code:name" entry completes to its code, ranked by code or name as isaac-classic ranks: prefix matches first, +// then matches at a word start, then anywhere, ties in the game's order. +void Overlay::suggestions_load() +{ + if (input == suggestedInput) return; + suggestedInput = input; + suggestions.clear(); + if (input.empty()) return; + + std::vector> ranked; + auto add = [&](std::string_view entry, std::string_view typed, std::string_view head, std::string_view tail) { + size_t colon = entry.find(':'); + std::string_view code = entry.substr(0, colon); + std::string_view name = colon == std::string_view::npos ? "" : entry.substr(colon + 1); + int rank = std::min(match_rank(code, typed), name.empty() ? NO_MATCH : match_rank(name, typed)); + std::string line = std::string(head) + std::string(code) + std::string(tail); + + if (rank != NO_MATCH && code.find(RANGE) == std::string_view::npos && text_lower(line) != text_lower(input)) + ranked.push_back({rank, {std::string(name), line}}); + }; + + size_t space = input.find(' '); + if (space == std::string::npos) + for (std::string_view name : command_names_get()) add(name, input, "", " "); + else + { + std::string_view command = std::string_view(input).substr(0, space); + size_t start = space + 1; + if (std::ranges::find(ROOM_COMMANDS, command) != std::end(ROOM_COMMANDS)) + start = std::max(start, input.rfind('.') + 1); + + std::vector entries = omnicomplete_get(input); + if (input.find(' ', space + 1) == std::string::npos) extra_entries_add(command, entries); + for (std::string& entry : entries) + add(entry, std::string_view(input).substr(start), std::string_view(input).substr(0, start), ""); + } + + std::ranges::stable_sort(ranked, {}, [](auto& entry) { return entry.first; }); + for (auto& [rank, suggestion] : ranked) suggestions.push_back(std::move(suggestion)); +} + +// A console color as the log shows it: white as ImGui's text, the echoed commands dimmed as ImGui dims, others as they +// are. +static ImVec4 line_color(uint32_t argb) +{ + if (argb == CONSOLE_WHITE) return ImGui::GetStyleColorVec4(ImGuiCol_Text); + if (argb == CONSOLE_ECHO) return ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled); + return ImGui::ColorConvertU32ToFloat4( + IM_COL32(argb >> RED_SHIFT & CHANNEL_MASK, argb >> GREEN_SHIFT & CHANNEL_MASK, argb & CHANNEL_MASK, UINT8_MAX)); +} + +// The console's own output, oldest line first, wrapped at the window's edge. A new command, or a log already at its +// end, keeps the end in view. +void Overlay::log_render() +{ + ImGui::BeginChild("log", {0, -ImGui::GetFrameHeightWithSpacing()}); + ImGui::PushTextWrapPos(0); + if (g_game) + { + std::deque& history = g_game->console.history; + for (auto line = history.rbegin(); line != history.rend(); line++) + { + if (line->text.empty() && &*line == &history.front()) continue; + ImGui::PushStyleColor(ImGuiCol_Text, line_color(line->color)); + ImGui::TextUnformatted(line->text.data(), line->text.data() + line->text.size()); + ImGui::PopStyleColor(); + } + } + ImGui::PopTextWrapPos(); + if (std::exchange(isScrollPending, false) || ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) + ImGui::SetScrollHereY(1); + ImGui::EndChild(); +} + +// The log above the input. Enter runs the line through the console as its own Enter does: recorded in its command +// history, echoed, then run. Commands wait for a run, as the console does. +void Overlay::console_render() +{ + constexpr ImGuiInputTextFlags FLAGS = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit | + ImGuiInputTextFlags_CallbackCompletion | + ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways; + bool isLive = is_run_live(); + // The input keeps the keyboard while the window has it, as when Escape let go of it. Repeated until it lands. + bool isIdle = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && !ImGui::IsAnyItemActive(); + isFocusPending = isLive && (isFocusPending || isIdle); + + log_render(); + ImGui::SetNextItemWidth(-FLT_MIN); + if (isFocusPending) ImGui::SetKeyboardFocusHere(); + + // While the list shows, it owns its keys so the input neither reverts on Escape nor submits a highlighted row. A + // claim outlives its frame, so keys the list no longer wants are handed back. + listId = ImGui::GetID(SUGGESTIONS_WINDOW); + bool isBrowsing = isListShown && selected >= 0; + for (auto [key, isClaimed] : {std::pair{ImGuiKey_Escape, isListShown}, + {ImGuiKey_PageUp, isListShown}, + {ImGuiKey_PageDown, isListShown}, + {ImGuiKey_Home, isBrowsing}, + {ImGuiKey_End, isBrowsing}, + {ImGuiKey_Enter, isBrowsing}, + {ImGuiKey_KeypadEnter, isBrowsing}}) + if (isClaimed || ImGui::GetKeyOwner(key) == listId) + ImGui::SetKeyOwner(key, isClaimed ? listId : ImGuiKeyOwner_NoOwner); + + // ImGui repeats Enter while it is held: only a fresh press runs a line, and an empty one runs nothing. + bool isEnterFresh = ImGui::IsKeyPressed(ImGuiKey_Enter, false) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter, false); + ImGui::BeginDisabled(!isLive); + bool isEntered = ImGui::InputTextWithHint("##input", isLive ? "**Type a command" : "**Commands run during a run", + &input, FLAGS, input_respond, this); + ImGui::EndDisabled(); + if (isEntered && isLive) + { + if (isEnterFresh && !input.empty()) + { + Console& console = g_game->console; + console.input = std::exchange(input, {}); + console.input_submit(); + isScrollPending = true; + } + ImGui::SetKeyboardFocusHere(-1); // Enter lets go of the input: keep typing there. + } + + bool isInputActive = ImGui::IsItemActive(); + isFocusPending = isFocusPending && !isInputActive; + if (isLive && g_game->console.commandCursor == 0) suggestions_load(); + else + { + suggestedInput.clear(); + suggestions.clear(); + } + selected = std::min(selected, (int)suggestions.size() - 1); + // A click on the list takes focus from the input, so a hovered list stays up until the click lands. + isListShown = !suggestions.empty() && !isDismissed && (isInputActive || isListHovered); + if (isListShown) suggestions_render(); +} + +// The greyed rest of the highlighted (or first) suggestion after the typed text, and the list under the input, or +// above it where the display ends first. +void Overlay::suggestions_render() +{ + constexpr ImGuiWindowFlags LIST_FLAGS = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | + ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDocking; + ImVec2 origin = ImGui::GetItemRectMin(); + ImVec2 size = ImGui::GetItemRectSize(); + const std::string& shown = suggestions[std::max(selected, 0)].line; + int count = (int)suggestions.size(); + + bool isContinued = shown.size() > input.size() && text_lower(shown.substr(0, input.size())) == text_lower(input); + if (ImGui::IsItemActive() && isContinued) + { + ImVec2 padding = ImGui::GetStyle().FramePadding; + ImGui::GetWindowDrawList()->AddText({origin.x + padding.x + ImGui::CalcTextSize(input.c_str()).x, + origin.y + padding.y}, + ImGui::GetColorU32(ImGuiCol_TextDisabled), shown.c_str() + input.size()); + } + + float rowHeight = ImGui::GetTextLineHeightWithSpacing(); + float height = (float)std::min(count, MAX_SUGGESTIONS) * rowHeight + ImGui::GetStyle().WindowPadding.y * 2; + float below = origin.y + size.y; + ImGui::SetNextWindowPos({origin.x, below + height > ImGui::GetIO().DisplaySize.y ? origin.y - height : below}); + ImGui::SetNextWindowSize({size.x, height}); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {ImGui::GetStyle().ItemSpacing.x, 0}); + ImGui::Begin(SUGGESTIONS_WINDOW, nullptr, LIST_FLAGS); + ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); + isListHovered = ImGui::IsWindowHovered(); + + ImGuiListClipper clipper; + clipper.Begin(count, rowHeight); + if (selected >= 0) clipper.IncludeItemByIndex(selected); + while (clipper.Step()) + for (int index = clipper.DisplayStart; index < clipper.DisplayEnd; index++) + { + ImGui::PushID(index); + if (ImGui::Selectable(suggestions[index].line.c_str(), index == selected, 0, {0, rowHeight})) + { + input = suggestions[index].line; + selected = -1; + isFocusPending = isCursorEndPending = true; + } + if (index == selected && std::exchange(isSelectionScrollPending, false)) ImGui::SetScrollHereY(); + ImGui::SameLine(); + ImGui::TextDisabled("%s", suggestions[index].descriptor.c_str()); + ImGui::PopID(); + } + + ImGui::End(); + ImGui::PopStyleVar(); +} + +// Up and Down (and PageUp, PageDown, Home and End once a row is highlighted) move through the suggestions, or walk the +// console's command history as its own Up and Down do when there are none. Tab, Right at the end, or Enter on a +// highlighted row accept one. Escape hides the list until the next edit. +int Overlay::input_respond(ImGuiInputTextCallbackData* data) +{ + Overlay& self = *(Overlay*)data->UserData; + auto text_set = [&](const std::string& text) { + data->DeleteChars(0, data->BufTextLen); + data->InsertChars(0, text.c_str()); + }; + auto is_pressed = [&](ImGuiKey key) { return ImGui::IsKeyPressed(key, ImGuiInputFlags_Repeat, self.listId); }; + auto select = [&](int index) { + self.selected = index; + self.isSelectionScrollPending = true; + }; + int count = self.isListShown ? (int)self.suggestions.size() : 0; + bool isAccepted = data->EventFlag == ImGuiInputTextFlags_CallbackCompletion || + (data->EventFlag == ImGuiInputTextFlags_CallbackAlways && + ((ImGui::IsKeyPressed(ImGuiKey_RightArrow) && data->CursorPos == data->BufTextLen) || + is_pressed(ImGuiKey_Enter) || is_pressed(ImGuiKey_KeypadEnter))); + + if (data->EventFlag == ImGuiInputTextFlags_CallbackEdit) + { + g_game->console.commandCursor = 0; + self.selected = -1; + self.isDismissed = false; + } + else if (std::exchange(self.isCursorEndPending, false)) + data->CursorPos = data->SelectionStart = data->SelectionEnd = data->BufTextLen; + else if (isAccepted && count > 0) + { + text_set(self.suggestions[std::max(self.selected, 0)].line); + self.selected = -1; + } + else if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory && count > 0) + { + bool isUp = data->EventKey == ImGuiKey_UpArrow; + select(((self.selected < 0 && isUp ? 0 : self.selected) + (isUp ? count - 1 : 1)) % count); + } + else if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory) + { + std::deque& history = g_game->console.commandHistory; + int& cursor = g_game->console.commandCursor; + + if (data->EventKey == ImGuiKey_UpArrow && cursor != (int)history.size()) text_set(history[cursor++]); + else if (data->EventKey == ImGuiKey_DownArrow) + text_set(cursor == 0 || --cursor == 0 ? std::string() : history[cursor - 1]); + } + else if (count > 0 && is_pressed(ImGuiKey_Escape)) self.isDismissed = true; + else if (count > 0 && (is_pressed(ImGuiKey_PageUp) || is_pressed(ImGuiKey_PageDown))) + { + int step = is_pressed(ImGuiKey_PageUp) ? -MAX_SUGGESTIONS : MAX_SUGGESTIONS; + select(std::clamp(self.selected + step, 0, count - 1)); + } + else if (count > 0 && (is_pressed(ImGuiKey_Home) || is_pressed(ImGuiKey_End))) + select(is_pressed(ImGuiKey_Home) ? 0 : count - 1); + return 0; +} diff --git a/src/ui/overlay/debug.cpp b/src/ui/overlay/debug.cpp new file mode 100644 index 0000000..fbf951b --- /dev/null +++ b/src/ui/overlay/debug.cpp @@ -0,0 +1,42 @@ +#include "ui/overlay/overlay.h" +#include "game/game.h" +#include "game/manager.h" +#include "ui/console.h" +#include + +// Splits a console suggestion "value:name" into its value and name. +static std::pair suggestion_split(std::string_view entry) +{ + size_t colon = entry.find(':'); + return {std::string(entry.substr(0, colon)), std::string(entry.substr(colon + 1))}; +} + +// The run's debug state the console sets: each flag the debug command toggles, by the name the console suggests it by, +// and the curses the curse command forces on floors. A box runs that command, so it does exactly what typing it does. +void Overlay::debug_render() +{ + if (!g_game || g_manager->state != MANAGER_STATE_GAME) + { + ImGui::TextDisabled("**Debug flags and curses belong to a run."); + return; + } + + Game& game = *g_game; + ImGui::SeparatorText("Debug flags"); + for (std::string_view entry : DEBUG_FLAG_SUGGESTIONS) + { + auto [number, name] = suggestion_split(entry); + bool isOn = game.debugFlags >> (std::stoi(number) - 1) & 1; + if (ImGui::Checkbox((number + " " + name).c_str(), &isOn)) game.console.RunCommand("debug " + number); + } + + ImGui::SeparatorText("Curses"); + for (std::string_view entry : CURSE_SUGGESTIONS) + { + auto [value, name] = suggestion_split(entry); + uint32_t curse = (uint32_t)std::stoul(value); + bool isOn = curse ? (game.debugCurses & curse) != 0 : game.debugCurses == 0; + if (ImGui::Checkbox(name.c_str(), &isOn)) + game.console.RunCommand("curse " + std::to_string(curse ? game.debugCurses ^ curse : 0)); + } +} diff --git a/src/ui/overlay/game_options.cpp b/src/ui/overlay/game_options.cpp new file mode 100644 index 0000000..8d85f57 --- /dev/null +++ b/src/ui/overlay/game_options.cpp @@ -0,0 +1,288 @@ +#include "ui/overlay/overlay.h" +#include "game/game.h" +#include "game/key_configs.h" +#include "game/manager.h" +#include "game/options_config.h" +#include "game/sfx_manager.h" +#include "game/string_table.h" +#include "ui/hud.h" +#include "ui/menu/key_config.h" +#include +#include + +constexpr float WIDGET_FONT_SIZES = 14; // A widget's width beside its label, in font sizes. +constexpr int KEY_COLUMNS = 3; +constexpr ImVec4 UNBOUND_COLOR = {0.8f, 0.2f, 0.2f, 1}; // The key config menu's red for an action with no key. + +// The window's tabs, Controls last. +enum OptionsTab +{ + OPTIONS_TAB_AUDIO, + OPTIONS_TAB_VIDEO, + OPTIONS_TAB_HUD, + OPTIONS_TAB_GAMEPLAY, + OPTIONS_TAB_CONSOLE, + OPTIONS_TAB_ONLINE, + OPTIONS_TAB_SYSTEM, + OPTIONS_TAB_COUNT +}; + +constexpr const char* OPTIONS_TAB_NAMES[OPTIONS_TAB_COUNT] = {"Audio", "Video", "HUD", "Gameplay", + "Console", "Online", "System"}; + +// Where an options.ini setting sits: its tab and label, the range of a number (a slider when it has one, else typed), +// and for a choice its labels, each standing for min plus its index. +struct OptionSpec +{ + std::string_view key; + const char* label; + OptionsTab tab; + float min = 0; + float max = 0; + const char* choices = nullptr; +}; + +constexpr OptionSpec OPTION_SPECS[] = { + {"SFXVolume", "SFX volume", OPTIONS_TAB_AUDIO, 0, 1}, + {"AnnouncerVoiceMode", "Announcer voice", OPTIONS_TAB_AUDIO, 0, 2, "Random\0Never\0Always\0"}, + {"AscentVoiceOver", "Ascent voice over", OPTIONS_TAB_AUDIO}, + {"Fullscreen", "Fullscreen", OPTIONS_TAB_VIDEO}, + {"UseExclusiveFullscreen", "Exclusive fullscreen", OPTIONS_TAB_VIDEO}, + {"VSync", "VSync", OPTIONS_TAB_VIDEO}, + {"Filter", "Filter", OPTIONS_TAB_VIDEO}, + {"Gamma", "Gamma", OPTIONS_TAB_VIDEO, 0.5f, 1.5f}, + {"Exposure", "Exposure", OPTIONS_TAB_VIDEO, 0, 2}, + {"MaxScale", "Max scale", OPTIONS_TAB_VIDEO, 1, DEFAULT_MAX_SCALE}, + {"MaxRenderScale", "Max render scale", OPTIONS_TAB_VIDEO, 1, DEFAULT_MAX_SCALE}, + {"WindowWidth", "Window width", OPTIONS_TAB_VIDEO}, + {"WindowHeight", "Window height", OPTIONS_TAB_VIDEO}, + {"WindowPosX", "Window x", OPTIONS_TAB_VIDEO}, + {"WindowPosY", "Window y", OPTIONS_TAB_VIDEO}, + {"HudOffset", "HUD offset", OPTIONS_TAB_HUD, 0, 1}, + {"MapOpacity", "Map opacity", OPTIONS_TAB_HUD, 0, 1}, + {"ShowRecentItems", "Recent items", OPTIONS_TAB_HUD, 0, 2, "Off\0On\0Mini\0"}, + {"PopUps", "Pop-ups", OPTIONS_TAB_HUD, 0, 2, "Off\0Large\0Small\0"}, + {"FoundHUD", "Found HUD", OPTIONS_TAB_HUD}, + {"ChargeBars", "Charge bars", OPTIONS_TAB_HUD}, + {"BulletVisibility", "Bullet visibility", OPTIONS_TAB_HUD}, + {"BossHpOnBottom", "Boss HP at bottom", OPTIONS_TAB_HUD}, + {"ItemInfoDisplayEnabled", "Item descriptions", OPTIONS_TAB_HUD}, + {"CameraStyle", "Camera", OPTIONS_TAB_GAMEPLAY, 1, 2, "Active\0Fixed\0"}, + {"JacobEsauControls", "Jacob & Esau controls", OPTIONS_TAB_GAMEPLAY, 0, 1}, + {"AimLock", "Aim lock", OPTIONS_TAB_GAMEPLAY}, + {"MouseControl", "Mouse control", OPTIONS_TAB_GAMEPLAY}, + {"TouchMode", "Touch mode", OPTIONS_TAB_GAMEPLAY}, + {"RumbleEnabled", "Rumble", OPTIONS_TAB_GAMEPLAY}, + {"ControllerHotplug", "Controller hotplug", OPTIONS_TAB_GAMEPLAY}, + {"PauseOnFocusLost", "Pause on focus lost", OPTIONS_TAB_GAMEPLAY}, + {"EnableDebugConsole", "Debug console", OPTIONS_TAB_CONSOLE}, + {"ConsoleFont", "Console font", OPTIONS_TAB_CONSOLE, 0, 2, "Default\0Small\0Tiny\0"}, + {"FadedConsoleDisplay", "Faded console display", OPTIONS_TAB_CONSOLE}, + {"SaveCommandHistory", "Save command history", OPTIONS_TAB_CONSOLE}, + {"OnlineHud", "Online HUD", OPTIONS_TAB_ONLINE, 0, 3}, + {"StreamerMode", "Streamer mode", OPTIONS_TAB_ONLINE}, + {"OnlinePlayerVolume", "Player volume", OPTIONS_TAB_ONLINE, 0, ONLINE_LEVEL_MAX}, + {"OnlinePlayerOpacity", "Player opacity", OPTIONS_TAB_ONLINE, 0, ONLINE_LEVEL_MAX}, + {"OnlineChatEnabled", "Chat", OPTIONS_TAB_ONLINE}, + {"OnlineChatFilterEnabled", "Chat filter", OPTIONS_TAB_ONLINE}, + {"MultiplayerColorSet", "Player colors", OPTIONS_TAB_ONLINE, 0, 3}, + {"OnlineInputDelay", "Input delay", OPTIONS_TAB_ONLINE, 1, 5}, + {"EosCrossplay", "Crossplay", OPTIONS_TAB_ONLINE}, + {"EnableEpicOverlay", "Epic overlay", OPTIONS_TAB_ONLINE}, + {"EnableMods", "Mods", OPTIONS_TAB_SYSTEM}, + {"SteamCloud", "Steam Cloud", OPTIONS_TAB_SYSTEM}, + {"TryImportSave", "Import save", OPTIONS_TAB_SYSTEM}, + {"AcceptedPublicBeta_v1.9.7.17", "Public beta accepted", OPTIONS_TAB_SYSTEM}, + {"AcceptedDataCollectionDisclaimer", "Data collection accepted", OPTIONS_TAB_SYSTEM}}; + +static const OptionSpec* spec_find(std::string_view key) +{ + for (const OptionSpec& spec : OPTION_SPECS) + if (spec.key == key) return &spec; + return nullptr; +} + +// Applies a changed setting the way the game's Options menu, its Lua Options and options.ini's loader apply it. +// Anything else the game reads as it goes. +static void option_apply(std::string_view key) +{ + OptionsConfig& config = g_manager->optionsConfig; + + if (key == "SFXVolume") g_manager->sfxManager.ClearVolumeModifier(); + else if (key == "Fullscreen" || key == "UseExclusiveFullscreen" || key == "WindowWidth" || key == "WindowHeight") + window_apply(config, WINDOW_FULLSCREEN); + else if (key == "WindowPosX" || key == "WindowPosY") window_apply(config, WINDOW_POSITION); + else if (key == "VSync") window_apply(config, WINDOW_VSYNC); + else if (key == "MouseControl") window_apply(config, WINDOW_CURSOR); + else if (key == "ShowRecentItems" && g_game && g_manager->state == MANAGER_STATE_GAME) + g_game->hud.mark_all_slots_dirty(HISTORY_REBUILD_ICONS, HISTORY_KEEP_ITEMS); + else if (key == "ConsoleFont" && g_game) g_game->console.lines_wrap(); +} + +// A setting's widget by its type: a checkbox, a slider within its range, a choice's combo, or a typed number that +// applies on Enter. Whether it changed. +template static bool is_option_edited(const OptionSpec& spec, T& value) +{ + if constexpr (std::is_same_v) return ImGui::Checkbox(spec.label, &value); + else if constexpr (std::is_same_v) + return ImGui::SliderFloat(spec.label, &value, spec.min, spec.max, "%.2f", ImGuiSliderFlags_AlwaysClamp); + else + { + int number = (int)value; + int index = number - (int)spec.min; + bool isEdited = false; + + if (spec.choices) + { + isEdited = ImGui::Combo(spec.label, &index, spec.choices); + number = index + (int)spec.min; + } + else if (spec.max > spec.min) + isEdited = ImGui::SliderInt(spec.label, &number, (int)spec.min, (int)spec.max, "%d", + ImGuiSliderFlags_AlwaysClamp); + else isEdited = ImGui::InputInt(spec.label, &number, 1, 1, ImGuiInputTextFlags_EnterReturnsTrue); + if (isEdited) value = (T)number; + return isEdited; + } +} + +// Every setting options.ini holds, a tab each by subject, then the key bindings. A change applies at once and is saved +// to options.ini as the game saves it, once no widget is held. +void Overlay::options_render() +{ + OptionsConfig& config = g_manager->optionsConfig; + if (!ImGui::BeginTabBar("##tabs")) return; + + for (int tab = 0; tab < OPTIONS_TAB_COUNT; tab++) + { + if (!ImGui::BeginTabItem(OPTIONS_TAB_NAMES[tab])) continue; + ImGui::PushItemWidth(ImGui::GetFontSize() * WIDGET_FONT_SIZES); + if (tab == OPTIONS_TAB_AUDIO) + { + float music = config.musicVolume; + if (ImGui::SliderFloat("Music volume", &music, 0, 1, "%.2f", ImGuiSliderFlags_AlwaysClamp)) + { + config.SetMusicVolume(music); + isOptionsSavePending = true; + } + ImGui::SetItemTooltip("options.ini: MusicVolume, MusicEnabled"); + } + if (tab == OPTIONS_TAB_SYSTEM) + { + std::string language(Manager::GetLanguage()); + ImGui::TextDisabled("Language: %s (read only)", language.c_str()); + } + + options_visit(config, [&](const char* key, auto& value) { + const OptionSpec* spec = spec_find(key); + if (!spec || spec->tab != tab) return; + + ImGui::PushID(key); + if (is_option_edited(*spec, value)) + { + option_apply(key); + isOptionsSavePending = true; + } + ImGui::SetItemTooltip("options.ini: %s", key); + ImGui::PopID(); + }); + if (tab == OPTIONS_TAB_CONSOLE) + ImGui::TextDisabled("**The overlay's console works whatever these say. They drive the original's."); + ImGui::PopItemWidth(); + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Controls")) + { + controls_render(); + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); + + if (!isOptionsSavePending || ImGui::IsAnyItemActive()) return; + config.Save(); + isOptionsSavePending = false; +} + +// A control waiting for its binding takes the next key press, or the next button press on the gamepad being bound, as +// the key config menu binds it (start excluded). Escape leaves it as it was. Whether the event went to it. +bool Overlay::is_binding_taken(const SDL_Event& event) +{ + std::shared_ptr device = KAGE::Input::manager.device_find(bindingDevice); + bool isKey = event.type == SDL_EVENT_KEY_DOWN; + bool isButton = event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN; + int button = KAGE::Input::BUTTON_NONE; + + if (!device || (isKey && event.key.scancode == SDL_SCANCODE_ESCAPE)) + { + bindingAction = -1; + return isKey; + } + if (isKey && device->type == KAGE::Input::DEVICE_KEYBOARD) + button = KAGE::Input::key_from_scancode(event.key.scancode); + else if (isButton && device->gamepad && device->joystick == event.gbutton.which) + button = KAGE::Input::button_from_gamepad((SDL_GamepadButton)event.gbutton.button); + + if (button != KAGE::Input::BUTTON_NONE && button != KAGE::Input::BUTTON_START) + { + key_config_bind(*device, bindingAction, bindingSlot, button); + g_manager->keyConfigs.SaveButtonMaps(); + bindingAction = -1; + } + return isKey || isButton; +} + +// Each device's rows of the key config menu, both keys of each a button that waits for the next press, saved to +// inputconfigs.dat as the menu saves them. An action left with no key is red, as in the menu. +void Overlay::controls_render() +{ + for (std::shared_ptr& device : KAGE::Input::manager.devices) + { + ImGui::PushID(device->id); + if (!ImGui::CollapsingHeader(device->name.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) + { + ImGui::PopID(); + continue; + } + + if (ImGui::BeginTable("##keys", KEY_COLUMNS, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerH)) + { + for (const char* column : {"Action", "Primary", "Secondary"}) ImGui::TableSetupColumn(column); + ImGui::TableHeadersRow(); + for (const KeyConfigRow& row : key_config_rows_get(*device)) + { + ActionBinding binding = g_manager->keyConfigs.binding_get(*device, row.action); + bool isUnbound = binding[0] == KAGE::Input::BUTTON_NONE && binding[1] == KAGE::Input::BUTTON_NONE; + + ImGui::PushID(row.action); + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (isUnbound) ImGui::PushStyleColor(ImGuiCol_Text, UNBOUND_COLOR); + ImGui::TextUnformatted(std::string(string_table_translate(g_manager->stringTable, row.label)).c_str()); + if (isUnbound) ImGui::PopStyleColor(); + for (int slot = 0; slot < CONFIG_SLOTS; slot++) + { + bool isWaiting = bindingAction == row.action && bindingDevice == device->id && bindingSlot == slot; + std::string name(device->button_name(binding[slot])); + + ImGui::TableNextColumn(); + ImGui::PushID(slot); + if (ImGui::Button(isWaiting ? "Press a key" : name.c_str(), {-FLT_MIN, 0})) + { + bindingAction = row.action; + bindingDevice = device->id; + bindingSlot = slot; + } + ImGui::PopID(); + } + ImGui::PopID(); + } + ImGui::EndTable(); + } + if (ImGui::Button("Reset to defaults")) + { + key_config_reset(*device); + g_manager->keyConfigs.SaveButtonMaps(); + } + ImGui::PopID(); + } +} diff --git a/src/ui/overlay/mods.cpp b/src/ui/overlay/mods.cpp new file mode 100644 index 0000000..f3d0a01 --- /dev/null +++ b/src/ui/overlay/mods.cpp @@ -0,0 +1,198 @@ +#include "ui/overlay/overlay.h" +#include "engine/data.h" +#include "engine/gl.h" +#include "engine/platform.h" +#include "game/manager.h" +#include "game/mod_manager.h" +#include "stb_image.h" +#include "ui/menu/manager.h" +#include +#include + +constexpr float MOD_THUMBNAIL = 144; // A card's smallest thumbnail side, in Unifont pixels. +constexpr int MOD_BLURB_LINES = 4; // The description's room on a card. Longer ones scroll. +constexpr float MOD_TOOLTIP_COLUMNS = 32; // The tooltip's wrap width, in font sizes. +constexpr const char* MODS_FOLDER = "mods/"; +constexpr const char* THUMBNAIL_FILE = "/thumb.png"; +constexpr const char* NO_THUMBNAIL = "No Thumbnail"; +constexpr const char* RELOAD = "Reload"; +constexpr const char* VIEWS[] = {"Thumbnail", "Compact"}; + +// The mod's thumb.png as a texture, loaded once. 0 when it has none or it will not load. +unsigned int Overlay::thumbnail_get(ModEntry& mod) +{ + std::string path = resource_path(MODS_FOLDER + mod.directory + THUMBNAIL_FILE); + auto found = thumbnails.find(path); + if (found != thumbnails.end()) return found->second; + + unsigned int texture = 0; + int bound = 0; + int channels = 0; + int height = 0; + int width = 0; + if (stbi_uc* pixels = stbi_load(path.c_str(), &width, &height, &channels, STBI_rgb_alpha)) + { + gl.GetIntegerv(GL_TEXTURE_BINDING_2D, &bound); + gl.GenTextures(1, &texture); + gl.BindTexture(GL_TEXTURE_2D, texture); + gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + gl.BindTexture(GL_TEXTURE_2D, bound); + stbi_image_free(pixels); + } + return thumbnails[path] = texture; +} + +// Text cut to width with an ellipsis. +static std::string text_fit(std::string text, float width) +{ + constexpr const char* ELLIPSIS = "..."; + + if (ImGui::CalcTextSize(text.c_str()).x <= width) return text; + while (!text.empty() && ImGui::CalcTextSize((text + ELLIPSIS).c_str()).x > width) text.pop_back(); + return text + ELLIPSIS; +} + +// Turns a mod on or off as the Mods menu does, through its disable.it, for the next Reload. +static void mod_toggle(ModEntry& mod, bool& isModsChanged) +{ + mod.isEnabled = !mod.isEnabled; + mod.disable_marker_save(); + isModsChanged = true; +} + +// The mod's whole metadata, shown while its card or line is hovered. +static void mod_tooltip_render(ModEntry& mod) +{ + if (!ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort) || !ImGui::BeginTooltip()) return; + + ImGui::PushTextWrapPos(MOD_TOOLTIP_COLUMNS * ImGui::GetFontSize()); + ImGui::TextUnformatted(mod.name.c_str()); + ImGui::TextDisabled("Version %s, folder %s", mod.metadataVersion.c_str(), mod.directory.c_str()); + ImGui::Separator(); + ImGui::TextDisabled("%s", mod.metadataDescription.c_str()); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); +} + +// The mod as a card width wide: its square thumbnail, name and version, scrolling description, and the checkbox that +// turns it on. A mod that is off is greyed, and an outdated one says so. +void Overlay::mod_render(ModEntry& mod, float width) +{ + const ImGuiStyle& style = ImGui::GetStyle(); + float side = width - style.WindowPadding.x * 2; + float line = ImGui::GetTextLineHeightWithSpacing(); + float height = side + line * (2 + MOD_BLURB_LINES) + ImGui::GetFrameHeight() + style.WindowPadding.y * 2 + + style.ItemSpacing.y * 2; + bool isGreyed = !mod.isEnabled; + + ImGui::PushID(mod.directory.c_str()); + if (isGreyed) ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_FrameBg)); + ImGui::BeginChild("##mod", {width, height}, ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollbar); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, isGreyed ? style.DisabledAlpha : 1); + + if (unsigned int texture = thumbnail_get(mod)) ImGui::Image((ImTextureID)texture, {side, side}); + else + { + ImVec2 corner = ImGui::GetCursorScreenPos(); + float wrap = side - style.FramePadding.x * 2; + ImVec2 label = ImGui::CalcTextSize(NO_THUMBNAIL, nullptr, false, wrap); + ImDrawList* draw = ImGui::GetWindowDrawList(); + + draw->AddRectFilled(corner, {corner.x + side, corner.y + side}, ImGui::GetColorU32(ImGuiCol_Button)); + draw->AddText(nullptr, 0, {corner.x + (side - label.x) / 2, corner.y + (side - label.y) / 2}, + ImGui::GetColorU32(ImGuiCol_TextDisabled), NO_THUMBNAIL, nullptr, wrap); + ImGui::Dummy({side, side}); + } + + ImGui::TextUnformatted(mod.name.c_str()); + ImGui::TextDisabled("%s%s", mod.metadataVersion.c_str(), mod.isOutdated ? " [Old]" : ""); + ImGui::BeginChild("##blurb", {side, line * MOD_BLURB_LINES}, ImGuiChildFlags_None, ImGuiWindowFlags_NoScrollbar); + ImGui::PushTextWrapPos(0); + ImGui::TextDisabled("%s", mod.metadataDescription.c_str()); + ImGui::PopTextWrapPos(); + ImGui::EndChild(); + ImGui::PopStyleVar(); + + bool isOn = mod.isEnabled; + if (ImGui::Checkbox("On", &isOn)) mod_toggle(mod, isModsChanged); + ImGui::EndChild(); + + mod_tooltip_render(mod); + if (isGreyed) ImGui::PopStyleColor(); + ImGui::PopID(); +} + +// The mods ModManager found, as cards or a line each, then a strip with the switch for every mod (the Mods menu's tab), +// the view, and Reload. Reload does what leaving the Mods menu after a change does, so it waits for the menus. +void Overlay::mods_render() +{ + const ImGuiStyle& style = ImGui::GetStyle(); + std::vector>& mods = g_manager->modManager.mods; + bool& isModsEnabled = g_manager->optionsConfig.isModsEnabled; + float stripHeight = ImGui::GetFrameHeight() + style.WindowPadding.y * 2 + style.ItemSpacing.y; + + ImGui::BeginChild("##mods", {0, -stripHeight}); + if (mods.empty()) ImGui::TextDisabled("**No mods in %s", platform.modsDirectory.c_str()); + ImGui::BeginDisabled(!isModsEnabled); + if (modsView == MODS_VIEW_COMPACT) + for (std::unique_ptr& mod : mods) + { + bool isOn = mod->isEnabled; + ImGui::PushID(mod->directory.c_str()); + if (ImGui::Checkbox("##on", &isOn)) mod_toggle(*mod, isModsChanged); + ImGui::SameLine(); + ImGui::TextUnformatted(mod->name.c_str()); + mod_tooltip_render(*mod); + ImGui::SameLine(); + ImGui::TextDisabled("%s%s", mod->metadataVersion.c_str(), mod->isOutdated ? " [Old]" : ""); + ImGui::PopID(); + } + else + { + // As many cards to a row as fit at their smallest, stretched together to fill the row. + float space = ImGui::GetContentRegionAvail().x; + float gap = style.ItemSpacing.x; + float smallest = MOD_THUMBNAIL * scale + style.WindowPadding.x * 2; + int columns = std::max(1, (int)((space + gap) / (smallest + gap))); + float width = std::max(smallest, (space - gap * (float)(columns - 1)) / (float)columns); + + for (size_t index = 0; index < mods.size(); index++) + { + if (index % columns != 0) ImGui::SameLine(); + mod_render(*mods[index], width); + } + } + ImGui::EndDisabled(); + ImGui::EndChild(); + + ImGui::BeginChild("##strip", {0, 0}, ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollbar); + if (ImGui::Checkbox("Mods on", &isModsEnabled)) + { + isModsChanged = true; + g_manager->optionsConfig.Save(); + } + for (int view = 0; view < (int)std::size(VIEWS); view++) + { + ImGui::SameLine(); + ImGui::RadioButton(VIEWS[view], (int*)&modsView, view); + } + + bool isMenu = g_menuManager && g_manager->state == MANAGER_STATE_MENU; + float reloadLeft = ImGui::GetContentRegionMax().x - ImGui::CalcTextSize(RELOAD).x - style.FramePadding.x * 2; + ImGui::SameLine(); + ImGui::AlignTextToFramePadding(); + std::string hint = isMenu ? "**Changes apply on Reload" : "**Reload from the main menu"; + ImGui::TextDisabled("%s", text_fit(hint, reloadLeft - ImGui::GetCursorPosX() - style.ItemSpacing.x).c_str()); + ImGui::SameLine(reloadLeft); + ImGui::BeginDisabled(!isModsChanged || !isMenu); + if (ImGui::Button(RELOAD)) + { + g_manager->modManager.Reset(); + if (g_manager->currentSaveSlot != 0) g_manager->LoadGameState(g_manager->currentSaveSlot); + isModsChanged = false; + } + ImGui::EndDisabled(); + ImGui::EndChild(); +} diff --git a/src/ui/overlay/overlay.cpp b/src/ui/overlay/overlay.cpp new file mode 100644 index 0000000..c78faae --- /dev/null +++ b/src/ui/overlay/overlay.cpp @@ -0,0 +1,238 @@ +// The developer overlay, ported from isaac-classic's (src/overlay/) to Repentance+'s console, options and mods. +#include "ui/overlay/overlay.h" +#include "engine/data.h" +#include "engine/gl.h" +#include "engine/platform.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr float FONT_PIXELS = 16; // Unifont's pixel grid: whole multiples of it stay crisp. +constexpr float SCALE_HEIGHT = 540; // Display height per font multiple (the game's 960x540 window). +constexpr float ICON_PIXELS = 13; // Font Awesome glyphs sized and lowered to sit on Unifont's text. +constexpr float ICON_DROP = 1; +constexpr float DOCK_MARGIN = 16; +constexpr float DOCK_WIDTH_SHARE = .6f; +constexpr float DOCK_HEIGHT_SHARE = .6f; +constexpr const char* UNIFONT = "fonts/unifont-15.1.04.otf"; +constexpr const char* ICON_FONT = "fonts/Font Awesome 6 Free-Solid-900.otf"; +constexpr const char* LAYOUT_FILE = "overlay.ini"; +// The OpenGL 3 backend's shaders for the game's OpenGL 2 context. +constexpr const char* GLSL_VERSION = "#version 120"; + +// The Font Awesome icons the overlay draws, merged into Unifont's atlas. +constexpr ImWchar ICON_HIDE = 0xF104; // angle-left +constexpr ImWchar ICON_TOOLS = 0xF7D9; // screwdriver-wrench +constexpr ImWchar ICON_TERMINAL = 0xF120; +constexpr ImWchar ICON_GEARS = 0xF085; +constexpr ImWchar ICON_SPARKLES = 0xE2CA; // wand-magic-sparkles +constexpr ImWchar ICON_BUG = 0xF188; +constexpr ImWchar ICON_RANGES[] = {ICON_GEARS, ICON_GEARS, ICON_HIDE, ICON_HIDE, ICON_TERMINAL, + ICON_TERMINAL, ICON_TOOLS, ICON_TOOLS, ICON_BUG, ICON_BUG, + ICON_SPARKLES, ICON_SPARKLES, 0}; + +// Each window's name and icon, in OverlayWindow order. +constexpr const char* WINDOW_NAMES[OVERLAY_WINDOW_COUNT] = {"Console", "Game Options", "Mods", "Debug"}; +constexpr ImWchar WINDOW_ICONS[OVERLAY_WINDOW_COUNT] = {ICON_TERMINAL, ICON_GEARS, ICON_SPARKLES, ICON_BUG}; + +Overlay overlay; + +// An icon, then text after a space when there is any. +static std::string icon_label(ImWchar icon, const std::string& text = {}) +{ + char glyph[5]; + ImTextCharToUtf8(glyph, icon); + return text.empty() ? glyph : glyph + (" " + text); +} + +// ImGui's dark scheme with roomier metrics and square corners, titles centred, at a whole multiple of Unifont's pixel +// size. +static void style_load(float scale) +{ + ImGuiStyle& style = ImGui::GetStyle(); + style = ImGuiStyle(); + + style.WindowPadding = {8, 8}; + style.FramePadding = {6, 4}; + style.ItemSpacing = {8, 6}; + style.ItemInnerSpacing = {6, 4}; + style.WindowRounding = style.ChildRounding = style.PopupRounding = style.FrameRounding = style.GrabRounding = + style.ScrollbarRounding = style.TabRounding = style.ImageRounding = style.TreeLinesRounding = + style.MenuItemRounding = style.SelectableRounding = style.DragDropTargetRounding = 0; + style.WindowTitleAlign = {.5f, .5f}; + style.ScrollbarSize = 12; + + style.ScaleAllSizes(scale); + style.FontSizeBase = FONT_PIXELS * scale; +} + +// Unifont, with Font Awesome's icons merged in, from the repository's assets. ImGui's own font stands in without them. +void Overlay::fonts_load() +{ + ImGuiIO& io = ImGui::GetIO(); + std::string unifont = asset_path(UNIFONT); + std::string icons = asset_path(ICON_FONT); + ImFontConfig pixels; + std::error_code error; + + pixels.PixelSnapH = true; + pixels.OversampleH = pixels.OversampleV = 1; + if (!std::filesystem::exists(unifont, error)) return; + if (!io.Fonts->AddFontFromFileTTF(unifont.c_str(), FONT_PIXELS, &pixels)) return; + if (!std::filesystem::exists(icons, error)) return; + + ImFontConfig merged = pixels; + merged.MergeMode = true; + merged.GlyphMinAdvanceX = FONT_PIXELS; // Icons share one width, so menu labels line up. + merged.GlyphOffset.y = ICON_DROP; + io.Fonts->AddFontFromFileTTF(icons.c_str(), ICON_PIXELS, &merged, ICON_RANGES); +} + +// Starts ImGui on the game's window and GL context, its layout kept in the save folder. A first run docks the windows +// together. +void Overlay::load() +{ + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + layoutPath = platform.userDataDirectory + LAYOUT_FILE; + io.IniFilename = layoutPath.c_str(); + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + + fonts_load(); + ImGui_ImplSDL3_InitForOpenGL(platform.window, platform.context); + ImGui_ImplOpenGL3_Init(GLSL_VERSION); + ImGui::LoadIniSettingsFromDisk(io.IniFilename); + isDockPending = std::ranges::none_of(WINDOW_NAMES, [](const char* name) { + ImGuiWindowSettings* settings = ImGui::FindWindowSettingsByID(ImHashStr(name)); + return settings && settings->DockId; + }); + isReady = true; +} + +// Saves the layout and lets ImGui go, with the thumbnails' textures, while the GL context is still there. +void Overlay::unload() +{ + if (!std::exchange(isReady, false)) return; + + for (auto& [path, texture] : thumbnails) gl.DeleteTextures(1, &texture); + thumbnails.clear(); + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplSDL3_Shutdown(); + ImGui::DestroyContext(); +} + +// ` shows or hides the overlay. While it shows it takes every event but the window's, the key releases and the +// gamepads coming and going, which the game still needs. A control waiting for its binding takes the next press. +bool Overlay::is_event_captured(const SDL_Event& event) +{ + if (!isReady) return false; + + bool isToggle = event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_GRAVE && !event.key.repeat; + if (isToggle && bindingAction < 0) + { + visible_set(!isVisible); + return true; + } + if (!isVisible) return false; + if (bindingAction >= 0 && is_binding_taken(event)) return true; + + // The toggle key's own text never reaches the input. + bool isToggleText = event.type == SDL_EVENT_TEXT_INPUT && std::string_view(event.text.text) == "`"; + if (!isToggleText) ImGui_ImplSDL3_ProcessEvent(&event); + bool isWindowEvent = event.type >= SDL_EVENT_WINDOW_FIRST && event.type <= SDL_EVENT_WINDOW_LAST; + return !isWindowEvent && event.type != SDL_EVENT_QUIT && event.type != SDL_EVENT_KEY_UP && + event.type != SDL_EVENT_GAMEPAD_ADDED && event.type != SDL_EVENT_GAMEPAD_REMOVED; +} + +// Showing captures the input and starts text input, bringing the console to the front with its input focused. Hiding gives them back and lets go +// of every key ImGui holds, since it hears no release while hidden. +void Overlay::visible_set(bool isShown) +{ + isVisible = isFocusPending = isConsoleFrontPending = isShown; + platform.isInputCaptured = isShown; + if (isShown) + { + SDL_StartTextInput(platform.window); + return; + } + + SDL_StopTextInput(platform.window); + bindingAction = -1; + ImGui::GetIO().ClearEventsQueue(); + ImGui::GetIO().ClearInputKeys(); +} + +// The bar's < hides the overlay as ` does, and Tools shows or hides each window. +void Overlay::menu_bar_render() +{ + if (!ImGui::BeginMainMenuBar()) return; + + if (ImGui::Button(icon_label(ICON_HIDE).c_str())) visible_set(false); + if (ImGui::BeginMenu(icon_label(ICON_TOOLS, "Tools").c_str())) + { + for (int window = 0; window < OVERLAY_WINDOW_COUNT; window++) + ImGui::MenuItem(icon_label(WINDOW_ICONS[window], WINDOW_NAMES[window]).c_str(), nullptr, &isOpen[window]); + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); +} + +// A floating window's close button. Docked tabs go without, so each label sits centred in its tab, and Tools still +// closes them. +static bool* close_get(const char* name, bool& isOpen) +{ + ImGuiWindow* window = ImGui::FindWindowByName(name); + return window && window->DockIsActive ? nullptr : &isOpen; +} + +// Draws the overlay over the finished frame, on the window's own framebuffer. Unifont grows by whole multiples with +// the window, and the metrics with it. +void Overlay::render() +{ + constexpr void (Overlay::*WINDOW_RENDERS[OVERLAY_WINDOW_COUNT])() = { + &Overlay::console_render, &Overlay::options_render, &Overlay::mods_render, &Overlay::debug_render}; + + if (!isReady || !isVisible) return; + + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplSDL3_NewFrame(); + float displayScale = std::max(1.0f, std::round(ImGui::GetIO().DisplaySize.y / SCALE_HEIGHT)); + if (displayScale != std::exchange(scale, displayScale)) style_load(displayScale); + ImGui::NewFrame(); + menu_bar_render(); + + // The first dock picks its own front tab, so the console comes to the front a frame later. + bool isDocking = std::exchange(isDockPending, false); + if (isDocking) + { + ImVec2 display = ImGui::GetIO().DisplaySize; + ImGuiID dock = ImGui::DockBuilderAddNode(); + ImGui::DockBuilderSetNodePos(dock, {DOCK_MARGIN, ImGui::GetFrameHeight() + DOCK_MARGIN}); + ImGui::DockBuilderSetNodeSize(dock, {display.x * DOCK_WIDTH_SHARE, display.y * DOCK_HEIGHT_SHARE}); + for (const char* name : WINDOW_NAMES) ImGui::DockBuilderDockWindow(name, dock); + ImGui::DockBuilderFinish(dock); + } + for (int window = 0; window < OVERLAY_WINDOW_COUNT; window++) + { + if (!isOpen[window]) continue; + if (window == OVERLAY_CONSOLE && !isDocking && std::exchange(isConsoleFrontPending, false)) + ImGui::SetNextWindowFocus(); + if (ImGui::Begin(WINDOW_NAMES[window], close_get(WINDOW_NAMES[window], isOpen[window]))) + (this->*WINDOW_RENDERS[window])(); + ImGui::End(); + } + ImGui::Render(); + + int framebuffer = 0; + gl.GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer); + gl.BindFramebuffer(GL_FRAMEBUFFER, 0); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + gl.BindFramebuffer(GL_FRAMEBUFFER, framebuffer); +} diff --git a/src/ui/overlay/overlay.h b/src/ui/overlay/overlay.h new file mode 100644 index 0000000..c96efb0 --- /dev/null +++ b/src/ui/overlay/overlay.h @@ -0,0 +1,94 @@ +#pragma once + +#include +#include +#include +#include + +struct ImGuiInputTextCallbackData; +struct ModEntry; + +// The overlay's windows, docked together as tabs and each shown or hidden from the Tools menu. +enum OverlayWindow +{ + OVERLAY_CONSOLE, + OVERLAY_OPTIONS, + OVERLAY_MODS, + OVERLAY_DEBUG, + OVERLAY_WINDOW_COUNT +}; + +// How the Mods window lays the mods out: as thumbnail cards, or a line each. +enum ModsView : int +{ + MODS_VIEW_THUMBNAIL, + MODS_VIEW_COMPACT +}; + +// A completion the console offers: the whole line it makes, with a dim descriptor beside it. +struct OverlaySuggestion +{ + std::string descriptor; + std::string line; +}; + +// The developer overlay (Dear ImGui) in place of the drop-down console, toggled with ` or a mod's console input: the +// Console, Game Options, Mods and Debug windows. It is never made under the test harness. +// While it shows it takes the keyboard, mouse, gamepads and text from the game, and a run pauses as for the console. +// Its windows are drawn in console.cpp, game_options.cpp, mods.cpp and debug.cpp. +class Overlay +{ +public: + void load(); + void unload(); + bool is_event_captured(const SDL_Event& event); + void render(); + void visible_set(bool isShown); + bool is_ready() { return isReady; } + bool is_visible() { return isVisible; } + +private: + std::map thumbnails; + std::vector suggestions; + std::string input; + std::string layoutPath; + std::string suggestedInput; + ModsView modsView = MODS_VIEW_THUMBNAIL; + float scale = 0; + int bindingAction = -1; + int bindingDevice = -1; + int bindingSlot = 0; + int selected = -1; + unsigned int listId = 0; + bool isOpen[OVERLAY_WINDOW_COUNT] = {true, true, true, true}; + bool isConsoleFrontPending = false; + bool isCursorEndPending = false; + bool isDismissed = false; + bool isDockPending = false; + bool isFocusPending = false; + bool isListHovered = false; + bool isListShown = false; + bool isModsChanged = false; + bool isOptionsSavePending = false; + bool isReady = false; + bool isScrollPending = false; + bool isSelectionScrollPending = false; + bool isVisible = false; + + void fonts_load(); + void menu_bar_render(); + void console_render(); + void log_render(); + void suggestions_load(); + void suggestions_render(); + static int input_respond(ImGuiInputTextCallbackData* data); + void options_render(); + void controls_render(); + bool is_binding_taken(const SDL_Event& event); + void mods_render(); + void mod_render(ModEntry& mod, float width); + unsigned int thumbnail_get(ModEntry& mod); + void debug_render(); +}; + +extern Overlay overlay;