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.
Differentiate types of on_gui_closed
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Differentiate types of on_gui_closed
+1 for event.confirmed :: boolean
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Differentiate types of on_gui_closed
+100. I think it would make more sense to fire `on_gui_confirmed` itself, so you can also pick up on the alt-keys.
Don't forget, you're here forever.
Re: Differentiate types of on_gui_closed
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.
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.
If you want to get ahold of me I'm almost always on Discord.
Re: Differentiate types of on_gui_closed
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.
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.