[patch - New Feature] Input Function enhancements

Notes on testing the latest builds of MapTool

Moderators: dorpond, trevor, Azhrei

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

[patch - New Feature] Input Function enhancements

Post by Lee »

As promised, here's the modified input function. I was busy this week else I would have released it sooner. Apart from the promised text area, I also thought to open the actual window model itself for MTScript users to manipulate. Please test it out so I can fix whatever's broken; though I think everything should be fine. In order for the new JSON functionality to work, however, I had to expose some private functions found in the JSON class. IDK how Azhrei and the others feel about this, but I took my cue from other classes that seemed to have had their private methods exposed as well. Anyway, to the the meatier stuff:

New functionality:

1. TEXTAREA input type - I didn't need to break the grid model as I opted for a simple containment scheme. It follows the basic input model of variable, value, prompt, and options. Value will hold the eventual contents of the text area. Options are ROWS and COLS, which sets the depth and breadth of the text area, SPAN works like it always has and is set to false by default.
Example: [input("txtAreaVar | Content | Prompt | rows=5 cols=50")]

Edit: For those who don't know, you can do ctrl+enter to emulate hitting enter on another input type and ctrl+tab and shift+tab for traversal. These were the defaults MT has been using along with what most are used to.

2. JSON - works like PROPS but is more flexible. Guided by the suggestions of aliasMask, it allows the passing of json Arrays or Objects for manipulation in an input window. The value parameter holds this passed information, of course. Options are SPAN (default=false), which only works/is meaningful for JSON Objects since I suppressed prompts for JSON array items, seeing that these are merely junk and are discarded after the transaction, and using the JSON input type is mainly focused on manipulating/creating values. WIDTH sets the text field length for all items.
Example: [input(strformat("jsonVar | %s | Prompt type | width=50", json.set("{}", "a", 1, "b", 2, "c", 3)))]

3. WINDOW - Allows MTScript users to manipulate the input window a bit. Hence, it is important to note that it is not an input type; even if it follows the input function form. The variable parameter is useless and inaccessible to MT scripters. The value parameter holds the eventual title of the window. The prompt will be the window's tool tip text. Owing to its nature of not being an input type, the code for setting prompts is skipped for aesthetic purposes, among other things. Options are as follows:

a. TYPE accepts values of -1 (plain message), 0 (error message), 1 (information message), 2 (warning message), and 3 (question message). Default is set to -1, what everyone has been using so far. Basically, this is used for aesthetics, to have that L&F icon on display depending on the type chosen.
b. CHOICES accepts values of 0 (Yes, No), 1 (Yes, No, Cancel), and 2 (Ok, Cancel). Default is set to 2, what most MT users are familiar with. More on this later.
c. OPTIONS accepts a string similar to the JSON array form, i.e. [a, b, c], to a maximum of 3 items (due to the nature of JOptionPane and how MT incorporated an HTMLPane). Each item in the "array" becomes the label for a particular button. OPTIONS overrides the CHOICES model; meaning even if a 2-button choice option is set, a 3 item OPTIONS parameter will result in a 3 button window. The only exception to this is when a blank set is passed, i.e. "[]"; here the input window reverts to whatever is set for CHOICES. Default for this is null, though this is non-impacting. Using this option parameter results in the input window becoming "customized" in nature. More on this below

Return values, default window types, "customized" mode
To avoid affecting existing MT scripts out there. The default return values are as follows:
a. Ok - returns 1 as it always has
b. Cancel - returns 0, as it always has
c. Yes - returns 1
d. No - returns 2
e Closing window through the 'X' - returns 0 for all window types including customized
f. Customized buttons - returns different values. 1 for the leftmost button, 2 for the middle, and 3 for the 3rd. This was intended to provide MT scripters with added capability a 3-button input window provides.

Example: [input("junkVar|winTitle|winToolTip|window|type=-1 choices=1 options=[Bacon, Eggs, Toast]")]

4. Radio - added the option SOF (short for SelectOnFocus). This accepts true or false values, set to false as default. What this does is, as the name states, select the radio button after it receives focus while tabbing through the input window; handy for input windows containing single radio button groups.

5 Props - added the WIDTH option to set the length for all prop fields.

Changes and Fixes:
1. In order for the new functionality to work, several functions in the JSON class were made public. Modified class included in the patch.
2. Fixed the bug where html content made tab traversal require 2 hits before moving on to the next component.
3. Set default value for text fields to a blank instead of 0
4. Other changes to make this work are found with comments in the code.

Do test this out and see if it's to your liking. I've made other stuff not related to this and will put it up shortly once I'm done with my newest drop-in. Please feel free to leave any questions or comments.

Thank you.
Last edited by Lee on Tue May 28, 2013 5:09 pm, edited 8 times in total.


Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

Patch uploaded anew. Cleaned up some comments and the like. Hopefully, this didn't affect the actual code in any way.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [patch] Input Function improvements(?)

Post by aliasmask »

