Game Development Reference
In-Depth Information
}
if ( m_index >= m_children.size() )
{
m_index = 0;
}
auto& next = m_children.at(m_index);
++m_index;
return next;
}
The first part will return nullptr if this node has no children, the second part will wrap the
index around to prevent accessing the vector out of bounds, and finally we will retrieve the
node at the index, increment the index and return.
Thebestpartofusingsuchaself-containedsolutionisthatusingthisfeaturebecomestrivi-
al and can be reused by different systems.
Finally we will need to apply the auto completion, we store the portion of auto completion
text asaseparate member variable, thiswaywecanappendthisvariable totheuser'sinput
using a different font style or color to indicate that it's a suggestion and only if the player
commits the auto completion by pressing TAB or ENTER then it becomes the contents of
the text box and we clear the stored auto complete text.
void textbox::AutoComplete(bool reset = false)
{
if ( reset || m_currentResult == nullptr ) {
m_currentResult = m_trie->find_prefix(m_text);
}
if ( m_currentResult != nullptr ) {
m_autocompleteText.clear();
m_trie->get_from_prefix(m_currentResult->next(), m_autocompleteText);
}
else {
m_autocompleteText.clear();
}
}
Theparameterresetisusedwhentheautocompletetextmayhavechangedenoughthatthe
prefixisnolongervalid,thiscanhappenwhentheuserpressesbackspaceanderasesapart
of the prefix.
4.3.7 Message Box
It's useful to have a way to communicate with the user, whether it's the player or the de-
veloper that something has happened. One example of a situation in which a message box
Search WWH ::




Custom Search