Skip to content

Commit 2e6cb6e

Browse files
authored
- Add chat notification back to AutoUpdate (#2146)
- ImRaii UI elements in AutoUpdate tab - Fix scoping in IconButton
1 parent f7ef68d commit 2e6cb6e

File tree

5 files changed

+166
-114
lines changed

5 files changed

+166
-114
lines changed

Dalamud/Configuration/Internal/DalamudConfiguration.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
249249
/// Gets or sets a value indicating whether or not docking should be globally enabled in ImGui.
250250
/// </summary>
251251
public bool IsDocking { get; set; }
252-
252+
253253
/// <summary>
254254
/// Gets or sets a value indicating whether or not plugin user interfaces should trigger sound effects.
255255
/// This setting is effected by the in-game "System Sounds" option and volume.
@@ -484,10 +484,15 @@ public string EffectiveLanguage
484484
public AutoUpdateBehavior? AutoUpdateBehavior { get; set; } = null;
485485

486486
/// <summary>
487-
/// Gets or sets a value indicating whether or not users should be notified regularly about pending updates.
487+
/// Gets or sets a value indicating whether users should be notified regularly about pending updates.
488488
/// </summary>
489489
public bool CheckPeriodicallyForUpdates { get; set; } = true;
490490

491+
/// <summary>
492+
/// Gets or sets a value indicating whether users should be notified about updates in chat.
493+
/// </summary>
494+
public bool SendUpdateNotificationToChat { get; set; } = false;
495+
491496
/// <summary>
492497
/// Load a configuration from the provided path.
493498
/// </summary>
@@ -504,7 +509,7 @@ public static DalamudConfiguration Load(string path, ReliableFileStorage fs)
504509
{
505510
deserialized =
506511
JsonConvert.DeserializeObject<DalamudConfiguration>(text, SerializerSettings);
507-
512+
508513
// If this reads as null, the file was empty, that's no good
509514
if (deserialized == null)
510515
throw new Exception("Read config was null.");
@@ -530,7 +535,7 @@ public static DalamudConfiguration Load(string path, ReliableFileStorage fs)
530535
{
531536
Log.Error(e, "Failed to set defaults for DalamudConfiguration");
532537
}
533-
538+
534539
return deserialized;
535540
}
536541

@@ -549,7 +554,7 @@ public void ForceSave()
549554
{
550555
this.Save();
551556
}
552-
557+
553558
/// <inheritdoc/>
554559
void IInternalDisposableService.DisposeService()
555560
{
@@ -595,14 +600,14 @@ private void SetDefaults()
595600
this.ReduceMotions = winAnimEnabled == 0;
596601
}
597602
}
598-
603+
599604
// Migrate old auto-update setting to new auto-update behavior
600605
this.AutoUpdateBehavior ??= this.AutoUpdatePlugins
601606
? Plugin.Internal.AutoUpdate.AutoUpdateBehavior.UpdateAll
602607
: Plugin.Internal.AutoUpdate.AutoUpdateBehavior.OnlyNotify;
603608
#pragma warning restore CS0618
604609
}
605-
610+
606611
private void Save()
607612
{
608613
ThreadSafety.AssertMainThread();

Dalamud/Interface/Components/ImGuiComponents.IconButton.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,14 @@ public static bool IconButtonWithText(FontAwesomeIcon icon, string text, Vector4
272272
/// <returns>Width.</returns>
273273
public static float GetIconButtonWithTextWidth(FontAwesomeIcon icon, string text)
274274
{
275+
Vector2 iconSize;
275276
using (ImRaii.PushFont(UiBuilder.IconFont))
276277
{
277-
var iconSize = ImGui.CalcTextSize(icon.ToIconString());
278-
279-
var textSize = ImGui.CalcTextSize(text);
280-
281-
var iconPadding = 3 * ImGuiHelpers.GlobalScale;
282-
283-
return iconSize.X + textSize.X + (ImGui.GetStyle().FramePadding.X * 2) + iconPadding;
278+
iconSize = ImGui.CalcTextSize(icon.ToIconString());
284279
}
280+
281+
var textSize = ImGui.CalcTextSize(text);
282+
var iconPadding = 3 * ImGuiHelpers.GlobalScale;
283+
return iconSize.X + textSize.X + (ImGui.GetStyle().FramePadding.X * 2) + iconPadding;
285284
}
286285
}

Dalamud/Interface/Internal/DesignSystem/DalamudComponents.PluginPicker.cs

+7-9
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ internal static uint DrawPluginPicker(string id, ref string pickerSearch, Action
3232
var pm = Service<PluginManager>.GetNullable();
3333
if (pm == null)
3434
return 0;
35-
35+
3636
var addPluginToProfilePopupId = ImGui.GetID(id);
3737
using var popup = ImRaii.Popup(id);
3838

3939
if (popup.Success)
4040
{
4141
var width = ImGuiHelpers.GlobalScale * 300;
42-
42+
4343
ImGui.SetNextItemWidth(width);
4444
ImGui.InputTextWithHint("###pluginPickerSearch", Locs.SearchHint, ref pickerSearch, 255);
4545

4646
var currentSearchString = pickerSearch;
47-
if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
47+
48+
using var listBox = ImRaii.ListBox("###pluginPicker", new Vector2(width, width - 80));
49+
if (listBox.Success)
4850
{
4951
// TODO: Plugin searching should be abstracted... installer and this should use the same search
5052
var plugins = pm.InstalledPlugins.Where(
@@ -53,19 +55,15 @@ internal static uint DrawPluginPicker(string id, ref string pickerSearch, Action
5355
currentSearchString,
5456
StringComparison.InvariantCultureIgnoreCase)))
5557
.Where(pluginFiltered ?? (_ => true));
56-
58+
5759
foreach (var plugin in plugins)
5860
{
59-
using var disabled2 =
60-
ImRaii.Disabled(pluginDisabled(plugin));
61-
61+
using var disabled2 = ImRaii.Disabled(pluginDisabled(plugin));
6262
if (ImGui.Selectable($"{plugin.Manifest.Name}{(plugin is LocalDevPlugin ? "(dev plugin)" : string.Empty)}###selector{plugin.Manifest.InternalName}"))
6363
{
6464
onClicked(plugin);
6565
}
6666
}
67-
68-
ImGui.EndListBox();
6967
}
7068
}
7169

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

+40-36
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ public class SettingsTabAutoUpdates : SettingsTab
2323
{
2424
private AutoUpdateBehavior behavior;
2525
private bool checkPeriodically;
26+
private bool chatNotification;
2627
private string pickerSearch = string.Empty;
2728
private List<AutoUpdatePreference> autoUpdatePreferences = [];
28-
29-
public override SettingsEntry[] Entries { get; } = Array.Empty<SettingsEntry>();
29+
30+
public override SettingsEntry[] Entries { get; } = [];
3031

3132
public override string Title => Loc.Localize("DalamudSettingsAutoUpdates", "Auto-Updates");
3233

@@ -36,15 +37,15 @@ public override void Draw()
3637
"Dalamud can update your plugins automatically, making sure that you always " +
3738
"have the newest features and bug fixes. You can choose when and how auto-updates are run here."));
3839
ImGuiHelpers.ScaledDummy(2);
39-
40+
4041
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdateDisclaimer1",
4142
"You can always update your plugins manually by clicking the update button in the plugin list. " +
4243
"You can also opt into updates for specific plugins by right-clicking them and selecting \"Always auto-update\"."));
4344
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdateDisclaimer2",
4445
"Dalamud will only notify you about updates while you are idle."));
45-
46+
4647
ImGuiHelpers.ScaledDummy(8);
47-
48+
4849
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudWhite, Loc.Localize("DalamudSettingsAutoUpdateBehavior",
4950
"When the game starts..."));
5051
var behaviorInt = (int)this.behavior;
@@ -62,46 +63,47 @@ public override void Draw()
6263
"These updates are not reviewed by the Dalamud team and may contain malicious code.");
6364
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudOrange, warning);
6465
}
65-
66+
6667
ImGuiHelpers.ScaledDummy(8);
67-
68+
69+
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdateChatMessage", "Show notification about updates available in chat"), ref this.chatNotification);
6870
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdatePeriodically", "Periodically check for new updates while playing"), ref this.checkPeriodically);
6971
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdatePeriodicallyHint",
7072
"Plugins won't update automatically after startup, you will only receive a notification while you are not actively playing."));
71-
73+
7274
ImGuiHelpers.ScaledDummy(5);
7375
ImGui.Separator();
7476
ImGuiHelpers.ScaledDummy(5);
75-
77+
7678
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudWhite, Loc.Localize("DalamudSettingsAutoUpdateOptedIn",
7779
"Per-plugin overrides"));
78-
80+
7981
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudWhite, Loc.Localize("DalamudSettingsAutoUpdateOverrideHint",
8082
"Here, you can choose to receive or not to receive updates for specific plugins. " +
8183
"This will override the settings above for the selected plugins."));
8284