Lee wrote:Example: [input(strformat("jsonVar | %s | Prompt type | width=50", json.set("{}", "a", 1, "b", 2, "c", 3)))]
Cool, that'll actually work. I was afraid the syntax of the json would be a problem, especially for quotes.

I'm going to use the heck out of TEXTAREA. WINDOW seems interesting and I'll probably use the customize version. SOF is interesting, but on mouseover IMO could cause selection problems.

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

I've tried and it accepts [input('jsonVar|["a", "b", "c"]|prompt|json')] (hope I didn't miss a closer there) as well. I thought to float a poll on SOF on whether people would like it set to true or false by default, but I opted to let people try it out with true as default and let them come back to me if they didn't like it. As for the mouseover, I'm not sure if I understand, do you mean behavior with SPAN and tooltips? I'll look into it if you have more detail.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [patch] Input Function improvements(?)

Post by aliasmask »

Maybe I missed something about SOF. Is select on focus when you mouse over the radio button or label it will select that option? Or do you mean when using the tab key to change the focus it will select it? I'm sure you now meant the second one, but I didn't get that the first time.

As for json option, will I have to format it like this:

Code: Select all

[H: input(strformat("jsonVar|%s||JSON",json.set("{}","one",1))]
or like this:

Code: Select all

[H: input(strformat('jsonVar|%s||JSON',json.set("{}","one",1))]
because the substitution puts double quotes with in double quotes for the input string. What happens if my json value has a single quote in there?

Code: Select all

[H: input(strformat('jsonVar|%s||JSON',json.set("{}","singleQuote"," ' "))]

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

Yes, I meant the latter, tabbing through a radio group will select radio buttons when they receive focus. As for the examples you gave, all went through just fine. There was a missing right parenthesis on each of the samples, however, but other than that, I encountered no problems.

Edit: I forgot to mention, with regard to the posts above, that I'm glad I was able to provide something useful. It was always the intention to provide the tools and get out of the way of all the creative people in the MT community :)

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [patch] Input Function improvements(?)

Post by wolph42 »

Very usefull and many thanks. Can you provide some actual useable sample scripts especially on the use of WINDOWS as I d quite get the implementatiom method. But examples of the other methods would be nice as well.

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

I'll see what I can do. I did place some examples on the 1st post. I guess they weren't obvious so I highlighted them in bold. All of them, however, still follow the basic input form of [input(var|value|prompt|options)]. As for Windows, perhaps this Java resource will be more informative :).

JSON can manipulate/create both JSON Arrays and Objects, and they display in a PROPS-like display. With A.M.s suggestions, JSON object keys can hold html formatting, though I haven't taken the time to try out how full the HTML capability is. Who knows? Maybe a full frame can find its way into the input window :lol: I tried putting some buttons in and they turned out fine; though linking them to macrolinks, I didn't have time to do.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [patch] Input Function improvements(?)

Post by wolph42 »

Lee wrote:I'll see what I can do. I did place some examples on the 1st post. I guess they weren't obvious so I highlighted them in bold. All of them, however, still follow the basic input form of [input(var|value|prompt|options)]. As for Windows, perhaps this Java resource will be more informative :).

JSON can manipulate/create both JSON Arrays and Objects, and they display in a PROPS-like display. With A.M.s suggestions, JSON object keys can hold html formatting, though I haven't taken the time to try out how full the HTML capability is. Who knows? Maybe a full frame can find its way into the input window :lol: I tried putting some buttons in and they turned out fine; though linking them to macrolinks, I didn't have time to do.
indeed... I noticed the first two, but missed the one concerning windows. I guess thats good enough, its just to get a feel of the correct syntax. Thanks!

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

No problem, you're welcome :)

I uploaded a new version of the patch. I missed something in the last one that I intended to go back to, but didn't; specifically the html label fix and its interaction with radio's SELECTED option. Got that all squared out and should be all good now.

Nildik
Cave Troll
Posts: 76
Joined: Mon Oct 31, 2011 7:32 pm

Re: [patch] Input Function improvements(?)

Post by Nildik »

Sorry by the question, but... how can I install the patch?

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

You would need to set up the developer environment for MapTool to apply patches to the source code. A tutorial is found here. Depending on your knowledge level, you might want to wait till it gets included on a build to try it out. In case it doesn't make it into the official build, let's wait till the final build is released and I can generate a special version with my patches in it.

Nildik
Cave Troll
Posts: 76
Joined: Mon Oct 31, 2011 7:32 pm

Re: [patch] Input Function improvements(?)

Post by Nildik »

Thanks Lee, I will make a try to do it for myself. I'm not experimented, but seems a good tutorial. I'm very interested in the implementations of your patch.

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: [patch] Input Function improvements(?)

Post by Lee »

Good luck with that. Once you do set it up, applying a patch is easy, just right click on the InputFunction.java (found under src -> net.rptools.maptool.client.functions), select Team and Apply the Patch you downloaded from here.

Post Reply

Return to “Testing”