From 1187efa243fe4e645770ca8dc1b80a6159ce0932 Mon Sep 17 00:00:00 2001 From: Exter-N Date: Mon, 5 Aug 2024 23:02:34 +0200 Subject: [PATCH] Reinstate single-row CT highlight --- .../Materials/MtrlTab.ColorTable.cs | 73 +++++++++++-------- .../Materials/MtrlTab.CommonColorTable.cs | 14 +++- .../Materials/MtrlTab.LegacyColorTable.cs | 14 +--- .../Materials/MtrlTab.LivePreview.cs | 28 ++++++- 4 files changed, 86 insertions(+), 43 deletions(-) diff --git a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.ColorTable.cs b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.ColorTable.cs index df8485c9..0fa38a5d 100644 --- a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.ColorTable.cs +++ b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.ColorTable.cs @@ -30,11 +30,14 @@ public partial class MtrlTab var buttonWidth = (ImGui.GetContentRegionAvail().X - itemSpacing * 7.0f) * 0.125f; var frameHeight = ImGui.GetFrameHeight(); var highlighterSize = ImUtf8.CalcIconSize(FontAwesomeIcon.Crosshairs) + framePadding * 2.0f; - var spaceWidth = ImUtf8.CalcTextSize(" "u8).X; - var spacePadding = (int)MathF.Ceiling((highlighterSize.X + framePadding.X + itemInnerSpacing) / spaceWidth); using var font = ImRaii.PushFont(UiBuilder.MonoFont); using var alignment = ImRaii.PushStyle(ImGuiStyleVar.ButtonTextAlign, new Vector2(0, 0.5f)); + + // This depends on the font being pushed for "proper" alignment of the pair indices in the buttons. + var spaceWidth = ImUtf8.CalcTextSize(" "u8).X; + var spacePadding = (int)MathF.Ceiling((highlighterSize.X + framePadding.X + itemInnerSpacing) / spaceWidth); + for (var i = 0; i < ColorTable.NumRows >> 1; i += 8) { for (var j = 0; j < 8; ++j) @@ -72,7 +75,7 @@ public partial class MtrlTab var cursor = ImGui.GetCursorScreenPos(); ImGui.SetCursorScreenPos(rcMin with { Y = float.Lerp(rcMin.Y, rcMax.Y, 0.5f) - highlighterSize.Y * 0.5f }); font.Pop(); - ColorTableHighlightButton(pairIndex, disabled); + ColorTablePairHighlightButton(pairIndex, disabled); font.Push(UiBuilder.MonoFont); ImGui.SetCursorScreenPos(cursor); } @@ -83,6 +86,8 @@ public partial class MtrlTab { var retA = false; var retB = false; + var rowAIdx = _colorTableSelectedPair << 1; + var rowBIdx = rowAIdx | 1; var dyeA = dyeTable?[_colorTableSelectedPair << 1] ?? default; var dyeB = dyeTable?[(_colorTableSelectedPair << 1) | 1] ?? default; var previewDyeA = _stainService.GetStainCombo(dyeA.Channel).CurrentSelection.Key; @@ -91,23 +96,15 @@ public partial class MtrlTab var dyePackB = _stainService.GudStmFile.GetValueOrNull(dyeB.Template, previewDyeB); using (var columns = ImUtf8.Columns(2, "ColorTable"u8)) { - using (ImUtf8.PushId("ClipboardA"u8)) + using (ImUtf8.PushId("RowHeaderA"u8)) { - ColorTableCopyClipboardButton(_colorTableSelectedPair << 1); - ImUtf8.SameLineInner(); - retA |= ColorTablePasteFromClipboardButton(_colorTableSelectedPair << 1, disabled); + retA |= DrawRowHeader(rowAIdx, disabled); } - ImGui.SameLine(); - CenteredTextInRest($"Row {_colorTableSelectedPair + 1}A"); columns.Next(); - using (ImUtf8.PushId("ClipboardB"u8)) + using (ImUtf8.PushId("RowHeaderB"u8)) { - ColorTableCopyClipboardButton((_colorTableSelectedPair << 1) | 1); - ImUtf8.SameLineInner(); - retB |= ColorTablePasteFromClipboardButton((_colorTableSelectedPair << 1) | 1, disabled); + retB |= DrawRowHeader(rowBIdx, disabled); } - ImGui.SameLine(); - CenteredTextInRest($"Row {_colorTableSelectedPair + 1}B"); } DrawHeader(" Colors"u8); @@ -116,13 +113,13 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("ColorsA"u8)) { - retA |= DrawColors(table, dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawColors(table, dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("ColorsB"u8)) { - retB |= DrawColors(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawColors(table, dyeTable, dyePackB, rowBIdx); } } @@ -132,13 +129,13 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("PbrA"u8)) { - retA |= DrawPbr(table, dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawPbr(table, dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("PbrB"u8)) { - retB |= DrawPbr(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawPbr(table, dyeTable, dyePackB, rowBIdx); } } @@ -148,13 +145,13 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("SheenA"u8)) { - retA |= DrawSheen(table, dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawSheen(table, dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("SheenB"u8)) { - retB |= DrawSheen(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawSheen(table, dyeTable, dyePackB, rowBIdx); } } @@ -164,13 +161,13 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("BlendingA"u8)) { - retA |= DrawBlending(table, dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawBlending(table, dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("BlendingB"u8)) { - retB |= DrawBlending(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawBlending(table, dyeTable, dyePackB, rowBIdx); } } @@ -180,13 +177,13 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("TemplateA"u8)) { - retA |= DrawTemplate(table, dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawTemplate(table, dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("TemplateB"u8)) { - retB |= DrawTemplate(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawTemplate(table, dyeTable, dyePackB, rowBIdx); } } @@ -197,13 +194,13 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("DyeA"u8)) { - retA |= DrawDye(dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawDye(dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("DyeB"u8)) { - retB |= DrawDye(dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawDye(dyeTable, dyePackB, rowBIdx); } } @@ -213,20 +210,20 @@ public partial class MtrlTab using var dis = ImRaii.Disabled(disabled); using (ImUtf8.PushId("FurtherA"u8)) { - retA |= DrawFurther(table, dyeTable, dyePackA, _colorTableSelectedPair << 1); + retA |= DrawFurther(table, dyeTable, dyePackA, rowAIdx); } columns.Next(); using (ImUtf8.PushId("FurtherB"u8)) { - retB |= DrawFurther(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1); + retB |= DrawFurther(table, dyeTable, dyePackB, rowBIdx); } } if (retA) - UpdateColorTableRowPreview(_colorTableSelectedPair << 1); + UpdateColorTableRowPreview(rowAIdx); if (retB) - UpdateColorTableRowPreview((_colorTableSelectedPair << 1) | 1); + UpdateColorTableRowPreview(rowBIdx); return retA | retB; } @@ -239,6 +236,20 @@ public partial class MtrlTab ImUtf8.CollapsingHeader(label, ImGuiTreeNodeFlags.Leaf); } + private bool DrawRowHeader(int rowIdx, bool disabled) + { + ColorTableCopyClipboardButton(rowIdx); + ImUtf8.SameLineInner(); + var ret = ColorTablePasteFromClipboardButton(rowIdx, disabled); + ImUtf8.SameLineInner(); + ColorTableRowHighlightButton(rowIdx, disabled); + + ImGui.SameLine(); + CenteredTextInRest($"Row {(rowIdx >> 1) + 1}{"AB"[rowIdx & 1]}"); + + return ret; + } + private static bool DrawColors(ColorTable table, ColorDyeTable? dyeTable, DyePack? dyePack, int rowIdx) { var dyeOffset = ImGui.GetContentRegionAvail().X diff --git a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.CommonColorTable.cs b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.CommonColorTable.cs index 09c8ea61..38f02100 100644 --- a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.CommonColorTable.cs +++ b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.CommonColorTable.cs @@ -228,7 +228,7 @@ public partial class MtrlTab } } - private void ColorTableHighlightButton(int pairIdx, bool disabled) + private void ColorTablePairHighlightButton(int pairIdx, bool disabled) { ImUtf8.IconButton(FontAwesomeIcon.Crosshairs, "Highlight this pair of rows on your character, if possible.\n\nHighlight colors can be configured in Penumbra's settings."u8, @@ -240,6 +240,18 @@ public partial class MtrlTab CancelColorTableHighlight(); } + private void ColorTableRowHighlightButton(int rowIdx, bool disabled) + { + ImUtf8.IconButton(FontAwesomeIcon.Crosshairs, + "Highlight this row on your character, if possible.\n\nHighlight colors can be configured in Penumbra's settings."u8, + ImGui.GetFrameHeight() * Vector2.One, disabled || _colorTablePreviewers.Count == 0); + + if (ImGui.IsItemHovered()) + HighlightColorTableRow(rowIdx); + else if (_highlightedColorTableRow == rowIdx) + CancelColorTableHighlight(); + } + private static void CtBlendRect(Vector2 rcMin, Vector2 rcMax, uint topColor, uint bottomColor) { var style = ImGui.GetStyle(); diff --git a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LegacyColorTable.cs b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LegacyColorTable.cs index 0ff2b01f..f21d86a9 100644 --- a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LegacyColorTable.cs +++ b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LegacyColorTable.cs @@ -103,11 +103,8 @@ public partial class MtrlTab ColorTableCopyClipboardButton(rowIdx); ImUtf8.SameLineInner(); var ret = ColorTablePasteFromClipboardButton(rowIdx, disabled); - if ((rowIdx & 1) == 0) - { - ImUtf8.SameLineInner(); - ColorTableHighlightButton(rowIdx >> 1, disabled); - } + ImUtf8.SameLineInner(); + ColorTableRowHighlightButton(rowIdx, disabled); ImGui.TableNextColumn(); using (ImRaii.PushFont(UiBuilder.MonoFont)) @@ -213,11 +210,8 @@ public partial class MtrlTab ColorTableCopyClipboardButton(rowIdx); ImUtf8.SameLineInner(); var ret = ColorTablePasteFromClipboardButton(rowIdx, disabled); - if ((rowIdx & 1) == 0) - { - ImUtf8.SameLineInner(); - ColorTableHighlightButton(rowIdx >> 1, disabled); - } + ImUtf8.SameLineInner(); + ColorTableRowHighlightButton(rowIdx, disabled); ImGui.TableNextColumn(); using (ImRaii.PushFont(UiBuilder.MonoFont)) diff --git a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LivePreview.cs b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LivePreview.cs index 6089f2d5..01a40980 100644 --- a/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LivePreview.cs +++ b/Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LivePreview.cs @@ -14,6 +14,7 @@ public partial class MtrlTab { private readonly List _materialPreviewers = new(4); private readonly List _colorTablePreviewers = new(4); + private int _highlightedColorTableRow = -1; private int _highlightedColorTablePair = -1; private readonly Stopwatch _highlightTime = new(); @@ -168,13 +169,35 @@ public partial class MtrlTab } } + private void HighlightColorTableRow(int rowIdx) + { + var oldRowIdx = _highlightedColorTableRow; + + if (_highlightedColorTableRow != rowIdx) + { + _highlightedColorTableRow = rowIdx; + _highlightTime.Restart(); + } + + if (oldRowIdx >= 0) + UpdateColorTableRowPreview(oldRowIdx); + + if (rowIdx >= 0) + UpdateColorTableRowPreview(rowIdx); + } + private void CancelColorTableHighlight() { + var rowIdx = _highlightedColorTableRow; var pairIdx = _highlightedColorTablePair; + _highlightedColorTableRow = -1; _highlightedColorTablePair = -1; _highlightTime.Reset(); + if (rowIdx >= 0) + UpdateColorTableRowPreview(rowIdx); + if (pairIdx >= 0) { UpdateColorTableRowPreview(pairIdx << 1); @@ -214,7 +237,7 @@ public partial class MtrlTab } } - if (_highlightedColorTablePair << 1 == rowIdx) + if (_highlightedColorTablePair << 1 == rowIdx || _highlightedColorTableRow == rowIdx) ApplyHighlight(ref row, ColorId.InGameHighlight, (float)_highlightTime.Elapsed.TotalSeconds); else if (((_highlightedColorTablePair << 1) | 1) == rowIdx) ApplyHighlight(ref row, ColorId.InGameHighlight2, (float)_highlightTime.Elapsed.TotalSeconds); @@ -247,6 +270,9 @@ public partial class MtrlTab rows.ApplyDye(_stainService.GudStmFile, stainIds, dyeRows); } + if (_highlightedColorTableRow >= 0) + ApplyHighlight(ref rows[_highlightedColorTableRow], ColorId.InGameHighlight, (float)_highlightTime.Elapsed.TotalSeconds); + if (_highlightedColorTablePair >= 0) { ApplyHighlight(ref rows[_highlightedColorTablePair << 1], ColorId.InGameHighlight, (float)_highlightTime.Elapsed.TotalSeconds);