8385
if (this.autoUpdatePreferences.Count == 0)
8486
{
8587
ImGuiHelpers.ScaledDummy(20);
86-
88+
8789
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudGrey))
8890
{
8991
ImGuiHelpers.CenteredText(Loc.Localize("DalamudSettingsAutoUpdateOptedInHint2",
9092
"You don't have auto-update rules for any plugins."));
9193
}
92-
94+
9395
ImGuiHelpers.ScaledDummy(2);
9496
}
9597
else
9698
{
9799
ImGuiHelpers.ScaledDummy(5);
98-
100+
99101
var pic = Service<PluginImageCache>.Get();
100102

101103
var windowSize = ImGui.GetWindowSize();
102104
var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale;
103105
Guid? wantRemovePluginGuid = null;
104-
106+
105107
foreach (var preference in this.autoUpdatePreferences)
106108
{
107109
var pmPlugin = Service<PluginManager>.Get().InstalledPlugins
@@ -120,11 +122,12 @@ public override void Draw()
120122
if (pmPlugin.IsDev)
121123
{
122124
ImGui.SetCursorPos(cursorBeforeIcon);
123-
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.7f);
124-
ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight));
125-
ImGui.PopStyleVar();
125+
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, 0.7f))
126+
{
127+
ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight));
128+
}
126129
}
127-
130+
128131
ImGui.SameLine();
129132

