libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::ConsoleWindow Class Reference

An ImGui window that provides an in-game developer console. More...

#include <ConsoleWindow.h>

Inheritance diagram for Ship::ConsoleWindow:
[legend]
Collaboration diagram for Ship::ConsoleWindow:
[legend]

Public Member Functions

 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.
 
virtual ~ConsoleWindow ()
 
void ClearLogs (std::string channel)
 Clears all log entries in the given channel.
 
void ClearLogs ()
 Clears all log entries across all channels.
 
void Dispatch (const std::string &line)
 Parses and executes a command string via the Console subsystem.
 
void SendInfoMessage (const char *fmt,...)
 Appends a formatted informational message to the active console channel.
 
void SendErrorMessage (const char *fmt,...)
 Appends a formatted error message to the active console channel.
 
void SendInfoMessage (const std::string &str)
 Appends a plain-string informational message to the active console channel.
 
void SendErrorMessage (const std::string &str)
 Appends a plain-string error message to the active console channel.
 
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.
 
std::string GetCurrentChannel ()
 Returns the name of the currently active log channel.
 
void ClearBindings ()
 Removes all key-to-command bindings registered via the "bind" command.
 
void DrawElement () override
 Renders the console window contents (log, input field, filters).
 
 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.
 
 GuiWindow (const std::string &consoleVariable, bool isVisible, const std::string &name, ImVec2 originalSize)
 Constructor with explicit size, using default ImGui window flags.
 
 GuiWindow (const std::string &consoleVariable, bool isVisible, const std::string &name, ImVec2 originalSize, uint32_t windowFlags)
 
 GuiWindow (const std::string &consoleVariable, bool isVisible, const std::string &name)
 Minimal constructor using default size and flags.
 
 GuiWindow (const std::string &consoleVariable, const std::string &name, ImVec2 originalSize, uint32_t windowFlags)
 Constructor deriving initial visibility from the CVar value.
 
 GuiWindow (const std::string &consoleVariable, const std::string &name, ImVec2 originalSize)
 Constructor deriving visibility from CVar, with default flags.
 
 GuiWindow (const std::string &consoleVariable, const std::string &name)
 Minimal constructor deriving visibility from CVar.
 
- Public Member Functions inherited from Ship::GuiWindow
 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.
 
 GuiWindow (const std::string &consoleVariable, bool isVisible, const std::string &name, ImVec2 originalSize)
 Constructor with explicit size, using default ImGui window flags.
 
 GuiWindow (const std::string &consoleVariable, bool isVisible, const std::string &name, ImVec2 originalSize, uint32_t windowFlags)
 
 GuiWindow (const std::string &consoleVariable, bool isVisible, const std::string &name)
 Minimal constructor using default size and flags.
 
 GuiWindow (const std::string &consoleVariable, const std::string &name, ImVec2 originalSize, uint32_t windowFlags)
 Constructor deriving initial visibility from the CVar value.
 
 GuiWindow (const std::string &consoleVariable, const std::string &name, ImVec2 originalSize)
 Constructor deriving visibility from CVar, with default flags.
 
 GuiWindow (const std::string &consoleVariable, const std::string &name)
 Minimal constructor deriving visibility from CVar.
 
void Draw () override
 Calls ImGui::Begin(), invokes DrawElement(), and calls ImGui::End().
 
- Public Member Functions inherited from Ship::GuiElement
 GuiElement (const std::string &name, bool isVisible)
 Constructs a GuiElement with an explicit initial visibility.
 
 GuiElement (const std::string &name)
 Constructs a GuiElement that starts hidden.
 
virtual ~GuiElement ()
 
void Update ()
 Updates element state for the current frame (called before Draw).
 
void Show ()
 Makes the element visible (equivalent to SetVisibility(true)).
 
void Hide ()
 Hides the element (equivalent to SetVisibility(false)).
 
void ToggleVisibility ()
 Flips the visibility state between shown and hidden.
 
bool IsVisible ()
 Returns true if the element is currently visible.
 
- Public Member Functions inherited from Ship::Component
 Component (const std::string &name, std::shared_ptr< Context > context=nullptr)
 Constructs a Component with the given name.
 
virtual ~Component ()
 
void Init (const nlohmann::json &initArgs=nlohmann::json::object())
 Performs one-time initialization of this component.
 
bool IsInitialized () const
 Returns true once Init() (or MarkInitialized()) has completed successfully.
 
const std::string & GetName () const
 Returns the name of this Component.
 
std::string ToString () const
 Returns a human-readable string representation (e.g. "Name (id)").
 
std::string ToTreeString (int depth=0) const
 Returns a human-readable tree representation of this component and its children.
 
 operator std::string () const
 Conversion operator to std::string; equivalent to ToString().
 
ParentComponentListGetParents ()
 Returns a mutable reference to the parent list.
 
const ParentComponentListGetParents () const
 Returns a const reference to the parent list.
 
