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.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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3237,11 +3271,17 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
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_OpenConfiguration => Loc.Localize("InstallerOpenConfig", "Open Configuration");
|
||||
public static string PluginButtonToolTip_OpenUi => Loc.Localize("InstallerTooltipOpenUi", "Open this plugin's interface");
|
||||
|
||||
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");
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,11 @@ public sealed class UiBuilder : IDisposable
|
|||
/// </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/>
|
||||
/// Any ImFontPtr objects that you store <strong>can be invalidated</strong> when fonts are rebuilt
|
||||
|
|
@ -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>
|
||||
|
|
@ -410,6 +420,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.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue