using Content.Client.Guidebook.Richtext;
using Content.Shared._DV.Tips;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.RichText;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;
namespace Content.Client._DV.Tips.UI;
///
/// Popup control that displays a tip to the player.
/// Appears in the top-left corner with a semi-transparent background.
///
[GenerateTypedNameReferences]
public sealed partial class TipPopup : Control
{
///
/// Event raised when the popup is closed. The bool parameter indicates
/// whether the "Don't show again" checkbox was checked.
///
public event Action? OnClose;
private readonly TipPrototype _tip;
///
/// Whether the "Don't show again" checkbox is checked.
///
public bool DontShowAgain => DontShowAgainCheckBox.Pressed;
public TipPopup(TipPrototype tip)
{
RobustXamlLoader.Load(this);
_tip = tip;
InitializeUI();
InitializeEvents();
}
private void InitializeUI()
{
TitleLabel.Text = Loc.GetString(_tip.Title);
var description = Loc.GetString(_tip.Description);
DescriptionLabel.SetMessage(FormattedMessage.FromMarkupPermissive(description),
tagsAllowed:
[
typeof(ItalicTag),
typeof(ColorTag),
typeof(BoldTag),
typeof(BoldItalicTag),
typeof(KeyBindTag),
]);
ApplyTransparentStyle();
}
private void ApplyTransparentStyle()
{
var styleBox = new StyleBoxFlat
{
BackgroundColor = Color.FromHex("#1a1a1a").WithAlpha(0.85f),
BorderColor = Color.FromHex("#3a3a3a"),
BorderThickness = new Thickness(1),
ContentMarginLeftOverride = 0,
ContentMarginRightOverride = 0,
ContentMarginTopOverride = 0,
ContentMarginBottomOverride = 0,
};
BackgroundPanel.PanelOverride = styleBox;
}
private void InitializeEvents()
{
OkayButton.OnPressed += OnOkayPressed;
}
private void OnOkayPressed(BaseButton.ButtonEventArgs args)
{
Close();
}
public void Close()
{
if (Parent == null)
{
return;
}
var dontShowAgain = DontShowAgain;
Parent.RemoveChild(this);
OnClose?.Invoke(dontShowAgain);
}
}