staubwirbel Posted May 1, 2020 Share Posted May 1, 2020 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: 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 More sharing options...
Pathoschild Posted May 2, 2020 Share Posted May 2, 2020 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 More sharing options...
staubwirbel Posted May 5, 2020 Author Share Posted May 5, 2020 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 More sharing options...
Recommended Posts