Page 1 of 1

[0.15] \data\core\lualib\mod-gui.lua

Posted: Mon Dec 11, 2017 7:39 pm
by darkfrei
Hi all! In the file Factorio\data\core\lualib\mod-gui.lua you can find:

Code: Select all

--[[

Hello script explorer, if you are looking to upgrade your mod to use the mod gui, its pretty simple.

Typically you will have something like:
player.gui.left.add{...}

All you will need to do, is change it to:
mod_gui.get_frame_flow(player).add{...}

And for buttons its just the same:
mod_gui.get_button_flow(player).add{...}

It should be as simple as find and replace.

Any other questions please feel free to ask on the modding help forum.

]]
How to use it?
It's very easy to make only one button:

Code: Select all

require("mod-gui")
function add_gui(player_index)
  local player = game.players[player_index]
  local value = 'roboport'
  mod_gui.get_button_flow(player).add{
    type = "sprite-button",
    style = "slot_button_style", 
    name = value,
    sprite  = "item/" .. value,
    tooltip = game.item_prototypes[value].localised_name
  }
end
and it's easy to make only one empty table:

Code: Select all

require("mod-gui")
function add_gui(player_index)
  local player = game.players[player_index]
  local value = 'roboport'
  mod_gui.get_frame_flow(player).add{type = "frame", name = "de-frame", direction = "horizontal"}
end
But how to add this button to this table?

Re: [0.15] \data\core\lualib\mod-gui.lua

Posted: Mon Dec 11, 2017 7:59 pm
by Bilka
The same way you add to any gui. you take the wanted parent and .add to it. getting that is also pretty easy, just get the frame flow and go from there, so mod-gui.get_frame_flow()["de-frame"].add{..} . Of course you can also first get the frame flow and go from there, so local frame_flow = mod-gui.get_frame_flow()
local child = frame_flow["de-frame"].add{...}

This works for any level of the gui. You can take a look at https://github.com/Bilka2/ChangeMapSettings for more usage of the mod gui. The mod is updated to 0.16 already but that shouldn't matter for you.