mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-13 20:24:17 +01:00
Draw associated BNPCs in debug tab.
This commit is contained in:
parent
23f46438a2
commit
f2ef0e15d3
2 changed files with 168 additions and 42 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6a0daf2f309c27c5a260825bce31094987fce3d1
|
Subproject commit 4a639dbeebc3cbbaf8518b7626892855689f7440
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
|
using Dalamud.Interface;
|
||||||
|
using Dalamud.Interface.Utility;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Widgets;
|
using OtterGui.Widgets;
|
||||||
|
using Penumbra.Collections.Cache;
|
||||||
using Penumbra.Collections.Manager;
|
using Penumbra.Collections.Manager;
|
||||||
using Penumbra.Meta.Manipulations;
|
using Penumbra.Meta.Manipulations;
|
||||||
using Penumbra.Mods;
|
using Penumbra.Mods;
|
||||||
|
|
@ -20,39 +24,88 @@ public class ModPanelConflictsTab : ITab
|
||||||
_selector = selector;
|
_selector = selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int? _currentPriority = null;
|
||||||
|
|
||||||
public ReadOnlySpan<byte> Label
|
public ReadOnlySpan<byte> Label
|
||||||
=> "Conflicts"u8;
|
=> "Conflicts"u8;
|
||||||
|
|
||||||
public bool IsVisible
|
public bool IsVisible
|
||||||
=> _collectionManager.Active.Current.Conflicts(_selector.Selected!).Count > 0;
|
=> _collectionManager.Active.Current.Conflicts(_selector.Selected!).Count > 0;
|
||||||
|
|
||||||
|
private readonly ConditionalWeakTable<IMod, object> _expandedMods = new();
|
||||||
|
|
||||||
|
private int GetPriority(ModConflicts conflicts)
|
||||||
|
{
|
||||||
|
if (conflicts.Mod2.Index < 0)
|
||||||
|
return conflicts.Mod2.Priority;
|
||||||
|
|
||||||
|
return _collectionManager.Active.Current[conflicts.Mod2.Index].Settings?.Priority ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawContent()
|
public void DrawContent()
|
||||||
{
|
{
|
||||||
using var box = ImRaii.ListBox("##conflicts", -Vector2.One);
|
using var table = ImRaii.Table("conflicts", 3, ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollY, ImGui.GetContentRegionAvail());
|
||||||
if (!box)
|
if (!table)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var buttonSize = new Vector2(ImGui.GetFrameHeight());
|
||||||
|
var spacing = ImGui.GetStyle().ItemInnerSpacing with { Y = ImGui.GetStyle().ItemSpacing.Y };
|
||||||
|
var priorityRowWidth = ImGui.CalcTextSize("Priority").X + 20 * ImGuiHelpers.GlobalScale + 2 * buttonSize.X;
|
||||||
|
var priorityWidth = priorityRowWidth - 2 * (buttonSize.X + spacing.X);
|
||||||
|
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, spacing);
|
||||||
|
ImGui.TableSetupColumn("Conflicting Mod", ImGuiTableColumnFlags.WidthStretch);
|
||||||
|
ImGui.TableSetupColumn("Priority", ImGuiTableColumnFlags.WidthFixed, priorityRowWidth);
|
||||||
|
ImGui.TableSetupColumn("Files", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("Files").X + spacing.X);
|
||||||
|
|
||||||
|
ImGui.TableSetupScrollFreeze(2, 2);
|
||||||
|
ImGui.TableHeadersRow();
|
||||||
|
DrawCurrentRow(priorityWidth);
|
||||||
|
|
||||||
// Can not be null because otherwise the tab bar is never drawn.
|
// Can not be null because otherwise the tab bar is never drawn.
|
||||||
var mod = _selector.Selected!;
|
var mod = _selector.Selected!;
|
||||||
foreach (var conflict in _collectionManager.Active.Current.Conflicts(mod))
|
foreach (var (conflict, index) in _collectionManager.Active.Current.Conflicts(mod).OrderByDescending(GetPriority)
|
||||||
|
.ThenBy(c => c.Mod2.Name.Lower).WithIndex())
|
||||||
{
|
{
|
||||||
|
using var id = ImRaii.PushId(index);
|
||||||
|
DrawConflictRow(conflict, priorityWidth, buttonSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawCurrentRow(float priorityWidth)
|
||||||
|
{
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
using var c = ImRaii.PushColor(ImGuiCol.Text, ColorId.FolderLine.Value());
|
||||||
|
ImGui.AlignTextToFramePadding();
|
||||||
|
ImGui.TextUnformatted(_selector.Selected!.Name);
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
var priority = _collectionManager.Active.Current[_selector.Selected!.Index].Settings!.Priority;
|
||||||
|
ImGui.SetNextItemWidth(priorityWidth);
|
||||||
|
if (ImGui.InputInt("##priority", ref priority, 0, 0, ImGuiInputTextFlags.EnterReturnsTrue))
|
||||||
|
_currentPriority = priority;
|
||||||
|
|
||||||
|
if (ImGui.IsItemDeactivatedAfterEdit() && _currentPriority.HasValue)
|
||||||
|
{
|
||||||
|
if (_currentPriority != _collectionManager.Active.Current[_selector.Selected!.Index].Settings!.Priority)
|
||||||
|
_collectionManager.Editor.SetModPriority(_collectionManager.Active.Current, (Mod)_selector.Selected!,
|
||||||
|
_currentPriority.Value);
|
||||||
|
|
||||||
|
_currentPriority = null;
|
||||||
|
}
|
||||||
|
else if (ImGui.IsItemDeactivated())
|
||||||
|
{
|
||||||
|
_currentPriority = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawConflictSelectable(ModConflicts conflict)
|
||||||
|
{
|
||||||
|
ImGui.AlignTextToFramePadding();
|
||||||
if (ImGui.Selectable(conflict.Mod2.Name) && conflict.Mod2 is Mod otherMod)
|
if (ImGui.Selectable(conflict.Mod2.Name) && conflict.Mod2 is Mod otherMod)
|
||||||
_selector.SelectByValue(otherMod);
|
_selector.SelectByValue(otherMod);
|
||||||
var hovered = ImGui.IsItemHovered();
|
var hovered = ImGui.IsItemHovered();
|
||||||
var rightClicked = ImGui.IsItemClicked(ImGuiMouseButton.Right);
|
var rightClicked = ImGui.IsItemClicked(ImGuiMouseButton.Right);
|
||||||
|
|
||||||
ImGui.SameLine();
|
|
||||||
using (var color = ImRaii.PushColor(ImGuiCol.Text,
|
|
||||||
conflict.HasPriority ? ColorId.HandledConflictMod.Value() : ColorId.ConflictingMod.Value()))
|
|
||||||
{
|
|
||||||
var priority = conflict.Mod2.Index < 0
|
|
||||||
? conflict.Mod2.Priority
|
|
||||||
: _collectionManager.Active.Current[conflict.Mod2.Index].Settings!.Priority;
|
|
||||||
ImGui.TextUnformatted($"(Priority {priority})");
|
|
||||||
hovered |= ImGui.IsItemHovered();
|
|
||||||
rightClicked |= ImGui.IsItemClicked(ImGuiMouseButton.Right);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conflict.Mod2 is Mod otherMod2)
|
if (conflict.Mod2 is Mod otherMod2)
|
||||||
{
|
{
|
||||||
if (hovered)
|
if (hovered)
|
||||||
|
|
@ -60,6 +113,12 @@ public class ModPanelConflictsTab : ITab
|
||||||
if (rightClicked && ImGui.GetIO().KeyCtrl)
|
if (rightClicked && ImGui.GetIO().KeyCtrl)
|
||||||
_collectionManager.Editor.SetModState(_collectionManager.Active.Current, otherMod2, false);
|
_collectionManager.Editor.SetModState(_collectionManager.Active.Current, otherMod2, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DrawExpandedFiles(ModConflicts conflict)
|
||||||
|
{
|
||||||
|
if (!_expandedMods.TryGetValue(conflict.Mod2, out _))
|
||||||
|
return false;
|
||||||
|
|
||||||
using var indent = ImRaii.PushIndent(30f);
|
using var indent = ImRaii.PushIndent(30f);
|
||||||
foreach (var data in conflict.Conflicts)
|
foreach (var data in conflict.Conflicts)
|
||||||
|
|
@ -74,6 +133,73 @@ public class ModPanelConflictsTab : ITab
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawConflictRow(ModConflicts conflict, float priorityWidth, Vector2 buttonSize)
|
||||||
|
{
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
DrawConflictSelectable(conflict);
|
||||||
|
var expanded = DrawExpandedFiles(conflict);
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
var conflictPriority = DrawPriorityInput(conflict, priorityWidth);
|
||||||
|
ImGui.SameLine();
|
||||||
|
var selectedPriority = _collectionManager.Active.Current[_selector.Selected!.Index].Settings!.Priority;
|
||||||
|
DrawPriorityButtons(conflict.Mod2 as Mod, conflictPriority, selectedPriority, buttonSize);
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
DrawExpandButton(conflict.Mod2, expanded, buttonSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawExpandButton(IMod mod, bool expanded, Vector2 buttonSize)
|
||||||
|
{
|
||||||
|
var (icon, tt) = expanded
|
||||||
|
? (FontAwesomeIcon.CaretUp.ToIconString(), "Hide the conflicting files for this mod.")
|
||||||
|
: (FontAwesomeIcon.CaretDown.ToIconString(), "Show the conflicting files for this mod.");
|
||||||
|
if (ImGuiUtil.DrawDisabledButton(icon, buttonSize, tt, false, true))
|
||||||
|
{
|
||||||
|
if (expanded)
|
||||||
|
_expandedMods.Remove(mod);
|
||||||
|
else
|
||||||
|
_expandedMods.Add(mod, new object());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int DrawPriorityInput(ModConflicts conflict, float priorityWidth)
|
||||||
|
{
|
||||||
|
using var color = ImRaii.PushColor(ImGuiCol.Text,
|
||||||
|
conflict.HasPriority ? ColorId.HandledConflictMod.Value() : ColorId.ConflictingMod.Value());
|
||||||
|
using var disabled = ImRaii.Disabled(conflict.Mod2.Index < 0);
|
||||||
|
var priority = _currentPriority ?? GetPriority(conflict);
|
||||||
|
|
||||||
|
ImGui.SetNextItemWidth(priorityWidth);
|
||||||
|
if (ImGui.InputInt("##priority", ref priority, 0, 0, ImGuiInputTextFlags.EnterReturnsTrue))
|
||||||
|
_currentPriority = priority;
|
||||||
|
|
||||||
|
if (ImGui.IsItemDeactivatedAfterEdit() && _currentPriority.HasValue)
|
||||||
|
{
|
||||||
|
if (_currentPriority != GetPriority(conflict))
|
||||||
|
_collectionManager.Editor.SetModPriority(_collectionManager.Active.Current, (Mod)conflict.Mod2, _currentPriority.Value);
|
||||||
|
|
||||||
|
_currentPriority = null;
|
||||||
|
}
|
||||||
|
else if (ImGui.IsItemDeactivated())
|
||||||
|
{
|
||||||
|
_currentPriority = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawPriorityButtons(Mod? conflict, int conflictPriority, int selectedPriority, Vector2 buttonSize)
|
||||||
|
{
|
||||||
|
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.SortNumericUpAlt.ToIconString(), buttonSize,
|
||||||
|
$"Set the priority of the currently selected mod to this mods priority plus one. ({selectedPriority} -> {conflictPriority + 1})", selectedPriority > conflictPriority, true))
|
||||||
|
_collectionManager.Editor.SetModPriority(_collectionManager.Active.Current, _selector.Selected!, conflictPriority + 1);
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.SortNumericDownAlt.ToIconString(), buttonSize,
|
||||||
|
$"Set the priority of this mod to the currently selected mods priority minus one. ({conflictPriority} -> {selectedPriority - 1})",
|
||||||
|
selectedPriority > conflictPriority || conflict == null, true))
|
||||||
|
_collectionManager.Editor.SetModPriority(_collectionManager.Active.Current, conflict!, selectedPriority - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue