Skip to content

Commit f0c034c

Browse files
committed
Merge branch 'master' into dt-shmod
# Conflicts: # Penumbra/Communication/MtrlLoaded.cs
2 parents a36f9cc + df58ac7 commit f0c034c

File tree

6 files changed

+93
-44
lines changed

6 files changed

+93
-44
lines changed

Penumbra/Communication/MtrlLoaded.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public sealed class MtrlLoaded() : EventWrapper<nint, nint, MtrlLoaded.Priority>
1010
{
1111
public enum Priority
1212
{
13-
/// <seealso cref="Penumbra.Interop.Hooks.PostProcessing.ShaderReplacementFixer.OnMtrlLoaded"/>
13+
/// <seealso cref="Interop.Hooks.PostProcessing.ShaderReplacementFixer.OnMtrlLoaded"/>
1414
ShaderReplacementFixer = 0,
1515
}
1616
}

Penumbra/Interop/MaterialPreview/LiveColorTablePreviewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public LiveColorTablePreviewer(ObjectManager objects, IFramework framework, Mate
3737

3838

3939
_originalColorTableTexture = new SafeTextureHandle(*_colorTableTexture, true);
40-
if (_originalColorTableTexture == null)
40+
if (_originalColorTableTexture.Texture == null)
4141
throw new InvalidOperationException("Material doesn't have a color table");
4242

4343
Width = (int)_originalColorTableTexture.Texture->Width;

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

Lines changed: 47 additions & 30 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,17 +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-
ColorTableCopyClipboardButton(_colorTableSelectedPair << 1);
95-
ImUtf8.SameLineInner();
96-
retA |= ColorTablePasteFromClipboardButton(_colorTableSelectedPair << 1, disabled);
97-
ImGui.SameLine();
98-
CenteredTextInRest($"Row {_colorTableSelectedPair + 1}A");
99+
using (ImUtf8.PushId("RowHeaderA"u8))
100+
{
101+
retA |= DrawRowHeader(rowAIdx, disabled);
102+
}
99103
columns.Next();
100-
ColorTableCopyClipboardButton((_colorTableSelectedPair << 1) | 1);
101-
ImUtf8.SameLineInner();
102-
retB |= ColorTablePasteFromClipboardButton((_colorTableSelectedPair << 1) | 1, disabled);
103-
ImGui.SameLine();
104-
CenteredTextInRest($"Row {_colorTableSelectedPair + 1}B");
104+
using (ImUtf8.PushId("RowHeaderB"u8))
105+
{
106+
retB |= DrawRowHeader(rowBIdx, disabled);
107+
}
105108
}
106109

