Add rename mod field.

This commit is contained in:
Ottermandias 2024-04-09 15:19:44 +02:00
parent e94cdaec46
commit 21a55b95d9
4 changed files with 117 additions and 12 deletions

View file

@ -11,6 +11,7 @@ using Penumbra.Mods;
using Penumbra.Mods.Manager;
using Penumbra.Services;
using Penumbra.UI.Classes;
using Penumbra.UI.ModsTab;
using Penumbra.UI.ResourceWatcher;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
@ -40,17 +41,18 @@ public class Configuration : IPluginConfiguration, ISavable
public bool HideUiWhenUiHidden { get; set; } = false;
public bool UseDalamudUiTextureRedirection { get; set; } = true;
public bool UseCharacterCollectionInMainWindow { get; set; } = true;
public bool UseCharacterCollectionsInCards { get; set; } = true;
public bool UseCharacterCollectionInInspect { get; set; } = true;
public bool UseCharacterCollectionInTryOn { get; set; } = true;
public bool UseOwnerNameForCharacterCollection { get; set; } = true;
public bool UseNoModsInInspect { get; set; } = false;
public bool HideChangedItemFilters { get; set; } = false;
public bool ReplaceNonAsciiOnImport { get; set; } = false;
public bool HidePrioritiesInSelector { get; set; } = false;
public bool HideRedrawBar { get; set; } = false;
public int OptionGroupCollapsibleMin { get; set; } = 5;
public bool UseCharacterCollectionInMainWindow { get; set; } = true;
public bool UseCharacterCollectionsInCards { get; set; } = true;
public bool UseCharacterCollectionInInspect { get; set; } = true;
public bool UseCharacterCollectionInTryOn { get; set; } = true;
public bool UseOwnerNameForCharacterCollection { get; set; } = true;
public bool UseNoModsInInspect { get; set; } = false;
public bool HideChangedItemFilters { get; set; } = false;
public bool ReplaceNonAsciiOnImport { get; set; } = false;
public bool HidePrioritiesInSelector { get; set; } = false;
public bool HideRedrawBar { get; set; } = false;
public RenameField ShowRename { get; set; } = RenameField.BothDataPrio;
public int OptionGroupCollapsibleMin { get; set; } = 5;
public Vector2 MinimumSize = new(Constants.MinimumSizeX, Constants.MinimumSizeY);

View file

@ -66,7 +66,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
SubscribeRightClickMain(() => ClearQuickMove(1, _config.QuickMoveFolder2, () => {_config.QuickMoveFolder2 = string.Empty; _config.Save();}), 120);
SubscribeRightClickMain(() => ClearQuickMove(2, _config.QuickMoveFolder3, () => {_config.QuickMoveFolder3 = string.Empty; _config.Save();}), 130);
UnsubscribeRightClickLeaf(RenameLeaf);
SubscribeRightClickLeaf(RenameLeafMod, 1000);
SetRenameSearchPath(_config.ShowRename);
AddButton(AddNewModButton, 0);
AddButton(AddImportModButton, 1);
AddButton(AddHelpButton, 2);
@ -92,6 +92,37 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
OnCollectionChange(CollectionType.Current, null, _collectionManager.Active.Current, "");
}
public void SetRenameSearchPath(RenameField value)
{
switch (value)
{
case RenameField.RenameSearchPath:
SubscribeRightClickLeaf(RenameLeafMod, 1000);
UnsubscribeRightClickLeaf(RenameMod);
break;
case RenameField.RenameData:
UnsubscribeRightClickLeaf(RenameLeafMod);
SubscribeRightClickLeaf(RenameMod, 1000);
break;
case RenameField.BothSearchPathPrio:
UnsubscribeRightClickLeaf(RenameLeafMod);
UnsubscribeRightClickLeaf(RenameMod);
SubscribeRightClickLeaf(RenameLeafMod, 1001);
SubscribeRightClickLeaf(RenameMod, 1000);
break;
case RenameField.BothDataPrio:
UnsubscribeRightClickLeaf(RenameLeafMod);
UnsubscribeRightClickLeaf(RenameMod);
SubscribeRightClickLeaf(RenameLeafMod, 1000);
SubscribeRightClickLeaf(RenameMod, 1001);
break;
default:
UnsubscribeRightClickLeaf(RenameLeafMod);
UnsubscribeRightClickLeaf(RenameMod);
break;
}
}
private static readonly string[] ValidModExtensions =
[
".ttmp",
@ -302,6 +333,22 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
RenameLeaf(leaf);
}
private void RenameMod(ModFileSystem.Leaf leaf)
{
ImGui.Separator();
var currentName = leaf.Value.Name.Text;
if (ImGui.IsWindowAppearing())
ImGui.SetKeyboardFocusHere(0);
ImGui.TextUnformatted("Rename Mod:");
if (ImGui.InputText("##RenameMod", ref currentName, 256, ImGuiInputTextFlags.EnterReturnsTrue))
{
_modManager.DataEditor.ChangeModName(leaf.Value, currentName);
ImGui.CloseCurrentPopup();
}
ImGuiUtil.HoverTooltip("Enter a new name here to rename the changed mod.");
}
private void DeleteModButton(Vector2 size)
=> DeleteSelectionButton(size, _config.DeleteModModifier, "mod", "mods", _modManager.DeleteMod);

