#ifndef CONSOLE_CLASS #define CONSOLE_CLASS #include #include #include #include #include class Font; class Box; class TextBox; // The in-game console. Commands get registered by name and run with whatever words follow them. class Console { public: using Arguments = std::vector; // the words after the command name using Command = std::function; explicit Console(Font* newFont); // usage is shown by help, like "give [count]". Names aren't case sensitive. void Register(const std::string& name, const std::string& usage, const std::string& description, Command run); void Execute(const std::string& line); void Print(const std::string& message); void Open(); void Close(); void Toggle() { open ? Close() : Open(); } bool IsOpen() const { return open; } // Feed these from the GLFW callbacks while it's open void OnChar(unsigned int codepoint); void OnKey(int key); // Positive goes back toward older lines void Scroll(int lines); // Once a frame, refreshes what's on screen void Update(float dt); private: struct Entry { std::string usage; std::string description; Command run; }; void CreateDisplay(); Font* font = nullptr; std::map commands; // sorted, so help lists them alphabetically std::deque log; std::vector history; int historyIndex = 0; // history.size() means the line being typed std::string input; int scroll = 0; // how many lines up from the newest float caretTimer = 0.0f; bool open = false; Box* background = nullptr; Box* inputBackground = nullptr; TextBox* logText = nullptr; TextBox* inputText = nullptr; }; #endif