diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor new file mode 100644 index 0000000..588b774 --- /dev/null +++ b/Blazor/Blazor/Components/Inventory.razor @@ -0,0 +1,23 @@ +@using Models; + +

Inventory

+ +
+ @for(int i = 0; i + } + else + { + + } + } +
+
+
Actions
+
+
+
+
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs new file mode 100644 index 0000000..a7f99ba --- /dev/null +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -0,0 +1,27 @@ +using Blazor.Models; +using Blazor.Pages; +using Microsoft.AspNetCore.Components; +using System.Collections.ObjectModel; + +namespace Blazor.Components +{ + partial class Inventory + { + public InventoryItem CurrentDragItem { get; set; } + public ObservableCollection Actions { get; set; } + + public Inventory() + { + Actions = new ObservableCollection(); + } + public void update() + { + this.StateHasChanged(); + return; + } + + [Parameter] + public InventoryList inventory { get; set; } + + } +} diff --git a/Blazor/Blazor/Components/Inventory.razor.css b/Blazor/Blazor/Components/Inventory.razor.css new file mode 100644 index 0000000..1995814 --- /dev/null +++ b/Blazor/Blazor/Components/Inventory.razor.css @@ -0,0 +1,6 @@ +.css-grid { + grid-template-columns: repeat(6,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 40%; +} \ No newline at end of file diff --git a/Blazor/Blazor/Components/InventoryAction.cs b/Blazor/Blazor/Components/InventoryAction.cs new file mode 100644 index 0000000..50ddc5e --- /dev/null +++ b/Blazor/Blazor/Components/InventoryAction.cs @@ -0,0 +1,16 @@ +using Blazor.Models; + +namespace Blazor.Components +{ + public class InventoryAction + { + public InventoryAction(String ac, int num,ItemInventory objet) { + Action = ac; + Index = num; + Item = objet; + } + public string Action { get; set; } + public int Index { get; set; } + public ItemInventory Item { get; set; } + } +} diff --git a/Blazor/Blazor/Components/ItemInventory.razor b/Blazor/Blazor/Components/ItemInventory.razor new file mode 100644 index 0000000..950c574 --- /dev/null +++ b/Blazor/Blazor/Components/ItemInventory.razor @@ -0,0 +1,22 @@ +
+ @if(Items != null) + { + @if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64)) + { + @Items.item.DisplayName + } + else + { + @Items.item.DisplayName + } + } + else + { + empty slot + } +
\ No newline at end of file diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs new file mode 100644 index 0000000..95df861 --- /dev/null +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -0,0 +1,84 @@ +using Blazor.Models; +using Blazorise.Extensions; +using Microsoft.AspNetCore.Components; + +namespace Blazor.Components +{ + public partial class ItemInventory + { + [Parameter] + public bool NoDrop { get; set; } + + [Parameter] + public InventoryItem Items { get; set; } + + [Parameter] + public int Index { get; set; } + + [CascadingParameter] + public Inventory Parent { get; set; } + + public void OnDragStart() + { + if(!NoDrop) + { + Parent.CurrentDragItem = null; + return; + } + Parent.CurrentDragItem = this.Items; + Parent.inventory.inventoryItems[this.Index] = null; + this.NoDrop = false; + Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this)); + Parent.update(); + } + + + public void OnDrop() + { + if (!NoDrop) + { + this.Items = Parent.CurrentDragItem; + NoDrop = true; + Parent.CurrentDragItem = null; + Parent.Actions.Add(new InventoryAction("On Drop",this.Index,this)); + return; + } + if(Parent.CurrentDragItem == null) + { + return; + } + if (Parent.CurrentDragItem.item.Id != this.Items.item.Id) + { + this.Items = Parent.CurrentDragItem; + this.NoDrop= true; + Parent.CurrentDragItem = null; + Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this)); + return; + } + else + { + int total = Parent.CurrentDragItem.Stack + this.Items.Stack; + if (total >this.Items.item.StackSize) + { + this.Items.Stack = this.Items.item.StackSize; + Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this)); + return; + } + else + { + this.Items.Stack = total; + return; + } + } + } + internal void OnDragEnter() + { + Parent.Actions.Add(new InventoryAction("Drag Enter",this.Index,this)); + } + + internal void OnDragLeave() + { + Parent.Actions.Add(new InventoryAction("Drag Leave",this.Index,this)); + } + } +} diff --git a/Blazor/Blazor/Models/InventoryItem.cs b/Blazor/Blazor/Models/InventoryItem.cs new file mode 100644 index 0000000..e6f09b3 --- /dev/null +++ b/Blazor/Blazor/Models/InventoryItem.cs @@ -0,0 +1,15 @@ +namespace Blazor.Models +{ + public class InventoryItem + { + public Item item; + int stack; + public int Stack { get; set; } + + public InventoryItem() + { + item = new Item(); + Stack = 64; + } + } +} diff --git a/Blazor/Blazor/Models/InventoryList.cs b/Blazor/Blazor/Models/InventoryList.cs new file mode 100644 index 0000000..6dfd9fb --- /dev/null +++ b/Blazor/Blazor/Models/InventoryList.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Http.Features; + +namespace Blazor.Models +{ + public partial class InventoryList + { + static public int size = 18; + public List inventoryItems = new List(new InventoryItem[size]); + + public InventoryList() + { + inventoryItems[0] = new InventoryItem(); + } + } +} diff --git a/Blazor/Blazor/Models/Item.cs b/Blazor/Blazor/Models/Item.cs index c5410a1..ad086c3 100644 --- a/Blazor/Blazor/Models/Item.cs +++ b/Blazor/Blazor/Models/Item.cs @@ -12,5 +12,17 @@ public DateTime CreatedDate { get; set; } public DateTime? UpdatedDate { get; set; } public string ImageBase64 { get; set; } + public Item() + { + Id = 2; + DisplayName = "Dirt"; + Name = "Block_of_dirt"; + StackSize = 64; + MaxDurability= 9999; + EnchantCategories = new List(); + RepairWith = new List(); + CreatedDate= DateTime.Now; + UpdatedDate = DateTime.Now; + } } } diff --git a/Blazor/Blazor/Pages/Index.razor b/Blazor/Blazor/Pages/Index.razor index 6765355..b919667 100644 --- a/Blazor/Blazor/Pages/Index.razor +++ b/Blazor/Blazor/Pages/Index.razor @@ -1,5 +1,5 @@ @page "/" @using Blazor.Components;
- +
diff --git a/Blazor/Blazor/Pages/Index.razor.cs b/Blazor/Blazor/Pages/Index.razor.cs index 0a77a38..1f3179b 100644 --- a/Blazor/Blazor/Pages/Index.razor.cs +++ b/Blazor/Blazor/Pages/Index.razor.cs @@ -7,6 +7,12 @@ namespace Blazor.Pages { public partial class Index { + /* TEST */ + + InventoryList inventory = new InventoryList(); + + + [Inject] public IDataService DataService { get; set; } diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index a647c05..8b87a04 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -7,7 +7,8 @@ - + @**@ +