diff --git a/BlazorApp/BlazorApp/Components/InventoryComp.razor b/BlazorApp/BlazorApp/Components/InventoryComp.razor index 92de893..3397363 100644 --- a/BlazorApp/BlazorApp/Components/InventoryComp.razor +++ b/BlazorApp/BlazorApp/Components/InventoryComp.razor @@ -37,37 +37,41 @@
-
Available items:
-
- - - - - - @if (!string.IsNullOrWhiteSpace(context.Item.ImageBase64)) - { - @context.Item.DisplayName - } - else - { - @context.Item.DisplayName - } - - - - +
+ +
Available items:
-
+
+ + + + + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + else + { + @context.DisplayName + } + + + + -
+ + + + + \ No newline at end of file diff --git a/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs b/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs index c52d526..7f792cd 100644 --- a/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs +++ b/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs @@ -34,7 +34,7 @@ namespace BlazorApp.Components for (int i = 0; i < 18; i++) { this.InventoryItems.Append(null); - } + } } private async Task OnReadData(DataGridReadDataEventArgs e) @@ -52,14 +52,19 @@ namespace BlazorApp.Components InventoryItem newI = new InventoryItem(); newI.Item = i; InvItems.Append(newI); - } } } + } private async Task SortByName() { Items = await DataService.SortedList(); } + void refresh() + { + StateHasChanged(); + } + } } \ No newline at end of file diff --git a/BlazorApp/BlazorApp/Components/InventoryItem.razor b/BlazorApp/BlazorApp/Components/InventoryItem.razor index e64e6cd..298b7eb 100644 --- a/BlazorApp/BlazorApp/Components/InventoryItem.razor +++ b/BlazorApp/BlazorApp/Components/InventoryItem.razor @@ -4,7 +4,8 @@ @ondragstart="@OnDragStart" @ondrop="@OnDrop" @ondragenter="@OnDragEnter" - @ondragleave="@OnDragLeave"> + @ondragleave="@OnDragLeave" + @ondragend="@OnDragEnd" > @if (Item != null) { diff --git a/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs b/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs index 4bb4d74..6af5477 100644 --- a/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs +++ b/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs @@ -44,15 +44,50 @@ namespace BlazorApp.Components return; } - Parent.InventoryItems[Parent.CurrentDragIndex] = this.Item; - this.Item = Parent.CurrentDragItem; - Parent.InventoryItems[this.Index] = this.Item; + if (Parent.CurrentDragItem != null) + { + Item tmp = this.Item; + this.Item = Parent.CurrentDragItem; + Parent.InventoryItems[this.Index] = this.Item; + Parent.CurrentDragItem = tmp; + Parent.CurrentDragIndex = this.Index; + } } private void OnDragStart() { - Parent.CurrentDragIndex = this.Index; + Parent.CurrentDragItem = this.Item; + if (this.Item != null) + { + if (!NoDrop) + { + Parent.CurrentDragIndex = this.Index; + this.Item = null; + Parent.InventoryItems[Index] = null; + } + else + { + Parent.CurrentDragIndex = -1; + } + + } + } + + internal void OnDragEnd() + { + if (NoDrop || Parent.CurrentDragItem==null) + { + return; + } + if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex!=this.Index) + { + Parent.InventoryItems[this.Index] = this.Item; + this.Item = Parent.CurrentDragItem; + } + Parent.CurrentDragIndex = -1; + Parent.CurrentDragItem = null; + } } }