Asset - Extension Text Inputs - GM Studio 1

Dragon47

Member


Demo: https://www.mediafir...qpb1o0g0uaztqrs


Poor input boxes make your game look and feel unprofessional, and can ruin the important first impression of a player. But they're a pain to program properly. With this text input extension you can avoid dozens of hours of UI programming, and get high quality text inputs in an instant!

This is the GM Studio 1 version of Text Inputs. Click here for the GM Studio 2 version.

Features:
  • Singleline and multiline text input.
  • Horizontal and vertical text alignment.
  • Text selection (with mouse, shift, Ctrl + A, and doubleclick).
  • Text navigation (with mouse, arrow keys, home/end and page up/down with Ctrl functionality).
  • Copying, cutting and pasting.
  • Local undo/redo memory. Ctrl + Z and Ctrl + Y (as well as Ctrl + Shift + Z).
  • Delete and backspace with Ctrl functionality.
  • Supports both monospaced and variable-width fonts.
  • Custom cursor sprite and cursor styles.
  • Supports octothorps (#).
  • Commented and organized code.
  • Fast and optimized, made with efficiency in mind.
  • Logic and display separation.
  • Irrespective of room speed, dependent on delta_time (and easily convertable to other game loops if need be).
  • All GML.
Marketplace link: https://marketplace....845/text-inputs

Screenshots from marketplace:





More:




 
Last edited:

JeffJ

Member
I've been using this a lot, and it's really good, but there is one feature I am sorely lacking: the ability to freely move around a field and have everything about it update realtime. Could this be added?
 

Dragon47

Member
I've been using this a lot, and it's really good, but there is one feature I am sorely lacking: the ability to freely move around a field and have everything about it update realtime. Could this be added?
You can move a text field around with input_text_set_transformation. Here you can specify the position.
 

JeffJ

Member
I completely missed that script. Awesome!

However, after moving it with that, I can no longer click in the field to activate it or write in it (where as using my own 'hack' making it jump to mouse coordinates did not give this result)
 

Dragon47

Member
The collision boxes used for activating a text field in the asset's example is not really part of the actual text fields, it's just an example implementation for how to activate/deactivate text inputs. The extension on its own focuses on the text and not how its input is activated/deactivated. So if you want the collision box to move around with the text input, this has to be programmed on the user's side.
 

JeffJ

Member
Of course, I didn't think about that. That's what you get for trying to work when tired.

Got it to work now. Thanks a lot!

There are two more issues, one is minor, the other is a little more annoying.

Minor: when you select a textfield that already has text in it, the cursor is not sent to the end of the text, but instead at the beginning as with an empty field. Is this by design? It seems counter intuitive.
Not so minor: trying to copy text from an external source (such as notepad) and paste it into a text field in the program doesn't work, nor does it the other way around (copying text from a text field inside the program and pasting it into an external source)

Otherwise this is perfect!
 

Dragon47

Member
Of course, I didn't think about that. That's what you get for trying to work when tired.

Got it to work now. Thanks a lot!

There are two more issues, one is minor, the other is a little more annoying.

Minor: when you select a textfield that already has text in it, the cursor is not sent to the end of the text, but instead at the beginning as with an empty field. Is this by design? It seems counter intuitive.
Not so minor: trying to copy text from an external source (such as notepad) and paste it into a text field in the program doesn't work, nor does it the other way around (copying text from a text field inside the program and pasting it into an external source)

Otherwise this is perfect!
The cursor should be placed in the location you click with your mouse. If you click to the left of the text input it will be placed at the beginning, to the right it will be placed at the end, and in between, it should be placed between the two closest letters. See the example code.

As for the other issue, the problem was that it was using the HTML5 version which only has local copying and pasting. I've updated the asset so that this works properly now, but haven't managed to upload it to the marketplace yet. I sent you a private message with the newest version.
 
C

Coralium

Guest
I got this, but I'm having trouble making it work. Could you give an example on how to actually set up an input box? I've been trying to work it out from looking at the example, but so far no dice. (I'm a bit of a GML noob at the moment)
 

Dragon47

Member
I got this, but I'm having trouble making it work. Could you give an example on how to actually set up an input box? I've been trying to work it out from looking at the example, but so far no dice. (I'm a bit of a GML noob at the moment)
Take a look at the script called "GUIDE". It explains how to use the asset's scripts.
 
C

Coralium

Guest
Well, I went for a walk, then came back and changed a couple of things and suddenly everything started working lol. Thanks for your time!
 
C

Colcoction

Guest
This looks incredible. I have one question: can the text be stored (in a variable) and then loaded somehow? I'm thinking of using something like this for a project where the user can write information, save it, and then load it between play sessions. Would that be possible?
 

Dragon47

Member
Yes, you can use input_text_get_text to get the content of an input field and input_text_set_text to set the input by code.
 

JeffJ

Member
When I save text from a multiline field with linebreaks to a file, the breaks are saved as "\n".
How would I go about changing it so that it will instead save them as "#"?
 

Dragon47

Member
When I save text from a multiline field with linebreaks to a file, the breaks are saved as "\n".
How would I go about changing it so that it will instead save them as "#"?
The character "chr(10)" is used for new lines. If you do "string_replace_all(string_obtained_from_input_field, chr(10), "#");" I think it will work.
 
C

Captain Pumpkinhead

Guest
Hey @Dragon47, I'm having an issue. I thought that drawing the text box in the spot I wanted would be as simple as getting the X, Y, Width, and Height variables right, but the text is not drawing where I'm telling it to. Instead, I'm getting this:
upload_2019-10-14_6-47-50.png

Weirdly, moving the view shows that the text's position isn't being drawn consistent to the room, but rather it's consistent to the view:
upload_2019-10-14_6-50-36.png

This becomes even more obvious after zooming out:
upload_2019-10-14_6-51-50.png


I think I can understand why this design choice was made. The majority of people using this will be implementing it for a menu/GUI/HUD-like display in a game, and so drawing relative to the view makes sense for those cases. I'm using it instead to write an application, and I want to draw the text at the X and Y positions in the room.

I've been trying to go through the Draw event to figure out exactly where this is done, and what I need to change to make it do what I want it to do, but a lot of it is stuff I don't understand. Can you help me, please?
 

Dragon47

Member
Hey @Dragon47, I'm having an issue. I thought that drawing the text box in the spot I wanted would be as simple as getting the X, Y, Width, and Height variables right, but the text is not drawing where I'm telling it to. Instead, I'm getting this:
View attachment 27037

Weirdly, moving the view shows that the text's position isn't being drawn consistent to the room, but rather it's consistent to the view:
View attachment 27038

This becomes even more obvious after zooming out:
View attachment 27039


I think I can understand why this design choice was made. The majority of people using this will be implementing it for a menu/GUI/HUD-like display in a game, and so drawing relative to the view makes sense for those cases. I'm using it instead to write an application, and I want to draw the text at the X and Y positions in the room.

I've been trying to go through the Draw event to figure out exactly where this is done, and what I need to change to make it do what I want it to do, but a lot of it is stuff I don't understand. Can you help me, please?
Yes, you are correct it's because it's normally used for GUI. If you go into the obj_input_text object, you can see I use the "Draw GUI" event. Changing this to just a normal draw event should solve it.
 
C

Captain Pumpkinhead

Guest
Yes, you are correct it's because it's normally used for GUI. If you go into the obj_input_text object, you can see I use the "Draw GUI" event. Changing this to just a normal draw event should solve it.
That did the trick!!
Thank you for your help, Dragon, and thank you for selling this awesome code! This has shortened my production time by a long shot!
 
C

Captain Pumpkinhead

Guest
Okay, I've run into another problem, and I was hoping to get some help again, if that's okay.

The input text boxes have been working great most of the time, but today I got an error: "Fatal Memory Error: Out of Memory!"

Here's the line of code I'm running:
Code:
next_question_desc_selected = input_text_create_multiline_ext(temp_x,1736 + th1, temp_width,            -1,        fnt_tahoma_16, c_black, 1, temp_width, -1, -1, -1, fa_left, fa_top, true, 0);
I have that -1 (height) separated out because that seems to be the cause of the error. I also went into debug mode to track exactly where the code was breaking. This is the line where the code broke:

obj_input_text, Draw End, line 10:
Code:
if (!surface_exists(sf_selection)) sf_selection = surface_create(width + eoln_width, height);
So 'surface_create();' must be the culprit, since that's where 'height' is called upon.

You might remember I changed Draw GUI to Draw End for my project, so I changed it back to see what would happen, and the memory error occurred at the same spot.

I'm confused, because in 'input_text_create()', it says "height: ... Set to -1 for no limit."

I can probably just work around it by throwing in a really big number, but that still technically limits it. I was hoping to ask for help again to see what I can do to fix it.
Thanks in advance!
 

Dragon47

Member
Okay, I've run into another problem, and I was hoping to get some help again, if that's okay.

The input text boxes have been working great most of the time, but today I got an error: "Fatal Memory Error: Out of Memory!"

Here's the line of code I'm running:
Code:
next_question_desc_selected = input_text_create_multiline_ext(temp_x,1736 + th1, temp_width,            -1,        fnt_tahoma_16, c_black, 1, temp_width, -1, -1, -1, fa_left, fa_top, true, 0);
I have that -1 (height) separated out because that seems to be the cause of the error. I also went into debug mode to track exactly where the code was breaking. This is the line where the code broke:

obj_input_text, Draw End, line 10:
Code:
if (!surface_exists(sf_selection)) sf_selection = surface_create(width + eoln_width, height);
So 'surface_create();' must be the culprit, since that's where 'height' is called upon.

You might remember I changed Draw GUI to Draw End for my project, so I changed it back to see what would happen, and the memory error occurred at the same spot.

I'm confused, because in 'input_text_create()', it says "height: ... Set to -1 for no limit."

I can probably just work around it by throwing in a really big number, but that still technically limits it. I was hoping to ask for help again to see what I can do to fix it.
Thanks in advance!
Oh, that's actually a mistake on my side! As you can see, the parameter description above in that same script is for "width, height". The description for "height" below should not be there, as it's explained in "width, height". You have to set a width and height in order for selections to be drawn to an underlying target. At the same time, width/height is used for auto-scrolling/scaling. The only things that can be set to -1 are max characters and max lines.
 
C

Captain Pumpkinhead

Guest
Oh, that's actually a mistake on my side! As you can see, the parameter description above in that same script is for "width, height". The description for "height" below should not be there, as it's explained in "width, height". You have to set a width and height in order for selections to be drawn to an underlying target. At the same time, width/height is used for auto-scrolling/scaling. The only things that can be set to -1 are max characters and max lines.
Okay, good to know. Thanks Dragon!
 
Top