94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public partial class Alert : Control {
|
|
Options _Options;
|
|
Reference _Reference;
|
|
|
|
Queue<string> AlertQueue = new Queue<string>();
|
|
|
|
public override void _Ready() {
|
|
_Options = GetNode<Options>( "/root/Options" );
|
|
_Reference = GetNode<Reference>("/root/Reference");
|
|
_Reference.Alert = this;
|
|
}
|
|
|
|
// This needs to notify the user
|
|
public void PerformAlert(string NotificationText ) {
|
|
if ( _Options.isServer ) {
|
|
GD.Print( NotificationText );
|
|
} else {
|
|
AlertQueue.Enqueue( NotificationText );
|
|
}
|
|
}
|
|
|
|
Panel working = null;
|
|
float CurrentStep;
|
|
float PauseCounter;
|
|
int task = 0;
|
|
public override void _Process( double delta ) {
|
|
switch( task ) {
|
|
|
|
// Create the label
|
|
case 0: {
|
|
if (AlertQueue.Count > 0 ) {
|
|
working = new Panel();
|
|
working.Size = new Vector2( 300, 50 );
|
|
AddChild( working );
|
|
working.Position = new Vector2( 0, -50 );
|
|
|
|
Label text = new Label();
|
|
text.Text = AlertQueue.Dequeue();
|
|
text.Size = new Vector2( 300, 50 );
|
|
text.HorizontalAlignment = HorizontalAlignment.Center;
|
|
text.VerticalAlignment = VerticalAlignment.Center;
|
|
working.AddChild( text );
|
|
CurrentStep = 0;
|
|
PauseCounter = 0;
|
|
task = 1;
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Bring down the label
|
|
case 1: {
|
|
if ( CurrentStep < _Options.AlertTime / 2 ) {
|
|
CurrentStep += Convert.ToSingle( delta );
|
|
float alertTime = _Options.AlertTime / 2;
|
|
working.Position = new Vector2( 0, Mathf.Lerp( -50, 25, CurrentStep / alertTime ) );
|
|
} else {
|
|
task = 2;
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Pause the label
|
|
case 2: {
|
|
PauseCounter += Convert.ToSingle( delta );
|
|
if (PauseCounter >= _Options.AlertPauseTime) {
|
|
task = 3;
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Bring Up the label
|
|
case 3: {
|
|
if ( CurrentStep > 0 ) {
|
|
CurrentStep -= Convert.ToSingle( delta );
|
|
float alertTime = _Options.AlertTime / 2;
|
|
working.Position = new Vector2( 0, Mathf.Lerp( -50, 25, CurrentStep / alertTime ) );
|
|
} else {
|
|
working.Free();
|
|
working = null;
|
|
task = 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|