Changing gui background colors?

Place to get help with not working mods / modding interface.
scruffyvoltherder
Inserter
Inserter
Posts: 30
Joined: Fri Jun 14, 2024 12:33 am
Contact:

Changing gui background colors?

Post by scruffyvoltherder »

How do i change the background colors of GUI elements like buttons or flows and panes? It doesn't look like that exists as part of luastyle.
User avatar
Osmo
Fast Inserter
Fast Inserter
Posts: 152
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

Re: Changing gui background colors?

Post by Osmo »

This needs to be done by defining gui styles at data stage https://lua-api.factorio.com/latest/pro ... Style.html
scruffyvoltherder
Inserter
Inserter
Posts: 30
Joined: Fri Jun 14, 2024 12:33 am
Contact:

Re: Changing gui background colors?

Post by scruffyvoltherder »

Since the style prototype is limited to one total instance, how do i extend that?

Unless I'm just blind, also appears that most of the data-stage style specifications don't have background colors either.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16124
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Changing gui background colors?

Post by Rseding91 »

It’s not a specific color code in the style, but part of the image set used by the style - in the PNG.
If you want to get ahold of me I'm almost always on Discord.
scruffyvoltherder
Inserter
Inserter
Posts: 30
Joined: Fri Jun 14, 2024 12:33 am
Contact:

Re: Changing gui background colors?

Post by scruffyvoltherder »

That's using ElementImageSetLayer?

I'll probably be able to understand that once i'm sober.

How do i add my new styles to the existing GUI style instance?
Pi-C
Smart Inserter
Smart Inserter
Posts: 1770
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Changing gui background colors?

Post by Pi-C »

scruffyvoltherder wrote: Sat Aug 16, 2025 5:07 am How do i add my new styles to the existing GUI style instance?
With other prototypes, you'd use something like

Code: Select all

local new_proto = table.deepcopy(data.raw[old_type][old_name])
new_proto.name = new_name
...
data:extend({new_proto})


With GUI-styles, this doesn't work. The only style that will be used is data.raw['gui-style'].default. However, you can add new styles to that! You don't even have to create everything from scratch, just pass on a 'parent' and all properties you don't set directly will be inherited. This is how I've defined styles in Autodrive:

Code: Select all

local styles = {}

-- Define button styles
styles.autodrive_button_off = {
  type = "button_style",
  parent = "shortcut_bar_button",
  padding = 4,
}

styles.autodrive_button_on = {
  type = "button_style",
  parent = "shortcut_bar_button_green",
  padding = 4,
}

-- Define textfield styles
styles.AD_highlighted_value_textfield = {
  type                  = "textbox_style",
  parent                = "highlighted_value_textfield",
  font                  = "default",
  font_color            = {},
}

styles.AD_stretchable_textfield = {
  type                  = "textbox_style",
  parent                = "stretchable_textfield",
  disabled_font         = "default-bold",
  disabled_font_color   = {1, 1, 1, 1},
}


styles.AD_inner_frame = {
    type = "frame_style",
    parent = "inside_shallow_frame_with_padding",
    vertically_stretchable = "on",
    horizontal_align = "center",
    vertical_align = "center",
}

-- Create styles
for s_name, s_data in pairs(styles) do
  data.raw['gui-style'].default[s_name] = s_data
end
Hope that helps! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Modding help”