Setting image in a button_style

Place to get help with not working mods / modding interface.
JasonC
Filter Inserter
Filter Inserter
Posts: 451
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Setting image in a button_style

Post by JasonC »

In a button_style with slot_button_style as the parent, how do I set an image that appears inside the button when defining the style (it doesn't need to be done from control.lua, it can be done when setting up the styles)?

Same deal with button_style as a parent, actually.

Things I've tried:
  • Setting the image in the *_graphical_set's monoliths. But this destroys the borders and backgrounds (which are a graphic).
  • Setting the image in the *_background pictures. But these are ignored for these styles (I guess *_graphical_set overrides them? It's all undocumented so I don't know.)
  • Making my own graphics with the icon and the button borders in them. But this is not acceptable in this case. I need to use game icon graphics, and lots of them. I can't redo the entire graphic set (not to mention keeping it up to date with any graphics changes in game updates).
I can't really think of much else.

Monoliths, entity-specific styles are all undocumented so I've been wild guessing from examples.

There's these "composition" things too but I don't know what they are and no info about them exists.

Alternatively if anybody knows of a mod with graphical buttons that still have their borders and hover effects, please direct me towards it so I can look at it as an example. That works too.
Last edited by JasonC on Tue Apr 19, 2016 5:48 pm, edited 1 time in total.
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.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Setting image in a button_style

Post by Adil »

Well, there's concrete logistics by Afforres although the sheer amount of code there may rather daunting.
He also provided this remark on the matter:
Afforess wrote: It's no secret, just clever use of the API. All the code is on github.

So there are two parts to having an icon on a button. The first part is in the prototypes/styles/icon.lua. I generate an button style for every item in the game, so I can use them later in the GUI. You can set the monolith_image of a button_style to create an button with an image. Then I set the default, clicked, hover, and disabled style to use this monolith_image configuration, so no matter whether the icon is clicked / hovered by the user it looks correct.

Then in my gui code, I create a button with the style for each particular item. icon_name is actually the name of the factorio entity, like 'transport-belt' or whatever you want the icon to represent.

If you want some more detailed help / discussion, I'm on #factorio IRC in esper.net most afternoons (EDT) and all day on weekends.
And also this floated in the thread list recently:
viewtopic.php?f=92&t=23680
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
JasonC
Filter Inserter
Filter Inserter
Posts: 451
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: Setting image in a button_style

Post by JasonC »

Adil wrote:Well, there's concrete logistics by Afforres although the sheer amount of code there may rather daunting.
He also provided this remark on the matter:
Afforess wrote: It's no secret, just clever use of the API. All the code is on github.

So there are two parts to having an icon on a button. The first part is in the prototypes/styles/icon.lua. I generate an button style for every item in the game, so I can use them later in the GUI. You can set the monolith_image of a button_style to create an button with an image. Then I set the default, clicked, hover, and disabled style to use this monolith_image configuration, so no matter whether the icon is clicked / hovered by the user it looks correct.

Then in my gui code, I create a button with the style for each particular item. icon_name is actually the name of the factorio entity, like 'transport-belt' or whatever you want the icon to represent.

If you want some more detailed help / discussion, I'm on #factorio IRC in esper.net most afternoons (EDT) and all day on weekends.
Thanks. I'm actually doing the exact same thing (inspiration). But setting the graphical_set kills the background and border; which works fine in his GUI but isn't quite right for my situation. I'll chat him up though I see him sometimes on IRC.
And also this floated in the thread list recently:
viewtopic.php?f=92&t=23680
Yup, I actually checked out that very mod this morning when researching this. He's got hard-coded support for those mods with graphics made for each, and the graphics already include the border and highlight color.

My challenge is using the existing game icons but also maintaining the buttons borders (and ideally the background highlight color). Just like how e.g. the character inventory has slot_buttons (where the background and border are actually images) then overlays icon graphics (with transparent backgrounds) over top of them.
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: Setting image in a button_style

Post by JasonC »

The buttons in question are the buttons on this GUI:

Image

I want them to have the icons but also have borders and proper hover effects.
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”