Add some temporary context menu things.

This commit is contained in:
Ottermandias 2024-12-31 17:10:18 +01:00
parent dbef1cccb2
commit a2258e6160
2 changed files with 87 additions and 78 deletions

@ -1 +1 @@
Subproject commit fcc96daa02633f673325c14aeea6b6b568924f1e Subproject commit fd387218d2d2d237075cb35be6ca89eeb53e14e5

View file

@ -62,8 +62,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
SubscribeRightClickFolder(f => SetQuickMove(f, 1, _config.QuickMoveFolder2, s => { _config.QuickMoveFolder2 = s; _config.Save(); }), 120); SubscribeRightClickFolder(f => SetQuickMove(f, 1, _config.QuickMoveFolder2, s => { _config.QuickMoveFolder2 = s; _config.Save(); }), 120);
SubscribeRightClickFolder(f => SetQuickMove(f, 2, _config.QuickMoveFolder3, s => { _config.QuickMoveFolder3 = s; _config.Save(); }), 130); SubscribeRightClickFolder(f => SetQuickMove(f, 2, _config.QuickMoveFolder3, s => { _config.QuickMoveFolder3 = s; _config.Save(); }), 130);
SubscribeRightClickLeaf(ToggleLeafFavorite); SubscribeRightClickLeaf(ToggleLeafFavorite);
SubscribeRightClickLeaf(RemoveTemporarySettings); SubscribeRightClickLeaf(DrawTemporaryOptions);
SubscribeRightClickLeaf(DisableTemporarily);
SubscribeRightClickLeaf(l => QuickMove(l, _config.QuickMoveFolder1, _config.QuickMoveFolder2, _config.QuickMoveFolder3)); SubscribeRightClickLeaf(l => QuickMove(l, _config.QuickMoveFolder1, _config.QuickMoveFolder2, _config.QuickMoveFolder3));
SubscribeRightClickMain(ClearDefaultImportFolder, 100); SubscribeRightClickMain(ClearDefaultImportFolder, 100);
SubscribeRightClickMain(() => ClearQuickMove(0, _config.QuickMoveFolder1, () => {_config.QuickMoveFolder1 = string.Empty; _config.Save();}), 110); SubscribeRightClickMain(() => ClearQuickMove(0, _config.QuickMoveFolder1, () => {_config.QuickMoveFolder1 = string.Empty; _config.Save();}), 110);
@ -135,7 +134,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
{ {
_dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m => _dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m =>
{ {
ImGui.TextUnformatted($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}"); ImUtf8.Text($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}");
return true; return true;
}); });
base.Draw(width); base.Draw(width);
@ -198,8 +197,8 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
var flags = selected ? ImGuiTreeNodeFlags.Selected | LeafFlags : LeafFlags; var flags = selected ? ImGuiTreeNodeFlags.Selected | LeafFlags : LeafFlags;
using var c = ImRaii.PushColor(ImGuiCol.Text, state.Color.Tinted(state.Tint)) using var c = ImRaii.PushColor(ImGuiCol.Text, state.Color.Tinted(state.Tint))
.Push(ImGuiCol.HeaderHovered, 0x4000FFFF, leaf.Value.Favorite); .Push(ImGuiCol.HeaderHovered, 0x4000FFFF, leaf.Value.Favorite);
using var id = ImRaii.PushId(leaf.Value.Index); using var id = ImUtf8.PushId(leaf.Value.Index);
ImRaii.TreeNode(leaf.Value.Name, flags).Dispose(); ImUtf8.TreeNode(leaf.Value.Name.Text, flags).Dispose();
if (ImGui.IsItemClicked(ImGuiMouseButton.Middle)) if (ImGui.IsItemClicked(ImGuiMouseButton.Middle))
{ {
_modManager.SetKnown(leaf.Value); _modManager.SetKnown(leaf.Value);
@ -244,48 +243,58 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private void DisableDescendants(ModFileSystem.Folder folder) private void DisableDescendants(ModFileSystem.Folder folder)
{ {
if (ImGui.MenuItem("Disable Descendants")) if (ImUtf8.MenuItem("Disable Descendants"u8))
SetDescendants(folder, false); SetDescendants(folder, false);
} }
private void InheritDescendants(ModFileSystem.Folder folder) private void InheritDescendants(ModFileSystem.Folder folder)
{ {
if (ImGui.MenuItem("Inherit Descendants")) if (ImUtf8.MenuItem("Inherit Descendants"u8))
SetDescendants(folder, true, true); SetDescendants(folder, true, true);
} }
private void OwnDescendants(ModFileSystem.Folder folder) private void OwnDescendants(ModFileSystem.Folder folder)
{ {
if (ImGui.MenuItem("Stop Inheriting Descendants")) if (ImUtf8.MenuItem("Stop Inheriting Descendants"u8))
SetDescendants(folder, false, true); SetDescendants(folder, false, true);
} }
private void ToggleLeafFavorite(FileSystem<Mod>.Leaf mod) private void ToggleLeafFavorite(FileSystem<Mod>.Leaf mod)
{ {
if (ImGui.MenuItem(mod.Value.Favorite ? "Remove Favorite" : "Mark as Favorite")) if (ImUtf8.MenuItem(mod.Value.Favorite ? "Remove Favorite"u8 : "Mark as Favorite"u8))
_modManager.DataEditor.ChangeModFavorite(mod.Value, !mod.Value.Favorite); _modManager.DataEditor.ChangeModFavorite(mod.Value, !mod.Value.Favorite);
} }
private void RemoveTemporarySettings(FileSystem<Mod>.Leaf mod) private void DrawTemporaryOptions(FileSystem<Mod>.Leaf mod)
{ {
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index); const string source = "yourself";
if (tempSettings is { Lock: <= 0 }) var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index);
if (ImUtf8.MenuItem("Remove Temporary Settings")) if (tempSettings is { Lock: > 0 })
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, null); return;
}
private void DisableTemporarily(FileSystem<Mod>.Leaf mod) if (tempSettings is { Lock: <= 0 } && ImUtf8.MenuItem("Remove Temporary Settings"u8))
{ _collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, null);
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index); var actual = _collectionManager.Active.Current.GetActualSettings(mod.Value.Index).Settings;
if (tempSettings is not { Lock: > 0 }) if (actual?.Enabled is true && ImUtf8.MenuItem("Disable Temporarily"u8))
if (ImUtf8.MenuItem("Disable Temporarily")) _collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value,
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, new TemporaryModSettings(actual, source) { Enabled = false });
TemporaryModSettings.DefaultSettings(mod.Value, "User Context-Menu"));
if (actual is not { Enabled: true } && ImUtf8.MenuItem("Enable Temporarily"u8))
{
var newSettings = actual is null
? TemporaryModSettings.DefaultSettings(mod.Value, source, true)
: new TemporaryModSettings(actual, source) { 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(actual, source));
} }
private void SetDefaultImportFolder(ModFileSystem.Folder folder) private void SetDefaultImportFolder(ModFileSystem.Folder folder)
{ {
if (!ImGui.MenuItem("Set As Default Import Folder")) if (!ImUtf8.MenuItem("Set As Default Import Folder"u8))
return; return;
var newName = folder.FullName(); var newName = folder.FullName();
@ -298,7 +307,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private void ClearDefaultImportFolder() private void ClearDefaultImportFolder()
{ {
if (!ImGui.MenuItem("Clear Default Import Folder") || _config.DefaultImportFolder.Length <= 0) if (!ImUtf8.MenuItem("Clear Default Import Folder"u8) || _config.DefaultImportFolder.Length <= 0)
return; return;
_config.DefaultImportFolder = string.Empty; _config.DefaultImportFolder = string.Empty;
@ -309,16 +318,15 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private void AddNewModButton(Vector2 size) private void AddNewModButton(Vector2 size)
{ {
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Plus.ToIconString(), size, "Create a new, empty mod of a given name.", if (ImUtf8.IconButton(FontAwesomeIcon.Plus, "Create a new, empty mod of a given name."u8, size, !_modManager.Valid))
!_modManager.Valid, true)) ImUtf8.OpenPopup("Create New Mod"u8);
ImGui.OpenPopup("Create New Mod");
} }
/// <summary> Add an import mods button that opens a file selector. </summary> /// <summary> Add an import mods button that opens a file selector. </summary>
private void AddImportModButton(Vector2 size) private void AddImportModButton(Vector2 size)
{ {
var button = ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.FileImport.ToIconString(), size, var button = ImUtf8.IconButton(FontAwesomeIcon.FileImport,
"Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files.", !_modManager.Valid, true); "Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files."u8, size, !_modManager.Valid);
_tutorial.OpenTutorial(BasicTutorialSteps.ModImport); _tutorial.OpenTutorial(BasicTutorialSteps.ModImport);
if (!button) if (!button)
return; return;
@ -351,14 +359,14 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
var currentName = leaf.Value.Name.Text; var currentName = leaf.Value.Name.Text;
if (ImGui.IsWindowAppearing()) if (ImGui.IsWindowAppearing())
ImGui.SetKeyboardFocusHere(0); ImGui.SetKeyboardFocusHere(0);
ImGui.TextUnformatted("Rename Mod:"); ImUtf8.Text("Rename Mod:"u8);
if (ImGui.InputText("##RenameMod", ref currentName, 256, ImGuiInputTextFlags.EnterReturnsTrue)) if (ImUtf8.InputText("##RenameMod"u8, ref currentName, flags: ImGuiInputTextFlags.EnterReturnsTrue))
{ {
_modManager.DataEditor.ChangeModName(leaf.Value, currentName); _modManager.DataEditor.ChangeModName(leaf.Value, currentName);
ImGui.CloseCurrentPopup(); ImGui.CloseCurrentPopup();
} }
ImGuiUtil.HoverTooltip("Enter a new name here to rename the changed mod."); ImUtf8.HoverTooltip("Enter a new name here to rename the changed mod."u8);
} }
private void DeleteModButton(Vector2 size) private void DeleteModButton(Vector2 size)
@ -366,8 +374,8 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private void AddHelpButton(Vector2 size) private void AddHelpButton(Vector2 size)
{ {
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.QuestionCircle.ToIconString(), size, "Open extended help.", false, true)) if (ImUtf8.IconButton(FontAwesomeIcon.QuestionCircle, "Open extended help."u8, size, false))
ImGui.OpenPopup("ExtendedHelp"); ImUtf8.OpenPopup("ExtendedHelp"u8);
_tutorial.OpenTutorial(BasicTutorialSteps.AdvancedHelp); _tutorial.OpenTutorial(BasicTutorialSteps.AdvancedHelp);
} }
@ -392,60 +400,61 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
ImGuiUtil.HelpPopup("ExtendedHelp", new Vector2(1000 * UiHelpers.Scale, 38.5f * ImGui.GetTextLineHeightWithSpacing()), () => ImGuiUtil.HelpPopup("ExtendedHelp", new Vector2(1000 * UiHelpers.Scale, 38.5f * ImGui.GetTextLineHeightWithSpacing()), () =>
{ {
ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeight()); ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeight());
ImGui.TextUnformatted("Mod Management"); ImUtf8.Text("Mod Management"u8);
ImGui.BulletText("You can create empty mods or import mods with the buttons in this row."); ImUtf8.BulletText("You can create empty mods or import mods with the buttons in this row."u8);
using var indent = ImRaii.PushIndent(); using var indent = ImRaii.PushIndent();
ImGui.BulletText("Supported formats for import are: .ttmp, .ttmp2, .pmp."); ImUtf8.BulletText("Supported formats for import are: .ttmp, .ttmp2, .pmp."u8);
ImGui.BulletText( ImUtf8.BulletText(
"You can also support .zip, .7z or .rar archives, but only if they already contain Penumbra-styled mods with appropriate metadata."); "You can also support .zip, .7z or .rar archives, but only if they already contain Penumbra-styled mods with appropriate metadata."u8);
indent.Pop(1); indent.Pop(1);
ImGui.BulletText("You can also create empty mod folders and delete mods."); ImUtf8.BulletText("You can also create empty mod folders and delete mods."u8);
ImGui.BulletText("For further editing of mods, select them and use the Edit Mod tab in the panel or the Advanced Editing popup."); ImUtf8.BulletText(
"For further editing of mods, select them and use the Edit Mod tab in the panel or the Advanced Editing popup."u8);
ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeight()); ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeight());
ImGui.TextUnformatted("Mod Selector"); ImUtf8.Text("Mod Selector"u8);
ImGui.BulletText("Select a mod to obtain more information or change settings."); ImUtf8.BulletText("Select a mod to obtain more information or change settings."u8);
ImGui.BulletText("Names are colored according to your config and their current state in the collection:"); ImUtf8.BulletText("Names are colored according to your config and their current state in the collection:"u8);
indent.Push(); indent.Push();
ImGuiUtil.BulletTextColored(ColorId.EnabledMod.Value(), "enabled in the current collection."); ImUtf8.BulletTextColored(ColorId.EnabledMod.Value(), "enabled in the current collection."u8);
ImGuiUtil.BulletTextColored(ColorId.DisabledMod.Value(), "disabled in the current collection."); ImUtf8.BulletTextColored(ColorId.DisabledMod.Value(), "disabled in the current collection."u8);
ImGuiUtil.BulletTextColored(ColorId.InheritedMod.Value(), "enabled due to inheritance from another collection."); ImUtf8.BulletTextColored(ColorId.InheritedMod.Value(), "enabled due to inheritance from another collection."u8);
ImGuiUtil.BulletTextColored(ColorId.InheritedDisabledMod.Value(), "disabled due to inheritance from another collection."); ImUtf8.BulletTextColored(ColorId.InheritedDisabledMod.Value(), "disabled due to inheritance from another collection."u8);
ImGuiUtil.BulletTextColored(ColorId.UndefinedMod.Value(), "unconfigured in all inherited collections."); ImUtf8.BulletTextColored(ColorId.UndefinedMod.Value(), "unconfigured in all inherited collections."u8);
ImGuiUtil.BulletTextColored(ColorId.HandledConflictMod.Value(), ImUtf8.BulletTextColored(ColorId.HandledConflictMod.Value(),
"enabled and conflicting with another enabled Mod, but on different priorities (i.e. the conflict is solved)."); "enabled and conflicting with another enabled Mod, but on different priorities (i.e. the conflict is solved)."u8);
ImGuiUtil.BulletTextColored(ColorId.ConflictingMod.Value(), ImUtf8.BulletTextColored(ColorId.ConflictingMod.Value(),
"enabled and conflicting with another enabled Mod on the same priority."); "enabled and conflicting with another enabled Mod on the same priority."u8);
ImGuiUtil.BulletTextColored(ColorId.FolderExpanded.Value(), "expanded mod folder."); ImUtf8.BulletTextColored(ColorId.FolderExpanded.Value(), "expanded mod folder."u8);
ImGuiUtil.BulletTextColored(ColorId.FolderCollapsed.Value(), "collapsed mod folder"); ImUtf8.BulletTextColored(ColorId.FolderCollapsed.Value(), "collapsed mod folder"u8);
indent.Pop(1); indent.Pop(1);
ImGui.BulletText("Middle-click a mod to disable it if it is enabled or enable it if it is disabled."); ImUtf8.BulletText("Middle-click a mod to disable it if it is enabled or enable it if it is disabled."u8);
indent.Push(); indent.Push();
ImGui.BulletText( ImUtf8.BulletText(
$"Holding {_config.DeleteModModifier.ForcedModifier(new DoubleModifier(ModifierHotkey.Control, ModifierHotkey.Shift))} while middle-clicking lets it inherit, discarding settings."); $"Holding {_config.DeleteModModifier.ForcedModifier(new DoubleModifier(ModifierHotkey.Control, ModifierHotkey.Shift))} while middle-clicking lets it inherit, discarding settings.");
indent.Pop(1); indent.Pop(1);
ImGui.BulletText("Right-click a mod to enter its sort order, which is its name by default, possibly with a duplicate number."); ImUtf8.BulletText("Right-click a mod to enter its sort order, which is its name by default, possibly with a duplicate number."u8);
indent.Push(); indent.Push();
ImGui.BulletText("A sort order differing from the mods name will not be displayed, it will just be used for ordering."); ImUtf8.BulletText("A sort order differing from the mods name will not be displayed, it will just be used for ordering."u8);
ImGui.BulletText( ImUtf8.BulletText(
"If the sort order string contains Forward-Slashes ('/'), the preceding substring will be turned into folders automatically."); "If the sort order string contains Forward-Slashes ('/'), the preceding substring will be turned into folders automatically."u8);
indent.Pop(1); indent.Pop(1);
ImGui.BulletText( ImUtf8.BulletText(
"You can drag and drop mods and subfolders into existing folders. Dropping them onto mods is the same as dropping them onto the parent of the mod."); "You can drag and drop mods and subfolders into existing folders. Dropping them onto mods is the same as dropping them onto the parent of the mod."u8);
indent.Push(); indent.Push();
ImGui.BulletText( ImUtf8.BulletText(
"You can select multiple mods and folders by holding Control while clicking them, and then drag all of them at once."); "You can select multiple mods and folders by holding Control while clicking them, and then drag all of them at once."u8);
ImGui.BulletText( ImUtf8.BulletText(
"Selected mods inside an also selected folder will be ignored when dragging and move inside their folder instead of directly into the target."); "Selected mods inside an also selected folder will be ignored when dragging and move inside their folder instead of directly into the target."u8);
indent.Pop(1); indent.Pop(1);
ImGui.BulletText("Right-clicking a folder opens a context menu."); ImUtf8.BulletText("Right-clicking a folder opens a context menu."u8);
ImGui.BulletText("Right-clicking empty space allows you to expand or collapse all folders at once."); ImUtf8.BulletText("Right-clicking empty space allows you to expand or collapse all folders at once."u8);
ImGui.BulletText("Use the Filter Mods... input at the top to filter the list for mods whose name or path contain the text."); ImUtf8.BulletText("Use the Filter Mods... input at the top to filter the list for mods whose name or path contain the text."u8);
indent.Push(); indent.Push();
ImGui.BulletText("You can enter n:[string] to filter only for names, without path."); ImUtf8.BulletText("You can enter n:[string] to filter only for names, without path."u8);
ImGui.BulletText("You can enter c:[string] to filter for Changed Items instead."); ImUtf8.BulletText("You can enter c:[string] to filter for Changed Items instead."u8);
ImGui.BulletText("You can enter a:[string] to filter for Mod Authors instead."); ImUtf8.BulletText("You can enter a:[string] to filter for Mod Authors instead."u8);
indent.Pop(1); indent.Pop(1);
ImGui.BulletText("Use the expandable menu beside the input to filter for mods fulfilling specific criteria."); ImUtf8.BulletText("Use the expandable menu beside the input to filter for mods fulfilling specific criteria."u8);
}); });
} }
@ -729,7 +738,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private bool DrawFilterCombo(ref bool everything) private bool DrawFilterCombo(ref bool everything)
{ {
using var combo = ImRaii.Combo("##filterCombo", string.Empty, using var combo = ImUtf8.Combo("##filterCombo"u8, ""u8,
ImGuiComboFlags.NoPreview | ImGuiComboFlags.PopupAlignLeft | ImGuiComboFlags.HeightLargest); ImGuiComboFlags.NoPreview | ImGuiComboFlags.PopupAlignLeft | ImGuiComboFlags.HeightLargest);
var ret = ImGui.IsItemClicked(ImGuiMouseButton.Right); var ret = ImGui.IsItemClicked(ImGuiMouseButton.Right);
if (!combo) if (!combo)
@ -738,7 +747,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing,
ImGui.GetStyle().ItemSpacing with { Y = 3 * UiHelpers.Scale }); ImGui.GetStyle().ItemSpacing with { Y = 3 * UiHelpers.Scale });
if (ImGui.Checkbox("Everything", ref everything)) if (ImUtf8.Checkbox("Everything"u8, ref everything))
{ {
_stateFilter = everything ? ModFilterExtensions.UnfilteredStateMods : 0; _stateFilter = everything ? ModFilterExtensions.UnfilteredStateMods : 0;
SetFilterDirty(); SetFilterDirty();
@ -784,7 +793,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
SetFilterDirty(); SetFilterDirty();
} }
ImGuiUtil.HoverTooltip("Filter mods for their activation status.\nRight-Click to clear all filters."); ImUtf8.HoverTooltip("Filter mods for their activation status.\nRight-Click to clear all filters."u8);
ImGui.SetCursorPos(pos); ImGui.SetCursorPos(pos);
return (remainingWidth, rightClick); return (remainingWidth, rightClick);
} }