mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-01 21:33:39 +01:00
- Add chat notification back to AutoUpdate (#2146)
- ImRaii UI elements in AutoUpdate tab - Fix scoping in IconButton
This commit is contained in:
parent
f7ef68d65e
commit
2e6cb6ef00
5 changed files with 166 additions and 114 deletions
|
|
@ -272,15 +272,14 @@ public static partial class ImGuiComponents
|
|||
/// <returns>Width.</returns>
|
||||
public static float GetIconButtonWithTextWidth(FontAwesomeIcon icon, string text)
|
||||
{
|
||||
Vector2 iconSize;
|
||||
using (ImRaii.PushFont(UiBuilder.IconFont))
|
||||
{
|
||||
var iconSize = ImGui.CalcTextSize(icon.ToIconString());
|
||||
|
||||
var textSize = ImGui.CalcTextSize(text);
|
||||
|
||||
var iconPadding = 3 * ImGuiHelpers.GlobalScale;
|
||||
|
||||
return iconSize.X + textSize.X + (ImGui.GetStyle().FramePadding.X * 2) + iconPadding;
|
||||
iconSize = ImGui.CalcTextSize(icon.ToIconString());
|
||||
}
|
||||
|
||||
var textSize = ImGui.CalcTextSize(text);
|
||||
var iconPadding = 3 * ImGuiHelpers.GlobalScale;
|
||||
return iconSize.X + textSize.X + (ImGui.GetStyle().FramePadding.X * 2) + iconPadding;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,19 +32,21 @@ internal static partial class DalamudComponents
|
|||
var pm = Service<PluginManager>.GetNullable();
|
||||
if (pm == null)
|
||||
return 0;
|
||||
|
||||
|
||||
var addPluginToProfilePopupId = ImGui.GetID(id);
|
||||
using var popup = ImRaii.Popup(id);
|
||||
|
||||
if (popup.Success)
|
||||
{
|
||||
var width = ImGuiHelpers.GlobalScale * 300;
|
||||
|
||||
|
||||
ImGui.SetNextItemWidth(width);
|
||||
ImGui.InputTextWithHint("###pluginPickerSearch", Locs.SearchHint, ref pickerSearch, 255);
|
||||
|
||||
var currentSearchString = pickerSearch;
|
||||
if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
|
||||
|
||||
using var listBox = ImRaii.ListBox("###pluginPicker", new Vector2(width, width - 80));
|
||||
if (listBox.Success)
|
||||
{
|
||||
// TODO: Plugin searching should be abstracted... installer and this should use the same search
|
||||
var plugins = pm.InstalledPlugins.Where(
|
||||
|
|
@ -53,19 +55,15 @@ internal static partial class DalamudComponents
|
|||
currentSearchString,
|
||||
StringComparison.InvariantCultureIgnoreCase)))
|
||||
.Where(pluginFiltered ?? (_ => true));
|
||||
|
||||
|
||||
foreach (var plugin in plugins)
|
||||
{
|
||||
using var disabled2 =
|
||||
ImRaii.Disabled(pluginDisabled(plugin));
|
||||
|
||||
using var disabled2 = ImRaii.Disabled(pluginDisabled(plugin));
|
||||
if (ImGui.Selectable($"{plugin.Manifest.Name}{(plugin is LocalDevPlugin ? "(dev plugin)" : string.Empty)}###selector{plugin.Manifest.InternalName}"))
|
||||
{
|
||||
onClicked(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndListBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
{
|
||||
private AutoUpdateBehavior behavior;
|
||||
private bool checkPeriodically;
|
||||
private bool chatNotification;
|
||||
private string pickerSearch = string.Empty;
|
||||
private List<AutoUpdatePreference> autoUpdatePreferences = [];
|
||||
|
||||
public override SettingsEntry[] Entries { get; } = Array.Empty<SettingsEntry>();
|
||||
|
||||
public override SettingsEntry[] Entries { get; } = [];
|
||||
|
||||
public override string Title => Loc.Localize("DalamudSettingsAutoUpdates", "Auto-Updates");
|
||||
|
||||
|
|
@ -36,15 +37,15 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
"Dalamud can update your plugins automatically, making sure that you always " +
|
||||
"have the newest features and bug fixes. You can choose when and how auto-updates are run here."));
|
||||
ImGuiHelpers.ScaledDummy(2);
|
||||
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdateDisclaimer1",
|
||||
"You can always update your plugins manually by clicking the update button in the plugin list. " +
|
||||
"You can also opt into updates for specific plugins by right-clicking them and selecting \"Always auto-update\"."));
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdateDisclaimer2",
|
||||
"Dalamud will only notify you about updates while you are idle."));
|
||||
|
||||
|
||||
ImGuiHelpers.ScaledDummy(8);
|
||||
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudWhite, Loc.Localize("DalamudSettingsAutoUpdateBehavior",
|
||||
"When the game starts..."));
|
||||
var behaviorInt = (int)this.behavior;
|
||||
|
|
@ -62,20 +63,21 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
"These updates are not reviewed by the Dalamud team and may contain malicious code.");
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudOrange, warning);
|
||||
}
|
||||
|
||||
|
||||
ImGuiHelpers.ScaledDummy(8);
|
||||
|
||||
|
||||
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdateChatMessage", "Show notification about updates available in chat"), ref this.chatNotification);
|
||||
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdatePeriodically", "Periodically check for new updates while playing"), ref this.checkPeriodically);
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdatePeriodicallyHint",
|
||||
"Plugins won't update automatically after startup, you will only receive a notification while you are not actively playing."));
|
||||
|
||||
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
ImGui.Separator();
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudWhite, Loc.Localize("DalamudSettingsAutoUpdateOptedIn",
|
||||
"Per-plugin overrides"));
|
||||
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudWhite, Loc.Localize("DalamudSettingsAutoUpdateOverrideHint",
|
||||
"Here, you can choose to receive or not to receive updates for specific plugins. " +
|
||||
"This will override the settings above for the selected plugins."));
|
||||
|
|
@ -83,25 +85,25 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
if (this.autoUpdatePreferences.Count == 0)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(20);
|
||||
|
||||
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudGrey))
|
||||
{
|
||||
ImGuiHelpers.CenteredText(Loc.Localize("DalamudSettingsAutoUpdateOptedInHint2",
|
||||
"You don't have auto-update rules for any plugins."));
|
||||
}
|
||||
|
||||
|
||||
ImGuiHelpers.ScaledDummy(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
|
||||
var pic = Service<PluginImageCache>.Get();
|
||||
|
||||
var windowSize = ImGui.GetWindowSize();
|
||||
var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale;
|
||||
Guid? wantRemovePluginGuid = null;
|
||||
|
||||
|
||||
foreach (var preference in this.autoUpdatePreferences)
|
||||
{
|
||||
var pmPlugin = Service<PluginManager>.Get().InstalledPlugins
|
||||
|
|
@ -120,11 +122,12 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
if (pmPlugin.IsDev)
|
||||
{
|
||||
ImGui.SetCursorPos(cursorBeforeIcon);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.7f);
|
||||
ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight));
|
||||
ImGui.PopStyleVar();
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, 0.7f))
|
||||
{
|
||||
ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
var text = $"{pmPlugin.Name}{(pmPlugin.IsDev ? " (dev plugin" : string.Empty)}";
|
||||
|
|
@ -147,7 +150,7 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (textHeight.Y / 2));
|
||||
ImGui.TextUnformatted(text);
|
||||
|
||||
|
||||
ImGui.SetCursorPos(before);
|
||||
}
|
||||
|
||||
|
|
@ -166,19 +169,18 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
}
|
||||
|
||||
ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 250);
|
||||
if (ImGui.BeginCombo(
|
||||
$"###autoUpdateBehavior{preference.WorkingPluginId}",
|
||||
OptKindToString(preference.Kind)))
|
||||
using (var combo = ImRaii.Combo($"###autoUpdateBehavior{preference.WorkingPluginId}", OptKindToString(preference.Kind)))
|
||||
{
|
||||
foreach (var kind in Enum.GetValues<AutoUpdatePreference.OptKind>())
|
||||
if (combo.Success)
|
||||
{
|
||||
if (ImGui.Selectable(OptKindToString(kind)))
|
||||
foreach (var kind in Enum.GetValues<AutoUpdatePreference.OptKind>())
|
||||
{
|
||||
preference.Kind = kind;
|
||||
if (ImGui.Selectable(OptKindToString(kind)))
|
||||
{
|
||||
preference.Kind = kind;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
|
@ -193,7 +195,7 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Loc.Localize("DalamudSettingsAutoUpdateOptInRemove", "Remove this override"));
|
||||
}
|
||||
|
||||
|
||||
if (wantRemovePluginGuid != null)
|
||||
{
|
||||
this.autoUpdatePreferences.RemoveAll(x => x.WorkingPluginId == wantRemovePluginGuid);
|
||||
|
|
@ -205,19 +207,19 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
var id = plugin.EffectiveWorkingPluginId;
|
||||
if (id == Guid.Empty)
|
||||
throw new InvalidOperationException("Plugin ID is empty.");
|
||||
|
||||
|
||||
this.autoUpdatePreferences.Add(new AutoUpdatePreference(id));
|
||||
}
|
||||
|
||||
|
||||
bool IsPluginDisabled(LocalPlugin plugin)
|
||||
=> this.autoUpdatePreferences.Any(x => x.WorkingPluginId == plugin.EffectiveWorkingPluginId);
|
||||
|
||||
|
||||
bool IsPluginFiltered(LocalPlugin plugin)
|
||||
=> !plugin.IsDev;
|
||||
|
||||
|
||||
var pickerId = DalamudComponents.DrawPluginPicker(
|
||||
"###autoUpdatePicker", ref this.pickerSearch, OnPluginPicked, IsPluginDisabled, IsPluginFiltered);
|
||||
|
||||
|
||||
const FontAwesomeIcon addButtonIcon = FontAwesomeIcon.Plus;
|
||||
var addButtonText = Loc.Localize("DalamudSettingsAutoUpdateOptInAdd", "Add new override");
|
||||
ImGuiHelpers.CenterCursorFor(ImGuiComponents.GetIconButtonWithTextWidth(addButtonIcon, addButtonText));
|
||||
|
|
@ -235,20 +237,22 @@ public class SettingsTabAutoUpdates : SettingsTab
|
|||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
|
||||
this.behavior = configuration.AutoUpdateBehavior ?? AutoUpdateBehavior.None;
|
||||
this.chatNotification = configuration.SendUpdateNotificationToChat;
|
||||
this.checkPeriodically = configuration.CheckPeriodicallyForUpdates;
|
||||
this.autoUpdatePreferences = configuration.PluginAutoUpdatePreferences;
|
||||
|
||||
|
||||
base.Load();
|
||||
}
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
|
||||
|
||||
configuration.AutoUpdateBehavior = this.behavior;
|
||||
configuration.SendUpdateNotificationToChat = this.chatNotification;
|
||||
configuration.CheckPeriodicallyForUpdates = this.checkPeriodically;
|
||||
configuration.PluginAutoUpdatePreferences = this.autoUpdatePreferences;
|
||||
|
||||
|
||||
base.Save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue