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-
try reading unity engine manual
https://docs.unity3d.com/ScriptReference/GUI.TextField.html
Ok, just tried to call GUI.TextField directly without wrappers - changes nothing :| Logfile is clean...
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...
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();
}
}
}
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?
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.
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
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.
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
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.
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
Thanks for the last post, finally saw my mistake.
I've updated the code above, now it works as desired.
and your update removes trace output
:facepalm:
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.
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!
}
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
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.