mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add OpenMainUi event on UiBuilder, respective button in PI
This commit is contained in:
parent
c027aacde2
commit
3272dbb0e2
3 changed files with 69 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.CorePlugin
|
namespace Dalamud.CorePlugin
|
||||||
{
|
{
|
||||||
|
|
@ -66,6 +67,7 @@ namespace Dalamud.CorePlugin
|
||||||
|
|
||||||
this.Interface.UiBuilder.Draw += this.OnDraw;
|
this.Interface.UiBuilder.Draw += this.OnDraw;
|
||||||
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
|
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." });
|
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;
|
// this.window.IsOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnOpenMainUi()
|
||||||
|
{
|
||||||
|
Log.Verbose("Opened main UI");
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2227,6 +2227,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
{
|
{
|
||||||
ImGuiHelpers.SafeTextWrapped($"{command.Key} → {command.Value.HelpMessage}");
|
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.
|
// Only if the plugin isn't broken.
|
||||||
this.DrawOpenPluginSettingsButton(plugin);
|
this.DrawOpenPluginSettingsButton(plugin);
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
ImGuiHelpers.ScaledDummy(5, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (applicableForProfiles && config.ProfilesEnabled)
|
if (applicableForProfiles && config.ProfilesEnabled)
|
||||||
|
|
@ -2637,10 +2642,39 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
|
|
||||||
private void DrawOpenPluginSettingsButton(LocalPlugin plugin)
|
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();
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -2648,7 +2682,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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_Unload => Loc.Localize("InstallerUnload", "Unload");
|
||||||
|
|
||||||
public static string PluginButton_SafeMode => Loc.Localize("InstallerSafeModeButton", "Can't change in safe mode");
|
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
|
#endregion
|
||||||
|
|
||||||
#region Plugin button tooltips
|
#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");
|
public static string PluginButtonToolTip_PickProfiles => Loc.Localize("InstallerPickProfiles", "Pick collections for this plugin");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,11 @@ public sealed class UiBuilder : IDisposable
|
||||||
/// Event that is fired when the plugin should open its configuration interface.
|
/// Event that is fired when the plugin should open its configuration interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action OpenConfigUi;
|
public event Action OpenConfigUi;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is fired when the plugin should open its main interface.
|
||||||
|
/// </summary>
|
||||||
|
public event Action OpenMainUi;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets an action that is called any time ImGui fonts need to be rebuilt.<br/>
|
/// 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>
|
/// </summary>
|
||||||
internal bool HasConfigUi => this.OpenConfigUi != null;
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the time this plugin took to draw on the last frame.
|
/// Gets or sets the time this plugin took to draw on the last frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -409,6 +419,14 @@ public sealed class UiBuilder : IDisposable
|
||||||
{
|
{
|
||||||
this.OpenConfigUi?.InvokeSafely();
|
this.OpenConfigUi?.InvokeSafely();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open the registered configuration UI, if it exists.
|
||||||
|
/// </summary>
|
||||||
|
internal void OpenMain()
|
||||||
|
{
|
||||||
|
this.OpenMainUi?.InvokeSafely();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Notify this UiBuilder about plugin UI being hidden.
|
/// Notify this UiBuilder about plugin UI being hidden.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue