diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor index 3755db3..809e8ba 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor @@ -3,7 +3,6 @@ class="inventory-item" ondragover="event.preventDefault();" draggable="true" - @ondragstart="@OnDragStart" @ondrop="@OnDrop" @ondragenter="@OnDragEnter" @@ -12,6 +11,7 @@ @if (Item != null) { @Item.DisplayName + @Item.StackSize } else { diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs index 3efe7a0..913b773 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs @@ -7,7 +7,9 @@ using myBlazorApp.Models; public partial class InventoryItem { [Parameter] - public Item Item { get; set; } + public Item? Item { get; set; } + + public string state { get; set; } = null; [Parameter] public int Index { get; set; } @@ -25,6 +27,21 @@ public partial class InventoryItem return; } Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); + state = "enter"; + if (this.Item != null) + { + Thread.Sleep(2000); + if (state == "enter") + { + Item item = Parent.CurrentDragItem; + Parent.CurrentDragItem = this.Item; + this.Item = item; + Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = item, Index = this.Index }); + Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = Parent.CurrentDragItem, Index = this.Index }); + + } + } + } internal void OnDragLeave() @@ -34,6 +51,7 @@ public partial class InventoryItem return; } Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); + state = "left"; } internal void OnDrop() @@ -42,15 +60,20 @@ public partial class InventoryItem { return; } - this.Item = Parent.CurrentDragItem; + if (this.Item == null) + { + this.Item = Parent.CurrentDragItem; + } Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index }); - + state = null; } private void OnDragStart() { Parent.CurrentDragItem = this.Item; + this.Item = null; Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); + state = "start"; } } diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor b/myBlazorApp/myBlazorApp/Components/MyInventory.razor index f4718ae..c32ed17 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor @@ -2,16 +2,16 @@