public static void RenderItemIcon(SpriteBatch spriteBatch, Texture2D texture, IItemProvider provider, byte metadata, Rectangle destination, Color color) { var icon = provider.GetIconTexture(metadata); var scale = texture.Width / 16; var source = new Rectangle(icon.Item1 * scale, icon.Item2 * scale, scale, scale); spriteBatch.Draw(texture, destination, source, color); }
public void Draw(GameTime gameTime) { if (Game.Client.CurrentWindow != null) { // TODO: slot == -999 when outside of the window and -1 when inside the window, but not on an item SelectedSlot = -999; IItemProvider provider = null; var scale = new Point((int)(16 * Game.ScaleFactor * 2)); var mouse = Mouse.GetState().Position.ToVector2().ToPoint() - new Point((int)(8 * Game.ScaleFactor * 2)); var rect = new Rectangle(mouse, scale); if (!HeldItem.Empty) { provider = Game.ItemRepository.GetItemProvider(HeldItem.ID); } SpriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.NonPremultiplied); SpriteBatch.Draw(Game.White1x1, new Rectangle(0, 0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), new Color(Color.Black, 180)); switch (Game.Client.CurrentWindow.Type) { case -1: SpriteBatch.Draw(Inventory, new Vector2( Game.GraphicsDevice.Viewport.Width / 2 - Scale(InventoryWindowRect.Width / 2), Game.GraphicsDevice.Viewport.Height / 2 - Scale(InventoryWindowRect.Height / 2)), InventoryWindowRect, Color.White, 0, Vector2.Zero, Game.ScaleFactor * 2, SpriteEffects.None, 1); DrawInventoryWindow(RenderStage.Sprites); break; case 1: // Crafting bench SpriteBatch.Draw(Crafting, new Vector2( Game.GraphicsDevice.Viewport.Width / 2 - Scale(CraftingWindowRect.Width / 2), Game.GraphicsDevice.Viewport.Height / 2 - Scale(CraftingWindowRect.Height / 2)), CraftingWindowRect, Color.White, 0, Vector2.Zero, Game.ScaleFactor * 2, SpriteEffects.None, 1); DrawCraftingWindow(RenderStage.Sprites); break; } if (provider != null) { if (provider.GetIconTexture((byte)HeldItem.Metadata) != null) { IconRenderer.RenderItemIcon(SpriteBatch, Items, provider, (byte)HeldItem.Metadata, rect, Color.White); } } SpriteBatch.End(); switch (Game.Client.CurrentWindow.Type) { case -1: DrawInventoryWindow(RenderStage.Models); break; case 1: // Crafting bench DrawCraftingWindow(RenderStage.Models); break; } if (provider != null) { if (provider.GetIconTexture((byte)HeldItem.Metadata) == null && provider is IBlockProvider) { IconRenderer.RenderBlockIcon(Game, provider as IBlockProvider, (byte)HeldItem.Metadata, rect); } } SpriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.NonPremultiplied); switch (Game.Client.CurrentWindow.Type) { case -1: DrawInventoryWindow(RenderStage.Text); break; case 1: // Crafting bench DrawCraftingWindow(RenderStage.Text); break; } if (provider != null) { if (HeldItem.Count > 1) { int offset = 10; if (HeldItem.Count >= 10) { offset -= 6; } mouse += new Point((int)Scale(offset), (int)Scale(5)); Font.DrawText(SpriteBatch, mouse.X, mouse.Y, HeldItem.Count.ToString(), Game.ScaleFactor); } } if (SelectedSlot >= 0) { var item = Game.Client.CurrentWindow[SelectedSlot]; if (!item.Empty) { var p = Game.ItemRepository.GetItemProvider(item.ID); var size = Font.MeasureText(p.DisplayName); mouse = Mouse.GetState().Position.ToVector2().ToPoint(); mouse += new Point(10, 10); SpriteBatch.Draw(Game.White1x1, new Rectangle(mouse, new Point(size.X + 10, size.Y + 15)), new Color(Color.Black, 200)); Font.DrawText(SpriteBatch, mouse.X + 5, mouse.Y, p.DisplayName); } } SpriteBatch.End(); } }