Friday Facts #174 - Mod gui

Posted by Klonan on 2017-01-20, all posts

Hello, a wave of illness has afflicted the team these last few weeks, but things are starting to pick up again. With the collective health of the office back to normal, progress is advancing well on the features for 0.15.

Mod gui

We offer a lot of freedom to the modders of Factorio, this freedom has been of huge advantage to everyone involved, allowing interesting and fresh mechanics to be implemented with simple Lua script and our API.

With freedoms comes the fact that we can't control everything the modders want to do. In terms of visual design we have our own GUI elements under lock down, but mods can put things together in any way they like, and with no style guides or templates, we can end up with situations like this:

The player will understand that it isn't really our 'fault' that the buttons are not in a uniform style, but still it's an issue I wanted to try to address.

Typically a mod Gui will be created something like this:

function create_gui(player)
  player.gui.left.add
  {
    type = "sprite-button",
    name = "My_mod_button",
    sprite = "item/my-mod-item",
    style = "My-mod-button-style"
  }
  player.gui.left.add
  {
    type = "frame",
    name = "My_mod_frame",
    caption = "My mod frame",
    style = "My-mod-frame-style"
  }
end

This is very simple, and easy enough to understand, but will require each mod to define their own style, or use the LuaStyle script interface to set their style during the game. The issue of odd styling comes from perhaps there being no built in simple and effective styling mods can use. Another problem is that with multiple mods installed, there is no overall control about how and where the Gui elements interact and 'fight' with one another for space.

So to begin to help this, I've implemented an optional Lua script that modders can use, which should help unify things, as well as being simple to use for anybody new.

require("mod-gui")
function create_gui(player)
  mod_gui.get_button_flow(player).add
  {
    type = "sprite-button",
    name = "My_mod_button",
    sprite = "item/my-mod-item",
    style = mod_gui.button_style
  }
  mod_gui.get_frame_flow(player).add
  {
    type = "frame",
    name = "My_mod_frame",
    caption = "My mod frame",
    style = mod_gui.frame_style
  }
end

Which can look something like this:

While this is definitely optional, it really helps to tie together the style of the buttons.The separation of the button and frame flows will help to stop Gui fighting in the main 'left' gui. I'd also be interested in expanding the functionality of the mod-gui utility, so input and feedback from modders will be very helpful.

Stations color

As Vaclav was finishing up the High-res train stop and signal fixes, he enlisted the help of Rseding to add the same color selection for stations as we have for the locomotives.

This minor addition really allows for much greater visual distinction between your different stations, and allow matching up your locomotives to their respective stations. There is also support to copy and paste the color from the train stop to the locomotive and vice-versa, so that you will always have a perfect match.

As always, if you have any comments or otherwise, please let us know on our forums.