Jump to content

Open Community  ·  421 members

Stardew Valley

Modding : How to draw below tooltips


staubwirbel

Recommended Posts

Hi you guys,

 

I'm new to modding for Stardew Valley (and C# for that matter), but I managed to create a nice little mod that adds "sparkles" to recipes I haven't crafted yet:

 

screenshot.png

 

However the sparkles are drawn over the tooltips that appear when the mouse hovers over an item. I want to draw them below the tooltips (and to be precise above the menu itself).

 

The sprite is drawn in IModHelper#Events.Display.RenderedActiveMenu via

spriteBatch.Draw(sparkleImage, targetRect, null, Color.White, 0, new Vector2(0, 0), SpriteEffects.None, 0);

I believe the last argument, layerDepth, is what should be used to draw the image in a specific layer. However it appears to me that both the main menu and the popups are drawn on layer 0. Is that correct? If so, is there a minimally invasive way to change either the popups or the menu to be drawn another layer? If it's not correct, what is the right way to do this?

 

(Also, as a bonus question: how do I trigger a rerendering of the screen?)

 

Thanks for your help! :smile:

 

 

Link to comment
Share on other sites

Hi,

 

Drawing under specific things in the game can be hard, because the game draws a lot at the same time (e.g. menu background and item tooltip are part of the same draw), and the game uses many sprite batches per tick (so layer depth only affects things drawn since the last sprite batch change). If you really want to, one workaround is to use a Harmony postfix to draw the sparkles as part of item sprite draw; that way it'll automatically be on the same layer as the item sprite itself.

 

You can't easily trigger a rerendering of the screen, but that shouldn't be necessary since it rerenders 60 times per second.

Link to comment
Share on other sites

Thanks for replying.

 

I thought about adding the sparkles directly to the sprite - the caveat being that the sparkle is then drawn transparent (if the materials are missing) or only its outline is (if the recipe is unknown).

 

But maybe that's better than the current alternative. What event would I listen to, to redraw the sprite sheet after a recipe is crafted?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...