Page 1 of 1

Differentiate types of on_gui_closed

Posted: Mon Nov 30, 2020 2:51 pm
by Therenas
With 1.1, the game now treats pressing 'E' on a GUI interface with a confirm-button as confirmation, which is fine. An issue arises though when mods try to emulate that behavior. What you want to do as a mod is to confirm your current dialog if possible, and close it if it doesn't have a submit-button. So, you listen to on_gui_closed and run through that logic.

The problem is that on_gui_closed also fires when the user presses Escape. Mods have no way to differentiate which of the two buttons was pressed, which means that we'd submit dialogs when the user presses Escape, which is almost certainly not their intention. The base game handles this correctly because it can differentiate the two.

I'm asking for some way for mods to emulate vanilla behavior. One way I can think of is to add a field to on_gui_closed indicating the intention ('close' for Escape, 'try-to-confirm' for E), but I'm open to other solutions that solve the problem.

Re: Differentiate types of on_gui_closed

Posted: Mon Nov 30, 2020 3:28 pm
by eradicator
+1 for event.confirmed :: boolean

Re: Differentiate types of on_gui_closed

Posted: Sun Jan 17, 2021 7:53 pm
by raiguard
+100. I think it would make more sense to fire `on_gui_confirmed` itself, so you can also pick up on the alt-keys.

Re: Differentiate types of on_gui_closed

Posted: Mon Jan 18, 2021 5:49 pm
by Rseding91
I'm not against the idea... the only issue is the game logic doesn't make any differentiation between confirm and close. The GUi is always closed regardless of the other stuff that happens before it's closed.

For example: most GUIs apply changes as you click. If you then press escape or confirm to close the GUI makes no difference to the rest of the changes you did. The few that do; don't tend to "close" a main GUI and are just pop-ups.

Re: Differentiate types of on_gui_closed

Posted: Sat Feb 10, 2024 6:46 pm
by nnotm
Just chiming in to express my support - I was pretty surprised to see there isn't an easy way to accomplish this. (For context, I was making a GUI styled after the train station renaming one, and not having the new name accepted when pressing E like that interface does is rather confusing.)

Edit: Though for people finding this thread in search of a solution, in discord I learned that one way to handle it now is to make a custom-input with linked-game-control set to confirm-gui, store the current tick in the associated event in global, and then check in the on_gui_closed event whether the current tick matches the tick stored in that event.