Cleanup fixed design display code a bit.

This commit is contained in:
Ottermandias 2023-06-11 01:59:20 +02:00
parent 79d2c63ddb
commit 2ebca491fc
3 changed files with 356 additions and 314 deletions

View file

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Dalamud.Configuration;
namespace Glamourer
{
namespace Glamourer;
public class GlamourerConfig : IPluginConfiguration
{
public class FixedDesign
@ -28,6 +28,7 @@ namespace Glamourer
public uint CustomizationColor { get; set; } = DefaultCustomizationColor;
public uint StateColor { get; set; } = DefaultStateColor;
public uint EquipmentColor { get; set; } = DefaultEquipmentColor;
public ushort GroupFixedWhen { get; set; } = 2;
public List<FixedDesign> FixedDesigns { get; set; } = new();
@ -44,4 +45,3 @@ namespace Glamourer
return config;
}
}
}

View file

@ -1,9 +1,10 @@
using System;
using System.Numerics;
using Dalamud.Interface;
using ImGuiNET;
namespace Glamourer.Gui
{
namespace Glamourer.Gui;
internal partial class Interface
{
private static void DrawConfigCheckMark(string label, string tooltip, bool value, Action<bool> setter)
@ -57,6 +58,8 @@ namespace Glamourer.Gui
"If Penumbra did not register the functions for some reason, pressing this button might help restore functionality.");
}
private int _currentFixedDesignGroup = -1;
private void DrawConfigTab()
{
using var raii = new ImGuiRaii();
@ -98,6 +101,7 @@ namespace Glamourer.Gui
else
Glamourer.PlayerWatcher.Disable();
});
DrawFixedDesignGroup();
ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeightWithSpacing() / 2);
@ -108,5 +112,28 @@ namespace Glamourer.Gui
DrawColorPicker("State Color", "The color for designs that only apply some state modification.",
cfg.StateColor, GlamourerConfig.DefaultStateColor, c => cfg.StateColor = c);
}
private void DrawFixedDesignGroup()
{
if (_currentFixedDesignGroup == -1)
_currentFixedDesignGroup = Glamourer.Config.GroupFixedWhen;
ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale);
ImGui.DragInt("Group Fixed Designs From", ref _currentFixedDesignGroup, 0.01f, 2, ushort.MaxValue);
if (ImGui.IsItemDeactivatedAfterEdit())
{
_currentFixedDesignGroup = Math.Clamp(_currentFixedDesignGroup, 2, ushort.MaxValue);
if (_currentFixedDesignGroup != Glamourer.Config.GroupFixedWhen)
{
Glamourer.Config.GroupFixedWhen = (ushort)_currentFixedDesignGroup;
Glamourer.Config.Save();
}
_currentFixedDesignGroup = -1;
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip(
"Set how many fixed designs have to be set to a specific character before their designs are grouped with a header in the Fixed Designs tab.");
}
}

View file

