This commit is contained in:
Oscar
2025-05-25 19:14:50 +03:00
parent df4b259d17
commit 4d212f2ff8
27 changed files with 735 additions and 142 deletions

View File

@@ -0,0 +1,66 @@
@using Sandbox;
@using Sandbox.UI;
@using System.Threading.Tasks;
@inherits PanelComponent
@namespace Sandbox
<root class="@(IsInteracting ? "interact" : "")" >
<!-- times 90 and plus 10 so that there is a minimal width. Otherwise the rounding doesn't play nice -->
<div class="ProgressBar" style="
width:@(ProgressionHold * 90 + 10)%;
@(ProgressionHold > 0 ? "opacity: 1;" : "opacity: 0;")
"></div>
<div class="Left">
<Image class="InteractionGlyph" Texture=@InputTexture/>
@if (IsHoldInteraction)
{
<div class="InteractionHold"> Hold </div>
}
</div>
<div class="Right">
<div class="InteractionTitle"> @InteractionString </div>
</div>
</root>
@code
{
private Texture InputTexture;
public string InteractionString {get; set;}
private bool IsInteracting = false;
public bool IsHoldInteraction = false;
public float ProgressionHold = 0;
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine( InputTexture, InteractionString, IsHoldInteraction, ProgressionHold);
protected override void OnUpdate()
{
InputTexture = Input.GetGlyph("use", InputGlyphSize.Medium, true);
}
/// <summary>
/// Triggers the interaction animation.
/// </summary>
public async Task TriggerInteractAnimation()
{
if (IsInteracting)
return; // Prevent overlapping animations
IsInteracting = true;
StateHasChanged();
// Wait for the animation duration (e.g., 300ms)
await Task.Delay(100);
IsInteracting = false;
StateHasChanged();
}
}

View File

@@ -0,0 +1,78 @@
InteractionPanel
{
position: absolute;
top: 0;
left: 0;
background-color: #444;
justify-content: center;
align-items: center;
font-weight: bold;
border-radius: 20px;
font-size: 25px;
font-family: Poppins;
color: #fff;
text-stroke: 8px black;
transform-origin: left center;
transition: all 0.1s ease-out;
transform: scale( 1 );
// When the element is created make it expand from nothing.
&:intro {
transform: scale( 0 );
}
&:outro {
transform: scale( 0 );
}
.InteractionTitle
{
color: #fff;
margin-right: 15px;
white-space: normal;
max-width: 300px;
align-items: center;
}
.ProgressBar {
position: absolute; /* Place the progress bar within the root */
top: 0;
left: 0;
height: 100%; /* Fill the entire height of the root */
z-index: 0; /* Ensure it is below the content */
border-radius: 20px;
background-color: #a2a2a2;
}
.Left
{
flex-direction: column;
align-items: center;
padding-left: 20px;
min-width: 110px;
}
.Right
{
width: 100%;
align-items: center;
margin-left: 30px;
}
.InteractionHold
{
margin-top: -13px;
margin-bottom: 5px;
}
&.interact {
transition: all 0.1s ease-out;
transform: scale(0.98);
}
}