How to change buttoms/frame background

Place to get help with not working mods / modding interface.
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

How to change buttoms/frame background

Post by ficolas »

Messing with the buttons, in style.lua, I noticed that there is a monolith_image field, Im not sure about how this works, so I would like somebody to explain
(I have messed arround with that but I cant find out how it works)

Also,I wanna know if it is possible to change the background of the frame

Also, the GUI buttons look much better now with style :)
kovarex
Factorio Staff
Factorio Staff
Posts: 8298
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: How to change buttoms/frame background

Post by kovarex »

Yes, you can change the background.

The monolith is the most simple, you just provide one image, and it is used to draw the background of the element. The image is stretched to fit the size of the element.
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How to change buttoms/frame background

Post by ficolas »

ok so I created this:

Code: Select all

data:extend({
      soldering_iron =
      {
        type = "monolith",
        top_monolith_border = 1,
        right_monolith_border = 1,
        bottom_monolith_border = 1,
        left_monolith_border = 1,
        monolith_image =
        {
          filename = "__F-mod__/resources/other/chipset.png",
          width = 220,
          height = 220,
          x = 0,
          y = 0
        }
      }
      
})
and if I do this in the code:

Code: Select all

game.player.gui.left.add({type="frame", name="menu", caption="Change frequency",direction="vertical",style="soldering_iron"})
it says that the style soldering_iron doesnt exist.
What do I need to do?

I also tried this:

Code: Select all

data:extend({
    type = "gui-style",
    name = "f-mod",
    soldering_iron =
    {
      type = "frame_style",
      font = "default-frame",
      font_color = {r=1, g=1, b=1},
      -- padding of the title area of the frame, when the frame title
      -- is empty, the area doesn't exist and these values are not used
      title_top_padding = 0,
      title_left_padding = 0,
      title_bottom_padding = 15,
      title_right_padding = 0,
      -- padding of the content area of the frame
      top_padding  = default_container_padding - 6,
      right_padding = default_container_padding,
      bottom_padding = default_container_padding,
      left_padding = default_container_padding,
      graphical_set =
      {
        type = "composition",
        filename = "__F-mod__/resources/other/chipset.png",
        corner_size = {220,220},
        position = {0, 0}
      },
      flow_style=
      {
        horizontal_spacing = default_container_padding,
        vertical_spacing = default_container_padding
      }
    },
})
kovarex
Factorio Staff
Factorio Staff
Posts: 8298
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: How to change buttoms/frame background

Post by kovarex »

The problem is, that you have to extend the "default-gui" object, and the soldering_iron you have there is just specification of the graphical set, but it has to be part of some gui specification.
Let's say it is frame.

Code: Select all

local soldering_iron =
{
  type="frame_style",
  parent="frame_style",
  graphical_set=
  {
    type = "monolith",
    top_monolith_border = 1,
    right_monolith_border = 1,
    bottom_monolith_border = 1,
    left_monolith_border = 1,
    monolith_image =
    {
      filename = "__F-mod__/resources/other/chipset.png",
      width = 220,
      height = 220,
      x = 0,
      y = 0
    }
  }
}

-- Here I extend the default gui style with the soldering_iron style.
data.raw["gui-style"].default["soldering_iron"] = soldering_iron

P.S. Unfortunately, when testing this, I discovered a bug in the processing of custom gui elements, when I repaired it, it worked, but in the current 1.5.2 it won't work, with other small bugs, to have 1.5. really stable, I think we should make 1.5.3 as well :)
User avatar
cube
Former Staff
Former Staff
Posts: 1111
Joined: Tue Mar 05, 2013 8:14 pm
Contact:

Re: How to change buttoms/frame background

Post by cube »

kovarex wrote:P.S. Unfortunately, when testing this, I discovered a bug in the processing of custom gui elements, when I repaired it, it worked, but in the current 1.5.2 it won't work, with other small bugs, to have 1.5. really stable, I think we should make 1.5.3 as well :)
... 0.5.2 and 0.5.3 :-)
I have no idea what I'm talking about.
JasonC
Filter Inserter
Filter Inserter
Posts: 451
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: How to change buttoms/frame background

Post by JasonC »

kovarex wrote:Yes, you can change the background.

The monolith is the most simple, you just provide one image, and it is used to draw the background of the element. The image is stretched to fit the size of the element.
@kovarex: Is there a way to prevent the monolith from scaling?

The algorithm is strange. It seems to automatically chop off the transparent areas around an image before scaling. So like if you have a 32x32 png with large transparent areas on the side, and a 32x32 monolith, it still stretches it. E.g. the in-game icon graphics used as monoliths in button styles yield:

Image

Notice how the electric pole in the top left is stretched. It's a monolith image on a 32x32 button. It's opaque portions have been stretched to fill the 32x32 area, even though the png itself is 32x32.
Took a break from 0.12.29 to 0.17.79, and then to ... oh god now it's 1.something. I never know what's happening.
JasonC
Filter Inserter
Filter Inserter
Posts: 451
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: How to change buttoms/frame background

Post by JasonC »

So it looks like (thanks Macros in chat) that for some reason only checkboxes with checkbox_styles support not scaling the image. So if you want a button but don't want the scaling, you have to create a checkbox with the image, then style it into something more button-esque.
Took a break from 0.12.29 to 0.17.79, and then to ... oh god now it's 1.something. I never know what's happening.
JasonC
Filter Inserter
Filter Inserter
Posts: 451
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: How to change buttoms/frame background

Post by JasonC »

I've written a guide on this topic: viewtopic.php?f=34&t=24007
Took a break from 0.12.29 to 0.17.79, and then to ... oh god now it's 1.something. I never know what's happening.
Post Reply

Return to “Modding help”