130133
var text = $"{pmPlugin.Name}{(pmPlugin.IsDev ? " (dev plugin" : string.Empty)}";
@@ -147,7 +150,7 @@ public override void Draw()
147150

148151
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (textHeight.Y / 2));
149152
ImGui.TextUnformatted(text);
150-
153+
151154
ImGui.SetCursorPos(before);
152155
}
153156

@@ -166,19 +169,18 @@ string OptKindToString(AutoUpdatePreference.OptKind kind)
166169
}
167170

168171
ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 250);
169-
if (ImGui.BeginCombo(
170-
$"###autoUpdateBehavior{preference.WorkingPluginId}",
171-
OptKindToString(preference.Kind)))
172+
using (var combo = ImRaii.Combo($"###autoUpdateBehavior{preference.WorkingPluginId}", OptKindToString(preference.Kind)))
172173
{
173-
foreach (var kind in Enum.GetValues<AutoUpdatePreference.OptKind>())
174+
if (combo.Success)
174175
{
175-
if (ImGui.Selectable(OptKindToString(kind)))
176+
foreach (var kind in Enum.GetValues<AutoUpdatePreference.OptKind>())
176177
{
177-
preference.Kind = kind;
178+
if (ImGui.Selectable(OptKindToString(kind)))
179+
{
180+
preference.Kind = kind;
181+
}
178182
}
179183
}
180-
181-
ImGui.EndCombo();
182184
}
183185

184186
ImGui.SameLine();
@@ -193,7 +195,7 @@ string OptKindToString(AutoUpdatePreference.OptKind kind)
193195
if (ImGui.IsItemHovered())
194196
ImGui.SetTooltip(Loc.Localize("DalamudSettingsAutoUpdateOptInRemove", "Remove this override"));
195197
}
196-
198+
197199
if (wantRemovePluginGuid != null)
198200
{
199201
this.autoUpdatePreferences.RemoveAll(x => x.WorkingPluginId == wantRemovePluginGuid);
@@ -205,19 +207,19 @@ void OnPluginPicked(LocalPlugin plugin)
205207
var id = plugin.EffectiveWorkingPluginId;
206208
if (id == Guid.Empty)
207209
throw new InvalidOperationException("Plugin ID is empty.");
208-
210+
209211
this.autoUpdatePreferences.Add(new AutoUpdatePreference(id));
210212
}
211-
213+
212214
bool IsPluginDisabled(LocalPlugin plugin)
213215
=> this.autoUpdatePreferences.Any(x => x.WorkingPluginId == plugin.EffectiveWorkingPluginId);
214-
216+
215217
bool IsPluginFiltered(LocalPlugin plugin)
216218
=> !plugin.IsDev;
217-
219+
218220
var pickerId = DalamudComponents.DrawPluginPicker(
219221
"###autoUpdatePicker", ref this.pickerSearch, OnPluginPicked, IsPluginDisabled, IsPluginFiltered);
220-
222+
221223
const FontAwesomeIcon addButtonIcon = FontAwesomeIcon.Plus;
222224
var addButtonText = Loc.Localize("DalamudSettingsAutoUpdateOptInAdd", "Add new override");
223225
ImGuiHelpers.CenterCursorFor(ImGuiComponents.GetIconButtonWithTextWidth(addButtonIcon, addButtonText));
@@ -235,20 +237,22 @@ public override void Load()
235237
var configuration = Service<DalamudConfiguration>.Get();
236238

237239
this.behavior = configuration.AutoUpdateBehavior ?? AutoUpdateBehavior.None;
240+
this.chatNotification = configuration.SendUpdateNotificationToChat;
238241
this.checkPeriodically = configuration.CheckPeriodicallyForUpdates;
239242
this.autoUpdatePreferences = configuration.PluginAutoUpdatePreferences;
240-
243+
241244
base.Load();
242245
}
243246

244247
public override void Save()
245248
{
246249
var configuration = Service<DalamudConfiguration>.Get();
247-
250+
248251
configuration.AutoUpdateBehavior = this.behavior;
252+
configuration.SendUpdateNotificationToChat = this.chatNotification;
249253
configuration.CheckPeriodicallyForUpdates = this.checkPeriodically;
250254
configuration.PluginAutoUpdatePreferences = this.autoUpdatePreferences;
251-
255+
252256
base.Save();
253257
}
254258
}

0 commit comments

Comments
 (0)