"Acion handled on list of items"

master
Aurian JAULT 2 years ago
parent ee46227910
commit 9cf768b4bd

@ -1,5 +1,5 @@
@using Blazor.Models @using Blazor.Models
<CascadingValue Value="@this.Parent">
<DataGrid TItem="Item" <DataGrid TItem="Item"
Data="@items" Data="@items"
TotalItems="@totalItem" TotalItems="@totalItem"
@ -19,3 +19,4 @@
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
</DataGrid> </DataGrid>
</CascadingValue>

@ -10,23 +10,32 @@ namespace Blazor.Components
public Item Item { get; set; } public Item Item { get; set; }
[CascadingParameter] [CascadingParameter]
public Crafting Parent { get; set; } public Inventory Parent { get; set; }
internal void OnDragEnter() internal void OnDragEnter()
{ {
Parent.CurrentDragItem = new InventoryItem(Item,1);
Parent.Actions.Add(new InventoryAction("On drag enter", Item.Id, Item));
return;
} }
internal void OnDragLeave() internal void OnDragLeave()
{ {
Parent.Actions.Add(new InventoryAction("On drag leave", Item.Id, Item));
return;
} }
internal void OnDrop() internal void OnDrop()
{ {
Parent.Actions.Add(new InventoryAction("On drop", Item.Id, Item));
Parent.CurrentDragItem = null;
return;
} }
private void OnDragStart() private void OnDragStart()
{ {
Parent.Actions.Add(new InventoryAction("On drag start", Item.Id, Item));
return;
} }
} }
} }

@ -20,7 +20,7 @@ namespace Blazor.Components
public void OnDragStart() public void OnDragStart()
{ {
if(!NoDrop) if(!this.NoDrop)
{ {
Parent.CurrentDragItem = null; Parent.CurrentDragItem = null;
return; return;
@ -36,12 +36,13 @@ namespace Blazor.Components
public void OnDrop() public void OnDrop()
{ {
if (!NoDrop) if (!this.NoDrop)
{ {
this.Items = Parent.CurrentDragItem; this.Items = Parent.CurrentDragItem;
NoDrop = true; NoDrop = true;
Parent.CurrentDragItem = null; Parent.CurrentDragItem = null;
if (this.Items == null) return; if (this.Items == null) return;
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.Actions.Add(new InventoryAction("On Drop",this.Index,Items.item)); Parent.Actions.Add(new InventoryAction("On Drop",this.Index,Items.item));
return; return;
} }
@ -55,6 +56,8 @@ namespace Blazor.Components
this.NoDrop= true; this.NoDrop= true;
Parent.CurrentDragItem = null; Parent.CurrentDragItem = null;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item)); Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.update();
return; return;
} }
else else
@ -64,11 +67,15 @@ namespace Blazor.Components
{ {
this.Items.Stack = this.Items.item.StackSize; this.Items.Stack = this.Items.item.StackSize;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item)); Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.update();
return; return;
} }
else else
{ {
this.Items.Stack = total; this.Items.Stack = total;
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.update();
return; return;
} }
} }

@ -11,5 +11,10 @@
item = new Item(); item = new Item();
Stack = 64; Stack = 64;
} }
public InventoryItem(Item item, int stack)
{
this.item = item;
this.stack = stack;
}
} }
} }

Loading…
Cancel
Save