using System;
using System.Collections.Generic;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using ImGuiScene;
namespace Dalamud.Interface
{
///
/// Class responsible for managing elements in the title screen menu.
///
[PluginInterface]
[InterfaceVersion("1.0")]
public class TitleScreenMenu
{
///
/// Gets the texture size needed for title screen menu logos.
///
internal const uint TextureSize = 64;
private readonly List entries = new();
///
/// Gets the list of entries in the title screen menu.
///
public IReadOnlyList Entries => this.entries;
///
/// Adds a new entry to the title screen menu.
///
/// The text to show.
/// The texture to show.
/// The action to execute when the option is selected.
/// A object that can be used to manage the entry.
/// Thrown when the texture provided does not match the required resolution(64x64).
public TitleScreenMenuEntry AddEntry(string text, TextureWrap texture, Action onTriggered)
{
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}
var entry = new TitleScreenMenuEntry(text, texture, onTriggered);
this.entries.Add(entry);
return entry;
}
///
/// Remove an entry from the title screen menu.
///
/// The entry to remove.
public void RemoveEntry(TitleScreenMenuEntry entry) => this.entries.Remove(entry);
///
/// Class representing an entry in the title screen menu.
///
public class TitleScreenMenuEntry
{
private readonly Action onTriggered;
///
/// Initializes a new instance of the class.
///
/// The text to show.
/// The texture to show.
/// The action to execute when the option is selected.
internal TitleScreenMenuEntry(string text, TextureWrap texture, Action onTriggered)
{
this.Name = text;
this.Texture = texture;
this.onTriggered = onTriggered;
}
///
/// Gets or sets the name of this entry.
///
public string Name { get; set; }
///
/// Gets or sets the texture of this entry.
///
public TextureWrap Texture { get; set; }
///
/// Gets the internal ID of this entry.
///
internal Guid Id { get; init; } = Guid.NewGuid();
///
/// Trigger the action associated with this entry.
///
internal void Trigger()
{
this.onTriggered();
}
}
}
}