aurian #2

Merged
remi.arnal merged 7 commits from aurian into master 2 years ago

@ -0,0 +1,23 @@
@using Models;
<h3>Inventory</h3>
<CascadingValue Value="@this">
<div class="css-grid">
@for(int i = 0; i<InventoryList.size;i++)
{
@if (inventory.inventoryItems[i] != null)
{
<ItemInventory items="@inventory.inventoryItems[i]" Index="@i" NoDrop=true />
}
else
{
<ItemInventory items="@inventory.inventoryItems[i]" Index="@i"/>
}
}
</div>
<div class="col-12">
<div>Actions</div>
<div class="actions" id="actions">
</div>
</div>
</CascadingValue>

@ -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<InventoryAction> Actions { get; set; }
public Inventory()
{
Actions = new ObservableCollection<InventoryAction>();
}
public void update()
{
this.StateHasChanged();
return;
}
[Parameter]
public InventoryList inventory { get; set; }
}
}

@ -0,0 +1,6 @@
.css-grid {
grid-template-columns: repeat(6,minmax(0,1fr));
gap: 10px;
display: grid;
width: 40%;
}

@ -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; }
}
}

@ -0,0 +1,22 @@
<div class="item"
ondragover="event.preventDefault();"
@ondragstart="@OnDragStart"
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
@if(Items != null)
{
@if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64))
{
<img src="data:image/png;base64, @(Items.item.ImageBase64)" class="img-thumbnail" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="width: 50px;" />
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="width: 50px; height: 50px" />
}
}
else
{
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAINJREFUeF7t18ENACAMAzE6OuLD1jDImREiGitz9n0r/EYAfoAT0AHhDlxKkAIUoAAFKBBOAIMYxCAGMRhGwBjCIAYxiEEMYjCcAAYxiEEMYjCMgDWIQQxiEIMYxGA4AQxiEIMYxGAYAWsQgxjEIAYxiMFwAhjEIAYxiMEwAtYgBusMfuMLowEYJcXzAAAAAElFTkSuQmCC" class="img-thumbnail" title="empty" alt="empty slot" style="width: 50px; height: 50px" />
}
</div>

@ -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));
}
}
}

@ -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;
}
}
}

@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Http.Features;
namespace Blazor.Models
{
public partial class InventoryList
{
static public int size = 18;
public List<InventoryItem> inventoryItems = new List<InventoryItem>(new InventoryItem[size]);
public InventoryList()
{
inventoryItems[0] = new InventoryItem();
}
}
}

@ -12,5 +12,17 @@
public DateTime CreatedDate { get; set; } public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; } public DateTime? UpdatedDate { get; set; }
public string ImageBase64 { get; set; } public string ImageBase64 { get; set; }
public Item()
{
Id = 2;
DisplayName = "Dirt";
Name = "Block_of_dirt";
StackSize = 64;
MaxDurability= 9999;
EnchantCategories = new List<string>();
RepairWith = new List<string>();
CreatedDate= DateTime.Now;
UpdatedDate = DateTime.Now;
}
} }
} }

@ -1,5 +1,5 @@
@page "/" @page "/"
@using Blazor.Components; @using Blazor.Components;
<div> <div>
<Crafting Items="Items" Recipes="Recipes" /> <Inventory inventory="inventory"/>
</div> </div>

@ -7,6 +7,12 @@ namespace Blazor.Pages
{ {
public partial class Index public partial class Index
{ {
/* TEST */
InventoryList inventory = new InventoryList();
[Inject] [Inject]
public IDataService DataService { get; set; } public IDataService DataService { get; set; }

@ -7,7 +7,8 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="https://codefirst.iut.uca.fr/containers/blazor-web-remiarnal/" /> @*<base href="https://codefirst.iut.uca.fr/containers/blazor-web-remiarnal/" />*@
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" /> <link href="css/site.css" rel="stylesheet" />
<link href="Blazor.styles.css" rel="stylesheet" /> <link href="Blazor.styles.css" rel="stylesheet" />

Loading…
Cancel
Save