Game Development Reference
In-Depth Information
variable, and after we can push the newly entered text to the front of the history's list and
reset the iterator to the front.
void console::AddHistory(const std::wstring& text) {
m_currentHistoryItem = m_history.begin();
We add the text to the front of the list because we want to iterate the list in reverse order as
we press the up key, showing the last added item first and so on. the Console
To render the game console we can take advantage of the UI controls we have already de-
veloped. We need two controls, a listbox and a textbox, the textbox will serve as user input
and we will take advantage of the auto completion feature we developed. The listbox will
allow us to keep the history of commands that we have entered and will also serve as the
place to provide the user with information related to the commands or variables they have
In our console class we will add our UI controls.
std::unique_ptr<textbox> m_textBox;
std::unique_ptr<listbox> m_listBox;
In the console's constructor we will initialize the console UI controls to the size and posi-
tion we want, typically this is the top of the viewport and extending about one third of the
auto viewport = m_core->GetDevice()->GetViewport();
m_rectangle = math::rectangle(viewport.Left(), viewport.Top(), viewport.Width(), viewport.Height() * 0.4f);
m_backgroundColor = render::color::DARKSLATEGRAY;
m_backgroundColor.A() = 0.4f;
math::rectangle textRectangle = m_rectangle;
textRectangle.Top() = m_rectangle.Bottom() - m_font->GetLineSpacing();
textRectangle.Height() = m_font->GetLineSpacing();
m_textBox = std::unique_ptr<textbox>(new textbox(m_core, m_font, m_spriteBatch));
m_textBox->OnTextEntered() += [this](void*, const std::wstring& text) { Execute(text); };
Search WWH ::

Custom Search