I've made a GUI containing a table with textfields. In response to on_gui_click and on_gui_text_changed, I change the textfield's style to highlighting mode, and when on_gui_confirmed fires, I reset the style again. This works great, but …
If the player is typing into one textfield and presses <TAB>, the focus is moved away from the current textfield to the next one available. I don't mind that the first textfield still is highlighted -- that's as expected because I want to warn the player that there still are unconfirmed changes. But I'd really like to change the style of the newly selected textfield as soon as it gets the focus.
In the following screenshot, the textfield for the Spidertron has been highlighted because it was active but the changes have not yet been confirmed. The textfield of the Heavy Truck still has the normal style you get when focusing a textfield with the tabulator key:
In the light of threads like 92021, I suppose that will not be possible to detect when a textfield gets the focus. Or is there some secret way I could get it to work?
GUI and textfield focus
GUI and textfield focus
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: GUI and textfield focus
Hello,
I hope you are well,
There is no event related to the focus, and making them by means of flag variables (variables that indicate that everything is going well) can become tedious, but I think it is one of the options you have.
The other option that I envision is that you validate everything in the confirmation event, but I know the problems that this causes, so you must choose which wrong to accept.
I hope you are well,
There is no event related to the focus, and making them by means of flag variables (variables that indicate that everything is going well) can become tedious, but I think it is one of the options you have.
The other option that I envision is that you validate everything in the confirmation event, but I know the problems that this causes, so you must choose which wrong to accept.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
Everything i write in English is translated by google.
Re: GUI and textfield focus
Hi, hope you are well, too!
Thanks for the suggestions! However, I've found another way in the meantime: I listen to on_gui_text_changed changed now, so I can verify the text as soon as a character has been entered. When the text in the textfield matches an existing name, I set its style to "invalid_value_textfield". Also, when the cursor has just moved into that textfield (i.e. if the textfield still has the default style), I set the style to "highlighted_value_textfield". Finally, in on_gui_confirmed, I reset the style to the default again.There is no event related to the focus, and making them by means of flag variables (variables that indicate that everything is going well) can become tedious, but I think it is one of the options you have.
The other option that I envision is that you validate everything in the confirmation event, but I know the problems that this causes, so you must choose which wrong to accept.
It is a compromise because the style won't be changed automatically -- the player must type something first. But it's less hassle than keeping track of what element has the focus and I think it will be sufficient.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: GUI and textfield focus
I like it is logical, maybe I implement it in my mod.Pi-C wrote: ↑Tue Jul 26, 2022 2:06 pmThanks for the suggestions! However, I've found another way in the meantime: I listen to on_gui_text_changed changed now, so I can verify the text as soon as a character has been entered. When the text in the textfield matches an existing name, I set its style to "invalid_value_textfield". Also, when the cursor has just moved into that textfield (i.e. if the textfield still has the default style), I set the style to "highlighted_value_textfield". Finally, in on_gui_confirmed, I reset the style to the default again.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
Everything i write in English is translated by google.