Skip to content

Commit

Permalink
Add Player and Interface to quick select collections and rework their…
Browse files Browse the repository at this point in the history
… tooltips and names slightly.
  • Loading branch information
Ottermandias committed Sep 11, 2023
1 parent 569fa06 commit 8eaf14d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 30 deletions.
1 change: 0 additions & 1 deletion Penumbra/Api/IpcTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata.Ecma335;
using System.Threading.Tasks;
using Dalamud.Utility;
using Penumbra.Api.Enums;
Expand Down
121 changes: 92 additions & 29 deletions Penumbra/UI/Classes/CollectionSelectHeader.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Linq;
using System.Numerics;
using ImGuiNET;
using OtterGui.Raii;
using OtterGui;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.Interop.PathResolving;
using Penumbra.UI.CollectionTab;
using Penumbra.UI.ModsTab;

Expand All @@ -16,28 +18,33 @@ public class CollectionSelectHeader
private readonly ActiveCollections _activeCollections;
private readonly TutorialService _tutorial;
private readonly ModFileSystemSelector _selector;
private readonly CollectionResolver _resolver;

public CollectionSelectHeader(CollectionManager collectionManager, TutorialService tutorial, ModFileSystemSelector selector)
public CollectionSelectHeader(CollectionManager collectionManager, TutorialService tutorial, ModFileSystemSelector selector,
CollectionResolver resolver)
{
_tutorial = tutorial;
_selector = selector;
_resolver = resolver;
_activeCollections = collectionManager.Active;
_collectionCombo = new CollectionCombo(collectionManager, () => collectionManager.Storage.OrderBy(c => c.Name).ToList());
}

/// <summary> Draw the header line that can quick switch between collections. </summary>
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));
var buttonSize = new Vector2(ImGui.GetContentRegionAvail().X / 8f, 0);

using var style = ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 0)
.Push(ImGuiStyleVar.ItemSpacing, new Vector2(0, spacing ? ImGui.GetStyle().ItemSpacing.Y : 0));
var comboWidth = ImGui.GetContentRegionAvail().X / 4f;
var buttonSize = new Vector2(comboWidth * 3f / 4f, 0f);
using (var _ = ImRaii.Group())
{
DrawDefaultCollectionButton(3 * buttonSize);
ImGui.SameLine();
DrawInheritedCollectionButton(3 * buttonSize);
ImGui.SameLine();
_collectionCombo.Draw("##collectionSelector", 2 * buttonSize.X, ColorId.SelectedCollection.Value());
DrawCollectionButton(buttonSize, GetDefaultCollectionInfo());
DrawCollectionButton(buttonSize, GetInterfaceCollectionInfo());
DrawCollectionButton(buttonSize, GetPlayerCollectionInfo());
DrawCollectionButton(buttonSize, GetInheritedCollectionInfo());

_collectionCombo.Draw("##collectionSelector", comboWidth, ColorId.SelectedCollection.Value());
}

_tutorial.OpenTutorial(BasicTutorialSteps.CollectionSelectors);
Expand All @@ -46,31 +53,87 @@ public void Draw(bool spacing)
ImGuiUtil.DrawTextButton("The currently selected collection is not used in any way.", -Vector2.UnitX, Colors.PressEnterWarningBg);
}

private void DrawDefaultCollectionButton(Vector2 width)
private enum CollectionState
{
Empty,
Selected,
Unavailable,
Available,
}

private CollectionState CheckCollection(ModCollection? collection, bool inheritance = false)
{
if (collection == null)
return CollectionState.Unavailable;
if (collection == ModCollection.Empty)
return CollectionState.Empty;
if (collection == _activeCollections.Current)
return inheritance ? CollectionState.Unavailable : CollectionState.Selected;

return CollectionState.Available;
}

