public TextureAtlasPosition this[string textureCode] { get { if (contentTextPos == null) { int textureSubId; textureSubId = ObjectCacheUtil.GetOrCreate <int>(capi, "contenttexture-" + contentTexture.ToString() + "-" + contentTexture.Alpha, () => { TextureAtlasPosition texPos; int id = 0; BitmapRef bmp = capi.Assets.TryGet(contentTexture.Base.Clone().WithPathPrefixOnce("textures/").WithPathAppendixOnce(".png"))?.ToBitmap(capi); if (bmp != null) { if (contentTexture.Alpha != 255) { bmp.MulAlpha(contentTexture.Alpha); } capi.BlockTextureAtlas.InsertTexture(bmp, out id, out texPos); bmp.Dispose(); } return(id); }); contentTextPos = capi.BlockTextureAtlas.Positions[textureSubId]; } return(contentTextPos); } }
private void OnDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds) { BitmapRef bmp = capi.Assets.Get("alchemy:textures/hud/alchemyhud.png").ToBitmap(capi); if (inactive) { bmp.MulAlpha(30); } Vintagestory.API.Common.SurfaceDrawImage.Image(surface, ((Vintagestory.API.Common.BitmapExternal)bmp), (int)currentBounds.drawX, (int)currentBounds.drawY, (int)currentBounds.InnerWidth, (int)currentBounds.InnerHeight); bmp.Dispose(); }