diff --git a/BlazorApp1/Components/Crafting.razor b/BlazorApp1/Components/Crafting.razor index c8f143d..ebc8ad6 100644 --- a/BlazorApp1/Components/Crafting.razor +++ b/BlazorApp1/Components/Crafting.razor @@ -10,6 +10,7 @@ @foreach (var item in Items) { + } diff --git a/BlazorApp1/Components/CraftingItem.razor b/BlazorApp1/Components/CraftingItem.razor index c1043b8..3ae8ec4 100644 --- a/BlazorApp1/Components/CraftingItem.razor +++ b/BlazorApp1/Components/CraftingItem.razor @@ -1,4 +1,6 @@ -
Inventory + + +
+
+ +
+
Recipe
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
Available items:
+
+
+ + @foreach (var item in Items) + { + + + } +
+
+ +
+ +
+
Actions
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/BlazorApp1/Components/InventoryComponent.razor.cs b/BlazorApp1/Components/InventoryComponent.razor.cs new file mode 100644 index 0000000..0e1b9a4 --- /dev/null +++ b/BlazorApp1/Components/InventoryComponent.razor.cs @@ -0,0 +1,38 @@ +using BlazorApp1.Models; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace BlazorApp1.Components +{ + public partial class InventoryComponent + { + public InventoryComponent() + { + Actions = new ObservableCollection(); + Actions.CollectionChanged += OnActionsCollectionChanged; + this.InventoryItems = new List { null, null, null, null, null, null, null, null, null }; + } + + public ObservableCollection Actions { get; set; } + public Item CurrentDragItem { get; set; } + + [Parameter] + public List Items { get; set; } + + public List InventoryItems { get; set; } + + /// + /// Gets or sets the java script runtime. + /// + [Inject] + internal IJSRuntime JavaScriptRuntime { get; set; } + + private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); + } + + } +} diff --git a/BlazorApp1/Components/InventoryComponent.razor.css b/BlazorApp1/Components/InventoryComponent.razor.css new file mode 100644 index 0000000..951f1f7 --- /dev/null +++ b/BlazorApp1/Components/InventoryComponent.razor.css @@ -0,0 +1,13 @@ +.css-inventory { + grid-template-columns: repeat(9,minmax(auto,auto)); + gap: 10px; + display: grid; + width: 212px; +} + +.css-grid { + grid-template-columns: repeat(4,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 286px; +} \ No newline at end of file diff --git a/BlazorApp1/Components/InventoryItem.razor b/BlazorApp1/Components/InventoryItem.razor new file mode 100644 index 0000000..3ae8ec4 --- /dev/null +++ b/BlazorApp1/Components/InventoryItem.razor @@ -0,0 +1,16 @@ +@using BlazorApp1.Models + +
+ + @if (Item != null) + { + @Item.DisplayName + } +
\ No newline at end of file diff --git a/BlazorApp1/Components/InventoryItem.razor.cs b/BlazorApp1/Components/InventoryItem.razor.cs new file mode 100644 index 0000000..a89a4a4 --- /dev/null +++ b/BlazorApp1/Components/InventoryItem.razor.cs @@ -0,0 +1,59 @@ +using BlazorApp1.Models; +using Microsoft.AspNetCore.Components; + +namespace BlazorApp1.Components +{ + public partial class InventoryItem + { + [Parameter] + public int Index { get; set; } + + [Parameter] + public Item Item { get; set; } + + [Parameter] + public bool NoDrop { get; set; } + + [CascadingParameter] + public InventoryComponent Parent { get; set; } + + internal void OnDragEnter() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new CraftingAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); + } + + internal void OnDragLeave() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new CraftingAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); + } + + internal void OnDrop() + { + if (NoDrop) + { + return; + } + + this.Item = Parent.CurrentDragItem; + + Parent.Actions.Add(new CraftingAction { Action = "Drop", Item = this.Item, Index = this.Index }); + } + + private void OnDragStart() + { + Parent.CurrentDragItem = this.Item; + + Parent.Actions.Add(new CraftingAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); + } + } +} diff --git a/BlazorApp1/Components/InventoryItem.razor.css b/BlazorApp1/Components/InventoryItem.razor.css new file mode 100644 index 0000000..b2d4521 --- /dev/null +++ b/BlazorApp1/Components/InventoryItem.razor.css @@ -0,0 +1,6 @@ +.item { + width: 64px; + height: 64px; + border: 1px solid; + overflow: hidden; +} diff --git a/BlazorApp1/Pages/Inventory.razor b/BlazorApp1/Pages/Inventory.razor new file mode 100644 index 0000000..309c4b8 --- /dev/null +++ b/BlazorApp1/Pages/Inventory.razor @@ -0,0 +1,14 @@ +@page "/inventory" +@using System.Globalization +@using BlazorApp1.Components + +Inventory + +
+ +
+ +

+ CurrentCulture: @CultureInfo.CurrentCulture +

+ diff --git a/BlazorApp1/Pages/Inventory.razor.cs b/BlazorApp1/Pages/Inventory.razor.cs new file mode 100644 index 0000000..cca96bf --- /dev/null +++ b/BlazorApp1/Pages/Inventory.razor.cs @@ -0,0 +1,28 @@ +using BlazorApp1.Components; +using BlazorApp1.Models; +using Microsoft.AspNetCore.Components; + +namespace BlazorApp1.Pages +{ + public partial class Inventory + { + [Inject] + public IDataService DataService { get; set; } + + public List Items { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } + + Items = await DataService.List(0, await DataService.Count()); + + StateHasChanged(); + } + } +} diff --git a/BlazorApp1/Shared/NavMenu.razor b/BlazorApp1/Shared/NavMenu.razor index 99c320f..cc162e8 100644 --- a/BlazorApp1/Shared/NavMenu.razor +++ b/BlazorApp1/Shared/NavMenu.razor @@ -20,7 +20,7 @@