private (ModCollection?, string, string, bool) GetDefaultCollectionInfo()
{
var collection = _activeCollections.Default;
return CheckCollection(collection) switch
{
CollectionState.Empty => (collection, "None", "The base collection is configured to use no mods.", true),
CollectionState.Selected => (collection, collection.Name,
"The configured base collection is already selected as the current collection.", true),
CollectionState.Available => (collection, collection.Name,
$"Select the configured base collection {collection.Name} as the current collection.", false),
_ => throw new Exception("Can not happen."),
};
}

private (ModCollection?, string, string, bool) GetPlayerCollectionInfo()
{
var collection = _resolver.PlayerCollection();
return CheckCollection(collection) switch
{
CollectionState.Empty => (collection, "None", "The base collection is configured to use no mods.", true),
CollectionState.Selected => (collection, collection.Name,
"The collection configured to apply to the loaded player character is already selected as the current collection.", true),
CollectionState.Available => (collection, collection.Name,
$"Select the collection {collection.Name} that applies to the loaded player character as the current collection.", false),
_ => throw new Exception("Can not happen."),
};
}

private (ModCollection?, string, string, bool) GetInterfaceCollectionInfo()
{
var name = $"{TutorialService.DefaultCollection} ({_activeCollections.Default.Name})";
var isCurrent = _activeCollections.Default == _activeCollections.Current;
var isEmpty = _activeCollections.Default == ModCollection.Empty;
var tt = isCurrent ? $"The current collection is already the configured {TutorialService.DefaultCollection}."
: isEmpty ? $"The {TutorialService.DefaultCollection} is configured to be empty."
: $"Set the {TutorialService.SelectedCollection} to the configured {TutorialService.DefaultCollection}.";
if (ImGuiUtil.DrawDisabledButton(name, width, tt, isCurrent || isEmpty))
_activeCollections.SetCollection(_activeCollections.Default, CollectionType.Current);
var collection = _activeCollections.Interface;
return CheckCollection(collection) switch
{
CollectionState.Empty => (collection, "None", "The interface collection is configured to use no mods.", true),
CollectionState.Selected => (collection, collection.Name,
"The configured interface collection is already selected as the current collection.", true),
CollectionState.Available => (collection, collection.Name,
$"Select the configured interface collection {collection.Name} as the current collection.", false),
_ => throw new Exception("Can not happen."),
};
}

private void DrawInheritedCollectionButton(Vector2 width)
private (ModCollection?, string, string, bool) GetInheritedCollectionInfo()
{
var noModSelected = _selector.Selected == null;
var collection = _selector.SelectedSettingCollection;
var modInherited = collection != _activeCollections.Current;
var (name, tt) = (noModSelected, modInherited) switch
var collection = _selector.Selected == null ? null : _selector.SelectedSettingCollection;
return CheckCollection(collection, true) switch
{
(true, _) => ("Inherited Collection", "No mod selected."),
(false, true) => ($"Inherited Collection ({collection.Name})",
"Set the current collection to the collection the selected mod inherits its settings from."),
(false, false) => ("Not Inherited", "The selected mod does not inherit its settings."),
CollectionState.Unavailable => (null, "Not Inherited",
"The settings of the selected mod are not inherited from another collection.", true),
CollectionState.Available => (collection, collection!.Name,
$"Select the collection {collection!.Name} from which the selected mod inherits its settings as the current collection.",
false),
_ => throw new Exception("Can not happen."),
};
if (ImGuiUtil.DrawDisabledButton(name, width, tt, noModSelected || !modInherited))
_activeCollections.SetCollection(collection, CollectionType.Current);
}

private void DrawCollectionButton(Vector2 buttonWidth, (ModCollection?, string, string, bool) tuple)
{
var (collection, name, tooltip, disabled) = tuple;
if (ImGuiUtil.DrawDisabledButton(name, buttonWidth, tooltip, disabled))
_activeCollections.SetCollection(collection!, CollectionType.Current);
ImGui.SameLine();
}
}

0 comments on commit 8eaf14d

Please sign in to comment.