Skip to content

Commit

Permalink
Addin equipment
Browse files Browse the repository at this point in the history
KrystianKempski committed May 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7b7e07b commit 5be4393
Showing 10 changed files with 189 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
border: 1px solid rgb(72, 69, 69);
border-radius: 10px;
margin: 6px;
padding:0 6px 0 6px;
}

.loading-gif{
@@ -92,7 +93,6 @@ td {
display: flex;
flex-direction: column;
width: 450px;
height: 565px;
position: relative;
}

121 changes: 92 additions & 29 deletions DagoniteEmpire/Pages/Components/EquipmentComponent.razor
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
<thead>
<tr>
<th scope="col" class="name-row">Name</th>
<th scope="col" class="description-row">Description</th>
<th scope="col" class="value-row text-center">Count</th>
<th scope="col" class="value-row text-center">Price</th>
<th scope="col" class="value-row text-center">Weight</th>
<th scope="col" class="action-row text-center">Actions</th>
@@ -16,26 +16,54 @@
@foreach (var obj in AllParams.Equipment)
{
<tr>
<td>
<td class="nobottomborder">
<label class="name-label">@obj.Name</label>
</td>
<td>
<label class="name-label">@obj.ShortDescr</label>
<td class="text-center nobottomborder">
<div class="control">
<span class="indicator">@obj.Count</span>
<div class="arrows">
<button @onclick="@(()=>IncrCount(obj))" class="carret"><i class="fa-regular fa-square-caret-up align-top"></i></button>
<button @onclick="@(()=>DecrCount(obj))" class="carret"><i class="fa-regular fa-square-caret-down align-top"></i></button>
</div>
</div>
</td>
<td class="text-center">
<label class="name-label text-center">@obj.Price</label>
<td class="text-center nobottomborder">
<label class="text-label text-center">@obj.Price.ToString("F3")</label>
</td>
<td class="text-center">
<label class="name-label text-center">@obj.Weight</label>
<td class="text-center nobottomborder">
<label class="text-label text-center">@obj.Weight.ToString("F1")</label>
</td>
<td>
<td class="text-center nobottomborder">
<div class="row m-0">
<button @onclick="@(()=>EditEquipment(obj))" class="col btn-small"><i class="fa-solid fa-pencil"></i></button>
<button @onclick="@(()=>DeleteEquipment(obj))" class="col btn-small"><i class="fa-solid fa-trash"></i></button>
</div>
</td>
</tr>
<tr >
<td colspan="5">
<label class="text-label">@obj.ShortDescr</label>
</td>
</tr>
}
<tr>
<td class="">
<label class="name-label">All equipment: </label>
</td>
<td >

</td>
<td class="text-center">
<label class="text-label text-center">@EquipmentPrice.ToString("F3")</label>
</td>
<td class="text-center">
<label class="text-label text-center">@EquipmentWeight.ToString("F1")</label>
</td>
<td class="text-center">

</td>
</tr>
</tbody>
</table>
</div>
@@ -66,6 +94,9 @@

private SfRichTextEditor DescrEdit = new();

private decimal EquipmentWeight;
private decimal EquipmentPrice;


private CustomEquipmentModel _customEquipmentComponent = new();
private CustomEquipmentModel CustomEquipmentComponent
@@ -109,24 +140,37 @@
}
}
OnTraitsChange.InvokeAsync();
CalculateEquipWeightAndPrice();

}
if (_equipmentChosen == value) return;
_equipmentChosen = value;

}
}

private async Task CalculateEquipWeightAndPrice()
{
EquipmentWeight = 0.0m;
EquipmentPrice = 0.0m;
foreach (var equ in AllParams.Equipment)
{
EquipmentWeight += equ.Weight;
EquipmentPrice += equ.Price;
}
StateHasChanged();
}

private async Task AddCustomEquipment()
{
CustomEquipmentComponent.EquipmentDTO = new();
CustomEquipmentComponent.Traits = new List<TraitDTO>();
CustomEquipmentComponent.IsVisible = true;
StateHasChanged();
}
private async Task AddExistingEquipment()
{
EquipmentChosen = new();
EquipmentChosen.IsVisible = true;
StateHasChanged();
}

private async Task EditEquipment(EquipmentDTO equ)
@@ -135,7 +179,7 @@
CustomEquipmentComponent.Traits = CustomEquipmentComponent.EquipmentDTO.Traits.OfType<TraitDTO>().ToList();
CustomEquipmentComponent.IsVisible = true;
CustomEquipmentComponent.IsEditMode = true;
StateHasChanged();
CalculateEquipWeightAndPrice();
}

private async Task DeleteEquipment(EquipmentDTO equ)
@@ -151,23 +195,42 @@
}
AllParams.Equipment = AllParams.Equipment.Where(u => u.Name != equ.Name).ToList();
OnTraitsChange.InvokeAsync();
StateHasChanged();
CalculateEquipWeightAndPrice();
}

// protected override async Task OnAfterRenderAsync(bool firstRender)
// {
// if (firstRender)
// {
// if (_customEquipmentComponent.EquipmentDTO is not null)
// {
// var shortDescr = (await DescrEdit.GetTextAsync());
// if (shortDescr is not null)
// {
// if (shortDescr.Length > 100)
// shortDescr = shortDescr?[0..100] + "...";
// CustomEquipmentComponent.EquipmentDTO.ShortDescr = shortDescr;
// }
// }
// }
// }

