Using draw_sprite() to make shadow background under item icon

Place to get help with not working mods / modding interface.
robot256
Filter Inserter
Filter Inserter
Posts: 847
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Using draw_sprite() to make shadow background under item icon

Post by robot256 »

I want to draw an icon in the same style as the cargo wagon contents in alt-mode. Right now, I use two steps to draw a background for contrast, then the item icon on top:

Code: Select all

rendering.draw_sprite{
      sprite="virtual-signal.signal-black",
      x_scale=1.4,
      y_scale=1.4,
      render_layer="entity-info-icon",
      target=target,
      target_offset={0,-0.5},
      surface=target.surface,
      only_in_alt_mode=true
    }
    rendering.draw_sprite{
      sprite="entity."..contents,
      x_scale=1,
      y_scale=1,
      render_layer="entity-info-icon",
      target=target,
      target_offset={0,-0.5},
      surface=target.surface,
      only_in_alt_mode=true
    }
Is there a way to invoke the built-in background generator, like is done for other alt-mode icons? I see "draw_shadow-in-background" as an option for GUI elements, but not in-game sprites (in draw_sprite or in the sprite prototype).

Edit: Here is an illustration. On the left is rendered icon with no background. Center is rendered with signal-black background as above. Right is the game-generated contents icon I would like to imitate.
script rendered contents icons.jpg
script rendered contents icons.jpg (313.71 KiB) Viewed 1292 times
Last edited by robot256 on Fri May 22, 2020 3:04 am, edited 1 time in total.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Using draw_sprite() to make shadow background under item icon

Post by darkfrei »

Why and where are you need it?

robot256
Filter Inserter
Filter Inserter
Posts: 847
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Using draw_sprite() to make shadow background under item icon

Post by robot256 »

I am working on the Vehicle Wagons mod, where car entities are "loaded" by flattened into a global data structure and storing a reference to the wagon they are loaded on, for later recreation when "unloaded". Because the same wagon sprite can be used for many different car entities, I would like to display the icon for the car loaded in that wagon in the same manner as the contents of cargo and fluid wagons are displayed. See the image I added to my first post for what I mean.

Basically, my question is do I have to make my own sprite for a blurred black circle to use as background? I could not find such an image in the base game, so I assume it is dynamically generated. In that case, this becomes a modding interface request for access to the background generator for generic rendered sprites.

User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 426
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Re: Using draw_sprite() to make shadow background under item icon

Post by kirazy »

robot256 wrote:
Fri May 22, 2020 3:09 am
I could not find such an image in the base game, so I assume it is dynamically generated.
Is it not entity-info-dark-background.png under the core folder?

robot256
Filter Inserter
Filter Inserter
Posts: 847
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Using draw_sprite() to make shadow background under item icon

Post by robot256 »

kirazy wrote:
Tue May 26, 2020 2:31 am
robot256 wrote:
Fri May 22, 2020 3:09 am
I could not find such an image in the base game, so I assume it is dynamically generated.
Is it not entity-info-dark-background.png under the core folder?
So it is! I did not think to look in the "core" folder, only in the "base" folder. Makes sense, since "base" is a mod and there's a lot of stuff that is not mod data that needs to go somewhere.

Hiladdar
Fast Inserter
Fast Inserter
Posts: 214
Joined: Mon May 14, 2018 6:47 pm
Contact:

Re: Using draw_sprite() to make shadow background under item icon

Post by Hiladdar »

Usually there will be a separate file that contains a semi transparent mask for the shadow, that has to match up entity graphic, with two graphic file definitions, one for the entity itself, and one for the shadow.

In this case there is an entity overlayed on top of an entity, hence there are two entity files involved, and should be two shadow masks involved. In the vanilla game it is fairly simple, with only the car and tank. But once mods, which introduce additional vehicles are included, of what can loaded on the flatbed cargo wagon, the complexity increases exponentially. The complexity continues increases since the base entity, the wagon, can rotate while traveling, hence rotating the entity, and it's shadow in synchronization with wagon.

Hiladdar

Post Reply

Return to “Modding help”