View file

@ -0,0 +1,26 @@
namespace Penumbra.UI.ModsTab;
public enum RenameField
{
None,
RenameSearchPath,
RenameData,
BothSearchPathPrio,
BothDataPrio,
}
public static class RenameFieldExtensions
{
public static (string Name, string Desc) GetData(this RenameField value)
=> value switch
{
RenameField.None => ("None", "Show no rename fields in the context menu for mods."),
RenameField.RenameSearchPath => ("Search Path", "Show only the search path / move field in the context menu for mods."),
RenameField.RenameData => ("Mod Name", "Show only the mod name field in the context menu for mods."),
RenameField.BothSearchPathPrio => ("Both (Focus Search Path)",
"Show both rename fields in the context menu for mods, but put the keyboard cursor on the search path field."),
RenameField.BothDataPrio => ("Both (Focus Mod Name)",
"Show both rename fields in the context menu for mods, but put the keyboard cursor on the mod name field"),
_ => (string.Empty, string.Empty),
};
}

View file

@ -533,12 +533,42 @@ public class SettingsTab : ITab
"Instead of keeping the mod-selector in the Installed Mods tab a fixed width, this will let it scale with the total size of the Penumbra window.");
}
private void DrawRenameSettings()
{
ImGui.SetNextItemWidth(UiHelpers.InputTextWidth.X);
using (var combo = ImRaii.Combo("##renameSettings", _config.ShowRename.GetData().Name))
{
if (combo)
foreach (var value in Enum.GetValues<RenameField>())
{
var (name, desc) = value.GetData();
if (ImGui.Selectable(name, _config.ShowRename == value))
{
_config.ShowRename = value;
_selector.SetRenameSearchPath(value);
_config.Save();
}
ImGuiUtil.HoverTooltip(desc);
}
}
ImGui.SameLine();
const string tt =
"Select which of the two renaming input fields are visible when opening the right-click context menu of a mod in the mod selector.";
ImGuiComponents.HelpMarker(tt);
ImGui.SameLine();
ImGui.TextUnformatted("Rename Fields in Mod Context Menu");
ImGuiUtil.HoverTooltip(tt);
}
/// <summary> Draw all settings pertaining to the mod selector. </summary>
private void DrawModSelectorSettings()
{
DrawFolderSortType();
DrawAbsoluteSizeSelector();
DrawRelativeSizeSelector();
DrawRenameSettings();
Checkbox("Open Folders by Default", "Whether to start with all folders collapsed or expanded in the mod selector.",
_config.OpenFoldersByDefault, v =>
{