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

Place to get help with not working mods / modding interface.
Post Reply
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

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

Post 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?

Bilka
Factorio Staff
Factorio Staff
Posts: 3129
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding help”