Skip to content

Commit a40a5d3

Browse files
committed
Merge remote-tracking branch 'Exter-N/single-row-highlight'
2 parents 0d1ed6a + 1187efa commit a40a5d3

File tree

4 files changed

+86
-43
lines changed

4 files changed

+86
-43
lines changed

Penumbra/UI/AdvancedWindow/Materials/MtrlTab.ColorTable.cs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ private void DrawColorTablePairSelector(ColorTable table, bool disabled)
3030
var buttonWidth = (ImGui.GetContentRegionAvail().X - itemSpacing * 7.0f) * 0.125f;
3131
var frameHeight = ImGui.GetFrameHeight();
3232
var highlighterSize = ImUtf8.CalcIconSize(FontAwesomeIcon.Crosshairs) + framePadding * 2.0f;
33-
var spaceWidth = ImUtf8.CalcTextSize(" "u8).X;
34-
var spacePadding = (int)MathF.Ceiling((highlighterSize.X + framePadding.X + itemInnerSpacing) / spaceWidth);
3533

3634
using var font = ImRaii.PushFont(UiBuilder.MonoFont);
3735
using var alignment = ImRaii.PushStyle(ImGuiStyleVar.ButtonTextAlign, new Vector2(0, 0.5f));
36+
37+
// This depends on the font being pushed for "proper" alignment of the pair indices in the buttons.
38+
var spaceWidth = ImUtf8.CalcTextSize(" "u8).X;
39+
var spacePadding = (int)MathF.Ceiling((highlighterSize.X + framePadding.X + itemInnerSpacing) / spaceWidth);
40+
3841
for (var i = 0; i < ColorTable.NumRows >> 1; i += 8)
3942
{
4043
for (var j = 0; j < 8; ++j)
@@ -72,7 +75,7 @@ private void DrawColorTablePairSelector(ColorTable table, bool disabled)
7275
var cursor = ImGui.GetCursorScreenPos();
7376
ImGui.SetCursorScreenPos(rcMin with { Y = float.Lerp(rcMin.Y, rcMax.Y, 0.5f) - highlighterSize.Y * 0.5f });
7477
font.Pop();
75-
ColorTableHighlightButton(pairIndex, disabled);
78+
ColorTablePairHighlightButton(pairIndex, disabled);
7679
font.Push(UiBuilder.MonoFont);
7780
ImGui.SetCursorScreenPos(cursor);
7881
}
@@ -83,6 +86,8 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
8386
{
8487
var retA = false;
8588
var retB = false;
89+
var rowAIdx = _colorTableSelectedPair << 1;
90+
var rowBIdx = rowAIdx | 1;
8691
var dyeA = dyeTable?[_colorTableSelectedPair << 1] ?? default;
8792
var dyeB = dyeTable?[(_colorTableSelectedPair << 1) | 1] ?? default;
8893
var previewDyeA = _stainService.GetStainCombo(dyeA.Channel).CurrentSelection.Key;
@@ -91,23 +96,15 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
9196
var dyePackB = _stainService.GudStmFile.GetValueOrNull(dyeB.Template, previewDyeB);
9297
using (var columns = ImUtf8.Columns(2, "ColorTable"u8))
9398
{
94-
using (ImUtf8.PushId("ClipboardA"u8))
99+
using (ImUtf8.PushId("RowHeaderA"u8))
95100
{
96-
ColorTableCopyClipboardButton(_colorTableSelectedPair << 1);
97-
ImUtf8.SameLineInner();
98-
retA |= ColorTablePasteFromClipboardButton(_colorTableSelectedPair << 1, disabled);
101+
retA |= DrawRowHeader(rowAIdx, disabled);
99102
}
100-
ImGui.SameLine();
101-
CenteredTextInRest($"Row {_colorTableSelectedPair + 1}A");
102103
columns.Next();
103-
using (ImUtf8.PushId("ClipboardB"u8))
104+
using (ImUtf8.PushId("RowHeaderB"u8))
104105
{
105-
ColorTableCopyClipboardButton((_colorTableSelectedPair << 1) | 1);
106-
ImUtf8.SameLineInner();
107-
retB |= ColorTablePasteFromClipboardButton((_colorTableSelectedPair << 1) | 1, disabled);
106+
retB |= DrawRowHeader(rowBIdx, disabled);
108107
}
109-
ImGui.SameLine();
110-
CenteredTextInRest($"Row {_colorTableSelectedPair + 1}B");
111108
}
112109

113110
DrawHeader(" Colors"u8);
@@ -116,13 +113,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
116113
using var dis = ImRaii.Disabled(disabled);
117114
using (ImUtf8.PushId("ColorsA"u8))
118115
{
119-
retA |= DrawColors(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
116+
retA |= DrawColors(table, dyeTable, dyePackA, rowAIdx);
120117
}
121118

122119
columns.Next();
123120
using (ImUtf8.PushId("ColorsB"u8))
124121
{
125-
retB |= DrawColors(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
122+
retB |= DrawColors(table, dyeTable, dyePackB, rowBIdx);
126123
}
127124
}
128125

@@ -132,13 +129,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
132129
using var dis = ImRaii.Disabled(disabled);
133130
using (ImUtf8.PushId("PbrA"u8))
134131
{
135-
retA |= DrawPbr(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
132+
retA |= DrawPbr(table, dyeTable, dyePackA, rowAIdx);
136133
}
137134

138135
columns.Next();
139136
using (ImUtf8.PushId("PbrB"u8))
140137
{
141-
retB |= DrawPbr(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
138+
retB |= DrawPbr(table, dyeTable, dyePackB, rowBIdx);
142139
}
143140
}
144141

@@ -148,13 +145,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
148145
using var dis = ImRaii.Disabled(disabled);
149146
using (ImUtf8.PushId("SheenA"u8))
150147
{
151-
retA |= DrawSheen(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
148+
retA |= DrawSheen(table, dyeTable, dyePackA, rowAIdx);
152149
}
153150

154151
columns.Next();
155152
using (ImUtf8.PushId("SheenB"u8))
156153
{
157-
retB |= DrawSheen(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
154+
retB |= DrawSheen(table, dyeTable, dyePackB, rowBIdx);
158155
}
159156
}
160157

@@ -164,13 +161,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
164161
using var dis = ImRaii.Disabled(disabled);
165162
using (ImUtf8.PushId("BlendingA"u8))
166163
{
167-
retA |= DrawBlending(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
164+
retA |= DrawBlending(table, dyeTable, dyePackA, rowAIdx);
168165
}
169166

170167
columns.Next();
171168
using (ImUtf8.PushId("BlendingB"u8))
172169
{
173-
retB |= DrawBlending(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
170+
retB |= DrawBlending(table, dyeTable, dyePackB, rowBIdx);
174171
}
175172
}
176173

@@ -180,13 +177,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
180177
using var dis = ImRaii.Disabled(disabled);
181178
using (ImUtf8.PushId("TemplateA"u8))
182179
{
183-
retA |= DrawTemplate(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
180+
retA |= DrawTemplate(table, dyeTable, dyePackA, rowAIdx);
184181
}
185182

186183
columns.Next();
187184
using (ImUtf8.PushId("TemplateB"u8))
188185
{
189-
retB |= DrawTemplate(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
186+
retB |= DrawTemplate(table, dyeTable, dyePackB, rowBIdx);
190187
}
191188
}
192189

@@ -197,13 +194,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
197194
using var dis = ImRaii.Disabled(disabled);
198195
using (ImUtf8.PushId("DyeA"u8))
199196
{
200-
retA |= DrawDye(dyeTable, dyePackA, _colorTableSelectedPair << 1);
197+
retA |= DrawDye(dyeTable, dyePackA, rowAIdx);
201198
}
202199

203200
columns.Next();
204201
using (ImUtf8.PushId("DyeB"u8))
205202
{
206-
retB |= DrawDye(dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
203+
retB |= DrawDye(dyeTable, dyePackB, rowBIdx);
207204
}
208205
}
209206

@@ -213,20 +210,20 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
213210
using var dis = ImRaii.Disabled(disabled);
214211
using (ImUtf8.PushId("FurtherA"u8))
215212
{
216-
retA |= DrawFurther(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
213+
retA |= DrawFurther(table, dyeTable, dyePackA, rowAIdx);
217214
}
218215

219216
columns.Next();
220217
using (ImUtf8.PushId("FurtherB"u8))
221218
{
222-
retB |= DrawFurther(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
219+
retB |= DrawFurther(table, dyeTable, dyePackB, rowBIdx);
223220
}
224221
}
225222

226223
if (retA)
227-
UpdateColorTableRowPreview(_colorTableSelectedPair << 1);
224+
UpdateColorTableRowPreview(rowAIdx);
228225
if (retB)
229-
UpdateColorTableRowPreview((_colorTableSelectedPair << 1) | 1);
226+
UpdateColorTableRowPreview(rowBIdx);
230227

231228
return retA | retB;
232229
}
@@ -239,6 +236,20 @@ private static void DrawHeader(ReadOnlySpan<byte> label)
239236
ImUtf8.CollapsingHeader(label, ImGuiTreeNodeFlags.Leaf);
240237
}
241238

239+
private bool DrawRowHeader(int rowIdx, bool disabled)
240+
{
241+
ColorTableCopyClipboardButton(rowIdx);
242+
ImUtf8.SameLineInner();
243+
var ret = ColorTablePasteFromClipboardButton(rowIdx, disabled);
244+
ImUtf8.SameLineInner();
245+
ColorTableRowHighlightButton(rowIdx, disabled);
246+
247+
ImGui.SameLine();
248+
CenteredTextInRest($"Row {(rowIdx >> 1) + 1}{"AB"[rowIdx & 1]}");
249+
250+
return ret;
251+
}
252+
242253
private static bool DrawColors(ColorTable table, ColorDyeTable? dyeTable, DyePack? dyePack, int rowIdx)
243254
{
244255
var dyeOffset = ImGui.GetContentRegionAvail().X

Penumbra/UI/AdvancedWindow/Materials/MtrlTab.CommonColorTable.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private bool ColorTablePasteFromClipboardButton(int rowIdx, bool disabled)
228228
}
229229
}
230230

231-
private void ColorTableHighlightButton(int pairIdx, bool disabled)
231+
private void ColorTablePairHighlightButton(int pairIdx, bool disabled)
232232
{
233233
ImUtf8.IconButton(FontAwesomeIcon.Crosshairs,
234234
"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 @@ private void ColorTableHighlightButton(int pairIdx, bool disabled)
240240
CancelColorTableHighlight();
241241
}
242242

243+
private void ColorTableRowHighlightButton(int rowIdx, bool disabled)
244+
{
245+
ImUtf8.IconButton(FontAwesomeIcon.Crosshairs,
246+
"Highlight this row on your character, if possible.\n\nHighlight colors can be configured in Penumbra's settings."u8,
247+
ImGui.GetFrameHeight() * Vector2.One, disabled || _colorTablePreviewers.Count == 0);
248+
249+
if (ImGui.IsItemHovered())
250+
HighlightColorTableRow(rowIdx);
251+
else if (_highlightedColorTableRow == rowIdx)
252+
CancelColorTableHighlight();
253+
}
254+
243255
private static void CtBlendRect(Vector2 rcMin, Vector2 rcMax, uint topColor, uint bottomColor)
244256
{
245257
var style = ImGui.GetStyle();

Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LegacyColorTable.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,8 @@ private bool DrawLegacyColorTableRow(LegacyColorTable table, LegacyColorDyeTable
103103
ColorTableCopyClipboardButton(rowIdx);
104104
ImUtf8.SameLineInner();
105105
var ret = ColorTablePasteFromClipboardButton(rowIdx, disabled);
106-
if ((rowIdx & 1) == 0)
107-
{
108-
ImUtf8.SameLineInner();
109-
ColorTableHighlightButton(rowIdx >> 1, disabled);
110-
}
106+
ImUtf8.SameLineInner();
107+
ColorTableRowHighlightButton(rowIdx, disabled);
111108

112109
ImGui.TableNextColumn();
113110
using (ImRaii.PushFont(UiBuilder.MonoFont))
@@ -213,11 +210,8 @@ private bool DrawLegacyColorTableRow(ColorTable table, ColorDyeTable? dyeTable,
213210
ColorTableCopyClipboardButton(rowIdx);
214211
ImUtf8.SameLineInner();
215212
var ret = ColorTablePasteFromClipboardButton(rowIdx, disabled);
216-
if ((rowIdx & 1) == 0)
217-
{
218-
ImUtf8.SameLineInner();
219-
ColorTableHighlightButton(rowIdx >> 1, disabled);
220-
}
213+
ImUtf8.SameLineInner();
214+
ColorTableRowHighlightButton(rowIdx, disabled);
221215

222216
ImGui.TableNextColumn();
223217
using (ImRaii.PushFont(UiBuilder.MonoFont))

Penumbra/UI/AdvancedWindow/Materials/MtrlTab.LivePreview.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public partial class MtrlTab
1414
{
1515
private readonly List<LiveMaterialPreviewer> _materialPreviewers = new(4);
1616
private readonly List<LiveColorTablePreviewer> _colorTablePreviewers = new(4);
17+
private int _highlightedColorTableRow = -1;
1718
private int _highlightedColorTablePair = -1;
1819
private readonly Stopwatch _highlightTime = new();
1920

@@ -168,13 +169,35 @@ private void HighlightColorTablePair(int pairIdx)
168169
}
169170
}
170171

172+
private void HighlightColorTableRow(int rowIdx)
173+
{
174+
var oldRowIdx = _highlightedColorTableRow;
175+
176+
if (_highlightedColorTableRow != rowIdx)
177+
{
178+
_highlightedColorTableRow = rowIdx;
179+
_highlightTime.Restart();
180+
}
181+
182+
if (oldRowIdx >= 0)
183+
UpdateColorTableRowPreview(oldRowIdx);
184+
185+
if (rowIdx >= 0)
186+
UpdateColorTableRowPreview(rowIdx);
187+
}
188+
171189
private void CancelColorTableHighlight()
172190
{
191+
var rowIdx = _highlightedColorTableRow;
173192
var pairIdx = _highlightedColorTablePair;
174193

194+
_highlightedColorTableRow = -1;
175195
_highlightedColorTablePair = -1;
176196
_highlightTime.Reset();
177197

198+
if (rowIdx >= 0)
199+
UpdateColorTableRowPreview(rowIdx);
200+
178201
if (pairIdx >= 0)
179202
{
180203
UpdateColorTableRowPreview(pairIdx << 1);
@@ -214,7 +237,7 @@ private void UpdateColorTableRowPreview(int rowIdx)
214237
}
215238
}
216239

217-
if (_highlightedColorTablePair << 1 == rowIdx)
240+
if (_highlightedColorTablePair << 1 == rowIdx || _highlightedColorTableRow == rowIdx)
218241
ApplyHighlight(ref row, ColorId.InGameHighlight, (float)_highlightTime.Elapsed.TotalSeconds);
219242
else if (((_highlightedColorTablePair << 1) | 1) == rowIdx)
220243
ApplyHighlight(ref row, ColorId.InGameHighlight2, (float)_highlightTime.Elapsed.TotalSeconds);
@@ -247,6 +270,9 @@ private void UpdateColorTablePreview()
247270
rows.ApplyDye(_stainService.GudStmFile, stainIds, dyeRows);
248271
}
249272

273+
if (_highlightedColorTableRow >= 0)
274+
ApplyHighlight(ref rows[_highlightedColorTableRow], ColorId.InGameHighlight, (float)_highlightTime.Elapsed.TotalSeconds);
275+
250276
if (_highlightedColorTablePair >= 0)
251277
{
252278
ApplyHighlight(ref rows[_highlightedColorTablePair << 1], ColorId.InGameHighlight, (float)_highlightTime.Elapsed.TotalSeconds);

0 commit comments

Comments
 (0)