public override void HandleInput(InputState input) { string text = input.GetTextSinceUpdate(ControllingPlayer); text = text.Replace("\n", ""); PlayerIndex outs; if(text.Length > 0) { int index = text.IndexOf('\b'); text = text.Replace("\b", ""); int displacement = (cursorPosition > 0 && index != -1 ? -1 : 0); Content = Content.Substring(0, cursorPosition + displacement) + text + Content.Substring(cursorPosition); cursorPosition += text.Length + displacement; } else if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Left, null, out outs)) cursorPosition--; else if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Right, null, out outs)) cursorPosition++; else base.HandleInput(input); cursorPosition = (int)MathHelper.Clamp(cursorPosition, 0, Content.Length); }
public override void HandleInput(InputState input) { if (mReadingInput) { string text = input.GetTextSinceUpdate(ControllingPlayer); if (text.Length == 0) return; if (text[text.Length - 1] == '\n') { text = text.Remove(text.Length - 1); mReadingInput = false; } if (text.Length > 0 && text[0] == '\b') { if (mProfiles[mSelectedButton].Name.Length > 0) mProfiles[mSelectedButton].Name = mProfiles[mSelectedButton].Name.Remove(mProfiles[mSelectedButton].Name.Length - 1) + text.Substring(1); else mProfiles[mSelectedButton].Name = text.Substring(1); } else mProfiles[mSelectedButton].Name += text; Buttons[mSelectedButton].Text = mProfiles[mSelectedButton].Name; CreateDimensions(); if (!mReadingInput) { if (mProfiles[mSelectedButton].Name.Length < 1) mProfiles[mSelectedButton].Name = " "; ProfileSelectedButton(Buttons[mSelectedButton], null); if (ProfileSaved != null) ProfileSaved(this, new PlayerIndexEventArgs(ControllingPlayer.HasValue ? ControllingPlayer.Value : PlayerIndex.One)); mProfiles[mSelectedButton].Register(); ExitScreen(); } } else { base.HandleInput(input); PlayerIndex pl; if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Delete, ControllingPlayer, out pl)) { MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen("Are you sure you want to delete Profile:\n " + mProfiles[mSelectedButton].Name); confirmExitMessageBox.Buttons[0].Pressed += ConfirmExitMessageBoxAccepted; ScreenManager.AddScreen(confirmExitMessageBox, pl); } } }