Skip to content

Commit

Permalink
Add option to always work in temporary settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Feb 17, 2025
1 parent b7b9def commit a561e70
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 32 deletions.
1 change: 1 addition & 0 deletions Penumbra/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public bool EnableMods
public bool HidePrioritiesInSelector { get; set; } = false;
public bool HideRedrawBar { get; set; } = false;
public bool HideMachinistOffhandFromChangedItems { get; set; } = true;
public bool DefaultTemporaryMode { get; set; } = false;
public RenameField ShowRename { get; set; } = RenameField.BothDataPrio;
public int OptionGroupCollapsibleMin { get; set; } = 5;

Expand Down
9 changes: 5 additions & 4 deletions Penumbra/Mods/Settings/TemporaryModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ namespace Penumbra.Mods.Settings;

public sealed class TemporaryModSettings : ModSettings
{
public string Source = string.Empty;
public int Lock = 0;
public bool ForceInherit;
public const string OwnSource = "yourself";
public string Source = string.Empty;
public int Lock = 0;
public bool ForceInherit;

// Create default settings for a given mod.
public static TemporaryModSettings DefaultSettings(Mod mod, string source, bool enabled = false, int key = 0)
Expand All @@ -20,7 +21,7 @@ public static TemporaryModSettings DefaultSettings(Mod mod, string source, bool
public TemporaryModSettings()
{ }

public TemporaryModSettings(Mod mod, ModSettings? clone, string source, int key = 0)
public TemporaryModSettings(Mod mod, ModSettings? clone, string source = OwnSource, int key = 0)
{
Source = source;
Lock = key;
Expand Down
43 changes: 37 additions & 6 deletions Penumbra/UI/Classes/CollectionSelectHeader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Dalamud.Interface;
using ImGuiNET;
using OtterGui.Raii;
using OtterGui;
using OtterGui.Services;
using OtterGui.Text;
using OtterGui.Text.Widget;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.Interop.PathResolving;
Expand All @@ -12,18 +15,21 @@ namespace Penumbra.UI.Classes;

public class CollectionSelectHeader : IUiService
{
private readonly CollectionCombo _collectionCombo;
private readonly ActiveCollections _activeCollections;
private readonly TutorialService _tutorial;
private readonly ModSelection _selection;
private readonly CollectionResolver _resolver;
private readonly CollectionCombo _collectionCombo;
private readonly ActiveCollections _activeCollections;
private readonly TutorialService _tutorial;
private readonly ModSelection _selection;
private readonly CollectionResolver _resolver;
private readonly FontAwesomeCheckbox _temporaryCheckbox = new(FontAwesomeIcon.Stopwatch);
private readonly Configuration _config;

public CollectionSelectHeader(CollectionManager collectionManager, TutorialService tutorial, ModSelection selection,
CollectionResolver resolver)
CollectionResolver resolver, Configuration config)
{
_tutorial = tutorial;
_selection = selection;
_resolver = resolver;
_config = config;
_activeCollections = collectionManager.Active;
_collectionCombo = new CollectionCombo(collectionManager, () => collectionManager.Storage.OrderBy(c => c.Identity.Name).ToList());
}
Expand All @@ -33,6 +39,8 @@ public void Draw(bool spacing)
{
using var style = ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 0)
.Push(ImGuiStyleVar.ItemSpacing, new Vector2(0, spacing ? ImGui.GetStyle().ItemSpacing.Y : 0));
DrawTemporaryCheckbox();
ImGui.SameLine();
var comboWidth = ImGui.GetContentRegionAvail().X / 4f;
var buttonSize = new Vector2(comboWidth * 3f / 4f, 0f);
using (var _ = ImRaii.Group())
Expand All @@ -51,6 +59,29 @@ public void Draw(bool spacing)
ImGuiUtil.DrawTextButton("The currently selected collection is not used in any way.", -Vector2.UnitX, Colors.PressEnterWarningBg);
}

private void DrawTemporaryCheckbox()
{
var hold = _config.DeleteModModifier.IsActive();
using (ImRaii.PushStyle(ImGuiStyleVar.FrameBorderSize, ImUtf8.GlobalScale))
{
var tint = ImGuiCol.Text.Tinted(ColorId.TemporaryModSettingsTint);
using var color = ImRaii.PushColor(ImGuiCol.FrameBgHovered, ImGui.GetColorU32(ImGuiCol.FrameBg), !hold)
.Push(ImGuiCol.FrameBgActive, ImGui.GetColorU32(ImGuiCol.FrameBg), !hold)
.Push(ImGuiCol.CheckMark, tint)
.Push(ImGuiCol.Border, tint, _config.DefaultTemporaryMode);
if (_temporaryCheckbox.Draw("##tempCheck"u8, _config.DefaultTemporaryMode, out var newValue) && hold)
{
_config.DefaultTemporaryMode = newValue;
_config.Save();
}
}

ImUtf8.HoverTooltip(ImGuiHoveredFlags.AllowWhenDisabled,
"Toggle the temporary settings mode, where all changes you do create temporary settings first and need to be made permanent if desired.\n"u8);
if (!hold)
ImUtf8.HoverTooltip(ImGuiHoveredFlags.AllowWhenDisabled, $"Hold {_config.DeleteModModifier} while clicking to toggle.");
}

private enum CollectionState
{
Empty,
Expand Down
9 changes: 6 additions & 3 deletions Penumbra/UI/ModsTab/Groups/ModGroupDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ public sealed class ModGroupDrawer(Configuration config, CollectionManager colle
private bool _temporary;
private bool _locked;
private TemporaryModSettings? _tempSettings;
private ModSettings? _settings;

public void Draw(Mod mod, ModSettings settings, TemporaryModSettings? tempSettings)
{
if (mod.Groups.Count <= 0)
return;

_blockGroupCache.Clear();
_settings = settings;
_tempSettings = tempSettings;
_temporary = tempSettings != null;
_locked = (tempSettings?.Lock ?? 0) > 0;
Expand Down Expand Up @@ -242,10 +244,11 @@ private ModCollection Current
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void SetModSetting(IModGroup group, int groupIdx, Setting setting)
{
if (_temporary)
if (_temporary || config.DefaultTemporaryMode)
{
_tempSettings!.ForceInherit = false;
_tempSettings!.Settings[groupIdx] = setting;
_tempSettings ??= new TemporaryModSettings(group.Mod, _settings);
_tempSettings!.ForceInherit = false;
_tempSettings!.Settings[groupIdx] = setting;
collectionManager.Editor.SetTemporarySettings(Current, group.Mod, _tempSettings);
}
else
Expand Down
11 changes: 5 additions & 6 deletions Penumbra/UI/ModsTab/ModFileSystemSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ private void ToggleLeafFavorite(FileSystem<Mod>.Leaf mod)

private void DrawTemporaryOptions(FileSystem<Mod>.Leaf mod)
{
const string source = "yourself";
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index);
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index);
if (tempSettings is { Lock: > 0 })
return;

Expand All @@ -284,19 +283,19 @@ private void DrawTemporaryOptions(FileSystem<Mod>.Leaf mod)
var actual = _collectionManager.Active.Current.GetActualSettings(mod.Value.Index).Settings;
if (actual?.Enabled is true && ImUtf8.MenuItem("Disable Temporarily"u8))
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value,
new TemporaryModSettings(mod.Value, actual, source) { Enabled = false });
new TemporaryModSettings(mod.Value, actual) { Enabled = false });

if (actual is not { Enabled: true } && ImUtf8.MenuItem("Enable Temporarily"u8))
{
var newSettings = actual is null
? TemporaryModSettings.DefaultSettings(mod.Value, source, true)
: new TemporaryModSettings(mod.Value, actual, source) { Enabled = true };
? TemporaryModSettings.DefaultSettings(mod.Value, TemporaryModSettings.OwnSource, true)
: new TemporaryModSettings(mod.Value, actual) { Enabled = true };
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, newSettings);
}

if (tempSettings is null && ImUtf8.MenuItem("Turn Temporary"u8))
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value,
new TemporaryModSettings(mod.Value, actual, source));
new TemporaryModSettings(mod.Value, actual));
}

