Display quality overlay on a sprite and sprite-button

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 81
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Display quality overlay on a sprite and sprite-button

Post by hgschmie »

For a sprite button, I can have it overlay a number (for count), by adding a "number = 100" to the LuaGuiElement.

However, with Space Age, there are icons like this (this is the signal display from a combinator):
Screenshot 2024-11-23 at 16.59.28.png
Screenshot 2024-11-23 at 16.59.28.png (20.92 KiB) Viewed 434 times
How do I get the quality overlay for a sprite (or a sprite button)? There is a workaround using a "choose-elem-button" which allows using "item-with-quality" and then in turn use that to display an item with the quality overlay but that can not display a number.

Is there a way to draw a sprite-button that looks like the button in the constant combinator? If not, is it possible to add some additional attributes to sprite-button (and probably also sprite) that allows for the quality overlay?
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 81
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: Display quality overlay on a sprite and sprite-button

Post by hgschmie »

[ replying to my own post first]

At this point, I can get the hovers over the icons to work (by using the elem_tooltip attribute):

Code: Select all

button.elem_tooltip = {
  type = 'item-with-quality',
  name = signal_name,
  quality = signal.signal.quality,
}
However, the icons still do not show the quality information:
Screenshot 2024-11-23 at 22.37.11.png
Screenshot 2024-11-23 at 22.37.11.png (127.29 KiB) Viewed 376 times
In the filter selector at the botttom, the icons have a quality marker (this is a table of choose-elem-buttons which display the quality). In the top, the elements (sprite-button) are all plain, even though the tooltips show the quality correctly (see the hover).

The question is still on how to get the quality marker on the sprite buttons.
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 81
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: Display quality overlay on a sprite and sprite-button

Post by hgschmie »

[pinging this topic]

This is still sorely lacking and I have a few circuit network related mods that suffer from the fact that there is no gui element that can do what the builtin combinators can (show a number and quality at the same time).

Please? Pretty please? Pretty pretty pleeeeease? ;-)

(At least give us a “will do at some point/will never do/here is a workaround”. Heck, at this point I would settle for “overlay two sprites on a sprite button”)
curiosity
Filter Inserter
Filter Inserter
Posts: 558
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Display quality overlay on a sprite and sprite-button

Post by curiosity »

hgschmie wrote: Tue Jan 21, 2025 10:49 pm (At least give us a “will do at some point/will never do/here is a workaround”. Heck, at this point I would settle for “overlay two sprites on a sprite button”)
Guess what, any GUI element can have children. It's more cursed than it seems. Make of it what you will.
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 81
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: Display quality overlay on a sprite and sprite-button

Post by hgschmie »

curiosity wrote: Wed Jan 22, 2025 7:27 pm
hgschmie wrote: Tue Jan 21, 2025 10:49 pm (At least give us a “will do at some point/will never do/here is a workaround”. Heck, at this point I would settle for “overlay two sprites on a sprite button”)
Guess what, any GUI element can have children. It's more cursed than it seems. Make of it what you will.
You know, this was a shockingly good comment. Thank you for this. :-)

this actually works:

add to prototypes:

Code: Select all

data.raw['gui-style'].default['quality_style'] = {
    type = 'image_style',
    left_padding = 16,
}
and then in your code (e.g. for a Signal) do

Code: Select all

local button = parent_gui_element.add {
    type = "sprite-button",
    sprite = signal.signal.type .. "/" .. signal.signal.name,
    number = signal.count,
}
if signal.signal.quality and signal.signal.quality ~= 'normal' then
    button.add {
        type = 'sprite',
        style = 'quality_style',
        sprite = 'quality/' .. signal.signal.quality,
    }
end
and you end up with this:
Screenshot 2025-01-24 at 17.36.03.png
Screenshot 2025-01-24 at 17.36.03.png (11.11 KiB) Viewed 100 times

why not at the bottom left as the builtin buttons do? Because this image consists of multiple layers:

1) the background image
2) the icon
3) the quality overlay
4) the number

The builtin buttons render (bottom to top): 1, 2, 3, 4. So the number is on top of the quality overlay.

This workaround renders 1, 2, 4, 3. So the quality overlay would cover part of the number. Moving it to the top right corner avoids that.
User avatar
EvilPLa
Inserter
Inserter
Posts: 23
Joined: Sat Nov 14, 2020 7:26 am
Contact:

Re: Display quality overlay on a sprite and sprite-button

Post by EvilPLa »

Thanks for documenting this.
I had to set the size in the style definition and restrict the sprite widget to

Code: Select all

resize_to_sprite = false
01-27-2025, 10-44-49.png
01-27-2025, 10-44-49.png (16.9 KiB) Viewed 42 times
01-27-2025, 10-46-11.png
01-27-2025, 10-46-11.png (41.31 KiB) Viewed 42 times
(setting the actual sprite happens somewhere else)
01-27-2025, 10-44-06.png
01-27-2025, 10-44-06.png (11.42 KiB) Viewed 42 times
I havent lost my mind, it's backed up on tape somewhere.
Post Reply

Return to “Modding interface requests”