From 2fb441904206dfde13670753561e93917bd75070 Mon Sep 17 00:00:00 2001 From: Lucie Bedouret Date: Sun, 18 Dec 2022 14:05:22 +0100 Subject: [PATCH] ADD : stacksizen and css of the inventory item --- .../Controllers/InventoryController.cs | 7 +++-- .../Data/inventory.json | 28 +++++++++++------- .../Models/InventoryModel.cs | 2 ++ .../myBlazorApp/Components/InventoryAction.cs | 1 + .../Components/InventoryItem.razor | 7 +++-- .../Components/InventoryItem.razor.cs | 29 +++++++++++++------ .../Components/InventoryItem.razor.css | 21 +++++++++++++- .../Components/InventoryListItem.cs | 4 ++- .../myBlazorApp/Components/MyInventory.razor | 2 +- .../Components/MyInventory.razor.cs | 3 +- 10 files changed, 74 insertions(+), 30 deletions(-) diff --git a/myBlazorApp/Minecraft.Crafting.Api/Controllers/InventoryController.cs b/myBlazorApp/Minecraft.Crafting.Api/Controllers/InventoryController.cs index c0443a5..de68196 100644 --- a/myBlazorApp/Minecraft.Crafting.Api/Controllers/InventoryController.cs +++ b/myBlazorApp/Minecraft.Crafting.Api/Controllers/InventoryController.cs @@ -125,9 +125,10 @@ namespace Minecraft.Crafting.Api.Controllers throw new Exception("Unable to get the inventory."); } - data.ToArray()[Int32.Parse(infos[1])-1].ItemName = infos[0]; - data.ToArray()[Int32.Parse(infos[1])-1].Position = Int32.Parse(infos[1]); - data.ToArray()[Int32.Parse(infos[1])-1].Number = Int32.Parse(infos[2]); + data.ToArray()[Int32.Parse(infos[1]) - 1].ItemName = infos[0]; + data.ToArray()[Int32.Parse(infos[1]) - 1].Position = Int32.Parse(infos[1]); + data.ToArray()[Int32.Parse(infos[1]) - 1].Number = Int32.Parse(infos[2]); + data.ToArray()[Int32.Parse(infos[1]) - 1].StackSize = Int32.Parse(infos[3]); System.IO.File.WriteAllText("Data/inventory.json", JsonSerializer.Serialize(data, _jsonSerializerOptions)); diff --git a/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json b/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json index 806f26e..45ccd38 100644 --- a/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json +++ b/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json @@ -4,13 +4,16 @@ "position": 1 }, { - "itemName": "lili", + "itemName": "toto", "position": 2, - "number": 11 + "number": 3, + "stackSize": 6 }, { - "itemName": "null", - "position": 3 + "itemName": "lulu", + "position": 3, + "number": 11, + "stackSize": 12 }, { "itemName": "null", @@ -33,17 +36,20 @@ "position": 8 }, { - "itemName": "null", - "position": 9 + "itemName": "toto", + "position": 9, + "number": 3, + "stackSize": 6 }, { - "itemName": "lulu", - "position": 10, - "number": 11 + "itemName": "null", + "position": 10 }, { - "itemName": "null", - "position": 11 + "itemName": "lili", + "position": 11, + "number": 11, + "stackSize": 64 }, { "itemName": "null", diff --git a/myBlazorApp/Minecraft.Crafting.Api/Models/InventoryModel.cs b/myBlazorApp/Minecraft.Crafting.Api/Models/InventoryModel.cs index 22b1b81..ab7325b 100644 --- a/myBlazorApp/Minecraft.Crafting.Api/Models/InventoryModel.cs +++ b/myBlazorApp/Minecraft.Crafting.Api/Models/InventoryModel.cs @@ -22,5 +22,7 @@ namespace Minecraft.Crafting.Api.Models public int Position { get; set; } public int Number { get; set; } + + public int StackSize { get; set; } } } \ No newline at end of file diff --git a/myBlazorApp/myBlazorApp/Components/InventoryAction.cs b/myBlazorApp/myBlazorApp/Components/InventoryAction.cs index bdb47b6..2108c84 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryAction.cs +++ b/myBlazorApp/myBlazorApp/Components/InventoryAction.cs @@ -8,6 +8,7 @@ namespace myBlazorApp.Components public int Index { get; set; } public string ItemName { get; set; } public int Number { get; set; } + public int StackSize { get; set; } } } diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor index 7502998..97abaf3 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor @@ -9,12 +9,13 @@ @ondragleave="@OnDragLeave"> @if (Item != "null") { -

@Item

-

@Number

+ + + } else { -

Empty

+

Empty

} diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs index 85cc073..0e50916 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs @@ -17,6 +17,9 @@ public partial class InventoryItem [Parameter] public int Number { get; set; } + [Parameter] + public int StackSize { get; set; } + [Parameter] public bool NoDrop { get; set; } @@ -29,7 +32,7 @@ public partial class InventoryItem { return; } - Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number }); + Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize }); } internal void OnDragLeave() @@ -38,7 +41,7 @@ public partial class InventoryItem { return; } - Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number }); + Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize }); } internal void OnDrop() @@ -54,22 +57,26 @@ public partial class InventoryItem this.Number = this.Number + Parent.CurrentDragNumber; Parent.CurrentInventoryItem.Number = 0; Parent.CurrentInventoryItem.Item = "null"; - Parent.ItemsInventory[Parent.CurrentInventoryItem.Index-1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number); - Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number }); + 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.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number, StackSize = Parent.CurrentInventoryItem.StackSize }); } else { string tmpItem = this.Item; int tmpNumber = this.Number; - Parent.ItemsInventory[Parent.CurrentDragIndex-1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber); + int tmpStackSize = this.StackSize; + Parent.ItemsInventory[Parent.CurrentDragIndex-1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber, tmpStackSize); this.Item = Parent.CurrentDragItem; this.Number = Parent.CurrentDragNumber; + this.StackSize = Parent.CurrentDragStackSize; Parent.CurrentInventoryItem.Item = tmpItem; Parent.CurrentInventoryItem.Number = tmpNumber; + Parent.CurrentInventoryItem.StackSize = tmpStackSize; } } - Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number }); + Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize }); } internal void OnDragEnd() @@ -80,14 +87,16 @@ public partial class InventoryItem } if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex != this.Index) { - Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber); + Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber, Parent.CurrentDragStackSize); this.Item = Parent.CurrentDragItem; this.Number = Parent.CurrentDragNumber; + this.StackSize = Parent.CurrentDragStackSize; } Parent.CurrentDragIndex = -1; Parent.CurrentDragItem = "null"; Parent.CurrentDragNumber = 0; - Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number }); + Parent.CurrentDragStackSize = 0; + Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize }); } @@ -97,9 +106,11 @@ public partial class InventoryItem Parent.CurrentDragIndex = this.Index; Parent.CurrentDragItem = this.Item; Parent.CurrentDragNumber = this.Number; + Parent.CurrentDragStackSize = this.StackSize; this.Item = "null"; this.Number = 0; - Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number}); + this.StackSize = 0; + Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize}); } } diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.css b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.css index 252e639..662090f 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.css +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.css @@ -1,7 +1,26 @@ .inventory-item { + display:flex; + flex-direction:column; width: 64px; height: 64px; border: 1px solid; overflow: hidden; - align-content:center + align-content:center; + +} +#name { + text-align: center; +} +#number { + text-align: center; +} +#stackSize { + font-weight:lighter; + text-align:right; + margin-top:-5px; + margin-right:2px; +} +#vide { + align-self:center; + margin-top:20px; } \ No newline at end of file diff --git a/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs b/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs index f7a3ef1..17201db 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs +++ b/myBlazorApp/myBlazorApp/Components/InventoryListItem.cs @@ -6,16 +6,18 @@ namespace myBlazorApp.Components { //public InventoryListItem() { } - public InventoryListItem(string itemName, int position, int number) + public InventoryListItem(string itemName, int position, int number, int stackSize) { this.itemName = itemName; this.position = position; this.number = number; + this.stackSize = stackSize; } public string itemName { get; set; } public int position { get; set; } public int number { get; set; } + public int stackSize { get; set; } } } diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor b/myBlazorApp/myBlazorApp/Components/MyInventory.razor index cef2ec2..db46643 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor @@ -5,7 +5,7 @@
@foreach(InventoryListItem i in ItemsInventory) { - + }
diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs index 0359582..627dd62 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs @@ -19,6 +19,7 @@ namespace myBlazorApp.Components public string CurrentDragItem { get; set; } public int CurrentDragIndex { get; set; } public int CurrentDragNumber { get; set; } + public int CurrentDragStackSize { get; set; } public InventoryItem CurrentInventoryItem {get; set;} = new InventoryItem(); public MyInventory() @@ -45,7 +46,7 @@ namespace myBlazorApp.Components JavaScriptRuntime.InvokeVoidAsync("MyInventory.AddActions", e.NewItems); if (this.Actions.Last().Action == "End" || this.Actions.Last().Action == "Drop" || this.Actions.Last().Action == "Start") { - string[] infos = new string[] { this.Actions.Last().ItemName, this.Actions.Last().Index.ToString(), this.Actions.Last().Number.ToString() }; + string[] infos = new string[] { this.Actions.Last().ItemName, this.Actions.Last().Index.ToString(), this.Actions.Last().Number.ToString(), this.Actions.Last().StackSize.ToString() }; await DataService.UpdateInventory(infos); } }