Jump to content

Deciding on what to use for text input in C# & MonoGame / Xna

Go to solution Solved by gastew15,

Update : I found out that Nuclex's input framework doesn't work right with Monogame and is a pain in the butt and I haven't really found anything else that does, so I went and made another of my own implementations and it turned out sort of ok now. (I still have to make definitions for each non alpha-numeric character though.)

 

My multi-line input kind of textbox code (I'm using it for an in game terminal window. NOTE: I took off the code that restricts horizontal play and moves the viewable area as the string length increases due to it being kind of specific.)

*Variables
KeyboardState currentKeyboardState, previousKeyboardState;
string[] textArray; //Intilize Array Bellow, or in declaration
textLineNumber;

public void Update()
{
    previousKeyboardState = currentKeyboardState;
    currentKeyboardState = Keyboard.GetState();

    Keys[] pressedKeys;
    pressedKeys = currentKeyboardState.GetPressedKeys();

    foreach (Keys key in pressedKeys)
    {
        if (previousKeyboardState.IsKeyUp(key))
        {
            if (key == Keys.Back)
                {
                    if (textArray[textLineNumber].Length > 0)
                        textArray[textLineNumber] = textArray[textLineNumber].Remove(textArray[textLineNumber].Length - 1, 1);
                }
            else if (key == Keys.Space)
                textArray[textLineNumber] = textArray[textLineNumber].Insert(textArray[textLineNumber].Length, " ");
            else if (key == Keys.Enter)
                {
                if (textLineNumber < textArray.Length - 1)
                    textLineNumber++;
                else
                {
                    for (int j = 0; j < textArray.Length - 1; j++)
                    {
                        textArray[j] = textArray[j + 1];
                    }
                textArray[textArray.Length - 1] = "";
                }
                //Do other enter functions here
            }
            else
                textArray[textLineNumber] += key.ToString();
        }
    }
}

 

*I wonder if it's bad to solve your own topic?

Alright so I've been working on a game in Monogame for quite awhile now and the time has finally come for the terribleness that is handling text input in the frameworks. Instead of making my own horrible system for dealing with the issue, I actually tried and it was horrible and locked to the refresh rate missing some inputs, I'm going to use a framework of some kind. At the moment I think I've decided on using the Nuclex Framework, link here: http://nuclexframework.codeplex.com/wikipage?title=Nuclex.Input&referringTitle=Home, but before I jump right on board using anything I was curious if anyone had any better suggestions. Personally it seems like one of the best options out there at the moment, but I've been wrong in the past and appreciate any input, thank you for any time you take to give any suggestions.

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to comment
Share on other sites

Link to post
Share on other sites

I thought Microsoft killed off xna years back.

Link to comment
Share on other sites

Link to post
Share on other sites

I thought Microsoft killed off xna years back.

They did, but quite a few people still use it because Monogame makes it work again and gives Xna cross platform support to Linux, Mac, IOS, Android, and even Oyua. The only problem is that it's buggy as hell alot of the time. (Still really great for some stuff though)

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to comment
Share on other sites

Link to post
Share on other sites

Update : I found out that Nuclex's input framework doesn't work right with Monogame and is a pain in the butt and I haven't really found anything else that does, so I went and made another of my own implementations and it turned out sort of ok now. (I still have to make definitions for each non alpha-numeric character though.)

 

My multi-line input kind of textbox code (I'm using it for an in game terminal window. NOTE: I took off the code that restricts horizontal play and moves the viewable area as the string length increases due to it being kind of specific.)

*Variables
KeyboardState currentKeyboardState, previousKeyboardState;
string[] textArray; //Intilize Array Bellow, or in declaration
textLineNumber;

public void Update()
{
    previousKeyboardState = currentKeyboardState;
    currentKeyboardState = Keyboard.GetState();

    Keys[] pressedKeys;
    pressedKeys = currentKeyboardState.GetPressedKeys();

    foreach (Keys key in pressedKeys)
    {
        if (previousKeyboardState.IsKeyUp(key))
        {
            if (key == Keys.Back)
                {
                    if (textArray[textLineNumber].Length > 0)
                        textArray[textLineNumber] = textArray[textLineNumber].Remove(textArray[textLineNumber].Length - 1, 1);
                }
            else if (key == Keys.Space)
                textArray[textLineNumber] = textArray[textLineNumber].Insert(textArray[textLineNumber].Length, " ");
            else if (key == Keys.Enter)
                {
                if (textLineNumber < textArray.Length - 1)
                    textLineNumber++;
                else
                {
                    for (int j = 0; j < textArray.Length - 1; j++)
                    {
                        textArray[j] = textArray[j + 1];
                    }
                textArray[textArray.Length - 1] = "";
                }
                //Do other enter functions here
            }
            else
                textArray[textLineNumber] += key.ToString();
        }
    }
}

 

*I wonder if it's bad to solve your own topic?

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×