From 0ce7e05aba64c55774805be593281329493a09e3 Mon Sep 17 00:00:00 2001 From: Lucie Bedouret Date: Wed, 7 Dec 2022 12:00:42 +0100 Subject: [PATCH] =?UTF-8?q?ADD:=20Drag=20and=20drop=20fonctionnels,=20mais?= =?UTF-8?q?=20besoin=20de=20corriger=20les=20bugs=20d=C3=BBs=20aux=20ancie?= =?UTF-8?q?ns=20=C3=A9l=C3=A9ments=20de=20la=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/InventoryItem.razor | 2 +- .../Components/InventoryItem.razor.cs | 29 +++++++++++++++++-- .../myBlazorApp/Components/MyInventory.razor | 6 ++-- 3 files changed, 30 insertions(+), 7 deletions(-) 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 @@

My Inventory

- @foreach (var item in ItemsInventory) { index++; } - @for (int i = @index; i < 18; i++) + @for (int i = 0; i < 18; i++) { - + } +