|
|
@ -1,38 +1,77 @@
|
|
|
|
using System;
|
|
|
|
/// IMPORTS ///
|
|
|
|
namespace myBlazorApp.Components;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
using Blazorise;
|
|
|
|
using Blazorise;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
using myBlazorApp.Models;
|
|
|
|
using myBlazorApp.Models;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace myBlazorApp.Components;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class InventoryItem
|
|
|
|
public partial class InventoryItem
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// -------- PARAMETERS -------- ///
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// gets or sets the item name
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public string Item { get; set; }
|
|
|
|
public string Item { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// gets or sets the index
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public int Index { get; set; }
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// gets or sets the number of items
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public int Number { get; set; }
|
|
|
|
public int Number { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// gets or sets the stack size
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public int StackSize { get; set; }
|
|
|
|
public int StackSize { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// gets or sets the capability to drop the item
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public bool NoDrop { get; set; }
|
|
|
|
public bool NoDrop { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// gets or sets the image of the item
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public string Image { get; set; }
|
|
|
|
public string Image { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// -------- DEPENDENCIES INJECTION -------- ///
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Gets or sets the localizer
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public IStringLocalizer<InventoryItem> Localizer { get; set; }
|
|
|
|
public IStringLocalizer<InventoryItem> Localizer { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// -------- CASCADING PARAMETER -------- ///
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Gets or sets the cascading parameter Parent ( MyInventory ).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[CascadingParameter]
|
|
|
|
[CascadingParameter]
|
|
|
|
public MyInventory Parent { get; set; }
|
|
|
|
public MyInventory Parent { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// -------- DRAG AND DROP METHODS -------- ///
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creating a new action when the user enter in an item of the Inventory items
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
internal void OnDragEnter()
|
|
|
|
internal void OnDragEnter()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (NoDrop)
|
|
|
|
if (NoDrop)
|
|
|
@ -42,6 +81,9 @@ public partial class InventoryItem
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creating a new action when the user leaves an item of the Inventory items
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
internal void OnDragLeave()
|
|
|
|
internal void OnDragLeave()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (NoDrop)
|
|
|
|
if (NoDrop)
|
|
|
@ -51,35 +93,52 @@ public partial class InventoryItem
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creating a new action when the user drops an item in an Inventory item in the Invnetory item
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
internal void OnDrop()
|
|
|
|
internal void OnDrop()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Parent.CurrentDragItem != "null")
|
|
|
|
if (Parent.CurrentDragItem != "null")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Case when the item comes from the list of items
|
|
|
|
if(Parent.CurrentDragIndex == 0)
|
|
|
|
if(Parent.CurrentDragIndex == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (this.Item == Parent.CurrentDragItem)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Number = this.Number + Parent.CurrentDragNumber;
|
|
|
|
this.Number = this.Number + Parent.CurrentDragNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.Number = Parent.CurrentDragNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
|
|
this.StackSize = Parent.CurrentDragStackSize;
|
|
|
|
this.StackSize = Parent.CurrentDragStackSize;
|
|
|
|
Parent.ItemsInventory[this.Index - 1] = new InventoryListItem(this.Item, this.Index, this.Number, this.StackSize);
|
|
|
|
Parent.ItemsInventory[this.Index - 1] = new InventoryListItem(this.Item, this.Index, this.Number, this.StackSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Case when the item dropped is the same than the item inside the Inventory item
|
|
|
|
else if (this.Item == Parent.CurrentDragItem)
|
|
|
|
else if (this.Item == Parent.CurrentDragItem)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Number = this.Number + Parent.CurrentDragNumber;
|
|
|
|
this.Number = this.Number + Parent.CurrentDragNumber;
|
|
|
|
|
|
|
|
|
|
|
|
Parent.CurrentInventoryItem.Number = 0;
|
|
|
|
Parent.CurrentInventoryItem.Number = 0;
|
|
|
|
Parent.CurrentInventoryItem.Item = "null";
|
|
|
|
Parent.CurrentInventoryItem.Item = "null";
|
|
|
|
Parent.CurrentInventoryItem.StackSize = 0;
|
|
|
|
Parent.CurrentInventoryItem.StackSize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
Parent.ItemsInventory[Parent.CurrentInventoryItem.Index - 1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number, Parent.CurrentInventoryItem.StackSize);
|
|
|
|
Parent.ItemsInventory[Parent.CurrentInventoryItem.Index - 1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number, Parent.CurrentInventoryItem.StackSize);
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number, StackSize = Parent.CurrentInventoryItem.StackSize });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Case when the item must be exchanged with another or just be inserted.
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string tmpItem = this.Item;
|
|
|
|
string tmpItem = this.Item;
|
|
|
|
int tmpNumber = this.Number;
|
|
|
|
int tmpNumber = this.Number;
|
|
|
|
int tmpStackSize = this.StackSize;
|
|
|
|
int tmpStackSize = this.StackSize;
|
|
|
|
|
|
|
|
|
|
|
|
Parent.ItemsInventory[Parent.CurrentDragIndex - 1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber, tmpStackSize);
|
|
|
|
Parent.ItemsInventory[Parent.CurrentDragIndex - 1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber, tmpStackSize);
|
|
|
|
|
|
|
|
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
|
|
this.Number = Parent.CurrentDragNumber;
|
|
|
|
this.Number = Parent.CurrentDragNumber;
|
|
|
|
this.StackSize = Parent.CurrentDragStackSize;
|
|
|
|
this.StackSize = Parent.CurrentDragStackSize;
|
|
|
|
|
|
|
|
|
|
|
|
Parent.CurrentInventoryItem.Item = tmpItem;
|
|
|
|
Parent.CurrentInventoryItem.Item = tmpItem;
|
|
|
|
Parent.CurrentInventoryItem.Number = tmpNumber;
|
|
|
|
Parent.CurrentInventoryItem.Number = tmpNumber;
|
|
|
|
Parent.CurrentInventoryItem.StackSize = tmpStackSize;
|
|
|
|
Parent.CurrentInventoryItem.StackSize = tmpStackSize;
|
|
|
@ -90,27 +149,31 @@ public partial class InventoryItem
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creating a new action when the user end the drag and dropped the item in an Inventory item
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
internal void OnDragEnd()
|
|
|
|
internal void OnDragEnd()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(NoDrop || Parent.CurrentDragItem == "null")
|
|
|
|
if(NoDrop || Parent.CurrentDragItem == "null")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex != this.Index)
|
|
|
|
|
|
|
|
|
|
|
|
if (Parent.CurrentDragIndex != this.Index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber, Parent.CurrentDragStackSize);
|
|
|
|
Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber, Parent.CurrentDragStackSize);
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
|
|
this.Number = Parent.CurrentDragNumber;
|
|
|
|
this.Number = Parent.CurrentDragNumber;
|
|
|
|
this.StackSize = Parent.CurrentDragStackSize;
|
|
|
|
this.StackSize = Parent.CurrentDragStackSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Parent.CurrentDragIndex = -1;
|
|
|
|
|
|
|
|
Parent.CurrentDragItem = "null";
|
|
|
|
|
|
|
|
Parent.CurrentDragNumber = 0;
|
|
|
|
|
|
|
|
Parent.CurrentDragStackSize = 0;
|
|
|
|
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creating a new action when the user starts dragging an item
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
private void OnDragStart()
|
|
|
|
private void OnDragStart()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Parent.CurrentInventoryItem = this;
|
|
|
|
Parent.CurrentInventoryItem = this;
|
|
|
@ -118,9 +181,15 @@ public partial class InventoryItem
|
|
|
|
Parent.CurrentDragItem = this.Item;
|
|
|
|
Parent.CurrentDragItem = this.Item;
|
|
|
|
Parent.CurrentDragNumber = this.Number;
|
|
|
|
Parent.CurrentDragNumber = this.Number;
|
|
|
|
Parent.CurrentDragStackSize = this.StackSize;
|
|
|
|
Parent.CurrentDragStackSize = this.StackSize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove the element if it's not in the list of items
|
|
|
|
|
|
|
|
if (this.Index != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
this.Item = "null";
|
|
|
|
this.Item = "null";
|
|
|
|
this.Number = 0;
|
|
|
|
this.Number = 0;
|
|
|
|
this.StackSize = 0;
|
|
|
|
this.StackSize = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize});
|
|
|
|
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|