Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
console.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Strings/components/classes/events/events.h>
6 
7 #define CWT_CONSOLE "CONSOLE"
8 
13 {
14 private:
15  bool needs_reconfigure = false;
16  bool needs_deconfigure = false;
17 
18 public:
21  byte opacity = 255;
22  BlamLogMessage message;
23 
24  int visible_ticks = 0;
25 
28 
37  void Reconfigure(BlamLogMessage _message);
38 
45  void Deconfigure();
46 
47  void Draw();
48 };
49 
56 class BlamUIWidget_Console : public BlamUIWidget, public BlamEventListener
57 {
58 private:
59  BlamUIWidget_Text* prompt = nullptr;
60  BlamUIWidget_Text* input = nullptr;
61 
62  std::vector<BlamConsoleHistoryEntry*> history = std::vector<BlamConsoleHistoryEntry*>();
63 
64  std::vector<std::vector<BlamConsoleHistoryEntry*>> help_columns = std::vector<std::vector<BlamConsoleHistoryEntry*>>();
65 
66  std::vector<std::string> input_history = std::vector<std::string>();
67  int selected_history_index = -1;
68 
69  std::string command_input = "";
70  int cursor_position = 0;
71  bool prompt_hidden = true;
72 
73  int column_count = 6;
74  int column_width = 346;
75  int max_output_lines = 32;
76  float output_line_height = 16.0f;
77 
81  void ResizeColumns();
82 
88  void RebuildHelpColumns(bool keep_content);
89 
93  void BuildHelpGuide();
94 
95  void AppendLogMessage(BlamLogMessage message);
96 
97 public:
98 
105 
107 
108  void Draw() override;
109  void ShowImGuiPropertyEditor() override;
110  void UpdateMetrics() override;
111  void RefreshRelativePosition() override;
112 
113  void OnKeyPressEvent(KeyPressEvent* event) override;
114  void OnCharacterInputEvent(CharacterInputEvent* event) override;
115  void OnTickEvent(TickEvent* event) override;
116  void OnLogMessageEvent(LogMessageEvent* event) override;
117 
128  void PrintAsColumns(std::vector<std::string> items);
129 
142  void PrintAsColumns(std::vector<BlamLogMessage> items);
143 
147  void ClearOutput();
148 };
ui.h
BlamUIWidget_Console::ShowImGuiPropertyEditor
void ShowImGuiPropertyEditor() override
Displays an ImGUI-based property editor.
Definition: BlamUIWidget_Console.cpp:177
BlamConsoleHistoryEntry::text_element
BlamUIWidget_Text * text_element
The UI widget used for displaying the message.
Definition: console.h:20
BlamConsoleHistoryEntry::visible_ticks
int visible_ticks
The amount of ticks that the message has been visible.
Definition: console.h:24
BlamConsoleHistoryEntry::BlamConsoleHistoryEntry
BlamConsoleHistoryEntry()
Definition: BlamConsoleHistoryEntry.cpp:6
BlamUIWidget_Group
Class representing a Group widget.
Definition: ui.h:287
logger.h
BlamConsoleHistoryEntry::creation_tick
uint64_t creation_tick
The tick when this entry was created.
Definition: console.h:19
BlamUIWidget_Console::UpdateMetrics
void UpdateMetrics() override
Updates metrics for the widget.
Definition: BlamUIWidget_Console.cpp:195
BlamUIWidget_Console::~BlamUIWidget_Console
~BlamUIWidget_Console()
Definition: BlamUIWidget_Console.cpp:61
BlamUIWidget_Console::OnCharacterInputEvent
void OnCharacterInputEvent(CharacterInputEvent *event) override
Definition: BlamUIWidget_Console.cpp:332
BlamUIWidget_Console::PrintAsColumns
void PrintAsColumns(std::vector< std::string > items)
Displays a list of strings within the console column display.
Definition: BlamUIWidget_Console.cpp:686
BlamUIWidget_Console::BlamUIWidget_Console
BlamUIWidget_Console(BlamUIWidget_Group *_parent)
Constructs a new console widget.
Definition: BlamUIWidget_Console.cpp:16
BlamConsoleHistoryEntry::~BlamConsoleHistoryEntry
~BlamConsoleHistoryEntry()
Definition: BlamConsoleHistoryEntry.cpp:18
BlamConsoleHistoryEntry::Draw
void Draw()
Definition: BlamConsoleHistoryEntry.cpp:39
BlamUIWidget_Console::RefreshRelativePosition
void RefreshRelativePosition() override
Updates the relative position of the widget, relative to its parent.
Definition: BlamUIWidget_Console.cpp:233
uint64_t
unsigned long long uint64_t
Definition: stdint.h:18
BlamUIWidget_Console::Draw
void Draw() override
Draws the widget on-screen.
Definition: BlamUIWidget_Console.cpp:89
BlamConsoleHistoryEntry::Reconfigure
void Reconfigure(BlamLogMessage _message)
Reconfigures this console history entry.
Definition: BlamConsoleHistoryEntry.cpp:24
BlamConsoleHistoryEntry::opacity
byte opacity
The opacity of the message text.
Definition: console.h:21
BlamUIWidget_Console::ClearOutput
void ClearOutput()
Clears the console output.
Definition: BlamUIWidget_Console.cpp:775
BlamUIWidget
Base class for a UI widget.
Definition: ui.h:81
BlamConsoleHistoryEntry::Deconfigure
void Deconfigure()
Deconfigures this console history entry.
Definition: BlamConsoleHistoryEntry.cpp:34
BlamUIWidget_Console
Class for the console UI widget.
Definition: console.h:56
BlamUIWidget_Console::OnLogMessageEvent
void OnLogMessageEvent(LogMessageEvent *event) override
Definition: BlamUIWidget_Console.cpp:477
BlamConsoleHistoryEntry
Class representing a console history entry.
Definition: console.h:12
BlamUIWidget_Console::OnTickEvent
void OnTickEvent(TickEvent *event) override
Definition: BlamUIWidget_Console.cpp:362
BlamConsoleHistoryEntry::message
BlamLogMessage message
The message that this entry is displaying.
Definition: console.h:22
BlamUIWidget_Text
Class representing a Text widget.
Definition: ui.h:550
BlamUIWidget_Console::OnKeyPressEvent
void OnKeyPressEvent(KeyPressEvent *event) override
Definition: BlamUIWidget_Console.cpp:251