diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor index e711bf1..350dd59 100644 --- a/Blazor/Blazor/Components/Inventory.razor +++ b/Blazor/Blazor/Components/Inventory.razor @@ -1,10 +1,18 @@ @using Models;

Inventory

- -
- @for(int i = 0; i - } -
\ No newline at end of file + +
+ @for(int i = 0; i + } + else + { + + } + } +
+
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs index 5ecc191..c8846b1 100644 --- a/Blazor/Blazor/Components/Inventory.razor.cs +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -7,12 +7,18 @@ namespace Blazor.Components { partial class Inventory { + public InventoryItem CurrentDragItem { get; set; } + public ObservableCollection Actions { get; set; } public Inventory() { Actions = new ObservableCollection(); } - public ObservableCollection Actions { get; set; } + public void update() + { + this.StateHasChanged(); + } + [Parameter] public InventoryList inventory { get; set; } public void Add(Item item) diff --git a/Blazor/Blazor/Components/InventoryAction.cs b/Blazor/Blazor/Components/InventoryAction.cs index 746e0f2..b3436d5 100644 --- a/Blazor/Blazor/Components/InventoryAction.cs +++ b/Blazor/Blazor/Components/InventoryAction.cs @@ -6,6 +6,6 @@ namespace Blazor.Components { public string Action { get; set; } public int Index { get; set; } - public Item Item { get; set; } + public ItemInventory Item { get; set; } } } diff --git a/Blazor/Blazor/Components/ItemInventory.razor b/Blazor/Blazor/Components/ItemInventory.razor index 56d5c4a..fdee5e9 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor +++ b/Blazor/Blazor/Components/ItemInventory.razor @@ -1,13 +1,18 @@ -
- @if(items != null) +
+ @if(Items != null) { - @if(!string.IsNullOrWhiteSpace(items.item.ImageBase64)) + @if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64)) { - @items.item.DisplayName + @Items.item.DisplayName } else { - @items.item.DisplayName + @Items.item.DisplayName } } else diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index c1ad38e..e7e80e2 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -1,4 +1,5 @@ using Blazor.Models; +using Blazorise.Extensions; using Microsoft.AspNetCore.Components; namespace Blazor.Components @@ -6,9 +7,65 @@ namespace Blazor.Components public partial class ItemInventory { [Parameter] - public InventoryItem items { get; set; } + public bool NoDrop { get; set; } [Parameter] - public int index { get; set; } + public InventoryItem Items { get; set; } + + [Parameter] + public int Index { get; set; } + + [CascadingParameter] + public Inventory Parent { get; set; } + + public void OnDragStart() + { + if(!NoDrop) + { + return; + } + Parent.CurrentDragItem = this.Items; + Parent.inventory.inventoryItems[Index] = null; + Parent.update(); + } + + + public void OnDrop() + { + if (!NoDrop) + { + this.Items = Parent.CurrentDragItem; + NoDrop = true; + } + + if (Parent.CurrentDragItem != this.Items) + { + InventoryItem tmp = Parent.CurrentDragItem; + Parent.CurrentDragItem = this.Items; + this.Items = tmp; + } + else + { + int total = Parent.CurrentDragItem.Stack + this.Items.Stack; + if (total >this.Items.item.StackSize) + { + this.Items.Stack = this.Items.item.StackSize; + Parent.CurrentDragItem.Stack=total - this.Items.item.StackSize; + } + else + { + this.Items.Stack = total; + } + } + } + internal void OnDragEnter() + { + Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this, Index = this.Index }); + } + + internal void OnDragLeave() + { + Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this, Index = this.Index }); + } } } diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index 1fdfc6e..f647c5b 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -8,6 +8,7 @@ @**@ +