New LuaGuiElement: window

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
andrei
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Aug 27, 2019 8:32 pm
Contact:

New LuaGuiElement: window

Post by andrei »

TL;DR
Allow mods to create windows that behave similarly to built-in game windows.
What ?
A window can be added only to `player.gui.screen` GUI root. A window behaves similarly to built-in game windows like inventory or entity details. In particular:
  1. It has a close button in the top-right corner.
  2. It is automatically closed when another window is opened, e.g. when the player presses “E”.
  3. It is closed if the player presses “Escape”.
This can be implemented as a new LuaGuiElement type (“window”) or by adding certain flags to the “frame” element.
Why ?
Many mods need to create windows, this is a popular request: viewtopic.php?t=44378, viewtopic.php?t=29876. It was partially fixed in version 0.17.59 when `LuaGui::screen` was added. The suggested solution was to add a “frame” GUI element to the “screen” root in order to create a window. This does solve part of the problem: the created window is draggable and in many respects behaves as one would expect. However it doesn't have the properties mentioned above:
  1. Close button needs to be added manually and it's quite tiresome (if you want it you basically cannot use “caption” to set window title and need to re-implement the title bar by hand).
  2. Closing the window when another window is opened also needs to be done manually.
  3. Overriding “Escape” is outright impossible if I understand correctly.
Would be nice if we could have an out-of-the-box solution for windows that just works.
Update
PFQNiet pointed out that 2. and 3. can be both implemented by setting `player.opened = frame`, i.e. it is possible to fully replicate behavior of built-in windows, it just needs some work.
Last edited by andrei on Tue Jun 22, 2021 1:56 pm, edited 1 time in total.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: New LuaGuiElement: window

Post by PFQNiet »

Point 1 is resolved by using a decent framework, or making your own - it's a fairly trivial matter to define a function, say "create_window", and let that handle creating the close button etc.

Points 2 and 3 are resolved by setting "player.opened = window". The player can only have one GUI "opened" at a time, so opening another will first close the open one (firing gui_closed event as expected) and E and Escape both close it too.

I don't think this suggestion is needed, personally.
andrei
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Aug 27, 2019 8:32 pm
Contact:

Re: New LuaGuiElement: window

Post by andrei »

Hmm, I didn't know the `player.opened = ...` trick. Thanks! Updated the post.

I still think that it makes sense to have a built-in window class because it's more future-proof: if Factorio decides to add new windows management features (tiling, snapping, collapsing, etc.) they would be supported by all mods immediately. But I agree that it is a weaker argument.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3734
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: New LuaGuiElement: window

Post by DaveMcW »

Here is a reference implementation for 1. 98713
Post Reply

Return to “Modding interface requests”