Questions on GUI creation from a fresh modder
Posted: Wed Jan 23, 2019 12:36 pm
A few days ago, I started working on a mod. It's my first contact with Factorio modding and LUA. The purpose is to create a GUI displaying some information I would like to be able to see at a glance.
Data collection and a bare-bones version of the GUI work already. Before continuing, I would like to ask a few questions, mostly about best-practice when it comes to GUIs in Factorio.
1. I want to be able to toggle the UI on and off. Most mods I looked at seem to implement that by calling destroy() on their UI's top-most element and rebuild it when needed. My intuitive approach would have been to build it just once on init and use the style.visible property to show and hide. Which approach is better and why? Are invisible GUI elements properly persisted through save/load? Do invisible GUI elements impact performance?
2. What is the best way to reference and modify existing UI elements? Should I store a reference to that element in global (potentially for every player, if multiplayer were to ever become an issue)? Or a "path", i.e. a chain of parent elements? What is the most efficient way to update ~20 different label captions, spread over several UI elements?
3. Is there a way to reorder cells in a table after creation? I would like to delete or replace rows. So far, the best way seems to be to clear the entire table and populate it from scratch.
4. Is the built-in tabbed pane (used to display production statistics) available to modders? style.lua has an entry for a tabbed_pane_style, but the documentation for LuaGuiElement does not list anything like it.
Data collection and a bare-bones version of the GUI work already. Before continuing, I would like to ask a few questions, mostly about best-practice when it comes to GUIs in Factorio.
1. I want to be able to toggle the UI on and off. Most mods I looked at seem to implement that by calling destroy() on their UI's top-most element and rebuild it when needed. My intuitive approach would have been to build it just once on init and use the style.visible property to show and hide. Which approach is better and why? Are invisible GUI elements properly persisted through save/load? Do invisible GUI elements impact performance?
2. What is the best way to reference and modify existing UI elements? Should I store a reference to that element in global (potentially for every player, if multiplayer were to ever become an issue)? Or a "path", i.e. a chain of parent elements? What is the most efficient way to update ~20 different label captions, spread over several UI elements?
3. Is there a way to reorder cells in a table after creation? I would like to delete or replace rows. So far, the best way seems to be to clear the entire table and populate it from scratch.
4. Is the built-in tabbed pane (used to display production statistics) available to modders? style.lua has an entry for a tabbed_pane_style, but the documentation for LuaGuiElement does not list anything like it.