ComponentListGetChildren ()
 Returns a mutable reference to the child list.
 
const ComponentListGetChildren () const
 Returns a const reference to the child list.
 
virtual std::shared_ptr< ComponentTryGetSharedComponent () noexcept
 Returns a shared_ptr to this Component when available, otherwise nullptr.
 
virtual std::shared_ptr< ComponentGetSharedComponent ()
 Returns a shared_ptr to this Component via the correct enable_shared_from_this base.
 
template<typename T >
bool HasInChildren () const
 Checks whether any descendant Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInChildren () const
 Returns the first descendant that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInChildren () const
 Returns all descendants that match type T via BFS.
 
template<typename T >
bool HasInParents () const
 Checks whether any ancestor Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInParents () const
 Returns the first ancestor that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInParents () const
 Returns all ancestors that match type T via BFS.
 
- Public Member Functions inherited from Ship::Part
 Part ()
 Constructs a Part and assigns it a unique ID.
 
 Part (std::shared_ptr< Context > context)
 Constructs a Part with an explicit Context reference and unique ID.
 
virtual ~Part ()=default
 
uint64_t GetId () const
 Returns the unique identifier for this Part.
 
bool operator== (const Part &other) const
 Compares two Parts for equality by their unique IDs.
 
std::shared_ptr< ContextGetContext () const
 Returns the Context this Part belongs to, or nullptr if unset.
 
void SetContext (std::shared_ptr< Context > ctx)
 Sets the Context this Part belongs to.
 

Protected Member Functions

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 OnInit (const nlohmann::json &initArgs=nlohmann::json::object()) override
 Registers built-in console commands (clear, help, bind, set, get, …).
 
void UpdateElement () override
 Processes key bindings and clears expired auto-complete state.
 
- Protected Member Functions inherited from Ship::GuiWindow
void SetVisibility (bool visible) override
 Overrides SetVisibility to also write the new state to the backing CVar.
 
void BeginGroupPanel (const char *name, const ImVec2 &size)
 Begins a visually grouped labelled panel.
 
void EndGroupPanel (float minHeight)
 Ends the previously opened group panel, adding a bottom margin.
 
void SyncVisibilityConsoleVariable ()
 Reads the CVar and updates mIsVisible accordingly.
 
void OnInit (const nlohmann::json &initArgs={}) override
 Component initialization hook.
 
std::shared_ptr< WindowGetWindow () const
 Returns the Window this GuiWindow belongs to.
 
- Protected Member Functions inherited from Ship::Component
void MarkInitialized ()
 Marks this component as initialized without going through Init().
 
template<typename T >
std::shared_ptr< T > RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const
 Returns a cached dependency after validating it exists and is initialized.
 
- Protected Member Functions inherited from Ship::Part
virtual void OnAdded (bool forced)
 Called after this Part has been added to a PartList.
 
virtual void OnRemoved (bool forced)
 Called after this Part has been removed from a PartList.
 

Additional Inherited Members

- Protected Attributes inherited from Ship::GuiElement
bool mIsVisible
 Current visibility state. Subclasses may read this directly.
 

Detailed Description

An ImGui window that provides an in-game developer console.

ConsoleWindow renders a scrollable log view with a command-input field and delegates command execution to the Console subsystem. It supports:

  • Multiple named log channels (Console / Logs).
  • Key bindings (bind/unbind commands).
  • Log-level filtering.
  • Command history and auto-complete.

The window integrates with spdlog through a custom sink that routes log output to the "Logs" channel automatically.

Obtain the instance from Gui::GetGuiWindow("Console").

Constructor & Destructor Documentation

◆ ConsoleWindow()

Ship::ConsoleWindow::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.

Parameters
consoleVariableConsoleVariable dependency (threaded from GuiWindow).
windowWindow dependency (threaded from GuiWindow).
consoleConsole subsystem for command dispatch.
visibilityCvarCVar name for window visibility.
nameWindow title.
originalSizeDefault window size.
windowFlagsImGui window flags.

◆ ~ConsoleWindow()

virtual Ship::ConsoleWindow::~ConsoleWindow ( )
virtual

Member Function Documentation

◆ Append() [1/2]

void Ship::ConsoleWindow::Append ( const std::string &  channel,
spdlog::level::level_enum  priority,
const char *  fmt,
va_list  args 
)
protected

Appends a log entry using a pre-parsed va_list (called by the public overloads).

Parameters
channelLog channel.
priorityspdlog log level.
fmtprintf-style format string.
argsArgument list.

◆ Append() [2/2]

void Ship::ConsoleWindow::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.

Parameters
channelLog channel to write to (e.g. "Console").
priorityspdlog log level used to colour the entry.
fmtprintf-style format string.

◆ ClearBindings()

void Ship::ConsoleWindow::ClearBindings ( )

Removes all key-to-command bindings registered via the "bind" command.

