"Acion handled on list of items"

master
Aurian JAULT 2 years ago
parent ee46227910
commit 9cf768b4bd

@ -1,35 +1,35 @@
using Blazor.Models;
using Blazor.Pages;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Collections.ObjectModel;
using Blazor.Models;
using Blazor.Pages;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
namespace Blazor.Components
{
partial class Inventory
{
public Models.InventoryList inventory = new Models.InventoryList();
public Models.InventoryItem CurrentDragItem { get; set; }
public ObservableCollection<InventoryAction> Actions { get; set; }
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
public Inventory()
{
namespace Blazor.Components
{
partial class Inventory
{
public Models.InventoryList inventory = new Models.InventoryList();
public Models.InventoryItem CurrentDragItem { get; set; }
public ObservableCollection<InventoryAction> Actions { get; set; }
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
public Inventory()
{
Actions = new ObservableCollection<InventoryAction>();
Actions.CollectionChanged += OnActionsCollectionChanged;
}
public void update()
{
this.StateHasChanged();
return;
}
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
}
}
Actions.CollectionChanged += OnActionsCollectionChanged;
}
public void update()
{
this.StateHasChanged();
return;
}
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
}
}

@ -1,21 +1,22 @@
@using Blazor.Models
<DataGrid TItem="Item"
Data="@items"
TotalItems="@totalItem"
PageSize="10"
ShowPager
Filterable
Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="#" Width="15%"/>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image" Filterable="false">
<DisplayTemplate>
<InventoryListImage Item="context"/>
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Display name">
<DisplayTemplate>
<span style="font-weight: bold; font-size: 2rem; display: flex; justify-content: center;">@context.DisplayName</span>
</DisplayTemplate>
<CascadingValue Value="@this.Parent">
<DataGrid TItem="Item"
Data="@items"
TotalItems="@totalItem"
PageSize="10"
ShowPager
Filterable
Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="#" Width="15%"/>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image" Filterable="false">
<DisplayTemplate>
<InventoryListImage Item="context"/>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Display name">
<DisplayTemplate>
<span style="font-weight: bold; font-size: 2rem; display: flex; justify-content: center;">@context.DisplayName</span>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>
</CascadingValue>

@ -10,23 +10,32 @@ namespace Blazor.Components
public Item Item { get; set; }
[CascadingParameter]
public Crafting Parent { get; set; }
public Inventory Parent { get; set; }
internal void OnDragEnter()
{
Parent.CurrentDragItem = new InventoryItem(Item,1);
Parent.Actions.Add(new InventoryAction("On drag enter", Item.Id, Item));
return;
}
internal void OnDragLeave()
{
Parent.Actions.Add(new InventoryAction("On drag leave", Item.Id, Item));
return;
}
internal void OnDrop()
{
Parent.Actions.Add(new InventoryAction("On drop", Item.Id, Item));
Parent.CurrentDragItem = null;
return;
}
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()
{
if(!NoDrop)
if(!this.NoDrop)
{
Parent.CurrentDragItem = null;
return;
@ -36,12 +36,13 @@ namespace Blazor.Components
public void OnDrop()
{
if (!NoDrop)
if (!this.NoDrop)
{
this.Items = Parent.CurrentDragItem;
NoDrop = true;
Parent.CurrentDragItem = null;
if (this.Items == null) return;
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.Actions.Add(new InventoryAction("On Drop",this.Index,Items.item));
return;
}
@ -55,6 +56,8 @@ namespace Blazor.Components
this.NoDrop= true;
Parent.CurrentDragItem = null;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.update();
return;
}
else
@ -64,11 +67,15 @@ namespace Blazor.Components
{
this.Items.Stack = this.Items.item.StackSize;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.update();
return;
}
else
{
this.Items.Stack = total;
Parent.inventory.inventoryItems[this.Index] = this.Items;
Parent.update();
return;
}
}

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

Loading…
Cancel
Save