You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.3 KiB
103 lines
2.3 KiB
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace BlazorApp1.Components
|
|
{
|
|
public partial class InventoryItem : ItemDisplay
|
|
{
|
|
[Parameter]
|
|
public int Index { get; set; }
|
|
|
|
[Parameter]
|
|
public Item Item { get; set; }
|
|
|
|
[Parameter]
|
|
public bool NoDrop { get; set; }
|
|
|
|
public int nbElem { get; set; }
|
|
|
|
[CascadingParameter]
|
|
public Inventory Parent { get; set; }
|
|
|
|
public void changeState()
|
|
{
|
|
StateHasChanged();
|
|
}
|
|
|
|
public Item getItem()
|
|
{
|
|
return Item;
|
|
}
|
|
|
|
public int getNbElement()
|
|
{
|
|
return nbElem;
|
|
}
|
|
|
|
public String getTypeID()
|
|
{
|
|
return "InventoryItem";
|
|
}
|
|
|
|
internal void OnDragEnter()
|
|
{
|
|
if (NoDrop)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
internal void OnDragLeave()
|
|
{
|
|
if (NoDrop)
|
|
{
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
internal void OnDrop()
|
|
{
|
|
if (NoDrop)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.Item is not null)
|
|
{
|
|
if (this.Item.Equals(Parent.CurrentDragItem) && this.nbElem < 64)
|
|
this.nbElem++;
|
|
}
|
|
else
|
|
{
|
|
Item tmp = this.Item;
|
|
int tmpNb = this.nbElem;
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
this.nbElem = Parent.CurrentEllement.getNbElement();
|
|
|
|
if (Parent.CurrentEllement.getTypeID() == "InventoryItem")
|
|
{
|
|
InventoryItem invItem = (InventoryItem)Parent.CurrentEllement;
|
|
|
|
invItem.Item = tmp;
|
|
invItem.nbElem = tmpNb;
|
|
|
|
Parent.CurrentEllement = invItem;
|
|
}
|
|
else if (Parent.CurrentEllement.getTypeID() == "ListItem")
|
|
{
|
|
|
|
}
|
|
}
|
|
Parent.CurrentEllement.changeState();
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void OnDragStart()
|
|
{
|
|
Parent.CurrentDragItem = this.Item;
|
|
Parent.CurrentEllement = this;
|
|
}
|
|
}
|
|
}
|