private async Task IncrCount(EquipmentDTO obj)
{

decimal unitWeigh = obj.Weight / obj.Count;
decimal unitPrice = obj.Price / obj.Count;
obj.Count++;
obj.Weight = unitWeigh * obj.Count;
obj.Price = unitPrice * obj.Count;

CalculateEquipWeightAndPrice();
}

private async Task DecrCount(EquipmentDTO obj)
{
if (obj.Count>1)
{
decimal unitWeigh = obj.Weight / obj.Count;
decimal unitPrice = obj.Price / obj.Count;

obj.Count--;

obj.Weight = unitWeigh * obj.Count;
obj.Price = unitPrice * obj.Count;
CalculateEquipWeightAndPrice();
}
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
CalculateEquipWeightAndPrice();
}
}
}
70 changes: 58 additions & 12 deletions DagoniteEmpire/Pages/Components/EquipmentComponent.razor.css
Original file line number Diff line number Diff line change
@@ -6,13 +6,16 @@
align-items: center;
}

.name-row {
width: 80px;
}

.name-label {

.text-label {
font-size: 13px;
}
.name-label {
font-size: 15px;
font-weight:bold;
}


.description-row {
font-size: 13px;
@@ -33,16 +36,11 @@
padding: 2px;
}

.add-trait {
border: 1px solid gray;
border-radius: 3px;
font-size: 14px;
}

.name-row {
font-size: 13px;
width: 40px;
text-align: left;
padding: 5px;
padding: 2px;
vertical-align: middle;
}
td {
@@ -73,9 +71,56 @@ h3 {
flex: 2;
}

.carret {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
margin-top: 0px;
height: 18px;
width: 18px;
font-size: 18px;
color: dimgray;
border: 0px solid gray;
background-color: transparent;
text-align: start;
}

/*arrows*/
.control {
display: flex;
flex-direction: row;
width: 50px;
height: 30px;
justify-items: right;
align-items: center
}

.indicator {
display: flex;
justify-content: center;
align-items: center;
border: 1px solid gray;
font-size: 12px;
border-radius: 4px;
width: 100%;
height: 28px;
margin-top: 0px;
margin-right: 2px;
}
.arrows {
display: grid;
padding: 0px;
margin: 0px;
margin-top: 2px;
}

.nobottomborder {
border: 0px solid black;
}



.add-trait {
border: 1px solid black;
border: 1px solid darkgray;
border-radius: 6px;
width: 120px;
height: 32px;
@@ -86,6 +131,7 @@ h3 {
background-size: cover;
background-position: center;
font-weight: bold;
font-size: 14px;
transition: transform 0.1s;
}

Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ h3 {
}

.add-trait {
border: 1px solid black;
border: 1px solid darkgray;
border-radius: 6px;
width: 120px;
height: 32px;
@@ -67,6 +67,7 @@ h3 {
background-size: cover;
background-position: center;
font-weight: bold;
font-size: 14px;
transition: transform 0.1s;
}
.add-trait:hover {
3 changes: 2 additions & 1 deletion DagoniteEmpire/Pages/Components/RaceComponent.razor.css
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ h3 {
}

.add-trait {
border: 1px solid black;
border: 1px solid darkgray;
border-radius: 6px;
width: 120px;
height: 32px;
@@ -102,6 +102,7 @@ h3 {
background-size: cover;
background-position: center;
font-weight: bold;
font-size: 14px;
transition: transform 0.1s;
}

3 changes: 2 additions & 1 deletion DagoniteEmpire/Pages/Components/TraitsComponent.razor.css
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
}

.add-trait {
border: 1px solid black;
border: 1px solid darkgray;
border-radius: 6px;
width: 120px;
height: 32px;
@@ -47,6 +47,7 @@
background-size: cover;
background-position: center;
font-weight: bold;
font-size: 14px;
transition: transform 0.1s;
}

15 changes: 8 additions & 7 deletions DagoniteEmpire/Pages/Dialogs/CharDescriptionDialog.razor
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@
@* <img src="../images/old_paper2.png" class="stretch" /> *@
</div>
<h3 class="my-3 ml-3 text-center">DESCRIPTION</h3>
<div class="description-richtext">
<SfRichTextEditor Height="100%" @ref="DescrShow" @bind-Value="@SavedDescription" Readonly="true" ShowTooltip="false">
<RichTextEditorToolbarSettings Items="@NoTools" />
<p>Here write a description of your character</p>
</SfRichTextEditor>
<div class="descr-container">
<div class="description-richtext">
<SfRichTextEditor Height="100%" @ref="DescrShow" @bind-Value="@SavedDescription" Readonly="true" ShowTooltip="false">
<RichTextEditorToolbarSettings Items="@NoTools" />
<p>Here write a description of your character</p>
</SfRichTextEditor>
</div>
<button class="add-trait" @onclick="OnStartDescriptionDialog">Description</button>
</div>
<button class="add-trait" @onclick="OnStartDescriptionDialog">Description</button>

<SfDialog Width="80%" Height="80%" @bind-Visible="@IsDescrDialVisible" IsModal="true" AllowDragging="true" CloseOnEscape="false" EnableResize="true">
<DialogEvents Opened="@DialogOpen"></DialogEvents>
<DialogTemplates>
Loading

0 comments on commit 5be4393

Please sign in to comment.