private void SetDefaultImportFolder(ModFileSystem.Folder folder)
Expand Down
27 changes: 15 additions & 12 deletions Penumbra/UI/ModsTab/ModPanelSettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ private void DrawEnabledInput()
return;

modManager.SetKnown(selection.Mod!);
if (_temporary)
if (_temporary || config.DefaultTemporaryMode)
{
selection.TemporarySettings!.ForceInherit = false;
selection.TemporarySettings!.Enabled = enabled;
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!, selection.TemporarySettings);
var temporarySettings = selection.TemporarySettings ?? new TemporaryModSettings(selection.Mod!, selection.Settings);
temporarySettings.ForceInherit = false;
temporarySettings.Enabled = enabled;
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!, temporarySettings);
}
else
{
Expand Down Expand Up @@ -154,12 +155,13 @@ private void DrawPriorityInput()
{
if (_currentPriority != settings.Priority.Value)
{
if (_temporary)
if (_temporary || config.DefaultTemporaryMode)
{
selection.TemporarySettings!.ForceInherit = false;
selection.TemporarySettings!.Priority = new ModPriority(_currentPriority.Value);
var temporarySettings = selection.TemporarySettings ?? new TemporaryModSettings(selection.Mod!, selection.Settings);
temporarySettings.ForceInherit = false;
temporarySettings.Priority = new ModPriority(_currentPriority.Value);
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!,
selection.TemporarySettings);
temporarySettings);
}
else
{
Expand Down Expand Up @@ -205,11 +207,12 @@ private void DrawRemoveSettings()
};
if (inherit)
{
if (_temporary)
if (_temporary || config.DefaultTemporaryMode)
{
selection.TemporarySettings!.ForceInherit = true;
var temporarySettings = selection.TemporarySettings ?? new TemporaryModSettings(selection.Mod!, selection.Settings);
temporarySettings.ForceInherit = true;
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!,
selection.TemporarySettings);
temporarySettings);
}
else
{
Expand Down Expand Up @@ -252,7 +255,7 @@ private void DrawRemoveSettings()
var actual = collectionManager.Active.Current.GetActualSettings(selection.Mod!.Index).Settings;
if (ImUtf8.ButtonEx("Turn Temporary"u8, "Copy the current settings over to temporary settings to experiment with them."u8))
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!,
new TemporaryModSettings(selection.Mod!, actual, "yourself"));
new TemporaryModSettings(selection.Mod!, actual));
}
}
}
4 changes: 3 additions & 1 deletion Penumbra/UI/Tabs/SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ private void DrawMiscSettings()
Checkbox("Automatically Select Character-Associated Collection",
"On every login, automatically select the collection associated with the current character as the current collection for editing.",
_config.AutoSelectCollection, _autoSelector.SetAutomaticSelection);

Checkbox("Print Chat Command Success Messages to Chat",
"Chat Commands usually print messages on failure but also on success to confirm your action. You can disable this here.",
_config.PrintSuccessfulCommandsToChat, v => _config.PrintSuccessfulCommandsToChat = v);
Expand Down Expand Up @@ -618,6 +617,9 @@ private void DrawModSelectorSettings()
/// <summary> Draw all settings pertaining to import and export of mods. </summary>
private void DrawModHandlingSettings()
{
Checkbox("Use Temporary Settings Per Default",
"When you make any changes to your collection, apply them as temporary changes first and require a click to 'turn permanent' if you want to keep them.",
_config.DefaultTemporaryMode, v => _config.DefaultTemporaryMode = v);
Checkbox("Replace Non-Standard Symbols On Import",
"Replace all non-ASCII symbols in mod and option names with underscores when importing mods.", _config.ReplaceNonAsciiOnImport,
v => _config.ReplaceNonAsciiOnImport = v);
Expand Down

0 comments on commit a561e70

Please sign in to comment.