Files
linuxdistro-roguelite/Assets/Scripts/UI/ScreenFrameController.cs
T
2026-10-22 21:59:50 +02:00

56 lines
1.7 KiB
C#

using System;
using UnityEngine.UIElements;
namespace KernelPanic.UI
{
/// <summary>
/// Binds shared command-style chrome used by terminal sub-screens.
/// </summary>
public sealed class ScreenFrameController
{
private Label _titleLabel;
private Label _hintLabel;
public void Bind(VisualElement panel, string title, string hint, Action onBack)
{
// TemplateContainer is a real layout node; hiding only its child leaves a flex slot.
if (panel.parent is TemplateContainer template)
{
template.AddToClassList("screen-slot");
template.EnableInClassList("hidden", panel.ClassListContains("hidden"));
}
_titleLabel = panel.Q<Label>(className: "screen-frame-title");
_hintLabel = panel.Q<Label>(className: "screen-frame-hint");
var back = new Button(() => onBack?.Invoke()) { text = "[Esc] back" };
back.AddToClassList("screen-back");
panel.Q(className: "screen-frame-footer")?.Insert(0, back);
if (_titleLabel != null)
{
_titleLabel.text = title;
}
if (_hintLabel != null)
{
_hintLabel.text = hint?.Replace("[esc] back", "").Trim();
}
}
public void SetHint(string hint)
{
if (_hintLabel != null)
{
_hintLabel.text = hint?.Replace("[esc] back", "").Trim();
}
}
public void SetTitle(string title)
{
if (_titleLabel != null)
{
_titleLabel.text = title;
}
}
}
}