Skip to content

Commit be252ba

Browse files
authored
Merge pull request #2161 from goaaats/feat/stabilize_window_additions
Stabilize WindowSystem additional options menu
2 parents 49a18e3 + 35b4982 commit be252ba

File tree

9 files changed

+301
-80
lines changed

9 files changed

+301
-80
lines changed

Dalamud/Configuration/Internal/DalamudConfiguration.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Dalamud.Interface.Internal;
1313
using Dalamud.Interface.Internal.ReShadeHandling;
1414
using Dalamud.Interface.Style;
15+
using Dalamud.Interface.Windowing.Persistence;
1516
using Dalamud.IoC.Internal;
1617
using Dalamud.Plugin.Internal.AutoUpdate;
1718
using Dalamud.Plugin.Internal.Profiles;
@@ -264,8 +265,7 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
264265
/// Gets or sets a value indicating whether or not an additional button allowing pinning and clickthrough options should be shown
265266
/// on plugin title bars when using the Window System.
266267
/// </summary>
267-
[JsonProperty("EnablePluginUiAdditionalOptionsExperimental")]
268-
public bool EnablePluginUiAdditionalOptions { get; set; } = false;
268+
public bool EnablePluginUiAdditionalOptions { get; set; } = true;
269269

270270
/// <summary>
271271
/// Gets or sets a value indicating whether viewports should always be disabled.
@@ -351,6 +351,11 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
351351
/// </summary>
352352
public bool ProfilesHasSeenTutorial { get; set; } = false;
353353

354+
/// <summary>
355+
/// Gets or sets the default UI preset.
356+
/// </summary>
357+
public PresetModel DefaultUiPreset { get; set; } = new();
358+
354359
/// <summary>
355360
/// Gets or sets the order of DTR elements, by title.
356361
/// </summary>

