@Item
+@Number
} else { diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs index 3efe7a0..85cc073 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs @@ -1,5 +1,7 @@ using System; namespace myBlazorApp.Components; + +using System.Reflection.Metadata; using Blazorise; using Microsoft.AspNetCore.Components; using myBlazorApp.Models; @@ -7,11 +9,14 @@ using myBlazorApp.Models; public partial class InventoryItem { [Parameter] - public Item Item { get; set; } + public string Item { get; set; } [Parameter] public int Index { get; set; } + [Parameter] + public int Number { get; set; } + [Parameter] public bool NoDrop { get; set; } @@ -24,7 +29,7 @@ public partial class InventoryItem { return; } - Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); + Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number }); } internal void OnDragLeave() @@ -33,7 +38,7 @@ public partial class InventoryItem { return; } - Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); + Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number }); } internal void OnDrop() @@ -42,15 +47,60 @@ public partial class InventoryItem { return; } - this.Item = Parent.CurrentDragItem; - Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index }); + if (Parent.CurrentDragItem != "null") + { + if(this.Item == Parent.CurrentDragItem) + { + this.Number = this.Number + Parent.CurrentDragNumber; + Parent.CurrentInventoryItem.Number = 0; + Parent.CurrentInventoryItem.Item = "null"; + Parent.ItemsInventory[Parent.CurrentInventoryItem.Index-1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number); + Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number }); + } + else + { + string tmpItem = this.Item; + int tmpNumber = this.Number; + Parent.ItemsInventory[Parent.CurrentDragIndex-1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber); + this.Item = Parent.CurrentDragItem; + this.Number = Parent.CurrentDragNumber; + Parent.CurrentInventoryItem.Item = tmpItem; + Parent.CurrentInventoryItem.Number = tmpNumber; + } + + } + Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number }); + } + + internal void OnDragEnd() + { + if(NoDrop || Parent.CurrentDragItem == "null") + { + return; + } + if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex != this.Index) + { + Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber); + this.Item = Parent.CurrentDragItem; + this.Number = Parent.CurrentDragNumber; + } + Parent.CurrentDragIndex = -1; + Parent.CurrentDragItem = "null"; + Parent.CurrentDragNumber = 0; + Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number }); } private void OnDragStart() { + Parent.CurrentInventoryItem = this; + Parent.CurrentDragIndex = this.Index; Parent.CurrentDragItem = this.Item; - Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); + Parent.CurrentDragNumber = this.Number; + this.Item = "null"; + this.Number = 0; + Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number}); + } } diff --git a/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs b/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs new file mode 100644 index 0000000..f7a3ef1 --- /dev/null +++ b/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs @@ -0,0 +1,22 @@ +using System; +using myBlazorApp.Models; +namespace myBlazorApp.Components +{ + public class InventoryListItem + { + //public InventoryListItem() { } + + public InventoryListItem(string itemName, int position, int number) + { + this.itemName = itemName; + this.position = position; + this.number = number; + } + + public string itemName { get; set; } + public int position { get; set; } + public int number { get; set; } + } + +} + diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor b/myBlazorApp/myBlazorApp/Components/MyInventory.razor index f4718ae..cef2ec2 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor @@ -1,17 +1,13 @@ -