feat: add OpenMainUi event on UiBuilder, respective button in PI

This commit is contained in:
goat 2023-08-22 22:20:08 +02:00
parent c027aacde2
commit 3272dbb0e2
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 69 additions and 4 deletions

View file

@ -7,6 +7,7 @@ using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin;
using Dalamud.Utility;
using Serilog;
namespace Dalamud.CorePlugin
{
@ -66,6 +67,7 @@ namespace Dalamud.CorePlugin
this.Interface.UiBuilder.Draw += this.OnDraw;
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
this.Interface.UiBuilder.OpenMainUi += this.OnOpenMainUi;
Service<CommandManager>.Get().AddHandler("/coreplug", new(this.OnCommand) { HelpMessage = $"Access the {this.Name} plugin." });
@ -143,6 +145,11 @@ namespace Dalamud.CorePlugin
// this.window.IsOpen = true;
}
private void OnOpenMainUi()
{
Log.Verbose("Opened main UI");
}
#endif
}
}

View file

@ -2227,6 +2227,8 @@ internal class PluginInstallerWindow : Window, IDisposable
{
ImGuiHelpers.SafeTextWrapped($"{command.Key} → {command.Value.HelpMessage}");
}
ImGuiHelpers.ScaledDummy(3);
}
}
@ -2573,6 +2575,9 @@ internal class PluginInstallerWindow : Window, IDisposable
{
// Only if the plugin isn't broken.
this.DrawOpenPluginSettingsButton(plugin);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5, 0);
}
if (applicableForProfiles && config.ProfilesEnabled)
@ -2637,10 +2642,39 @@ internal class PluginInstallerWindow : Window, IDisposable
private void DrawOpenPluginSettingsButton(LocalPlugin plugin)
{
if (plugin.DalamudInterface?.UiBuilder?.HasConfigUi ?? false)
var hasMainUi = plugin.DalamudInterface?.UiBuilder.HasMainUi ?? false;
var hasConfig = plugin.DalamudInterface?.UiBuilder.HasConfigUi ?? false;
if (hasMainUi)
{
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.Cog))
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.ArrowUpRightFromSquare, Locs.PluginButton_OpenUi))
{
try
{
plugin.DalamudInterface.UiBuilder.OpenMain();
}
catch (Exception ex)
{
Log.Error(ex, $"Error during OpenMain(): {plugin.Name}");
}
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(Locs.PluginButtonToolTip_OpenUi);
}
}
if (hasConfig)
{
if (hasMainUi)
{
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5, 0);
}
ImGui.SameLine();
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Cog, Locs.PluginButton_OpenSettings))
{
try
{
@ -2648,7 +2682,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
catch (Exception ex)
{
Log.Error(ex, $"Error during OpenConfigUi: {plugin.Name}");
Log.Error(ex, $"Error during OpenConfig: {plugin.Name}");
}
}
@ -3236,12 +3270,18 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButton_Unload => Loc.Localize("InstallerUnload", "Unload");
public static string PluginButton_SafeMode => Loc.Localize("InstallerSafeModeButton", "Can't change in safe mode");
public static string PluginButton_OpenUi => Loc.Localize("InstallerOpenPluginUi", "Open");
public static string PluginButton_OpenSettings => Loc.Localize("InstallerOpenPluginSettings", "Settings");
#endregion
#region Plugin button tooltips
public static string PluginButtonToolTip_OpenUi => Loc.Localize("InstallerTooltipOpenUi", "Open this plugin's interface");
public static string PluginButtonToolTip_OpenConfiguration => Loc.Localize("InstallerOpenConfig", "Open Configuration");
public static string PluginButtonToolTip_OpenConfiguration => Loc.Localize("InstallerTooltipOpenConfig", "Open this plugin's settings");
public static string PluginButtonToolTip_PickProfiles => Loc.Localize("InstallerPickProfiles", "Pick collections for this plugin");

View file

@ -69,6 +69,11 @@ public sealed class UiBuilder : IDisposable
/// Event that is fired when the plugin should open its configuration interface.
/// </summary>
public event Action OpenConfigUi;
/// <summary>
/// Event that is fired when the plugin should open its main interface.
/// </summary>
public event Action OpenMainUi;
/// <summary>
/// Gets or sets an action that is called any time ImGui fonts need to be rebuilt.<br/>
@ -212,6 +217,11 @@ public sealed class UiBuilder : IDisposable
/// </summary>
internal bool HasConfigUi => this.OpenConfigUi != null;
/// <summary>
/// Gets a value indicating whether this UiBuilder has a configuration UI registered.
/// </summary>
internal bool HasMainUi => this.OpenMainUi != null;
/// <summary>
/// Gets or sets the time this plugin took to draw on the last frame.
/// </summary>
@ -409,6 +419,14 @@ public sealed class UiBuilder : IDisposable
{
this.OpenConfigUi?.InvokeSafely();
}
/// <summary>
/// Open the registered configuration UI, if it exists.
/// </summary>
internal void OpenMain()
{
this.OpenMainUi?.InvokeSafely();
}
/// <summary>
/// Notify this UiBuilder about plugin UI being hidden.