Skip to content

Commit 1828881

Browse files
committed
Add partial copying of color and colordye tables.
1 parent cc97ea0 commit 1828881

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

Penumbra.GameData

Submodule Penumbra.GameData updated 41 files

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

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,74 @@ private bool ColorTablePasteFromClipboardButton(int rowIdx, bool disabled)
202202
if (Mtrl.Table == null)
203203
return false;
204204

205-
if (!ImUtf8.IconButton(FontAwesomeIcon.Paste, "Import an exported row from your clipboard onto this row."u8,
205+
if (ImUtf8.IconButton(FontAwesomeIcon.Paste,
206+
"Import an exported row from your clipboard onto this row.\n\nRight-Click for more options."u8,
206207
ImGui.GetFrameHeight() * Vector2.One, disabled))
208+
try
209+
{
210+
var text = ImGui.GetClipboardText();
211+
var data = Convert.FromBase64String(text);
212+
var row = Mtrl.Table.RowAsBytes(rowIdx);
213+
var dyeRow = Mtrl.DyeTable != null ? Mtrl.DyeTable.RowAsBytes(rowIdx) : [];
214+
if (data.Length != row.Length && data.Length != row.Length + dyeRow.Length)
215+
return false;
216+
217+
data.AsSpan(0, row.Length).TryCopyTo(row);
218+
data.AsSpan(row.Length).TryCopyTo(dyeRow);
219+
220+
UpdateColorTableRowPreview(rowIdx);
221+
222+
return true;
223+
}
224+
catch
225+
{
226+
return false;
227+
}
228+
229+
return ColorTablePasteFromClipboardContext(rowIdx, disabled);
230+
}
231+
232+
private unsafe bool ColorTablePasteFromClipboardContext(int rowIdx, bool disabled)
233+
{
234+
if (!disabled && ImGui.IsItemClicked(ImGuiMouseButton.Right))
235+
ImUtf8.OpenPopup("context"u8);
236+
237+
using var context = ImUtf8.Popup("context"u8);
238+
if (!context)
239+
return false;
240+
241+
using var _ = ImRaii.Disabled(disabled);
242+
243+
IColorTable.ValueTypes copy = 0;
244+
IColorDyeTable.ValueTypes dyeCopy = 0;
245+
if (ImUtf8.Selectable("Import Colors Only"u8))
246+
{
247+
copy = IColorTable.ValueTypes.Colors;
248+
dyeCopy = IColorDyeTable.ValueTypes.Colors;
249+
}
250+
251+
if (ImUtf8.Selectable("Import Other Values Only"u8))
252+
{
253+
copy = ~IColorTable.ValueTypes.Colors;
254+
dyeCopy = ~IColorDyeTable.ValueTypes.Colors;
255+
}
256+
257+
if (copy == 0)
207258
return false;
208259

209260
try
210261
{
211262
var text = ImGui.GetClipboardText();
212263
var data = Convert.FromBase64String(text);
213-
var row = Mtrl.Table.RowAsBytes(rowIdx);
264+
var row = Mtrl.Table!.RowAsHalves(rowIdx);
265+
var halves = new Span<Half>(Unsafe.AsPointer(ref data[0]), row.Length);
214266
var dyeRow = Mtrl.DyeTable != null ? Mtrl.DyeTable.RowAsBytes(rowIdx) : [];
215-
if (data.Length != row.Length && data.Length != row.Length + dyeRow.Length)
267+
if (!Mtrl.Table.MergeSpecificValues(row, halves, copy))
216268
return false;
217269

218-
data.AsSpan(0, row.Length).TryCopyTo(row);
219-
data.AsSpan(row.Length).TryCopyTo(dyeRow);
270+
Mtrl.DyeTable?.MergeSpecificValues(dyeRow, data.AsSpan(row.Length * 2), dyeCopy);
220271

221272
UpdateColorTableRowPreview(rowIdx);
222-
223273
return true;
224274
}
225275
catch

0 commit comments

Comments
 (0)