2022-03-21 21:52:44 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include "Lib/ImGui/imgui.h"
|
2022-08-09 21:47:39 -04:00
|
|
|
#define NOGDI
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include "spdlog/spdlog.h"
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
namespace Ship {
|
|
|
|
#define CMD_SUCCESS true
|
|
|
|
#define CMD_FAILED false
|
|
|
|
#define MAX_BUFFER_SIZE 255
|
|
|
|
#define NULLSTR "None"
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
typedef std::function<bool(std::vector<std::string> args)> CommandHandler;
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
enum class ArgumentType {
|
|
|
|
TEXT, NUMBER, PLAYER_POS, PLAYER_ROT
|
|
|
|
};
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
struct CommandArgument {
|
|
|
|
std::string info;
|
|
|
|
ArgumentType type = ArgumentType::NUMBER;
|
|
|
|
bool optional = false;
|
|
|
|
};
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
struct CommandEntry {
|
|
|
|
CommandHandler handler;
|
|
|
|
std::string description;
|
|
|
|
std::vector<CommandArgument> arguments;
|
|
|
|
};
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
struct ConsoleLine {
|
|
|
|
std::string text;
|
2022-08-09 21:47:39 -04:00
|
|
|
spdlog::level::level_enum priority = spdlog::level::info;
|
2022-07-31 23:36:21 -04:00
|
|
|
std::string channel = "Main";
|
|
|
|
};
|
2022-03-21 21:52:44 -04:00
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
class Console {
|
|
|
|
int selectedId = -1;
|
|
|
|
std::vector<int> selectedEntries;
|
|
|
|
std::string filter;
|
2022-08-09 21:47:39 -04:00
|
|
|
spdlog::level::level_enum level_filter = spdlog::level::trace;
|
|
|
|
std::vector<std::string> log_channels = { "Console", "Logs" };
|
|
|
|
std::vector<spdlog::level::level_enum> priority_filters = { spdlog::level::off, spdlog::level::critical, spdlog::level::err, spdlog::level::warn, spdlog::level::info, spdlog::level::debug, spdlog::level::trace };
|
2022-07-31 23:36:21 -04:00
|
|
|
std::vector<ImVec4> priority_colors = {
|
2022-08-09 21:47:39 -04:00
|
|
|
ImVec4(0.8f, 0.8f, 0.8f, 1.0f), // TRACE
|
|
|
|
ImVec4(0.9f, 0.9f, 0.9f, 1.0f), // DEBUG
|
|
|
|
ImVec4(1.0f, 1.0f, 1.0f, 1.0f), // INFO
|
|
|
|
ImVec4(1.0f, 0.875f, 0.125f, 1.0f), // WARN
|
|
|
|
ImVec4(0.65f, 0.18f, 0.25, 1.0f), // ERROR
|
|
|
|
ImVec4(0.95f, 0.11f, 0.25, 1.0f), // CRITICAL
|
|
|
|
ImVec4(0.0f, 0.0f, 0.0f, 0.0f) // OFF
|
2022-07-31 23:36:21 -04:00
|
|
|
};
|
2022-08-09 21:47:39 -04:00
|
|
|
protected:
|
|
|
|
void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, va_list args);
|
|
|
|
|
2022-07-31 23:36:21 -04:00
|
|
|
public:
|
|
|
|
std::map<std::string, std::vector<ConsoleLine>> Log;
|
|
|
|
std::map<std::string, CommandEntry> Commands;
|
|
|
|
std::vector<std::string> Autocomplete;
|
|
|
|
std::vector<std::string> History;
|
|
|
|
std::string CMDHint = NULLSTR;
|
|
|
|
char* FilterBuffer = nullptr;
|
|
|
|
char* InputBuffer = nullptr;
|
|
|
|
bool OpenAutocomplete = false;
|
|
|
|
int HistoryIndex = -1;
|
2022-08-09 21:47:39 -04:00
|
|
|
std::string selected_channel = "Console";
|
2022-07-31 23:36:21 -04:00
|
|
|
bool opened = false;
|
|
|
|
void Init();
|
|
|
|
void Update();
|
|
|
|
void Draw();
|
|
|
|
void Dispatch(const std::string& line);
|
|
|
|
static int CallbackStub(ImGuiInputTextCallbackData* data);
|
2022-08-09 21:47:39 -04:00
|
|
|
void SendInfoMessage(const char* fmt, ...);
|
|
|
|
void SendErrorMessage(const char* fmt, ...);
|
|
|
|
void SendInfoMessage(const std::string& str);
|
|
|
|
void SendErrorMessage(const std::string& str);
|
|
|
|
void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...);
|
2022-03-21 21:52:44 -04:00
|
|
|
};
|
2022-07-31 23:36:21 -04:00
|
|
|
}
|