Dalamud/Interface/Internal/InterfaceManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
using Dalamud.Interface.Style;
2828
using Dalamud.Interface.Utility;
2929
using Dalamud.Interface.Windowing;
30+
using Dalamud.Interface.Windowing.Persistence;
31+
using Dalamud.IoC.Internal;
3032
using Dalamud.Logging.Internal;
3133
using Dalamud.Utility;
3234
using Dalamud.Utility.Timing;
@@ -60,6 +62,7 @@ namespace Dalamud.Interface.Internal;
6062
/// This class manages interaction with the ImGui interface.
6163
/// </summary>
6264
[ServiceManager.EarlyLoadedService]
65+
[InherentDependency<WindowSystemPersistence>] // Used by window system windows to restore state from the configuration
6366
internal partial class InterfaceManager : IInternalDisposableService
6467
{
6568
/// <summary>

Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@ public class SettingsTabExperimental : SettingsTab
3939

4040
new GapSettingsEntry(5),
4141

42-
new SettingsEntry<bool>(
43-
Loc.Localize(
44-
"DalamudSettingEnablePluginUIAdditionalOptions",
45-
"Add a button to the title bar of plugin windows to open additional options"),
46-
Loc.Localize(
47-
"DalamudSettingEnablePluginUIAdditionalOptionsHint",
48-
"This will allow you to pin certain plugin windows, make them clickthrough or adjust their opacity.\nThis may not be supported by all of your plugins. Contact the plugin author if you want them to support this feature."),
49-
c => c.EnablePluginUiAdditionalOptions,
50-
(v, c) => c.EnablePluginUiAdditionalOptions = v),
51-
52-
new GapSettingsEntry(5),
53-
5442
new ButtonSettingsEntry(
5543
Loc.Localize("DalamudSettingsClearHidden", "Clear hidden plugins"),
5644
Loc.Localize(
@@ -65,7 +53,7 @@ public class SettingsTabExperimental : SettingsTab
6553
new GapSettingsEntry(5, true),
6654

6755
new DevPluginsSettingsEntry(),
68-
56+
6957
new SettingsEntry<bool>(
7058
Loc.Localize(
7159
"DalamudSettingEnableImGuiAsserts",
@@ -75,7 +63,7 @@ public class SettingsTabExperimental : SettingsTab
7563
"If this setting is enabled, a window containing further details will be shown when an internal assertion in ImGui fails.\nWe recommend enabling this when developing plugins."),
7664
c => Service<InterfaceManager>.Get().ShowAsserts,
7765
(v, _) => Service<InterfaceManager>.Get().ShowAsserts = v),
78-
66+
7967
new SettingsEntry<bool>(
8068
Loc.Localize(
8169
"DalamudSettingEnableImGuiAssertsAtStartup",

Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Dalamud.Interface.Internal.Windows.Settings.Tabs;
2424
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Internals")]
2525
public class SettingsTabLook : SettingsTab
2626
{
27-
private static readonly (string, float)[] GlobalUiScalePresets =
27+
private static readonly (string, float)[] GlobalUiScalePresets =
2828
{
2929
("80%##DalamudSettingsGlobalUiScaleReset96", 0.8f),
3030
("100%##DalamudSettingsGlobalUiScaleReset12", 1f),
@@ -107,7 +107,17 @@ private static readonly (string, float)[] GlobalUiScalePresets =
107107
Loc.Localize("DalamudSettingToggleDockingHint", "This will allow you to fuse and tab plugin windows."),
108108
c => c.IsDocking,
109109
(v, c) => c.IsDocking = v),
110-
110+
111+
new SettingsEntry<bool>(
112+
Loc.Localize(
113+
"DalamudSettingEnablePluginUIAdditionalOptions",
114+
"Add a button to the title bar of plugin windows to open additional options"),
115+
Loc.Localize(
116+
"DalamudSettingEnablePluginUIAdditionalOptionsHint",
117+
"This will allow you to pin certain plugin windows, make them clickthrough or adjust their opacity.\nThis may not be supported by all of your plugins. Contact the plugin author if you want them to support this feature."),
118+
c => c.EnablePluginUiAdditionalOptions,
119+
(v, c) => c.EnablePluginUiAdditionalOptions = v),
120+
111121
new SettingsEntry<bool>(
112122
Loc.Localize("DalamudSettingEnablePluginUISoundEffects", "Enable sound effects for plugin windows"),
113123
Loc.Localize("DalamudSettingEnablePluginUISoundEffectsHint", "This will allow you to enable or disable sound effects generated by plugin user interfaces.\nThis is affected by your in-game `System Sounds` volume settings."),
@@ -125,19 +135,19 @@ private static readonly (string, float)[] GlobalUiScalePresets =
125135
Loc.Localize("DalamudSettingToggleTsmHint", "This will allow you to access certain Dalamud and Plugin functionality from the title screen.\nDisabling this will also hide the Dalamud version text on the title screen."),
126136
c => c.ShowTsm,
127137
(v, c) => c.ShowTsm = v),
128-
138+
129139
new SettingsEntry<bool>(
130140
Loc.Localize("DalamudSettingInstallerOpenDefault", "Open the Plugin Installer to the \"Installed Plugins\" tab by default"),
131141
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."),
132142
c => c.PluginInstallerOpen == PluginInstallerOpenKind.InstalledPlugins,
133143
(v, c) => c.PluginInstallerOpen = v ? PluginInstallerOpenKind.InstalledPlugins : PluginInstallerOpenKind.AllPlugins),
134-
144+
135145
new SettingsEntry<bool>(
136146
Loc.Localize("DalamudSettingReducedMotion", "Reduce motions"),
137147
Loc.Localize("DalamudSettingReducedMotionHint", "This will suppress certain animations from Dalamud, such as the notification popup."),
138148
c => c.ReduceMotions ?? false,
139149
(v, c) => c.ReduceMotions = v),
140-
150+
141151
new SettingsEntry<float>(
142152
Loc.Localize("DalamudSettingImeStateIndicatorOpacity", "IME State Indicator Opacity (CJK only)"),
143153
Loc.Localize("DalamudSettingImeStateIndicatorOpacityHint", "When any of CJK IMEs is in use, the state of IME will be shown with the opacity specified here."),
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Collections.Generic;
2+
3+
using Newtonsoft.Json;
4+
5+
namespace Dalamud.Interface.Windowing.Persistence;
6+
7+
/// <summary>
8+
/// Class representing a Window System preset.
9+
/// </summary>
10+
internal class PresetModel
11+
{
12+
/// <summary>
13+
/// Gets or sets the ID of this preset.
14+
/// </summary>
15+
[JsonProperty("id")]
16+
public Guid Id { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the name of this preset.
20+
/// </summary>
21+
[JsonProperty("n")]
22+
public string Name { get; set; } = "New Preset";
23+
24+
/// <summary>
25+
/// Gets or sets a dictionary containing the windows in the preset, mapping their ID to the preset.
26+
/// </summary>
27+
[JsonProperty("w")]
28+
public Dictionary<uint, PresetWindow> Windows { get; set; } = new();
29+
30+
/// <summary>
31+
/// Class representing a window in a preset.
32+
/// </summary>
33+
internal class PresetWindow
34+
{
35+
/// <summary>
36+
/// Gets or sets a value indicating whether the window is pinned.
37+
/// </summary>
38+
[JsonProperty("p")]
39+
public bool IsPinned { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets a value indicating whether the window is clickthrough.
43+
/// </summary>
44+
[JsonProperty("ct")]
45+
public bool IsClickThrough { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the window's opacity override.
49+
/// </summary>
50+
[JsonProperty("a")]
51+
public float? Alpha { get; set; }
52+
}
53+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Dalamud.Configuration.Internal;
2+
3+
namespace Dalamud.Interface.Windowing.Persistence;
4+
5+
/// <summary>
6+
/// Class handling persistence for window system windows.
7+
/// </summary>
8+
[ServiceManager.EarlyLoadedService]
9+
internal class WindowSystemPersistence : IServiceType
10+
{
11+
[ServiceManager.ServiceDependency]
12+
private readonly DalamudConfiguration config = Service<DalamudConfiguration>.Get();
13+
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="WindowSystemPersistence"/> class.
16+
/// </summary>
17+
[ServiceManager.ServiceConstructor]
18+
public WindowSystemPersistence()
19+
{
20+
}
21+
22+
/// <summary>
23+
/// Gets the active window system preset.
24+
/// </summary>
25+
public PresetModel ActivePreset => this.config.DefaultUiPreset;
26+
27+
/// <summary>
28+
/// Get or add a window to the active preset.
29+
/// </summary>
30+
/// <param name="id">The ID of the window.</param>
31+
/// <returns>The preset window instance, or null if the preset does not contain this window.</returns>
32+
public PresetModel.PresetWindow? GetWindow(uint id)
33+
{
34+
return this.ActivePreset.Windows.TryGetValue(id, out var window) ? window : null;
35+
}
36+
37+
/// <summary>
38+
/// Persist the state of a window to the active preset.
39+
/// </summary>
40+
/// <param name="id">The ID of the window.</param>
41+
/// <param name="window">The preset window instance.</param>
42+
public void SaveWindow(uint id, PresetModel.PresetWindow window)
43+
{
44+
this.ActivePreset.Windows[id] = window;
45+
this.config.QueueSave();
46+
}
47+
}

0 commit comments

Comments
 (0)