Ludeon Forums

RimWorld => Mods => Help => Topic started by: m1st4x on October 01, 2020, 02:42:55 PM

Title: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 01, 2020, 02:42:55 PM
I'm trying to add a text field for user input into DoWindowContents() of a derived MainTabWindow class



string text = Verse.Widgets.TextField(rect, "Enter text here");



The widget appears, a prompt is indicating and I can select the preset text.
But on keypress no character shows up and string text leaves unchanged.

Same with Widgets.TextArea and listing_Standard.TextEntry

What's wrong? I don't get any further...

Thanks,
-m1st4x-
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 01, 2020, 04:48:29 PM
try reading unity engine manual

https://docs.unity3d.com/ScriptReference/GUI.TextField.html
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 01, 2020, 05:27:02 PM
Ok, just tried to call GUI.TextField directly without wrappers - changes nothing :| Logfile is clean...

Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 01, 2020, 07:47:12 PM
logfile is clean because you never added any trace output, adding trace output really helps, atleast you will know, is your code actually executing or not...

Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 02, 2020, 04:23:16 AM
Don't know what to trace here, it's a single line of code.

Or do you mean a global setting for more trace output?

No errors logged in my AppData/Rimworld/Player.txt

[UPDATE]
This is how it works:


class TabWindow : MainTabWindow
{
     public string str = "";

     public override void DoWindowContents(Rect rect)
     {
           base.DoWindowContents(rect);
           GUI.BeginGroup(rect);
           try {
               string text = GUI.TextField(rect, this.str);
               //validation etc.
               this.str = text; // stores the value
           }
           catch (Exception e) {
               Log.Message(e.StackTrace);
           } finally {
               GUI.EndGroup();
           }
     }
}

Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: LWM on October 02, 2020, 05:21:32 AM
You might have multilple things fighting for the same input in that rect.

Why not split up the rect into two parts, and pass one part to base.DoWindowContents, and then put your TextField into the other rect?
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 02, 2020, 06:34:07 AM
Hi, thanks for the hint.
I already had different rectangles for base class and my controls.
That's not the reason.
The code above is just a simplification for debugging.



Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 02, 2020, 08:13:42 AM
you still have no trace output, probably you actually need to add some?

if you don't know what to trace, i will give you a hints

Quotestring text
Quoteis your code actually executing or not
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 02, 2020, 11:26:15 AM
As I said
Quote
The widget appears, a prompt is indicating and I can select the preset text.
But on keypress no character shows up and string text leaves unchanged.
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 02, 2020, 11:30:53 AM
i wish you luck developing anything without using tracing or debugger*




*you may need multiple human sacrifices to actually get sufficient luck to develop this way, virgins and children works best
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 02, 2020, 01:59:11 PM
I use Verse.Log.Message for debug output or simply put my value somewhere on screen.
(Changed the code snippet just for you ;-)

Connecting the debugger to RW is indeed something I'm gonna try soon.
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 03, 2020, 06:10:14 AM
kay

string text = GUI.TextField(rect, str);
always empty string because you never set "str" and never actually save user input from method
ever if user typed anything into text field, you will replace it with empty string next frame.

with traceoutput set you will notice, that your input is registered but not saved, but you reject to use traceoutput.

i don't need your traceoutput, YOU NEED IT
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: m1st4x on October 06, 2020, 11:41:23 AM
Thanks for the last post, finally saw my mistake.
I've updated the code above, now it works as desired.
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 07, 2020, 10:24:20 AM
and your update removes trace output

:facepalm:
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: LWM on October 07, 2020, 01:10:01 PM
If you want to keep trace code around for possible future use, there's some slick features that C# lets you do that also keeps trace from showing up when you don't want - I can point you to an example if you like.
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 07, 2020, 11:55:20 PM
magical secret trick i just stolen from area51 about keeping trace output in code but not display it in production build:

if (debug)
{
trace output
and other debugging stuff
including magical and secret stuff
you can ever enable it at will with little hidden command handler
or use verbose flag from rimworld itself and this allows to enable and disable it from menu!
}
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: LWM on October 08, 2020, 12:49:36 AM
C# lets you set debug code that won't eve compile into Release code, so absolutely no performance hit for Release and you can even leave trace in sensitive places!  Super useful :D
Title: Re: Cannot enter text into Verse.Widgets.TextField/TextArea
Post by: RawCode on October 08, 2020, 05:26:44 AM
single branch instruction cause such significant performance drop, British science academy estimated that without using branch instructions Rimworld will run at least 10000 FPS!!!111

bro, people unable to use absolutely elementary technique like reading manual, performance is absolutely least concern here.