Allow renaming of collection.

This commit is contained in:
Ottermandias 2024-04-12 12:42:16 +02:00
parent ba8999914f
commit 1ef9346eab
4 changed files with 36 additions and 34 deletions

View file

@ -77,7 +77,7 @@ public partial class ModCollection
else
{
_cache.Meta.SetFiles();
Penumbra.Log.Debug($"Set CharacterUtility resources for collection {Name}.");
Penumbra.Log.Debug($"Set CharacterUtility resources for collection {Identifier}.");
}
}

View file

@ -28,7 +28,7 @@ public partial class ModCollection
public static readonly ModCollection Empty = CreateEmpty(EmptyCollectionName, 0, 0);
/// <summary> The name of a collection. </summary>
public string Name { get; set; } = string.Empty;
public string Name { get; set; }
public Guid Id { get; }

View file

@ -35,7 +35,8 @@ public sealed class CollectionPanel : IDisposable
private static readonly IReadOnlyDictionary<CollectionType, (string Name, uint Border)> Buttons = CreateButtons();
private static readonly IReadOnlyList<(CollectionType, bool, bool, string, uint)> AdvancedTree = CreateTree();
private readonly List<(CollectionType Type, ActorIdentifier Identifier)> _inUseCache = new();
private readonly List<(CollectionType Type, ActorIdentifier Identifier)> _inUseCache = [];
private string? _newName;
private int _draggedIndividualAssignment = -1;
@ -93,6 +94,18 @@ public sealed class CollectionPanel : IDisposable
var first = true;
Button(CollectionType.NonPlayerChild);
Button(CollectionType.NonPlayerElderly);
foreach (var race in Enum.GetValues<SubRace>().Skip(1))
{
Button(CollectionTypeExtensions.FromParts(race, Gender.Male, false));
Button(CollectionTypeExtensions.FromParts(race, Gender.Female, false));
Button(CollectionTypeExtensions.FromParts(race, Gender.Male, true));
Button(CollectionTypeExtensions.FromParts(race, Gender.Female, true));
}
return;
void Button(CollectionType type)
{
var (name, border) = Buttons[type];
@ -112,16 +125,6 @@ public sealed class CollectionPanel : IDisposable
if (ImGui.GetContentRegionAvail().X < buttonWidth.X + ImGui.GetStyle().ItemSpacing.X + ImGui.GetStyle().WindowPadding.X)
ImGui.NewLine();
}
Button(CollectionType.NonPlayerChild);
Button(CollectionType.NonPlayerElderly);
foreach (var race in Enum.GetValues<SubRace>().Skip(1))
{
Button(CollectionTypeExtensions.FromParts(race, Gender.Male, false));
Button(CollectionTypeExtensions.FromParts(race, Gender.Female, false));
Button(CollectionTypeExtensions.FromParts(race, Gender.Male, true));
Button(CollectionTypeExtensions.FromParts(race, Gender.Female, true));
}
}
/// <summary> Draw the panel containing new and existing individual assignments. </summary>
@ -228,12 +231,20 @@ public sealed class CollectionPanel : IDisposable
ImGui.SameLine();
ImGui.BeginGroup();
using var style = ImRaii.PushStyle(ImGuiStyleVar.ButtonTextAlign, new Vector2(0, 0.5f));
var name = collection.Name;
var name = _newName ?? collection.Name;
var identifier = collection.Identifier;
var width = ImGui.GetContentRegionAvail().X;
var fileName = _fileNames.CollectionFile(collection);
ImGui.SetNextItemWidth(width);
ImGui.InputText("##name", ref name, 128);
if (ImGui.InputText("##name", ref name, 128))
_newName = name;
if (ImGui.IsItemDeactivatedAfterEdit() && _newName != null)
{
collection.Name = _newName;
_newName = null;
}
else if (ImGui.IsItemDeactivated())
_newName = null;
using (ImRaii.PushFont(UiBuilder.MonoFont))
{
if (ImGui.Button(collection.Identifier, new Vector2(width, 0)))

View file

@ -2,30 +2,21 @@ using Dalamud.Interface;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Services;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.UI.Classes;
namespace Penumbra.UI.CollectionTab;
public class InheritanceUi
public class InheritanceUi(CollectionManager collectionManager, CollectionSelector selector) : IUiService
{
private const int InheritedCollectionHeight = 9;
private const string InheritanceDragDropLabel = "##InheritanceMove";
private readonly CollectionStorage _collections;
private readonly ActiveCollections _active;
private readonly InheritanceManager _inheritance;
private readonly CollectionSelector _selector;
public InheritanceUi(CollectionManager collectionManager, CollectionSelector selector)
{
_selector = selector;
_collections = collectionManager.Storage;
_active = collectionManager.Active;
_inheritance = collectionManager.Inheritances;
}
private readonly CollectionStorage _collections = collectionManager.Storage;
private readonly ActiveCollections _active = collectionManager.Active;
private readonly InheritanceManager _inheritance = collectionManager.Inheritances;
/// <summary> Draw the whole inheritance block. </summary>
public void Draw()
@ -59,7 +50,7 @@ public class InheritanceUi
private (int, int)? _inheritanceAction;
private ModCollection? _newCurrentCollection;
private void DrawRightText()
private static void DrawRightText()
{
using var group = ImRaii.Group();
ImGuiUtil.TextWrapped(
@ -68,7 +59,7 @@ public class InheritanceUi
"You can select inheritances from the combo below to add them.\nSince the order of inheritances is important, you can reorder them here via drag and drop.\nYou can also delete inheritances by dragging them onto the trash can.");
}
private void DrawHelpPopup()
private static void DrawHelpPopup()
=> ImGuiUtil.HelpPopup("InheritanceHelp", new Vector2(1000 * UiHelpers.Scale, 20 * ImGui.GetTextLineHeightWithSpacing()), () =>
{
ImGui.NewLine();
@ -123,7 +114,7 @@ public class InheritanceUi
_seenInheritedCollections.Contains(inheritance));
_seenInheritedCollections.Add(inheritance);
ImRaii.TreeNode($"{Name(inheritance)}###{inheritance.Name}",
ImRaii.TreeNode($"{Name(inheritance)}###{inheritance.Id}",
ImGuiTreeNodeFlags.NoTreePushOnOpen | ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.Bullet);
var (minRect, maxRect) = (ImGui.GetItemRectMin(), ImGui.GetItemRectMax());
DrawInheritanceTreeClicks(inheritance, false);
@ -134,7 +125,7 @@ public class InheritanceUi
// Draw the notch and increase the line length.
var midPoint = (minRect.Y + maxRect.Y) / 2f - 1f;
drawList.AddLine(new Vector2(lineStart.X, midPoint), new Vector2(lineStart.X + lineSize, midPoint), Colors.MetaInfoText,
drawList.AddLine(lineStart with { Y = midPoint }, new Vector2(lineStart.X + lineSize, midPoint), Colors.MetaInfoText,
UiHelpers.Scale);
lineEnd.Y = midPoint;
}
@ -321,5 +312,5 @@ public class InheritanceUi
}
private string Name(ModCollection collection)
=> _selector.IncognitoMode ? collection.AnonymizedName : collection.Name;
=> selector.IncognitoMode ? collection.AnonymizedName : collection.Name;
}