Page 1 of 1
Using draw_sprite() to make shadow background under item icon
Posted: Thu May 21, 2020 12:57 pm
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 (313.71 KiB) Viewed 1549 times
Re: Using draw_sprite() to make shadow background under item icon
Posted: Thu May 21, 2020 6:27 pm
by darkfrei
Why and where are you need it?
Re: Using draw_sprite() to make shadow background under item icon
Posted: Fri May 22, 2020 3:09 am
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.
Re: Using draw_sprite() to make shadow background under item icon
Posted: Tue May 26, 2020 2:31 am
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?
Re: Using draw_sprite() to make shadow background under item icon
Posted: Tue May 26, 2020 4:19 am
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.
Re: Using draw_sprite() to make shadow background under item icon
Posted: Tue May 26, 2020 6:54 pm
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