ADD: Drag and drop fonctionnels, mais besoin de corriger les bugs dûs aux anciens éléments de la liste

master
Lucie Bedouret 2 years ago
parent b7386f8be2
commit 0ce7e05aba

@ -3,7 +3,6 @@
class="inventory-item" class="inventory-item"
ondragover="event.preventDefault();" ondragover="event.preventDefault();"
draggable="true" draggable="true"
@ondragstart="@OnDragStart" @ondragstart="@OnDragStart"
@ondrop="@OnDrop" @ondrop="@OnDrop"
@ondragenter="@OnDragEnter" @ondragenter="@OnDragEnter"
@ -12,6 +11,7 @@
@if (Item != null) @if (Item != null)
{ {
@Item.DisplayName @Item.DisplayName
@Item.StackSize
} }
else else
{ {

@ -7,7 +7,9 @@ using myBlazorApp.Models;
public partial class InventoryItem public partial class InventoryItem
{ {
[Parameter] [Parameter]
public Item Item { get; set; } public Item? Item { get; set; }
public string state { get; set; } = null;
[Parameter] [Parameter]
public int Index { get; set; } public int Index { get; set; }
@ -25,6 +27,21 @@ public partial class InventoryItem
return; return;
} }
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); 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() internal void OnDragLeave()
@ -34,6 +51,7 @@ public partial class InventoryItem
return; return;
} }
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
state = "left";
} }
internal void OnDrop() internal void OnDrop()
@ -42,15 +60,20 @@ public partial class InventoryItem
{ {
return; return;
} }
if (this.Item == null)
{
this.Item = Parent.CurrentDragItem; this.Item = Parent.CurrentDragItem;
}
Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index }); Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index });
state = null;
} }
private void OnDragStart() private void OnDragStart()
{ {
Parent.CurrentDragItem = this.Item; Parent.CurrentDragItem = this.Item;
this.Item = null;
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
state = "start";
} }
} }

@ -2,16 +2,16 @@
<h3>My Inventory</h3> <h3>My Inventory</h3>
<div class="inventory-items"> <div class="inventory-items">
@foreach (var item in ItemsInventory) @foreach (var item in ItemsInventory)
{ {
<InventoryItem Index="@index" Item="item" NoDrop="true" /> <InventoryItem Index="@index" Item="item" NoDrop="true" />
index++; index++;
} }
@for (int i = @index; i < 18; i++) @for (int i = 0; i < 18; i++)
{ {
<InventoryItem Index="i" /> <InventoryItem Index="i" Item="null" />
} }
</div> </div>
</CascadingValue> </CascadingValue>

Loading…
Cancel
Save