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
Fast Inserter
Fast Inserter
Posts: 204
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: 5092
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
Filter Inserter
Filter Inserter
Posts: 325
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: 11884
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.

Post Reply

Return to “Modding interface requests”