Hi there,
I have co-written a mod named AbandonedRuins_updated_fork: https://mods.factorio.com/mod/AbandonedRuins_updated_fork Where I have (not committed/uploaded yet) a storage table storage.allowed_planets[name] = allowed where name is the name from LuaPlanet class and allowed is a boolean value. Since I cannot add "dynamic" settings with data:extend() during the runtime stage, I have write an own GUI where players can allow/disallow ruins to be spawned on all available planets. There is a mod named AbandonedRuins-PlanetSettings but as you can see in its control.lua and settings.lua they have a static list of planets which isn't exactly how it should be done.
So I came up with iterating over game.planets to find all registered planets. I already have written the logic part (no spawning when planet is disallowed) but the GUI part is missing.
So I wonder if you can provide some tutorials? I find the current example relatively hard to understand. And can you provide some "generic GUI elements" which can I simply use and invoke?
I imagine something like this:
-- Header:
local glib = require("__glib__/glib")
-- Somewhere in my code:
local gui = glib.create_default_gui("ruins-spawning-on-planets", features = {"apply-button", "cancel-button", "localized-2col-list"}) -- the string is taken as name and localization key, too.
-- Add localized headers so the player knows what is for what
gui.set_header_row({"ruins-planet", "ruins-allowed-spawning"})
-- Simply handle over the whole table
gui.add_boolean_rows(storage.allowed_planets, callback=planets.handle_allow_callback)
-- Show the GUI
gui.show()
So when the user clicks on "Apply" button, a temporary table with same name as key and allowed(true|false) is generated (by your code) and handled over to the callback function planets.handle_allow_callback where my code can handle the update of storage.allowed_planets. The "Cancel" button dismisses all changes, no callback is done.
My idea was that mod developers don't have to write all over again but can use simple functions to create their GUIs.