added dragged item rendering

This commit is contained in:
MasterGordon 2022-12-20 23:30:58 +01:00
parent 0320bbc6a6
commit 0520d617f3
2 changed files with 26 additions and 5 deletions

View File

@ -53,9 +53,9 @@ public class HudRenderer : IRenderer
}
var texture = stack.GetTexture();
renderer.DrawTexture(texture, (4 + i * 20) * uiScale, 4 * uiScale, 16 * uiScale, 16 * uiScale);
renderer.DrawText("" + stack.Count, (4 + i * 20) * uiScale, 14 * uiScale);
if (cursorPosition.X >= (4 + i * 20) * uiScale && cursorPosition.X <= (4 + i * 20 + 16) * uiScale && cursorPosition.Y >= 4 * uiScale && cursorPosition.Y <= (4 + 16) * uiScale)
renderer.DrawTexture(texture, (4 + (i * 24)) * uiScale, 4 * uiScale, 16 * uiScale, 16 * uiScale);
renderer.DrawText("" + stack.Count, (4 + (i * 24)) * uiScale, 14 * uiScale);
if (cursorPosition.X >= (4 + (i * 24)) * uiScale && cursorPosition.X <= (4 + (i * 24) + 16) * uiScale && cursorPosition.Y >= 4 * uiScale && cursorPosition.Y <= (4 + 16) * uiScale)
{
Context.Get().FrontendGameState.Tooltip = stack.GetName();
}

View File

@ -1,19 +1,40 @@
using Mine2d.engine;
using Mine2d.game.core;
using Mine2d.game.state;
namespace Mine2d.game.frontend.renderer
{
public class InventoryRenderer : IRenderer
{
public void Render() {
public void Render()
{
var ctx = Context.Get();
var inventory = ctx.FrontendGameState.OpenInventory;
if(inventory == InventoryKind.None) return;
if (inventory == InventoryKind.None) return;
ctx.Renderer.SetColor(0, 0, 0, 200);
ctx.Renderer.SetDrawBlendMode(SDL_BlendMode.SDL_BLENDMODE_BLEND);
ctx.Renderer.DrawRect(0, 0, ctx.FrontendGameState.WindowWidth, ctx.FrontendGameState.WindowHeight);
var inventoryRenderer = ctx.InventoryRegistry.GetInventory(inventory);
inventoryRenderer.Render();
var player = PlayerEntity.GetSelf();
if (player.Inventory.cursor != null)
{
var cursorPosition = ctx.FrontendGameState.CursorPosition;
var itemTexture = player.Inventory.cursor.GetTexture();
var uiScale = ctx.FrontendGameState.Settings.UiScale;
ctx.Renderer.DrawTexture(
itemTexture,
(int)(cursorPosition.X + 2),
(int)(cursorPosition.Y + 2),
16 * uiScale,
16 * uiScale
);
ctx.Renderer.DrawText(
"" + player.Inventory.cursor.Count,
(int)(cursorPosition.X + 2),
(int)(cursorPosition.Y + (12 * uiScale))
);
}
}
}
}