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"
ondragover="event.preventDefault();"
draggable="true"
@ondragstart="@OnDragStart"
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ -12,6 +11,7 @@
@if (Item != null)
{
@Item.DisplayName
@Item.StackSize
}
else
{

@ -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;
}
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";
}
}

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

Loading…
Cancel
Save