◆ ClearLogs() [1/2]

void Ship::ConsoleWindow::ClearLogs ( )

Clears all log entries across all channels.

◆ ClearLogs() [2/2]

void Ship::ConsoleWindow::ClearLogs ( std::string  channel)

Clears all log entries in the given channel.

Parameters
channelChannel name to clear (e.g. "Console" or "Logs").

◆ Dispatch()

void Ship::ConsoleWindow::Dispatch ( const std::string &  line)

Parses and executes a command string via the Console subsystem.

Equivalent to the user pressing Enter in the input field.

Parameters
lineRaw command string.

◆ DrawElement()

void Ship::ConsoleWindow::DrawElement ( )
overridevirtual

Renders the console window contents (log, input field, filters).

Implements Ship::GuiElement.

◆ GetCurrentChannel()

std::string Ship::ConsoleWindow::GetCurrentChannel ( )

Returns the name of the currently active log channel.

Returns
Channel name (e.g. "Console" or "Logs").

◆ GuiWindow() [1/7]

Ship::GuiWindow::GuiWindow ( const std::string &  consoleVariable,
bool  isVisible,
const std::string &  name 
)

Minimal constructor using default size and flags.

Parameters
consoleVariableCVar name for visibility.
isVisibleInitial visibility.
nameWindow title.

◆ GuiWindow() [2/7]

Ship::GuiWindow::GuiWindow ( const std::string &  consoleVariable,
bool  isVisible,
const std::string &  name,
ImVec2  originalSize 
)

Constructor with explicit size, using default ImGui window flags.

Parameters
consoleVariableCVar name for visibility.
isVisibleInitial visibility.
nameWindow title.
originalSizeDefault window size.

◆ GuiWindow() [3/7]

Ship::GuiWindow::GuiWindow ( const std::string &  consoleVariable,
bool  isVisible,
const std::string &  name,
ImVec2  originalSize,
uint32_t  windowFlags 
)

◆ GuiWindow() [4/7]

Ship::GuiWindow::GuiWindow ( const std::string &  consoleVariable,
const std::string &  name 
)

Minimal constructor deriving visibility from CVar.

Parameters
consoleVariableCVar name for visibility.
nameWindow title.

◆ GuiWindow() [5/7]

Ship::GuiWindow::GuiWindow ( const std::string &  consoleVariable,
const std::string &  name,
ImVec2  originalSize 
)

Constructor deriving visibility from CVar, with default flags.

Parameters
consoleVariableCVar name for visibility.
nameWindow title.
originalSizeDefault window size.

◆ GuiWindow() [6/7]

Ship::GuiWindow::GuiWindow ( const std::string &  consoleVariable,
const std::string &  name,
ImVec2  originalSize,
uint32_t  windowFlags 
)

Constructor deriving initial visibility from the CVar value.

Parameters
consoleVariableCVar name for visibility (its persisted value is used as initial state).
nameWindow title.
originalSizeDefault window size.
windowFlagsImGui window flags.

◆ GuiWindow() [7/7]

Ship::GuiWindow::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.

Parameters
consoleVariableConsoleVariable dependency for CVar read/write.
windowWindow dependency for GUI save scheduling.
visibilityCvarCVar name used to persist/read visibility (e.g. "gMyWindow").
isVisibleInitial visibility.
nameWindow title shown in the ImGui title bar.
originalSizeDefault size of the window on first open.
windowFlagsImGui window flags (e.g. ImGuiWindowFlags_NoResize).

◆ OnInit()

void Ship::ConsoleWindow::OnInit ( const nlohmann::json &  initArgs = nlohmann::json::object())
overrideprotectedvirtual

Registers built-in console commands (clear, help, bind, set, get, …).

Reimplemented from Ship::Component.

◆ SendErrorMessage() [1/2]

void Ship::ConsoleWindow::SendErrorMessage ( const char *  fmt,
  ... 
)

Appends a formatted error message to the active console channel.

Parameters
fmtprintf-style format string.

◆ SendErrorMessage() [2/2]

void Ship::ConsoleWindow::SendErrorMessage ( const std::string &  str)

Appends a plain-string error message to the active console channel.

Parameters
strMessage string.

◆ SendInfoMessage() [1/2]

void Ship::ConsoleWindow::SendInfoMessage ( const char *  fmt,
  ... 
)

Appends a formatted informational message to the active console channel.

Parameters
fmtprintf-style format string.

◆ SendInfoMessage() [2/2]

void Ship::ConsoleWindow::SendInfoMessage ( const std::string &  str)

Appends a plain-string informational message to the active console channel.

Parameters
strMessage string.

◆ UpdateElement()

void Ship::ConsoleWindow::UpdateElement ( )
overrideprotectedvirtual

Processes key bindings and clears expired auto-complete state.

Implements Ship::GuiElement.


The documentation for this class was generated from the following file: