Game Development Reference
In-Depth Information
m_textBox->SetPosition(textRectangle.Position());
m_textBox->SetSize(textRectangle.Size());
m_textBox->SetBackgroundColor(m_backgroundColor);
m_textBox->SetForegroundColor(render::color::WHITE);
m_textBox->OnTextEntered() += [this](void* sender, const std::wstring text) { Execute(text); };
m_textBox->SetAutoCompleteSource(runtime_variable::GetDatabase().GetTrie());
What is important is what happens when text has been entered and we need to take some
action with it. There are three things that may happen:
The player typed in the name of a runtime variable, but did not provide a value to set.
In this situation, it is useful to print into the console the variable name and the value it is
currently set to, ideally, we should also display the description this allows the user to get
more information about a particular variable.
The player typed in the name of a runtime variable followed by some value.
Inthiscasewewanttochangethevalueofthevariable,wewillneedtoparsethetexttyped
in by the player and convert it to the appropriate data type.
The player typed in some text that does not correspond to any runtime variable.
While not an error condition, we should notify the player that no such variable exists, our
auto-completion implementation makes this case less likely to happen, however, accidents
dooccurandweallmaketyposorhittheoccasionalrandomkeyjustbeforewepressenter.
void console::Execute(const std::wstring& text)
{
if ( text.size() == 0 )
return;
console_parser params(text.c_str());
auto& database = runtime_variable::GetDatabase();
if ( !database.GetTrie()->contains_word(params.GetString(0).c_str()) )
{
AddHistory(text);
AddItem(text + L" not found.", render::color::RED);
return;
}
for ( auto it : database.GetVariables() )
{
if ( wcscmp(it->Name().c_str(), params.GetString(0).c_str()) == 0 )
{
if (it->Parse(params.GetParametersFromIndex(1).c_str()))
{
AddItem(text, m_textBox->GetForegroundColor());
AddHistory(text);
}
Search WWH ::




Custom Search