XNA Guide text input - maximum length
- by simonalexander2005
so I am using Guide.BeginShowKeyboardInput to get the user to enter their username. I would like this to be limited to 20 characters, and it seems to break expected behaviour to let them input whatever they like and trim it later - so how would I go about limiting what they can input in the text box itself? I have the following code:
public string GetKeyboardInput(string title, string description, string defaultText, int maxLength)
{
if (input.CheckCancel())
{
useKeyboardResult = false;
KeyboardResult = null;
}
if (KeyboardResult == null && !Guide.IsVisible)
{
KeyboardResult = Guide.BeginShowKeyboardInput(PlayerIndex.One, title,
description, defaultText, null, null);
useKeyboardResult = true;
}
else if (KeyboardResult != null && KeyboardResult.IsCompleted)
{
string result = Guide.EndShowKeyboardInput(KeyboardResult);
KeyboardResult = null;
if (result == null)
{
useKeyboardResult = false;
return null;
}
if (useKeyboardResult)
{
KeyboardResult = null;
return result;
}
}
else //the user is still entering inputs
{
}
return null;
}
I assume the code I need would go in that final, empty else{} block, but I can't see any way to do this. Does anyone know how?