Compare commits

...

2 Commits

@ -1,23 +1,33 @@
[
{
"itemName": "null",
"position": 1
"itemName": "Sand",
"position": 1,
"number": 2,
"stackSize": 64
},
{
"itemName": "null",
"position": 2
"itemName": "Grass Block",
"position": 2,
"number": 3,
"stackSize": 64
},
{
"itemName": "null",
"position": 3
"itemName": "Cobblestone",
"position": 3,
"number": 3,
"stackSize": 64
},
{
"itemName": "null",
"position": 4
"itemName": "Sapling",
"position": 4,
"number": 1,
"stackSize": 64
},
{
"itemName": "null",
"position": 5
"itemName": "Dirt",
"position": 5,
"number": 2,
"stackSize": 64
},
{
"itemName": "null",

@ -7,15 +7,30 @@
@ondragend="@OnDragEnd"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
@if (Item != "null")
@if (NoDrop == true)
{
<label id="name">@Item</label>
<label id="number">@Number</label>
<label id="stackSize">@StackSize</label>
@if (!string.IsNullOrWhiteSpace(@Image))
{
<img src="data:image/png;base64, @(Image)" class="img-thumbnail" title="@Item" alt="@Item" style="width: 64px" />
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@Item" alt="@Item" style="max-width: 150px" />
}
}
else
{
<p id="vide">@Localizer["emptyElement"]</p>
@if (Item != "null")
{
<label id="name">@Item</label>
<label id="number">@Number</label>
<label id="stackSize">@StackSize</label>
}
else
{
<p id="vide">@Localizer["emptyElement"]</p>
}
}
</div>

@ -24,6 +24,9 @@ public partial class InventoryItem
[Parameter]
public bool NoDrop { get; set; }
[Parameter]
public string Image { get; set; }
[Inject]
public IStringLocalizer<InventoryItem> Localizer { get; set; }
@ -50,19 +53,22 @@ public partial class InventoryItem
internal void OnDrop()
{
if (NoDrop)
{
return;
}
if (Parent.CurrentDragItem != "null")
{
if(this.Item == Parent.CurrentDragItem)
if(Parent.CurrentDragIndex == 0)
{
this.Number = this.Number + Parent.CurrentDragNumber;
this.Item = Parent.CurrentDragItem;
this.StackSize = Parent.CurrentDragStackSize;
Parent.ItemsInventory[this.Index - 1] = new InventoryListItem(this.Item, this.Index, this.Number, this.StackSize);
}
else if (this.Item == Parent.CurrentDragItem)
{
this.Number = this.Number + Parent.CurrentDragNumber;
Parent.CurrentInventoryItem.Number = 0;
Parent.CurrentInventoryItem.Item = "null";
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 });
}
else
@ -70,7 +76,7 @@ public partial class InventoryItem
string tmpItem = this.Item;
int tmpNumber = this.Number;
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.Number = Parent.CurrentDragNumber;
this.StackSize = Parent.CurrentDragStackSize;
@ -81,6 +87,7 @@ public partial class InventoryItem
}
Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
}
internal void OnDragEnd()

@ -1,25 +1,26 @@
@using myBlazorApp.Models
<CascadingValue Value="@this">
<h3>@Localizer["Title"]</h3>
@using myBlazorApp.Components
<CascadingValue Value="@this">
<h3>@Localizer["Inventory"]</h3>
<div class="body">
<div class="inventory">
<div class="inventory-items">
@foreach(InventoryListItem i in ItemsInventory)
{
<InventoryItem Index="@i.position" Item="@i.itemName" Number="@i.number" StackSize="@i.stackSize" />
<InventoryItem Index="@i.position" Item="@i.itemName" Number="@i.number" StackSize="@i.stackSize"/>
}
</div>
</div>
<div id="ItemList" class="align-end">
<h3>List of Items</h3>
<h3>@Localizer["List"]</h3>
<input type="text" @bind-value="@SearchText"
@bind-value:event="oninput" placeholder="Search by Name"
@onchange="@inputValue" />
<button type="button" @onclick="@OnPress">Sort</button>
<button type="button" @onclick="@OnPress">@Localizer["Sort"]</button>
<DataGrid TItem="Item"
@ -32,20 +33,14 @@
<DataGridColumn Field="@nameof(Item.Id)">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="width: 50px" />
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 150px" />
}
<InventoryItem Item="@context.DisplayName" NoDrop="true" Number=1 StackSize="@context.StackSize" Image="@context.ImageBase64"/>
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" />
</DataGrid>
</div>
</div>
</CascadingValue>

@ -16,7 +16,7 @@ namespace myBlazorApp.Components
public partial class MyInventory
{
[Parameter]
public List<InventoryListItem> ItemsInventory { get; set; }
public List<InventoryListItem> ItemsInventory { get; set; } = new List<InventoryListItem>();
public int index { get; set; } = 0;
@ -97,6 +97,7 @@ namespace myBlazorApp.Components
totalItem = await DataService.Count();
items = await DataService.List(e.Page, e.PageSize);
full = await DataService.List(e.Page, totalItem);
ItemsInventory = await DataService.GetInventoryItems();
currentPage = e.Page;
pageSize = e.PageSize;
if (isSorted == false)

@ -5,5 +5,5 @@
@using Syncfusion.Blazor.Grids;
<div class="inventory">
<MyInventory ItemsInventory="@itemsInv"/>
<MyInventory/>
</div>

@ -60,9 +60,27 @@ namespace myBlazorApp.Resources {
/// <summary>
/// Looks up a localized string similar to My inventory.
/// </summary>
internal static string Title {
internal static string Inventory {
get {
return ResourceManager.GetString("Title", resourceCulture);
return ResourceManager.GetString("Inventory", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Available items.
/// </summary>
internal static string List {
get {
return ResourceManager.GetString("List", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to SORT.
/// </summary>
internal static string Sort {
get {
return ResourceManager.GetString("Sort", resourceCulture);
}
}
}

@ -117,8 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Title" xml:space="preserve">
<data name="Inventory" xml:space="preserve">
<value>Mon inventaire</value>
<comment/>
</data>
<data name="List" xml:space="preserve">
<value>Objets Disponibles</value>
<comment/>
</data>
<data name="Sort" xml:space="preserve">
<value>TRIER</value>
<comment/>
</data>
</root>

@ -117,8 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Title" xml:space="preserve">
<data name="Inventory" xml:space="preserve">
<value>My inventory</value>
<comment/>
</data>
<data name="List" xml:space="preserve">
<value>Available items</value>
<comment/>
</data>
<data name="Sort" xml:space="preserve">
<value>SORT</value>
<comment/>
</data>
</root>
Loading…
Cancel
Save