libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
ConsoleWindow.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <vector>
5#include <string>
6#include <functional>
7
10#include <imgui.h>
11#include <spdlog/spdlog.h>
12
13namespace Ship {
14
15class ConsoleVariable;
16
32class ConsoleWindow : public GuiWindow {
33 public:
44 ConsoleWindow(std::shared_ptr<ConsoleVariable> consoleVariable, std::shared_ptr<Window> window,
45 std::shared_ptr<Console> console, const std::string& visibilityCvar, const std::string& name,
46 ImVec2 originalSize, uint32_t windowFlags);
48 virtual ~ConsoleWindow();
49
54 void ClearLogs(std::string channel);
55
57 void ClearLogs();
58
65 void Dispatch(const std::string& line);
66
71 void SendInfoMessage(const char* fmt, ...);
72
77 void SendErrorMessage(const char* fmt, ...);
78
83 void SendInfoMessage(const std::string& str);
84
89 void SendErrorMessage(const std::string& str);
90
97 void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...);
98
103 std::string GetCurrentChannel();
104
109
111 void DrawElement() override;
112
113 protected:
121 void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, va_list args);
122
124 void OnInit(const nlohmann::json& initArgs = nlohmann::json::object()) override;
125
127 void UpdateElement() override;
128
129 private:
131 struct ConsoleLine {
132 std::string Text;
133 spdlog::level::level_enum Priority = spdlog::level::info;
134 std::string Channel = "Console";
135 };
136
137 static int CallbackStub(ImGuiInputTextCallbackData* data);
138 int32_t ClearCommand(const std::vector<std::string>& args, std::string* output);
139 int32_t HelpCommand(const std::vector<std::string>& args, std::string* output);
140 int32_t UnbindCommand(const std::vector<std::string>& args, std::string* output);
141 int32_t BindCommand(const std::vector<std::string>& args, std::string* output);
142 int32_t BindToggleCommand(const std::vector<std::string>& args, std::string* output);
143 int32_t SetCommand(const std::vector<std::string>& args, std::string* output);
144 int32_t GetCommand(const std::vector<std::string>& args, std::string* output);
145 static int32_t CheckVarType(const std::string& input);
146
147 int32_t mSelectedId = -1;
148 int32_t mHistoryIndex = -1;
149 std::vector<int> mSelectedEntries;
150 std::string mFilter;
151 std::string mCurrentChannel = "Console";
152 bool mOpenAutocomplete = false;
153 char* mInputBuffer = nullptr;
154 char* mFilterBuffer = nullptr;
155 std::string mCmdHint = "None";
156 spdlog::level::level_enum mLevelFilter = spdlog::level::trace;
157 std::map<ImGuiKey, std::string> mBindings;
158 std::map<ImGuiKey, std::string> mBindingToggle;
159 std::vector<std::string> mHistory;
160 std::vector<std::string> mAutoComplete;
161 std::map<std::string, std::vector<ConsoleLine>> mLog;
162 const std::vector<std::string> mLogChannels = { "Console", "Logs" };
163 const std::vector<spdlog::level::level_enum> mPriorityFilters = { spdlog::level::off, spdlog::level::critical,
164 spdlog::level::err, spdlog::level::warn,
165 spdlog::level::info, spdlog::level::debug,
166 spdlog::level::trace };
167 const std::vector<ImVec4> mPriorityColours = {
168 ImVec4(0.8f, 0.8f, 0.8f, 1.0f), // TRACE
169 ImVec4(0.9f, 0.9f, 0.9f, 1.0f), // DEBUG
170 ImVec4(1.0f, 1.0f, 1.0f, 1.0f), // INFO
171 ImVec4(1.0f, 0.875f, 0.125f, 1.0f), // WARN
172 ImVec4(0.65f, 0.18f, 0.25, 1.0f), // ERROR
173 ImVec4(0.95f, 0.11f, 0.25, 1.0f), // CRITICAL
174 ImVec4(0.0f, 0.0f, 0.0f, 0.0f) // OFF
175 };
176 static constexpr size_t gMaxBufferSize = 255;
177
178 std::shared_ptr<Console> mConsole;
179 std::shared_ptr<ConsoleVariable> mConsoleVariables;
180};
181} // namespace Ship
An ImGui window that provides an in-game developer console.
Definition ConsoleWindow.h:32
void SendInfoMessage(const std::string &str)
Appends a plain-string informational message to the active console channel.
void SendInfoMessage(const char *fmt,...)
Appends a formatted informational message to the active console channel.
virtual ~ConsoleWindow()
void Append(const std::string &channel, spdlog::level::level_enum priority, const char *fmt,...)
Appends a formatted log entry to the given channel with the given priority.
void OnInit(const nlohmann::json &initArgs=nlohmann::json::object()) override
Registers built-in console commands (clear, help, bind, set, get, …).
ConsoleWindow(std::shared_ptr< ConsoleVariable > consoleVariable, std::shared_ptr< Window > window, std::shared_ptr< Console > console, const std::string &visibilityCvar, const std::string &name, ImVec2 originalSize, uint32_t windowFlags)
Constructs a ConsoleWindow with constructor-injected dependencies.
void ClearBindings()
Removes all key-to-command bindings registered via the "bind" command.
void Append(const std::string &channel, spdlog::level::level_enum priority, const char *fmt, va_list args)
Appends a log entry using a pre-parsed va_list (called by the public overloads).
void SendErrorMessage(const char *fmt,...)
Appends a formatted error message to the active console channel.
std::string GetCurrentChannel()
Returns the name of the currently active log channel.
void UpdateElement() override
Processes key bindings and clears expired auto-complete state.
void SendErrorMessage(const std::string &str)
Appends a plain-string error message to the active console channel.
void Dispatch(const std::string &line)
Parses and executes a command string via the Console subsystem.
void DrawElement() override
Renders the console window contents (log, input field, filters).
void ClearLogs(std::string channel)
Clears all log entries in the given channel.
void ClearLogs()
Clears all log entries across all channels.
A floating ImGui window managed by the Ship Gui layer.
Definition GuiWindow.h:39
GuiWindow(std::shared_ptr< ConsoleVariable > consoleVariable, std::shared_ptr< Window > window, const std::string &visibilityCvar, bool isVisible, const std::string &name, ImVec2 originalSize, uint32_t windowFlags)
Full constructor with constructor-injected dependencies, explicit size and window flags.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14