MODULE: TextField v1.99.0

Started by Snarky, Wed 28/03/2018 15:39:51

Previous topic - Next topic

Snarky

This is a quick little module I made for the AGS Awards client. It provides one-line text input fields, as a replacement for the AGS TextInput control.

Ways in which TextField is better than TextInput:
-It has a blinking text cursor
-You can position the cursor anywhere in the text (using mouse or arrow keys), and edit at that point
-It has a notion of focus, so that you can have multiple TextFields displayed without all the text being entered into all the fields
-You can define a max string length the field will accept
-You can make the border partially transparent
-You can add more advanced logic to it, e.g. to only accept certain character types, or to *** out the display of the text

Ways in which TextField is worse than TextInput:
-It's implemented in script, so on slow computers or in a resource-intensive game it could be less responsive than TextInput
-You have to do a little bit of setup to make it work
-You can't link the OnActivate event, so it's a little more complicated to respond when the player presses Return/Enter

The TextField module is available on Github.

Download TextField v1.2.0

Download TextField v1.99.0 (v2.0 alpha version)

You can also try it out in a demo game for the Clipboard plugin:

Download Clipboard Demo

Changelog:
1.2.0
- Fixes crash if TextField initialized with non-empty String
- Adds support for Clipboard plugin

1.1.0
- Initial release
- Fixes poor SHIFT-key detection

1.0.0
- Unreleased (used in AGS Awards 2017 client)

selmiak

nice. What I really missed during the awards ceremony was copy+paste. Is it possible to implement this?

Snarky

#2
It would be pretty easy to do copy-paste between different text fields within an AGS game, but presumably you mean copy-paste from other applications.

That would require a plugin, in order to access the Windows clipboard. I have looked into it a tiny bit, and it's probably not very hard if you know your way around the APIs and libraries and build processes, but... I don't.

See thread here: http://www.adventuregamestudio.co.uk/forums/index.php?topic=55797.0

arj0n

Haven't tested this yet, but it looks like this could be very useful for textparser games. Thanx for making this!

Snarky

Quote from: selmiak on Wed 28/03/2018 17:19:03
nice. What I really missed during the awards ceremony was copy+paste. Is it possible to implement this?
Quote from: Snarky on Wed 28/03/2018 17:42:57
That would require a plugin, in order to access the Windows clipboard. I have looked into it a tiny bit, and it's probably not very hard if you know your way around the APIs and libraries and build processes, but... I don't.

I decided to go ahead and figure it out, and here's a plugin to do it. This module has been updated with support for the plugin, although because I haven't implemented selection, Ctrl-C will copy the entire text of the field.

Gurok

Quote from: Snarky on Fri 30/03/2018 15:41:18
Thanks. Sure, undo/history would be useful to have, but it wouldn't be part of the plugin, but rather something you implement in your game logic. I'll think about adding it to the TextField module.

Windows Forms stuff gives you one level of undo built into the control from memory. It might be nice to provide that, then let people implement their own if they need to.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Snarky

#6
It's something to think about for the TextField module. In that case I'd almost certainly make the size of the history buffer (how many levels of undo you can backtrack) configurable.

selmiak

that was fast (and hopefully easy enough). Thanks snarky  :-D

Monsieur OUXX

Snarky, if you could extend this to multiple lines, I'd be eternally grateful to you.
Also I'd really encourage you to implement highlight and simple copy/paste (data stays within AGS). You could probably get some inspiration about mouse-control and highlight from my (almost working but eternally slightly broken) module, TextArea.

I realy need a text area component, but I've never managed to release one that's bug free.
 

Snarky

#9
Here is an alpha/bugtesting release of v2 of this module: TextField v1.99.0

Main changes:
- Updated to support Unicode strings and the new text entry API (this version requires "Use old-style keyboard handling" to be set to false)
- This in turn fixes problems in the previous version where rapid typing could cause glitches
- Select parts of the text using mouse or keyboard (SHIFT+arrows)
- TextField is now scrollable, so you can type more than fits into the field! (Up to about 3000 characters; after that things seem to get a bit weird)
- Added various visual config options to control how the TextField appears (colors, transparency, border width, etc.)
- Added an internal clipboard so Cut/Copy/Paste works even if you don't use the Clipboard plugin
- Options to enable/disable clipboard, undo history, editable
- Fixed some bugs

Example of use:
Spoiler
Code: ags
TextField* inputField1;
TextField* inputField2;

function game_start() 
{
  // Turn btnTextField1 into a TextField
  inputField1 = TextField.Create(btnTextField1);

  // Configure appearance (font is taken from btnTextField1):
  inputField1.SetPadding(4, 4, 4, 4);
  // When focused, display black text on white background with a red border
  inputField1.SetColorsFocused(Game.GetColorFromRGB(0, 0, 0), 15, Game.GetColorFromRGB(255, 0, 0));
  // When not focused, border is black
  inputField1.SetColorsUnfocused(Game.GetColorFromRGB(0, 0, 0), 15, Game.GetColorFromRGB(0, 0, 0));
  // When disabled, grayed out
  inputField1.SetColorsDisabled(Game.GetColorFromRGB(64, 64, 64), Game.GetColorFromRGB(128, 128, 128), Game.GetColorFromRGB(64, 64, 64));
  // Selection: White text on dark blue
  inputField1.SelectionTextColor = 15;
  inputField1.SelectionBackgroundColor = Game.GetColorFromRGB(0, 0, 64);

  inputField1.BackgroundTransparency = 75;  // Background is semi-transparent
  inputField1.BorderWidth = 2;  // Thick border

  // Create another (pre-filled) text field with the same appearance as inputField1
  inputField2 = TextField.Create(btnTextField2, "Type text here", inputField1);

  inputField1.SetFocus();
}
[close]

SMF spam blocked by CleanTalk