diff --git a/blazor_lab.sln b/blazor_lab.sln index 6816149..79728d6 100644 --- a/blazor_lab.sln +++ b/blazor_lab.sln @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "blazor_lab", "blazor_lab\blazor_lab.csproj", "{7B8F9C82-6399-47FC-A996-8140F39484D6}" + ProjectSection(ProjectDependencies) = postProject + {F89D34E2-0DBC-4E98-BC77-E4CB00A33D19} = {F89D34E2-0DBC-4E98-BC77-E4CB00A33D19} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft.Crafting.Api", "Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{F89D34E2-0DBC-4E98-BC77-E4CB00A33D19}" EndProject diff --git a/blazor_lab/Components/InventoryGrid.razor b/blazor_lab/Components/InventoryGrid.razor new file mode 100644 index 0000000..8ce7449 --- /dev/null +++ b/blazor_lab/Components/InventoryGrid.razor @@ -0,0 +1,21 @@ +
+ @for (int row = 0; row < 3; row++) + { +
+ @for (int col = 0; col < 6; col++) + { +
+ @if (Inventory != null && Inventory.Count > (row * 6 + col)) + { + var slot = Inventory[row * 6 + col]; + @if (slot.NumberItem > 0) + { + @slot.ItemName +
@slot.NumberItem
+ } + } +
+ } +
+ } +
\ No newline at end of file diff --git a/blazor_lab/Components/InventoryGrid.razor.cs b/blazor_lab/Components/InventoryGrid.razor.cs new file mode 100644 index 0000000..87a879b --- /dev/null +++ b/blazor_lab/Components/InventoryGrid.razor.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Components; +using Minecraft.Crafting.Api.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Json; +using System.Threading.Tasks; + + +namespace blazor_lab.Components +{ + + public partial class InventoryGrid + { + [Parameter] + public List Inventory { get; set; } + + public List Items { get; set; } = new List(); + + [Inject] + public HttpClient HttpClient { get; set; } + + [Inject] + public IConfiguration Config { get; set; } + + protected override async Task OnInitializedAsync() + { + Items = await HttpClient.GetFromJsonAsync>($"{Config["CraftingApi:BaseUrl"]}/api/Crafting/all"); + } + + public string GetItemImageBase64(string displayName) + { + var item = Items.FirstOrDefault(i => i.DisplayName == displayName); + return item?.ImageBase64; + } + } +} diff --git a/blazor_lab/Components/InventoryGrid.razor.css b/blazor_lab/Components/InventoryGrid.razor.css new file mode 100644 index 0000000..155b226 --- /dev/null +++ b/blazor_lab/Components/InventoryGrid.razor.css @@ -0,0 +1,25 @@ +.inventory-grid { + display: flex; + flex-direction: column; +} + +.inventory-row { + display: flex; + flex-direction: row; +} + +.inventory-slot { + width: 64px; + height: 64px; + border: 1px solid; + margin: 5px; + display: flex; + flex-direction: column; + align-items: center; + overflow: hidden; +} + + +.item-count { + margin-top: 5px; +} diff --git a/blazor_lab/Pages/Inventory.razor b/blazor_lab/Pages/Inventory.razor new file mode 100644 index 0000000..6837b6b --- /dev/null +++ b/blazor_lab/Pages/Inventory.razor @@ -0,0 +1,7 @@ +@page "/inventory" +@using Minecraft.Crafting.Api.Models +@using blazor_lab.Components + +

Inventory

+ + \ No newline at end of file diff --git a/blazor_lab/Pages/Inventory.razor.cs b/blazor_lab/Pages/Inventory.razor.cs new file mode 100644 index 0000000..b5b367f --- /dev/null +++ b/blazor_lab/Pages/Inventory.razor.cs @@ -0,0 +1,9 @@ +using Minecraft.Crafting.Api.Models; + +namespace blazor_lab.Pages +{ + public partial class Inventory + { + private List Stuff = Enumerable.Range(1, 18).Select(_ => new InventoryModel()).ToList(); + } +} diff --git a/blazor_lab/Shared/NavMenu.razor b/blazor_lab/Shared/NavMenu.razor index 8c9d622..c5f2153 100644 --- a/blazor_lab/Shared/NavMenu.razor +++ b/blazor_lab/Shared/NavMenu.razor @@ -14,7 +14,11 @@