From 352b46c1f5b79be3320e1e91182122e2dd82b08d Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Sun, 31 Jul 2022 23:36:21 -0400 Subject: [PATCH] LUS Cleanup: Console class is now in the Ship namespace --- libultraship/libultraship/Console.cpp | 312 +++++++++--------- libultraship/libultraship/Console.h | 140 ++++---- libultraship/libultraship/ImGuiImpl.h | 4 +- .../libultraship/Lib/Fast3D/gfx_dxgi.cpp | 1 - .../include/spdlog/sinks/sohconsole_sink.h | 19 +- soh/soh/Enhancements/debugconsole.cpp | 53 ++- 6 files changed, 266 insertions(+), 263 deletions(-) diff --git a/libultraship/libultraship/Console.cpp b/libultraship/libultraship/Console.cpp index 85ba1f78d..b7158bd3b 100644 --- a/libultraship/libultraship/Console.cpp +++ b/libultraship/libultraship/Console.cpp @@ -10,115 +10,116 @@ #include "Utils/StringHelper.h" #include "Lib/ImGui/imgui_internal.h" -std::map Bindings; -std::map BindingToggle; +namespace Ship { + std::map Bindings; + std::map BindingToggle; -static bool HelpCommand(const std::vector&) { - INFO("SoH Commands:"); - for(const auto& cmd : SohImGui::console->Commands) { - INFO("%s", (" - " + cmd.first).c_str()); + static bool HelpCommand(const std::vector&) { + INFO("SoH Commands:"); + for (const auto& cmd : SohImGui::console->Commands) { + INFO("%s", (" - " + cmd.first).c_str()); + } + return CMD_SUCCESS; } - return CMD_SUCCESS; -} -static bool ClearCommand(const std::vector&) { - SohImGui::console->Log[SohImGui::console->selected_channel].clear(); - return CMD_SUCCESS; -} + static bool ClearCommand(const std::vector&) { + SohImGui::console->Log[SohImGui::console->selected_channel].clear(); + return CMD_SUCCESS; + } -std::string toLowerCase(std::string in) { - std::string cpy(in); - std::transform(cpy.begin(), cpy.end(), cpy.begin(), ::tolower); - return cpy; -} + std::string toLowerCase(std::string in) { + std::string cpy(in); + std::transform(cpy.begin(), cpy.end(), cpy.begin(), ::tolower); + return cpy; + } -static bool BindCommand(const std::vector& args) { - if(args.size() > 2) { - const ImGuiIO* io = &ImGui::GetIO();; - for (size_t k = 0; k < std::size(io->KeysData); k++) { - std::string key(ImGui::GetKeyName(k)); + static bool BindCommand(const std::vector& args) { + if (args.size() > 2) { + const ImGuiIO* io = &ImGui::GetIO();; + for (size_t k = 0; k < std::size(io->KeysData); k++) { + std::string key(ImGui::GetKeyName(k)); - if(toLowerCase(args[1]) == toLowerCase(key)) { - std::vector tmp; - const char* const delim = " "; - std::ostringstream imploded; - std::copy(args.begin() + 2, args.end(), std::ostream_iterator(imploded, delim)); - Bindings[k] = imploded.str(); - INFO("Binding '%s' to %s", args[1].c_str(), Bindings[k].c_str()); - break; + if (toLowerCase(args[1]) == toLowerCase(key)) { + std::vector tmp; + const char* const delim = " "; + std::ostringstream imploded; + std::copy(args.begin() + 2, args.end(), std::ostream_iterator(imploded, delim)); + Bindings[k] = imploded.str(); + INFO("Binding '%s' to %s", args[1].c_str(), Bindings[k].c_str()); + break; + } + } + } + return CMD_SUCCESS; + } + + static bool BindToggleCommand(const std::vector& args) { + if (args.size() > 2) { + const ImGuiIO* io = &ImGui::GetIO();; + for (size_t k = 0; k < std::size(io->KeysData); k++) { + std::string key(ImGui::GetKeyName(k)); + + if (toLowerCase(args[1]) == toLowerCase(key)) { + BindingToggle[k] = args[2]; + INFO("Binding toggle '%s' to %s", args[1].c_str(), BindingToggle[k].c_str()); + break; + } + } + } + return CMD_SUCCESS; + } + + std::string BuildUsage(const CommandEntry& entry) { + std::string usage; + for (const auto& arg : entry.arguments) + usage += StringHelper::Sprintf(arg.optional ? "[%s] " : "<%s> ", arg.info.c_str()); + return usage; + } + + void Console::Init() { + this->InputBuffer = new char[MAX_BUFFER_SIZE]; + strcpy(this->InputBuffer, ""); + this->FilterBuffer = new char[MAX_BUFFER_SIZE]; + strcpy(this->FilterBuffer, ""); + this->Commands["help"] = { HelpCommand, "Shows all the commands" }; + this->Commands["clear"] = { ClearCommand, "Clear the console history" }; + this->Commands["bind"] = { BindCommand, "Binds key to commands" }; + this->Commands["bind-toggle"] = { BindToggleCommand, "Bind key as a bool toggle" }; + } + + void Console::Update() { + for (auto [key, cmd] : Bindings) { + if (ImGui::IsKeyPressed(key)) Dispatch(cmd); + } + for (auto [key, var] : BindingToggle) { + if (ImGui::IsKeyPressed(key)) { + CVar* cvar = CVar_Get(var.c_str()); + Dispatch("set " + var + " " + std::to_string(cvar == nullptr ? 0 : !static_cast(cvar->value.valueS32))); } } } - return CMD_SUCCESS; -} -static bool BindToggleCommand(const std::vector& args) { - if (args.size() > 2) { - const ImGuiIO* io = &ImGui::GetIO();; - for (size_t k = 0; k < std::size(io->KeysData); k++) { - std::string key(ImGui::GetKeyName(k)); + void Console::Draw() { + bool input_focus = false; + if (!this->opened) return; - if (toLowerCase(args[1]) == toLowerCase(key)) { - BindingToggle[k] = args[2]; - INFO("Binding toggle '%s' to %s", args[1].c_str(), BindingToggle[k].c_str()); - break; - } - } - } - return CMD_SUCCESS; -} - -std::string BuildUsage(const CommandEntry& entry) { - std::string usage; - for (const auto& arg : entry.arguments) - usage += StringHelper::Sprintf(arg.optional ? "[%s] " : "<%s> ", arg.info.c_str()); - return usage; -} - -void Console::Init() { - this->InputBuffer = new char[MAX_BUFFER_SIZE]; - strcpy(this->InputBuffer, ""); - this->FilterBuffer = new char[MAX_BUFFER_SIZE]; - strcpy(this->FilterBuffer, ""); - this->Commands["help"] = { HelpCommand, "Shows all the commands" }; - this->Commands["clear"] = { ClearCommand, "Clear the console history" }; - this->Commands["bind"] = { BindCommand, "Binds key to commands" }; - this->Commands["bind-toggle"] = { BindToggleCommand, "Bind key as a bool toggle" }; -} - -void Console::Update() { - for(auto [key, cmd] : Bindings) { - if (ImGui::IsKeyPressed(key)) Dispatch(cmd); - } - for (auto [key, var] : BindingToggle) { - if (ImGui::IsKeyPressed(key)) { - CVar* cvar = CVar_Get(var.c_str()); - Dispatch("set " + var + " " + std::to_string(cvar == nullptr ? 0 : !static_cast(cvar->value.valueS32))); - } - } -} - -void Console::Draw() { - bool input_focus = false; - if (!this->opened) return; - - ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); - ImGui::Begin("Console", nullptr, ImGuiWindowFlags_NoFocusOnAppearing); + ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); + ImGui::Begin("Console", nullptr, ImGuiWindowFlags_NoFocusOnAppearing); const ImVec2 pos = ImGui::GetWindowPos(); const ImVec2 size = ImGui::GetWindowSize(); // SohImGui::ShowCursor(ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_RectOnly), SohImGui::Dialogues::dConsole); // Renders autocomplete window - if(this->OpenAutocomplete) { + if (this->OpenAutocomplete) { ImGui::SetNextWindowSize(ImVec2(350, std::min(static_cast(this->Autocomplete.size()), 3) * 20.f), ImGuiCond_Once); ImGui::SetNextWindowPos(ImVec2(pos.x + 8, pos.y + size.y - 1)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(3, 3)); - ImGui::Begin("##WndAutocomplete", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove ); + ImGui::Begin("##WndAutocomplete", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove); ImGui::BeginChild("AC_Child", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(.3f, .3f, .3f, 1.0f)); if (ImGui::BeginTable("AC_History", 1)) { - for (const auto &cmd : this->Autocomplete) { - std::string usage = BuildUsage(this->Commands[cmd]); + for (const auto& cmd : this->Autocomplete) { + std::string usage = BuildUsage(this->Commands[cmd]); std::string preview = cmd + " - " + this->Commands[cmd].description; std::string autocomplete = (usage == NULLSTR ? cmd : usage); ImGui::TableNextRow(); @@ -186,53 +187,53 @@ void Console::Draw() { // Renders console history const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar); - ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(.3f, .3f, .3f, 1.0f)); - if (ImGui::BeginTable("History", 1)) { + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(.3f, .3f, .3f, 1.0f)); + if (ImGui::BeginTable("History", 1)) { - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow))) - if (this->selectedId < (int)this->Log.size() - 1) ++this->selectedId; - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) - if (this->selectedId > 0) --this->selectedId; + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow))) + if (this->selectedId < (int)this->Log.size() - 1)++this->selectedId; + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) + if (this->selectedId > 0)--this->selectedId; - const std::vector channel = this->Log[this->selected_channel]; - for (int i = 0; i < static_cast(channel.size()); i++) { - ConsoleLine line = channel[i]; - if(!this->filter.empty() && line.text.find(this->filter) == std::string::npos) continue; - if(this->level_filter != NULLSTR && line.priority != (std::find(priority_filters.begin(), priority_filters.end(), this->level_filter) - priority_filters.begin()) - 1) continue; - std::string id = line.text + "##" + std::to_string(i); - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - const bool is_selected = (this->selectedId == i) || std::find(this->selectedEntries.begin(), this->selectedEntries.end(), i) != this->selectedEntries.end(); - ImGui::PushStyleColor(ImGuiCol_Text, this->priority_colors[line.priority]); - if (ImGui::Selectable(id.c_str(), is_selected)) { - if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_LeftCtrl)) && !is_selected) - this->selectedEntries.push_back(i); + const std::vector channel = this->Log[this->selected_channel]; + for (int i = 0; i < static_cast(channel.size()); i++) { + ConsoleLine line = channel[i]; + if (!this->filter.empty() && line.text.find(this->filter) == std::string::npos) continue; + if (this->level_filter != NULLSTR && line.priority != (std::find(priority_filters.begin(), priority_filters.end(), this->level_filter) - priority_filters.begin()) - 1) continue; + std::string id = line.text + "##" + std::to_string(i); + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + const bool is_selected = (this->selectedId == i) || std::find(this->selectedEntries.begin(), this->selectedEntries.end(), i) != this->selectedEntries.end(); + ImGui::PushStyleColor(ImGuiCol_Text, this->priority_colors[line.priority]); + if (ImGui::Selectable(id.c_str(), is_selected)) { + if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_LeftCtrl)) && !is_selected) + this->selectedEntries.push_back(i); - else this->selectedEntries.clear(); - this->selectedId = is_selected ? -1 : i; - } - ImGui::PopStyleColor(); - if (is_selected) ImGui::SetItemDefaultFocus(); + else this->selectedEntries.clear(); + this->selectedId = is_selected ? -1 : i; } - ImGui::EndTable(); + ImGui::PopStyleColor(); + if (is_selected) ImGui::SetItemDefaultFocus(); } - ImGui::PopStyleColor(); - if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) - ImGui::SetScrollHereY(1.0f); + ImGui::EndTable(); + } + ImGui::PopStyleColor(); + if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) + ImGui::SetScrollHereY(1.0f); ImGui::EndChild(); // Renders input textfield constexpr ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit | - ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; + ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; ImGui::PushItemWidth(-53); - if(ImGui::InputTextWithHint("##CMDInput", ">", this->InputBuffer, MAX_BUFFER_SIZE, flags, &Console::CallbackStub, this)) { + if (ImGui::InputTextWithHint("##CMDInput", ">", this->InputBuffer, MAX_BUFFER_SIZE, flags, &Console::CallbackStub, this)) { input_focus = true; - if(this->InputBuffer[0] != '\0' && this->InputBuffer[0] != ' ') + if (this->InputBuffer[0] != '\0' && this->InputBuffer[0] != ' ') this->Dispatch(std::string(this->InputBuffer)); memset(this->InputBuffer, 0, MAX_BUFFER_SIZE); } - if(this->CMDHint != NULLSTR) { + if (this->CMDHint != NULLSTR) { if (ImGui::IsItemFocused()) { ImGui::SetNextWindowPos(ImVec2(pos.x, pos.y + size.y)); ImGui::SameLine(); @@ -246,38 +247,38 @@ void Console::Draw() { ImGui::SameLine(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 50); - if(ImGui::Button("Submit") && !input_focus && this->InputBuffer[0] != '\0' && this->InputBuffer[0] != ' '){ - this->Dispatch(std::string(this->InputBuffer)); + if (ImGui::Button("Submit") && !input_focus && this->InputBuffer[0] != '\0' && this->InputBuffer[0] != ' ') { + this->Dispatch(std::string(this->InputBuffer)); memset(this->InputBuffer, 0, MAX_BUFFER_SIZE); } ImGui::SetItemDefaultFocus(); if (input_focus) ImGui::SetKeyboardFocusHere(-1); ImGui::PopItemWidth(); - ImGui::End(); -} - -void Console::Dispatch(const std::string& line) { - this->CMDHint = NULLSTR; - this->History.push_back(line); - this->Log[this->selected_channel].push_back({ "> " + line } ); - const std::vector cmd_args = StringHelper::Split(line, " "); - if (this->Commands.contains(cmd_args[0])) { - const CommandEntry entry = this->Commands[cmd_args[0]]; - if(!entry.handler(cmd_args) && !entry.arguments.empty()) - this->Log[this->selected_channel].push_back({ "[SOH] Usage: " + cmd_args[0] + " " + BuildUsage(entry), ERROR_LVL}); - return; + ImGui::End(); } - this->Log[this->selected_channel].push_back({ "[SOH] Command not found", ERROR_LVL }); -} -int Console::CallbackStub(ImGuiInputTextCallbackData* data) { - const auto instance = static_cast(data->UserData); - const bool empty_history = instance->History.empty(); - const int history_index = instance->HistoryIndex; - std::string history; + void Console::Dispatch(const std::string& line) { + this->CMDHint = NULLSTR; + this->History.push_back(line); + this->Log[this->selected_channel].push_back({ "> " + line }); + const std::vector cmd_args = StringHelper::Split(line, " "); + if (this->Commands.contains(cmd_args[0])) { + const CommandEntry entry = this->Commands[cmd_args[0]]; + if (!entry.handler(cmd_args) && !entry.arguments.empty()) + this->Log[this->selected_channel].push_back({ "[SOH] Usage: " + cmd_args[0] + " " + BuildUsage(entry), ERROR_LVL }); + return; + } + this->Log[this->selected_channel].push_back({ "[SOH] Command not found", ERROR_LVL }); + } - switch(data->EventKey) { + int Console::CallbackStub(ImGuiInputTextCallbackData* data) { + const auto instance = static_cast(data->UserData); + const bool empty_history = instance->History.empty(); + const int history_index = instance->HistoryIndex; + std::string history; + + switch (data->EventKey) { case ImGuiKey_Tab: instance->Autocomplete.clear(); for (auto& [cmd, entry] : instance->Commands) @@ -287,7 +288,7 @@ int Console::CallbackStub(ImGuiInputTextCallbackData* data) { break; case ImGuiKey_UpArrow: if (empty_history) break; - if(history_index < static_cast(instance->History.size()) - 1) instance->HistoryIndex += 1; + if (history_index < static_cast(instance->History.size()) - 1) instance->HistoryIndex += 1; data->DeleteChars(0, data->BufTextLen); data->InsertChars(0, instance->History[instance->HistoryIndex].c_str()); instance->CMDHint = NULLSTR; @@ -296,7 +297,7 @@ int Console::CallbackStub(ImGuiInputTextCallbackData* data) { if (empty_history) break; if (history_index > -1) instance->HistoryIndex -= 1; data->DeleteChars(0, data->BufTextLen); - if(history_index >= 0) + if (history_index >= 0) data->InsertChars(0, instance->History[history_index].c_str()); instance->CMDHint = NULLSTR; break; @@ -316,16 +317,17 @@ int Console::CallbackStub(ImGuiInputTextCallbackData* data) { } instance->CMDHint = NULLSTR; } + } + return 0; } - return 0; -} -void Console::Append(const std::string& channel, Priority priority, const char* fmt, ...) { - char buf[1024]; - va_list args; - va_start(args, fmt); - vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); - buf[IM_ARRAYSIZE(buf) - 1] = 0; - va_end(args); - this->Log[channel].push_back({ std::string(buf), priority }); -} + void Console::Append(const std::string& channel, Priority priority, const char* fmt, ...) { + char buf[1024]; + va_list args; + va_start(args, fmt); + vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); + buf[IM_ARRAYSIZE(buf) - 1] = 0; + va_end(args); + this->Log[channel].push_back({ std::string(buf), priority }); + } +} \ No newline at end of file diff --git a/libultraship/libultraship/Console.h b/libultraship/libultraship/Console.h index bfbffd0b9..a174450e1 100644 --- a/libultraship/libultraship/Console.h +++ b/libultraship/libultraship/Console.h @@ -7,75 +7,77 @@ #include "Lib/ImGui/imgui.h" -#define LOG(msg, ...) SohImGui::console->Append("Main", Priority::LOG_LVL, msg, ##__VA_ARGS__) -#define INFO(msg, ...) SohImGui::console->Append("Main", Priority::INFO_LVL, msg, ##__VA_ARGS__) -#define WARNING(msg, ...) SohImGui::console->Append("Main", Priority::WARNING_LVL, msg, ##__VA_ARGS__) -#define ERROR(msg, ...) SohImGui::console->Append("Main", Priority::ERROR_LVL, msg, ##__VA_ARGS__) -#define CMD_SUCCESS true -#define CMD_FAILED false -#define MAX_BUFFER_SIZE 255 -#define NULLSTR "None" +namespace Ship { + #define LOG(msg, ...) SohImGui::console->Append("Main", Ship::Priority::LOG_LVL, msg, ##__VA_ARGS__) + #define INFO(msg, ...) SohImGui::console->Append("Main", Ship::Priority::INFO_LVL, msg, ##__VA_ARGS__) + #define WARNING(msg, ...) SohImGui::console->Append("Main", Ship::Priority::WARNING_LVL, msg, ##__VA_ARGS__) + #define ERROR(msg, ...) SohImGui::console->Append("Main", Ship::Priority::ERROR_LVL, msg, ##__VA_ARGS__) + #define CMD_SUCCESS true + #define CMD_FAILED false + #define MAX_BUFFER_SIZE 255 + #define NULLSTR "None" -typedef std::function args)> CommandHandler; + typedef std::function args)> CommandHandler; -enum Priority { - INFO_LVL, - LOG_LVL, - WARNING_LVL, - ERROR_LVL -}; - -enum class ArgumentType { - TEXT, NUMBER, PLAYER_POS, PLAYER_ROT -}; - -struct CommandArgument { - std::string info; - ArgumentType type = ArgumentType::NUMBER; - bool optional = false; -}; - -struct CommandEntry { - CommandHandler handler; - std::string description; - std::vector arguments; -}; - -struct ConsoleLine { - std::string text; - Priority priority = Priority::INFO_LVL; - std::string channel = "Main"; -}; - -class Console { - int selectedId = -1; - std::vector selectedEntries; - std::string filter; - std::string level_filter = NULLSTR; - std::vector log_channels = { "Main", "SoH Logging"}; - std::vector priority_filters = { "None", "Info", "Log", "Warning", "Error" }; - std::vector priority_colors = { - ImVec4(1.0f, 1.0f, 1.0f, 1.0f), - ImVec4(0.2f, 1.0f, 0.2f, 1.0f), - ImVec4(0.9f, 0.8f, 0.4f, 0.01f), - ImVec4(1.0f, 0.2f, 0.2f, 1.0f) + enum Priority { + INFO_LVL, + LOG_LVL, + WARNING_LVL, + ERROR_LVL }; -public: - std::map> Log; - std::map Commands; - std::vector Autocomplete; - std::vector History; - std::string CMDHint = NULLSTR; - char* FilterBuffer = nullptr; - char* InputBuffer = nullptr; - bool OpenAutocomplete = false; - int HistoryIndex = -1; - std::string selected_channel = "Main"; - bool opened = false; - void Init(); - void Update(); - void Draw(); - void Append(const std::string& channel, Priority priority, const char* fmt, ...) IM_FMTARGS(4); - void Dispatch(const std::string& line); - static int CallbackStub(ImGuiInputTextCallbackData* data); -}; \ No newline at end of file + + enum class ArgumentType { + TEXT, NUMBER, PLAYER_POS, PLAYER_ROT + }; + + struct CommandArgument { + std::string info; + ArgumentType type = ArgumentType::NUMBER; + bool optional = false; + }; + + struct CommandEntry { + CommandHandler handler; + std::string description; + std::vector arguments; + }; + + struct ConsoleLine { + std::string text; + Priority priority = Priority::INFO_LVL; + std::string channel = "Main"; + }; + + class Console { + int selectedId = -1; + std::vector selectedEntries; + std::string filter; + std::string level_filter = NULLSTR; + std::vector log_channels = { "Main", "SoH Logging" }; + std::vector priority_filters = { "None", "Info", "Log", "Warning", "Error" }; + std::vector priority_colors = { + ImVec4(1.0f, 1.0f, 1.0f, 1.0f), + ImVec4(0.2f, 1.0f, 0.2f, 1.0f), + ImVec4(0.9f, 0.8f, 0.4f, 0.01f), + ImVec4(1.0f, 0.2f, 0.2f, 1.0f) + }; + public: + std::map> Log; + std::map Commands; + std::vector Autocomplete; + std::vector History; + std::string CMDHint = NULLSTR; + char* FilterBuffer = nullptr; + char* InputBuffer = nullptr; + bool OpenAutocomplete = false; + int HistoryIndex = -1; + std::string selected_channel = "Main"; + bool opened = false; + void Init(); + void Update(); + void Draw(); + void Append(const std::string& channel, Priority priority, const char* fmt, ...) IM_FMTARGS(4); + void Dispatch(const std::string& line); + static int CallbackStub(ImGuiInputTextCallbackData* data); + }; +} \ No newline at end of file diff --git a/libultraship/libultraship/ImGuiImpl.h b/libultraship/libultraship/ImGuiImpl.h index 01235d411..6913fce61 100644 --- a/libultraship/libultraship/ImGuiImpl.h +++ b/libultraship/libultraship/ImGuiImpl.h @@ -69,7 +69,7 @@ namespace SohImGui { WindowDrawFunc drawFunc; } CustomWindow; - extern Console* console; + extern Ship::Console* console; extern Ship::InputEditor* controller; extern Ship::GameOverlay* overlay; extern bool needs_save; @@ -92,7 +92,7 @@ namespace SohImGui { void Render(void); void CancelFrame(void); void ShowCursor(bool hide, Dialogues w); - void BindCmd(const std::string& cmd, CommandEntry entry); + void BindCmd(const std::string& cmd, Ship::CommandEntry entry); void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc, bool isEnabled=false, bool isHidden=false); void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint = ImVec4(1, 1, 1, 1)); void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha=false); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp index 6e0c2e4d6..aabeb0acf 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp @@ -358,7 +358,6 @@ static void gfx_dxgi_show_cursor(bool hide) { * @bug When menubar is open in windowed mode and you toggle fullscreen * ShowCursor no longer responds. Debugging shows the bool to be correct. **/ - INFO("renderer: %s", hide ? "true" : "false"); ShowCursor(hide); } diff --git a/libultraship/libultraship/Lib/spdlog/include/spdlog/sinks/sohconsole_sink.h b/libultraship/libultraship/Lib/spdlog/include/spdlog/sinks/sohconsole_sink.h index b9d3cdbf3..9f71bdee4 100644 --- a/libultraship/libultraship/Lib/spdlog/include/spdlog/sinks/sohconsole_sink.h +++ b/libultraship/libultraship/Lib/spdlog/include/spdlog/sinks/sohconsole_sink.h @@ -34,7 +34,7 @@ public: protected: void sink_it_(const details::log_msg &msg) override { - const Priority priority = convert_to_soh(msg.level); + const Ship::Priority priority = convert_to_soh(msg.level); memory_buf_t formatted; if (use_raw_msg_) { @@ -53,24 +53,25 @@ protected: void flush_() override {} private: - static Priority convert_to_soh(spdlog::level::level_enum level) { + static Ship::Priority convert_to_soh(spdlog::level::level_enum level) + { switch (level) { case spdlog::level::trace: - return Priority::INFO_LVL; + return Ship::Priority::INFO_LVL; case spdlog::level::debug: - return Priority::LOG_LVL; + return Ship::Priority::LOG_LVL; case spdlog::level::info: - return Priority::LOG_LVL; + return Ship::Priority::LOG_LVL; case spdlog::level::warn: - return Priority::WARNING_LVL; + return Ship::Priority::WARNING_LVL; case spdlog::level::err: - return Priority::ERROR_LVL; + return Ship::Priority::ERROR_LVL; case spdlog::level::critical: - return Priority::ERROR_LVL; + return Ship::Priority::ERROR_LVL; default: break; } - return Priority::LOG_LVL; + return Ship::Priority::LOG_LVL; } std::string tag_; diff --git a/soh/soh/Enhancements/debugconsole.cpp b/soh/soh/Enhancements/debugconsole.cpp index 73c54b742..ba5fb0b34 100644 --- a/soh/soh/Enhancements/debugconsole.cpp +++ b/soh/soh/Enhancements/debugconsole.cpp @@ -463,50 +463,49 @@ void DebugConsole_Init(void) { CMD_REGISTER("kill", { KillPlayerHandler, "Commit suicide." }); CMD_REGISTER("map", { LoadSceneHandler, "Load up kak?" }); CMD_REGISTER("rupee", { RuppeHandler, "Set your rupee counter.", { - {"amount", ArgumentType::NUMBER } + {"amount", Ship::ArgumentType::NUMBER } }}); - CMD_REGISTER("bItem", { BHandler, "Set an item to the B button.", { { "Item ID", ArgumentType::NUMBER } } }); - CMD_REGISTER("health", { SetPlayerHealthHandler, "Set the health of the player.", { - {"health", ArgumentType::NUMBER } + CMD_REGISTER("bItem", { BHandler, "Set an item to the B button.", { { "Item ID", Ship::ArgumentType::NUMBER } } }); + CMD_REGISTER("health", { SetPlayerHealthHandler, "Set the health of the player.", { { "health", Ship::ArgumentType::NUMBER } }}); - CMD_REGISTER("spawn", { ActorSpawnHandler, "Spawn an actor.", { - { "actor_id", ArgumentType::NUMBER }, - { "data", ArgumentType::NUMBER }, - { "x", ArgumentType::PLAYER_POS, true }, - { "y", ArgumentType::PLAYER_POS, true }, - { "z", ArgumentType::PLAYER_POS, true }, - { "rx", ArgumentType::PLAYER_ROT, true }, - { "ry", ArgumentType::PLAYER_ROT, true }, - { "rz", ArgumentType::PLAYER_ROT, true } + CMD_REGISTER("spawn", { ActorSpawnHandler, "Spawn an actor.", { { "actor_id", Ship::ArgumentType::NUMBER }, + { "data", Ship::ArgumentType::NUMBER }, + { "x", Ship::ArgumentType::PLAYER_POS, true }, + { "y", Ship::ArgumentType::PLAYER_POS, true }, + { "z", Ship::ArgumentType::PLAYER_POS, true }, + { "rx", Ship::ArgumentType::PLAYER_ROT, true }, + { "ry", Ship::ArgumentType::PLAYER_ROT, true }, + { "rz", Ship::ArgumentType::PLAYER_ROT, true } }}); - CMD_REGISTER("pos", { SetPosHandler, "Sets the position of the player.", { - { "x", ArgumentType::PLAYER_POS, true }, - { "y", ArgumentType::PLAYER_POS, true }, - { "z", ArgumentType::PLAYER_POS, true } + CMD_REGISTER("pos", { SetPosHandler, "Sets the position of the player.", { { "x", Ship::ArgumentType::PLAYER_POS, true }, + { "y", Ship::ArgumentType::PLAYER_POS, true }, + { "z", Ship::ArgumentType::PLAYER_POS, true } }}); CMD_REGISTER("set", { SetCVarHandler, "Sets a console variable.", - { { "varName", ArgumentType::TEXT }, { "varValue", ArgumentType::TEXT } } }); - CMD_REGISTER("get", { GetCVarHandler, "Gets a console variable.", { { "varName", ArgumentType::TEXT } } }); + { { "varName", Ship::ArgumentType::TEXT }, { "varValue", Ship::ArgumentType::TEXT } } }); + CMD_REGISTER("get", { GetCVarHandler, "Gets a console variable.", { { "varName", Ship::ArgumentType::TEXT } } }); CMD_REGISTER("reset", { ResetHandler, "Resets the game." }); CMD_REGISTER("ammo", { AmmoHandler, "Changes ammo of an item.", - { { "item", ArgumentType::TEXT }, - { "count", ArgumentType::NUMBER } } }); + { { "item", Ship::ArgumentType::TEXT }, { "count", Ship::ArgumentType::NUMBER } } }); CMD_REGISTER("bottle", { BottleHandler, "Changes item in a bottle slot.", - { { "item", ArgumentType::TEXT }, { "slot", ArgumentType::NUMBER } } }); + { { "item", Ship::ArgumentType::TEXT }, { "slot", Ship::ArgumentType::NUMBER } } }); CMD_REGISTER("item", { ItemHandler, "Sets item ID in arg 1 into slot arg 2. No boundary checks. Use with caution.", - { { "slot", ArgumentType::NUMBER }, { "item id", ArgumentType::NUMBER } } }); - CMD_REGISTER("entrance", - { EntranceHandler, "Sends player to the entered entrance (hex)", { { "entrance", ArgumentType::NUMBER } } }); + { { "slot", Ship::ArgumentType::NUMBER }, { "item id", Ship::ArgumentType::NUMBER } } }); + CMD_REGISTER("entrance", { EntranceHandler, + "Sends player to the entered entrance (hex)", + { { "entrance", Ship::ArgumentType::NUMBER } } }); CMD_REGISTER("save_state", { SaveStateHandler, "Save a state." }); CMD_REGISTER("load_state", { LoadStateHandler, "Load a state." }); - CMD_REGISTER("set_slot", { StateSlotSelectHandler, "Selects a SaveState slot", { - { "Slot number", ArgumentType::NUMBER, } + CMD_REGISTER("set_slot", { StateSlotSelectHandler, "Selects a SaveState slot", { { + "Slot number", + Ship::ArgumentType::NUMBER, + } } }); DebugConsole_LoadCVars(); }