107110
DrawHeader(" Colors"u8);
@@ -110,13 +113,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
110113
using var dis = ImRaii.Disabled(disabled);
111114
using (ImUtf8.PushId("ColorsA"u8))
112115
{
113-
retA |= DrawColors(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
116+
retA |= DrawColors(table, dyeTable, dyePackA, rowAIdx);
114117
}
115118

116119
columns.Next();
117120
using (ImUtf8.PushId("ColorsB"u8))
118121
{
119-
retB |= DrawColors(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
122+
retB |= DrawColors(table, dyeTable, dyePackB, rowBIdx);
120123
}
121124
}
122125

@@ -126,13 +129,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
126129
using var dis = ImRaii.Disabled(disabled);
127130
using (ImUtf8.PushId("PbrA"u8))
128131
{
129-
retA |= DrawPbr(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
132+
retA |= DrawPbr(table, dyeTable, dyePackA, rowAIdx);
130133
}
131134

132135
columns.Next();
133136
using (ImUtf8.PushId("PbrB"u8))
134137
{
135-
retB |= DrawPbr(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
138+
retB |= DrawPbr(table, dyeTable, dyePackB, rowBIdx);
136139
}
137140
}
138141

@@ -142,13 +145,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
142145
using var dis = ImRaii.Disabled(disabled);
143146
using (ImUtf8.PushId("SheenA"u8))
144147
{
145-
retA |= DrawSheen(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
148+
retA |= DrawSheen(table, dyeTable, dyePackA, rowAIdx);
146149
}
147150

148151
columns.Next();
149152
using (ImUtf8.PushId("SheenB"u8))
150153
{
151-
retB |= DrawSheen(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
154+
retB |= DrawSheen(table, dyeTable, dyePackB, rowBIdx);
152155
}
153156
}
154157

@@ -158,13 +161,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
158161
using var dis = ImRaii.Disabled(disabled);
159162
using (ImUtf8.PushId("BlendingA"u8))
160163
{
161-
retA |= DrawBlending(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
164+
retA |= DrawBlending(table, dyeTable, dyePackA, rowAIdx);
162165
}
163166

164167
columns.Next();
165168
using (ImUtf8.PushId("BlendingB"u8))
166169
{
167-
retB |= DrawBlending(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
170+
retB |= DrawBlending(table, dyeTable, dyePackB, rowBIdx);
168171
}
169172
}
170173

@@ -174,13 +177,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
174177
using var dis = ImRaii.Disabled(disabled);
175178
using (ImUtf8.PushId("TemplateA"u8))
176179
{
177-
retA |= DrawTemplate(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
180+
retA |= DrawTemplate(table, dyeTable, dyePackA, rowAIdx);
178181
}
179182

180183
columns.Next();
181184
using (ImUtf8.PushId("TemplateB"u8))
182185
{
183-
retB |= DrawTemplate(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
186+
retB |= DrawTemplate(table, dyeTable, dyePackB, rowBIdx);
184187
}
185188
}
186189

@@ -191,13 +194,13 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
191194
using var dis = ImRaii.Disabled(disabled);
192195
using (ImUtf8.PushId("DyeA"u8))
193196
{
194-
retA |= DrawDye(dyeTable, dyePackA, _colorTableSelectedPair << 1);
197+
retA |= DrawDye(dyeTable, dyePackA, rowAIdx);
195198
}
196199

197200
columns.Next();
198201
using (ImUtf8.PushId("DyeB"u8))
199202
{
200-
retB |= DrawDye(dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
203+
retB |= DrawDye(dyeTable, dyePackB, rowBIdx);
201204
}
202205
}
203206

@@ -207,20 +210,20 @@ private bool DrawColorTablePairEditor(ColorTable table, ColorDyeTable? dyeTable,
207210
using var dis = ImRaii.Disabled(disabled);
208211
using (ImUtf8.PushId("FurtherA"u8))
209212
{
210-
retA |= DrawFurther(table, dyeTable, dyePackA, _colorTableSelectedPair << 1);
213+
retA |= DrawFurther(table, dyeTable, dyePackA, rowAIdx);
211214
}
212215

213216
columns.Next();
214217
using (ImUtf8.PushId("FurtherB"u8))
215218
{
216-
retB |= DrawFurther(table, dyeTable, dyePackB, (_colorTableSelectedPair << 1) | 1);
219+
retB |= DrawFurther(table, dyeTable, dyePackB, rowBIdx);
217220
}
218221
}
219222

220223
if (retA)
221-
UpdateColorTableRowPreview(_colorTableSelectedPair << 1);
224+
UpdateColorTableRowPreview(rowAIdx);
222225
if (retB)
223-
UpdateColorTableRowPreview((_colorTableSelectedPair << 1) | 1);
226+
UpdateColorTableRowPreview(rowBIdx);
224227

225228
return retA | retB;
226229
}
@@ -233,6 +236,20 @@ private static void DrawHeader(ReadOnlySpan<byte> label)
233236
ImUtf8.CollapsingHeader(label, ImGuiTreeNodeFlags.Leaf);
234237
}
235238

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+
236253
private static bool DrawColors(ColorTable table, ColorDyeTable? dyeTable, DyePack? dyePack, int rowIdx)
237254
{
238255
var dyeOffset = ImGui.GetContentRegionAvail().X
@@ -589,7 +606,7 @@ private bool DrawDye(ColorDyeTable dyeTable, DyePack? dyePack, int rowIdx)
589606
if (_stainService.GudTemplateCombo.Draw("##dyeTemplate", dye.Template.ToString(), string.Empty,
590607
scalarSize + ImGui.GetStyle().ScrollbarSize / 2, ImGui.GetTextLineHeightWithSpacing(), ImGuiComboFlags.NoArrowButton))
591608
{
592-
dye.Template = _stainService.LegacyTemplateCombo.CurrentSelection;
609+
dye.Template = _stainService.GudTemplateCombo.CurrentSelection;
593610
ret = true;
594611
}
595612

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)