Differentiate types of on_gui_closed

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Differentiate types of on_gui_closed

Post 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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Differentiate types of on_gui_closed

Post by eradicator »

+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.

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: Differentiate types of on_gui_closed

Post 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.
Don't forget, you're here forever.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Differentiate types of on_gui_closed

Post 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.
If you want to get ahold of me I'm almost always on Discord.

nnotm
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Aug 25, 2018 1:15 pm
Contact:

Re: Differentiate types of on_gui_closed

Post 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.

Post Reply

Return to “Modding interface requests”