Chessistics/Scripts/UI/FlavorBanner.cs
Samuel Bouchet 2d1aea0a7a Snapshot campaign system progress before automation harness
Bundles in-flight work on the campaign/missions system (CampaignDef,
MissionDef, TerrainPatch, TransformerDef, MissionChecker, CampaignLoader,
FlavorBanner, transformer rules), plan files, and matching tests. Baseline
commit so the upcoming automation testing harness lands on a clean tree.
2026-04-16 21:22:49 +02:00

73 lines
2.1 KiB
C#

using Godot;
namespace Chessistics.Scripts.UI;
/// <summary>
/// Displays a one-line narrative blurb at the top of the screen when a mission starts.
/// Auto-fades out after a few seconds.
/// </summary>
public partial class FlavorBanner : PanelContainer
{
private Label _label = null!;
private Tween? _activeTween;
private static readonly Color BannerBg = new(0.12f, 0.10f, 0.08f, 0.92f);
private static readonly Color BorderColor = new("#B8942A");
private static readonly Color TextColor = new("#E8D4A0");
public override void _Ready()
{
// Style the panel
var style = new StyleBoxFlat
{
BgColor = BannerBg,
BorderColor = BorderColor,
BorderWidthBottom = 2,
ContentMarginLeft = 24,
ContentMarginRight = 24,
ContentMarginTop = 10,
ContentMarginBottom = 10,
CornerRadiusBottomLeft = 6,
CornerRadiusBottomRight = 6
};
AddThemeStyleboxOverride("panel", style);
_label = new Label
{
HorizontalAlignment = HorizontalAlignment.Center,
AutowrapMode = TextServer.AutowrapMode.WordSmart
};
_label.AddThemeFontSizeOverride("font_size", 13);
_label.AddThemeColorOverride("font_color", TextColor);
AddChild(_label);
MouseFilter = MouseFilterEnum.Ignore;
Visible = false;
}
public void ShowFlavor(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
Visible = false;
return;
}
_activeTween?.Kill();
_label.Text = text;
Visible = true;
Modulate = new Color(1, 1, 1, 0);
_activeTween = CreateTween();
// Fade in
_activeTween.TweenProperty(this, "modulate:a", 1f, 0.4f)
.SetEase(Tween.EaseType.Out);
// Hold
_activeTween.TweenInterval(5.0f);
// Fade out
_activeTween.TweenProperty(this, "modulate:a", 0f, 1.0f)
.SetEase(Tween.EaseType.In);
_activeTween.TweenCallback(Callable.From(() => Visible = false));
}
}