mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-19 14:27:45 +01:00
DalamudPluginInterface functions for opening Settings and DevMenu (#1795)
* Add functions for plugins to open the Developer Menu and Dalamud Settings windows * Do not break ABI by instead declaring a new method OpenPluginsInstallerTo Replace OpenDalamudSettings with OpenDalamudSettingsTo
This commit is contained in:
parent
5dd627d18e
commit
00311b4dca
10 changed files with 335 additions and 112 deletions
|
|
@ -2,6 +2,7 @@ using System.Linq;
|
|||
using System.Numerics;
|
||||
|
||||
using CheapLoc;
|
||||
|
||||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Internal.Windows.Settings.Tabs;
|
||||
|
|
@ -10,6 +11,7 @@ using Dalamud.Interface.Utility;
|
|||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Utility;
|
||||
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.Settings;
|
||||
|
|
@ -22,6 +24,9 @@ internal class SettingsWindow : Window
|
|||
private SettingsTab[]? tabs;
|
||||
|
||||
private string searchInput = string.Empty;
|
||||
private bool isSearchInputPrefilled = false;
|
||||
|
||||
private SettingsTab setActiveTab = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SettingsWindow"/> class.
|
||||
|
|
@ -39,6 +44,34 @@ internal class SettingsWindow : Window
|
|||
this.SizeCondition = ImGuiCond.FirstUseEver;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the settings window to the tab specified by <paramref name="kind"/>.
|
||||
/// </summary>
|
||||
/// <param name="kind">The tab of the settings window to open.</param>
|
||||
public void OpenTo(SettingsOpenKind kind)
|
||||
{
|
||||
this.IsOpen = true;
|
||||
this.SetOpenTab(kind);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current search text and marks it as prefilled.
|
||||
/// </summary>
|
||||
/// <param name="text">The search term.</param>
|
||||
public void SetSearchText(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
this.isSearchInputPrefilled = false;
|
||||
this.searchInput = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.isSearchInputPrefilled = true;
|
||||
this.searchInput = text;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void OnOpen()
|
||||
{
|
||||
|
|
@ -56,7 +89,7 @@ internal class SettingsWindow : Window
|
|||
settingsTab.Load();
|
||||
}
|
||||
|
||||
this.searchInput = string.Empty;
|
||||
if (!this.isSearchInputPrefilled) this.searchInput = string.Empty;
|
||||
|
||||
base.OnOpen();
|
||||
}
|
||||
|
|
@ -84,6 +117,12 @@ internal class SettingsWindow : Window
|
|||
|
||||
settingsTab.IsOpen = false;
|
||||
}
|
||||
|
||||
if (this.isSearchInputPrefilled)
|
||||
{
|
||||
this.isSearchInputPrefilled = false;
|
||||
this.searchInput = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -97,7 +136,15 @@ internal class SettingsWindow : Window
|
|||
{
|
||||
foreach (var settingsTab in this.tabs.Where(x => x.IsVisible))
|
||||
{
|
||||
if (ImGui.BeginTabItem(settingsTab.Title))
|
||||
var flags = ImGuiTabItemFlags.NoCloseWithMiddleMouseButton;
|
||||
if (this.setActiveTab == settingsTab)
|
||||
{
|
||||
flags |= ImGuiTabItemFlags.SetSelected;
|
||||
this.setActiveTab = null;
|
||||
}
|
||||
|
||||
using var tab = ImRaii.TabItem(settingsTab.Title, flags);
|
||||
if (tab)
|
||||
{
|
||||
if (!settingsTab.IsOpen)
|
||||
{
|
||||
|
|
@ -231,4 +278,28 @@ internal class SettingsWindow : Window
|
|||
|
||||
Service<InterfaceManager>.Get().RebuildFonts();
|
||||
}
|
||||
|
||||
private void SetOpenTab(SettingsOpenKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case SettingsOpenKind.General:
|
||||
this.setActiveTab = this.tabs[0];
|
||||
break;
|
||||
case SettingsOpenKind.LookAndFeel:
|
||||
this.setActiveTab = this.tabs[1];
|
||||
break;
|
||||
case SettingsOpenKind.ServerInfoBar:
|
||||
this.setActiveTab = this.tabs[2];
|
||||
break;
|
||||
case SettingsOpenKind.Experimental:
|
||||
this.setActiveTab = this.tabs[3];
|
||||
break;
|
||||
case SettingsOpenKind.About:
|
||||
this.setActiveTab = this.tabs[4];
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,8 +128,8 @@ public class SettingsTabLook : SettingsTab
|
|||
new SettingsEntry<bool>(
|
||||
Loc.Localize("DalamudSettingInstallerOpenDefault", "Open the Plugin Installer to the \"Installed Plugins\" tab by default"),
|
||||
Loc.Localize("DalamudSettingInstallerOpenDefaultHint", "This will allow you to open the Plugin Installer to the \"Installed Plugins\" tab by default, instead of the \"Available Plugins\" tab."),
|
||||
c => c.PluginInstallerOpen == PluginInstallerWindow.PluginInstallerOpenKind.InstalledPlugins,
|
||||
(v, c) => c.PluginInstallerOpen = v ? PluginInstallerWindow.PluginInstallerOpenKind.InstalledPlugins : PluginInstallerWindow.PluginInstallerOpenKind.AllPlugins),
|
||||
c => c.PluginInstallerOpen == PluginInstallerOpenKind.InstalledPlugins,
|
||||
(v, c) => c.PluginInstallerOpen = v ? PluginInstallerOpenKind.InstalledPlugins : PluginInstallerOpenKind.AllPlugins),
|
||||
|
||||
new SettingsEntry<bool>(
|
||||
Loc.Localize("DalamudSettingReducedMotion", "Reduce motions"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue