diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs index 637750e..e792288 100644 --- a/Blazor/Blazor/Components/Inventory.razor.cs +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -1,35 +1,35 @@ -using Blazor.Models; -using Blazor.Pages; -using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; -using System.Collections.ObjectModel; +using Blazor.Models; +using Blazor.Pages; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Collections.ObjectModel; using System.Collections.Specialized; -namespace Blazor.Components -{ - partial class Inventory - { - public Models.InventoryList inventory = new Models.InventoryList(); - public Models.InventoryItem CurrentDragItem { get; set; } - public ObservableCollection Actions { get; set; } - - [Inject] - internal IJSRuntime JavaScriptRuntime { get; set; } - - public Inventory() - { +namespace Blazor.Components +{ + partial class Inventory + { + public Models.InventoryList inventory = new Models.InventoryList(); + public Models.InventoryItem CurrentDragItem { get; set; } + public ObservableCollection Actions { get; set; } + + [Inject] + internal IJSRuntime JavaScriptRuntime { get; set; } + + public Inventory() + { Actions = new ObservableCollection(); - Actions.CollectionChanged += OnActionsCollectionChanged; - } - public void update() - { - this.StateHasChanged(); - return; - } - - private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) - { - JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); - } - } -} + Actions.CollectionChanged += OnActionsCollectionChanged; + } + public void update() + { + this.StateHasChanged(); + return; + } + + private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); + } + } +} diff --git a/Blazor/Blazor/Components/InventoryList.razor b/Blazor/Blazor/Components/InventoryList.razor index e111adb..4055e5e 100644 --- a/Blazor/Blazor/Components/InventoryList.razor +++ b/Blazor/Blazor/Components/InventoryList.razor @@ -1,21 +1,22 @@ @using Blazor.Models - - - - - - - - - - - @context.DisplayName - + + + + + + + - + + + @context.DisplayName + + + + \ No newline at end of file diff --git a/Blazor/Blazor/Components/InventoryListImage.razor.cs b/Blazor/Blazor/Components/InventoryListImage.razor.cs index 96a2427..b90a328 100644 --- a/Blazor/Blazor/Components/InventoryListImage.razor.cs +++ b/Blazor/Blazor/Components/InventoryListImage.razor.cs @@ -10,23 +10,32 @@ namespace Blazor.Components public Item Item { get; set; } [CascadingParameter] - public Crafting Parent { get; set; } + public Inventory Parent { get; set; } internal void OnDragEnter() { + Parent.CurrentDragItem = new InventoryItem(Item,1); + Parent.Actions.Add(new InventoryAction("On drag enter", Item.Id, Item)); + return; } internal void OnDragLeave() { + Parent.Actions.Add(new InventoryAction("On drag leave", Item.Id, Item)); + return; } internal void OnDrop() { - + Parent.Actions.Add(new InventoryAction("On drop", Item.Id, Item)); + Parent.CurrentDragItem = null; + return; } private void OnDragStart() { + Parent.Actions.Add(new InventoryAction("On drag start", Item.Id, Item)); + return; } } } diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index 607b6c5..98446ac 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -20,7 +20,7 @@ namespace Blazor.Components public void OnDragStart() { - if(!NoDrop) + if(!this.NoDrop) { Parent.CurrentDragItem = null; return; @@ -36,12 +36,13 @@ namespace Blazor.Components public void OnDrop() { - if (!NoDrop) + if (!this.NoDrop) { this.Items = Parent.CurrentDragItem; NoDrop = true; Parent.CurrentDragItem = null; if (this.Items == null) return; + Parent.inventory.inventoryItems[this.Index] = this.Items; Parent.Actions.Add(new InventoryAction("On Drop",this.Index,Items.item)); return; } @@ -55,6 +56,8 @@ namespace Blazor.Components this.NoDrop= true; Parent.CurrentDragItem = null; Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item)); + Parent.inventory.inventoryItems[this.Index] = this.Items; + Parent.update(); return; } else @@ -64,11 +67,15 @@ namespace Blazor.Components { this.Items.Stack = this.Items.item.StackSize; Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item)); + Parent.inventory.inventoryItems[this.Index] = this.Items; + Parent.update(); return; } else { this.Items.Stack = total; + Parent.inventory.inventoryItems[this.Index] = this.Items; + Parent.update(); return; } } diff --git a/Blazor/Blazor/Models/InventoryItem.cs b/Blazor/Blazor/Models/InventoryItem.cs index e6f09b3..c4a138c 100644 --- a/Blazor/Blazor/Models/InventoryItem.cs +++ b/Blazor/Blazor/Models/InventoryItem.cs @@ -11,5 +11,10 @@ item = new Item(); Stack = 64; } + public InventoryItem(Item item, int stack) + { + this.item = item; + this.stack = stack; + } } }