GUI guide/references?

Place to get help with not working mods / modding interface.
Post Reply
SmackDan
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Sep 26, 2017 3:18 pm
Contact:

GUI guide/references?

Post by SmackDan »

I read somewhere that the best way to learn about GUI's for Factorio was to read through some mods which got it's own GUI.
So far I haven't been able to find any mods where the creation of GUI's were displayed in a easy to read manner, nor did they utilize any of the functions that I was looking for.

Could I get some suggestions to where to read or which mods I should analyze to get me started?
As of right now I'm mostly looking for a button/grid GUI. Inventory slots like chests/machines would also be nice to look through later.

Thanks in advance!

-Smack

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

Re: GUI guide/references?

Post by Bilka »

Here is something that I explained Blank a few weeks ago, and he said that it helped, so here you go:
I've been wanting to write a mod gui tutorial, I might as well use your questions as inspiration lol. Basically, there are a few places on the screen where you can put player gui: top, left and center. You can access those with player.gui.center etc.
There is also the mod gui, which adds a flow in the gui.left space for buttons and gui. I'd suggest you to use that. For that you access the button flow using: mod_gui.get_button_flow(player). (You need to do require("mod-gui") at the top of the file). You can access the normal flow, where you will place your gui window using: mod_gui.get_frame_flow(player). To add a gui element, you simply add it to the parent gui, so in your case, the frame flow. Example:

Code: Select all

    local frame_flow = mod_gui.get_frame_flow(player)
    local config_frame = frame_flow.add{
        type = "frame",
        name = "new-game-plus-config-frame",
        direction = "vertical"
    }
You can find the possible types here http://lua-api.factorio.com/latest/LuaGuiElement.html
The name for your gui should be prefixed by your mod name, you share the "namepsace" with all other gui elements from all other mods, so prefixing with your mod name prevents weird interactions.
He wanted to make a gui similar to the players requester slots and wanted to be able to select items with the squares. It should be a 4x4 grid.
So, for you "choose an item button" you will need to use the type "choose-elem-button" with its "elem_type" set to "item". That makes that little square where you can choose an item when you click on it. Now, if you add more than one of it to you parent element (config_frame in my code example), it will be under the other one. But you want a 4x4 grid. So, you add a gui of the type table to your parent flow (config_frame) and set it colspan to 4, so that you have four columns. Now you can add 16 of the choose element buttons to that table, and voila, you have a 4x4 grid
That was mostly what I explained. For more info, definitely have a look at the api doc (LuaGui,LuaGuiElement, LuaStyle). I personally learned gui mostly by looking at this mod and I used Klonan's upgrade planner to learn how to use the mod gui. The mod-gui file in core/lualib also has some documentation to it though. You can see the fruits of my work in the New game+ mod, most of the code is at least somewhat commented, so it should be understandable.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

SmackDan
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Sep 26, 2017 3:18 pm
Contact:

Re: GUI guide/references?

Post by SmackDan »

Ey, thanks man!

This was exactly what I was hoping for to get me started.

-Smack

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: GUI guide/references?

Post by Helfima »


Post Reply

Return to “Modding help”