using Dalamud.Configuration.Internal; using Dalamud.Game.Addon.Events; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Plugin.Internal.Types; using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.System.String; using FFXIVClientStructs.FFXIV.Component.GUI; namespace Dalamud.Game.Gui.Dtr; /// /// Interface representing a read-only entry in the server info bar. /// public interface IReadOnlyDtrBarEntry { /// /// Gets the title of this entry. /// public string Title { get; } /// /// Gets a value indicating whether this entry has a click action. /// public bool HasClickAction { get; } /// /// Gets the text of this entry. /// public SeString? Text { get; } /// /// Gets a tooltip to be shown when the user mouses over the dtr entry. /// public SeString? Tooltip { get; } /// /// Gets a value indicating whether this entry should be shown. /// public bool Shown { get; } /// /// Gets a value indicating whether the user has hidden this entry from view through the Dalamud settings. /// public bool UserHidden { get; } /// /// Triggers the click action of this entry. /// /// True, if a click action was registered and executed. [Api13ToDo("Remove, doesn't mesh well with new click actions")] public bool TriggerClickAction(); } /// /// Interface representing an entry in the server info bar. /// public interface IDtrBarEntry : IReadOnlyDtrBarEntry { /// /// Gets or sets the text of this entry. /// public new SeString? Text { get; set; } /// /// Gets or sets a tooltip to be shown when the user mouses over the dtr entry. /// public new SeString? Tooltip { get; set; } /// /// Gets or sets a value indicating whether this entry is visible. /// public new bool Shown { get; set; } /// /// Gets or sets a action to be invoked when the user clicks on the dtr entry. /// [Api13ToDo("Remove this, and rename OnClicked to OnClick")] public Action? OnClick { get; set; } /// /// Gets or sets a action to be invoked when the user left-clicks on the dtr entry. /// public Action? OnLeftClick { get; set; } /// /// Gets or sets a action to be invoked when the user right-clicks on the dtr entry. /// public Action? OnRightClick { get; set; } /// /// Gets or sets a action to be invoked when the user clicks on the dtr entry. /// public Action? OnClicked { get; set; } /// /// Remove this entry from the bar. /// You will need to re-acquire it from DtrBar to reuse it. /// public void Remove(); } /// /// Class representing an entry in the server info bar. /// internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry { private readonly DalamudConfiguration configuration; private bool shownBacking = true; private SeString? textBacking; /// /// Initializes a new instance of the class. /// /// Dalamud configuration, used to check if the entry is hidden by the user. /// The title of the bar entry. /// The corresponding text node. internal DtrBarEntry(DalamudConfiguration configuration, string title, AtkTextNode* textNode) { this.configuration = configuration; this.Title = title; this.TextNode = textNode; } /// public string Title { get; init; } /// public SeString? Text { get => this.textBacking; set { this.textBacking = value; this.Dirty = true; } } /// public SeString? Tooltip { get; set; } /// /// Gets or sets a action to be invoked when the user clicks on the dtr entry. /// [Api13ToDo("Remove this and rename OnClicked to OnClick")] public Action? OnClick { get; set; } /// public Action? OnLeftClick { get; set; } /// public Action? OnRightClick { get; set; } /// public Action? OnClicked { get; set; } /// public bool HasClickAction => this.OnClick != null || this.OnLeftClick != null || this.OnRightClick != null || this.OnClicked != null; /// public bool Shown { get => this.shownBacking; set { if (value != this.shownBacking) { this.shownBacking = value; this.Dirty = true; } } } /// [Api13ToDo("Maybe make this config scoped to internalname?")] public bool UserHidden => this.configuration.DtrIgnore?.Contains(this.Title) ?? false; /// /// Gets or sets the internal text node of this entry. /// internal AtkTextNode* TextNode { get; set; } /// /// Gets or sets the storage for the text of this entry. /// internal Utf8String* Storage { get; set; } /// /// Gets or sets a value indicating whether this entry should be removed. /// internal bool ShouldBeRemoved { get; set; } /// /// Gets or sets a value indicating whether this entry is dirty. /// internal bool Dirty { get; set; } /// /// Gets or sets a value indicating whether this entry has just been added. /// internal bool Added { get; set; } /// /// Gets or sets the plugin that owns this entry. /// internal LocalPlugin? OwnerPlugin { get; set; } /// [Api13ToDo("Remove, doesn't mesh well with new click actions")] public bool TriggerClickAction() { if (this.OnClick == null) return false; this.OnClick.Invoke(); return true; } /// /// Remove this entry from the bar. /// You will need to re-acquire it from DtrBar to reuse it. /// public void Remove() { this.ShouldBeRemoved = true; } /// public void Dispose() { this.Remove(); } }