VaM 1.x Create edit field in Plugin?

Threads regarding the original VaM 1.x

Hiropop

New member
Joined
Apr 11, 2025
Messages
5
Reactions
1
Hi, I expect this is a dumb question but I really can't figure it out!

In my script I have a JSONStorableString - how I can I create a single line editable text field so the user can change the value?

I have found how to create sliders and buttons etc, but the CreateTextField method creates a multi-line block with nothing in it, and is not editable. What should I use instead?
 
Check VAMStory's code, everything is in there to create a "typable" textfield.
 
Thank you hazmhox!

(Glad it wasn't such as simple question!)

In case its useful, here is my CreateTextField equivalent based on what I found in VAMStory. I also found the storable has a register input field option so it can be updated for each key, or just at the end:

C#:
       private UIDynamicTextField CreateInputField(JSONStorableString jss, bool rightSide = false)
        {
            var height = 60;

            var tmpTextField = CreateTextField(jss, rightSide);
            tmpTextField.backgroundColor = Color.white;
            LayoutElement tfLayout = tmpTextField.GetComponent<LayoutElement>();
            tfLayout.preferredHeight = height;
            tfLayout.minHeight = height;
            tmpTextField.height = height;
            tmpTextField.UItext.supportRichText = false;

            var textInputField = tmpTextField.UItext.gameObject.AddComponent<InputField>();
            textInputField.textComponent = tmpTextField.UItext;
            textInputField.lineType = InputField.LineType.SingleLine;

            // This line causes the JSONStorableString to be updated on every keystroke.
            // If it is not present, the Storable will be updated on EditEnd only (pressing
            // Enter or the InputField losing focus).

            textInputField.onValueChanged.AddListener((string s) => {
                jss.val = s;
            });

            jss.RegisterInputField(textInputField);

            return tmpTextField;
        }

Use like so:

C#:
name = new JSONStorableString("Name", "", UpdateName);
CreateInputField(name);
 
Perfect! I'm glad you found your way in my indecent code :p
 
Back
Top Bottom