@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Glamourer.Designs;
using Glamourer.FileSystem;
using ImGuiNET;
using Penumbra.PlayerWatch;
namespace Glamourer.Gui
{
namespace Glamourer.Gui;
internal partial class Interface
{
private const string FixDragDropLabel = "##FixDragDrop";
@ -19,7 +19,7 @@ namespace Glamourer.Gui
private JobGroup? _newFixDesignGroup;
private Design? _newFixDesign;
private int _fixDragDropIdx = -1;
private readonly HashSet<string> _openNames = new();
private readonly HashSet<string> _closedGroups = new();
private static unsafe bool IsDropping()
=> ImGui.AcceptDragDropPayload(FixDragDropLabel).NativePtr != null;
@ -43,129 +43,144 @@ namespace Glamourer.Gui
_fullPathCache ??= _plugin.FixedDesigns.Data.Select(d => d.Design.FullName()).ToList();
raii.Begin(() => ImGui.BeginTable("##FixedTable", 4), ImGui.EndTable);
Action? endAction = null;
var buttonWidth = ImGui.GetFrameHeight();
var groups = _plugin.FixedDesigns.Data.Select((d, i) => (d, i)).GroupBy(d => d.d.Name)
.OrderBy(g => g.Key)
.Select(g => (g.Key, g.ToList()))
.ToList();
var buttonWidth = 23.5f * ImGuiHelpers.GlobalScale;
ImGui.TableSetupColumn("##DeleteColumn", ImGuiTableColumnFlags.WidthFixed, 2 * buttonWidth);
raii.PushStyle(ImGuiStyleVar.FrameRounding, 0);
raii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
if (ImGui.Button("Collapse All Groups", new Vector2(ImGui.GetContentRegionAvail().X / 2, 0)))
_closedGroups.UnionWith(groups.Select(kvp => kvp.Key));
ImGui.SameLine();
if (ImGui.Button("Expand All Groups", new Vector2(ImGui.GetContentRegionAvail().X, 0)))
_closedGroups.Clear();
raii.PopStyles(2);
raii.Begin(() => ImGui.BeginTable("##FixedTable", 5, ImGuiTableFlags.RowBg), ImGui.EndTable);
ImGui.TableSetupColumn("##DeleteColumn", ImGuiTableColumnFlags.WidthFixed, buttonWidth);
ImGui.TableSetupColumn("##EnableColumn", ImGuiTableColumnFlags.WidthFixed, buttonWidth);
ImGui.TableSetupColumn("Character", ImGuiTableColumnFlags.WidthFixed, 200 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("Jobs", ImGuiTableColumnFlags.WidthFixed, 175 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("Design", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableHeadersRow();
var grouping = new Dictionary<string, List<int>>();
for (var i = 0; i < _fullPathCache.Count; ++i)
void DrawDesign(FixedDesigns.FixedDesign design, int idx)
{
var name = _plugin.FixedDesigns.Data[i].Name;
grouping.TryAdd(name, new List<int>());
grouping[name].Add(i);
}
var xPos = 0f;
foreach (var (groupedName, indices) in grouping.OrderBy(kvp => kvp.Key))
{
ImGui.TableNextRow();
ImGui.PushID(idx);
var path = _fullPathCache[idx];
ImGui.TableNextColumn();
raii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing / 2);
raii.PushFont(UiBuilder.IconFont);
var isOpen = _openNames.Contains(groupedName);
var groupIcon = isOpen ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight;
if (ImGui.Button($"{groupIcon.ToIconChar()}##group_{NormalizeIdentifier(groupedName)}"))
if (ImGui.Button(FontAwesomeIcon.Trash.ToIconString()))
endAction = () =>
{
if (isOpen)
{
_openNames.Remove(groupedName);
} else
{
_openNames.Add(groupedName);
}
return;
}
raii.PopStyles();
_fullPathCache.RemoveAt(idx);
_plugin.FixedDesigns.Remove(design);
};
raii.PopFonts();
ImGui.SameLine();
xPos = ImGui.GetCursorPosX();
var tmp = design.Enabled;
ImGui.TableNextColumn();
ImGui.Text(groupedName);
if (!_openNames.Contains(groupedName))
if (ImGui.Checkbox("##Enabled", ref tmp))
if (tmp && _plugin.FixedDesigns.EnableDesign(design)
|| !tmp && _plugin.FixedDesigns.DisableDesign(design))
{
ImGui.TableNextRow();
continue;
}
foreach (var i in indices)
{
var path = _fullPathCache[i];
var name = _plugin.FixedDesigns.Data[i];
ImGui.TableNextRow();
ImGui.TableNextColumn();
raii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing / 2);
raii.PushFont(UiBuilder.IconFont);
if (ImGui.Button($"{FontAwesomeIcon.Trash.ToIconChar()}##{i}"))
{
_fullPathCache.RemoveAt(i);
_plugin.FixedDesigns.Remove(name);
continue;
}
var tmp = name.Enabled;
ImGui.SameLine();
xPos = ImGui.GetCursorPosX();
if (ImGui.Checkbox($"##Enabled{i}", ref tmp))
if (tmp && _plugin.FixedDesigns.EnableDesign(name)
|| !tmp && _plugin.FixedDesigns.DisableDesign(name))
{
Glamourer.Config.FixedDesigns[i].Enabled = tmp;
Glamourer.Config.FixedDesigns[idx].Enabled = tmp;
Glamourer.Config.Save();
}
raii.PopStyles();
raii.PopFonts();
ImGui.TableNextColumn();
ImGui.Selectable($"{name.Name}##Fix{i}");
ImGui.Selectable($"{design.Name}##Fix");
if (ImGui.BeginDragDropSource())
{
_fixDragDropIdx = i;
_fixDragDropIdx = idx;
ImGui.SetDragDropPayload("##FixDragDrop", IntPtr.Zero, 0);
ImGui.Text($"Dragging {name.Name} ({path})...");
ImGui.Text($"Dragging {design.Name} ({path})...");
ImGui.EndDragDropSource();
}
if (ImGui.BeginDragDropTarget())
{
if (IsDropping() && _fixDragDropIdx >= 0)
{
var i = _fixDragDropIdx;
var d = _plugin.FixedDesigns.Data[_fixDragDropIdx];
_plugin.FixedDesigns.Move(d, i);
var p = _fullPathCache[_fixDragDropIdx];
_fullPathCache.RemoveAt(_fixDragDropIdx);
_fullPathCache.Insert(i, p);
endAction = () =>
{
_plugin.FixedDesigns.Move(d, idx);
_fullPathCache.RemoveAt(i);
_fullPathCache.Insert(idx, p);
_fixDragDropIdx = -1;
};
}
ImGui.EndDragDropTarget();
}
ImGui.TableNextColumn();
ImGui.Text(_plugin.FixedDesigns.Data[i].Jobs.Name);
ImGui.TextUnformatted(_plugin.FixedDesigns.Data[idx].Jobs.Name);
ImGui.TableNextColumn();
ImGui.Text(path);
ImGui.TextUnformatted(path);
ImGui.PopID();
}
ImGui.TableNextRow();
foreach (var (playerName, designs) in groups)
{
if (designs.Count >= Glamourer.Config.GroupFixedWhen)
{
var isOpen = !_closedGroups.Contains(playerName);
var color = isOpen ? 0x40005000u : 0x40000050u;
ImGui.TableNextColumn();
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, color);
ImGui.TableNextColumn();
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, color);
var groupIcon = isOpen ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight;
ImGui.PushID(playerName);
raii.PushFont(UiBuilder.IconFont);
if (ImGui.Button(groupIcon.ToIconString(), new Vector2(buttonWidth)))
{
if (isOpen)
_closedGroups.Add(playerName);
else
_closedGroups.Remove(playerName);
isOpen = !isOpen;
}
ImGui.TableNextRow();
raii.PopFonts();
ImGui.TableNextColumn();
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, color);
ImGui.TextUnformatted(playerName);
ImGui.TableNextColumn();
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, color);
ImGui.TextUnformatted($"{designs.Count} Designs");
ImGui.TableNextColumn();
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, color);
if (isOpen)
foreach (var (d, i) in designs)
DrawDesign(d, i);
ImGui.PopID();
}
else
{
foreach (var (d, i) in designs)
DrawDesign(d, i);
}
}
endAction?.Invoke();
ImGui.TableNextColumn();
ImGui.TableNextColumn();
raii.PushFont(UiBuilder.IconFont);
ImGui.SetCursorPosX(xPos);
if (_newFixDesign == null || _newFixCharacterName == string.Empty)
{
raii.PushStyle(ImGuiStyleVar.Alpha, 0.5f);
@ -188,7 +203,7 @@ namespace Glamourer.Gui
raii.PopFonts();
ImGui.TableNextColumn();
ImGui.SetNextItemWidth(200 * ImGuiHelpers.GlobalScale);
ImGui.InputTextWithHint("##NewFix", "Enter new Character", ref _newFixCharacterName, 64);
ImGui.InputTextWithHint("##NewFix", "Enter new Character (current: {", ref _newFixCharacterName, 64);
ImGui.TableNextColumn();
ImGui.SetNextItemWidth(-1);
if (raii.Begin(() => ImGui.BeginCombo("##NewFixDesignGroup", _newFixDesignGroup.Value.Name), ImGui.EndCombo))
@ -199,6 +214,7 @@ namespace Glamourer.Gui
if (ImGui.Selectable($"{group.Name}##NewFixDesignGroup", group.Name == _newFixDesignGroup.Value.Name))
_newFixDesignGroup = group;
}
raii.End();
}
@ -219,4 +235,3 @@ namespace Glamourer.Gui
}
}
}
}