-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathSPCGExCollectionGridTile.cpp
More file actions
706 lines (651 loc) · 22 KB
/
SPCGExCollectionGridTile.cpp
File metadata and controls
706 lines (651 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
// Copyright 2026 Timothé Lapetite and contributors
// Released under the MIT license https://opensource.org/license/MIT/
#include "Details/Collections/SPCGExCollectionGridTile.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "AssetThumbnail.h"
#include "Editor.h"
#include "ScopedTransaction.h"
#include "Core/PCGExAssetCollection.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Input/SCheckBox.h"
#include "Widgets/Input/SComboBox.h"
#include "Widgets/Input/SEditableTextBox.h"
#include "Widgets/Input/SSpinBox.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Layout/SWidgetSwitcher.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/Text/STextBlock.h"
namespace PCGExCollectionGrid
{
static const FName NewCategorySentinel("__PCGEx_NewCategory__");
}
#pragma region SPCGExCollectionGridTile
void SPCGExCollectionGridTile::Construct(const FArguments& InArgs)
{
ThumbnailPool = InArgs._ThumbnailPool;
TileSize = InArgs._TileSize;
Collection = InArgs._Collection;
EntryIndex = InArgs._EntryIndex;
CategoryIndex = InArgs._CategoryIndex;
CategoryOptions = InArgs._CategoryOptions;
OnTileClicked = InArgs._OnTileClicked;
OnTileDragDetected = InArgs._OnTileDragDetected;
OnTileCategoryChanged = InArgs._OnTileCategoryChanged;
OnTilePropertyChanged = InArgs._OnTilePropertyChanged;
ThumbnailCachePtr = InArgs._ThumbnailCachePtr;
BatchFlagPtr = InArgs._BatchFlagPtr;
TWeakObjectPtr<UPCGExAssetCollection> WeakColl = Collection;
const int32 Idx = EntryIndex;
// Build picker widget via delegate (type-specific)
TSharedRef<SWidget> PickerWidget = SNullWidget::NullWidget;
if (InArgs._OnGetPickerWidget.IsBound())
{
FSimpleDelegate RefreshDelegate = FSimpleDelegate::CreateSP(this, &SPCGExCollectionGridTile::RefreshThumbnail);
PickerWidget = InArgs._OnGetPickerWidget.Execute(Collection, EntryIndex, RefreshDelegate);
}
// Build category widget — combobox with "New..." option
TSharedRef<SWidget> CategoryWidget = SNullWidget::NullWidget;
if (CategoryOptions.IsValid())
{
CategoryWidget =
SAssignNew(CategoryWidgetSwitcher, SWidgetSwitcher)
.WidgetIndex(0)
// Index 0: Combobox
+ SWidgetSwitcher::Slot()
[
SAssignNew(CategoryCombo, SComboBox<TSharedPtr<FName>>)
.OptionsSource(&(*CategoryOptions))
.OnSelectionChanged_Lambda([this, WeakColl, Idx](TSharedPtr<FName> Selected, ESelectInfo::Type SelectType)
{
if (!Selected.IsValid() || SelectType == ESelectInfo::Direct) { return; }
if (*Selected == PCGExCollectionGrid::NewCategorySentinel)
{
// Switch to text entry mode
if (CategoryWidgetSwitcher.IsValid())
{
CategoryWidgetSwitcher->SetActiveWidgetIndex(1);
}
return;
}
// Set the category value
UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return; }
FPCGExAssetCollectionEntry* Entry = Coll->EDITOR_GetMutableEntry(Idx);
if (!Entry) { return; }
if (BatchFlagPtr) { *BatchFlagPtr = true; }
FScopedTransaction Transaction(INVTEXT("Change Category"));
Coll->Modify();
Entry->Category = *Selected;
Coll->PostEditChange();
if (BatchFlagPtr) { *BatchFlagPtr = false; }
OnTileCategoryChanged.ExecuteIfBound();
})
.OnGenerateWidget_Lambda([](TSharedPtr<FName> Item) -> TSharedRef<SWidget>
{
FText DisplayText;
if (!Item.IsValid() || Item->IsNone())
{
DisplayText = INVTEXT("Uncategorized");
}
else if (*Item == PCGExCollectionGrid::NewCategorySentinel)
{
DisplayText = INVTEXT("+ New...");
}
else
{
DisplayText = FText::FromName(*Item);
}
return SNew(STextBlock)
.Text(DisplayText)
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 8));
})
[
// Content (header button) — shows current category
SNew(STextBlock)
.Text_Lambda([WeakColl, Idx]() -> FText
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return INVTEXT("?"); }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid()) { return INVTEXT("?"); }
return Result.Entry->Category.IsNone() ? INVTEXT("Uncategorized") : FText::FromName(Result.Entry->Category);
})
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 7))
]
]
// Index 1: Editable text box for new category
+ SWidgetSwitcher::Slot()
[
SNew(SEditableTextBox)
.HintText(INVTEXT("New category..."))
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 7))
.OnTextCommitted_Lambda([this, WeakColl, Idx](const FText& Text, ETextCommit::Type CommitType)
{
if (CommitType == ETextCommit::OnEnter && !Text.IsEmpty())
{
UPCGExAssetCollection* Coll = WeakColl.Get();
if (Coll)
{
FPCGExAssetCollectionEntry* Entry = Coll->EDITOR_GetMutableEntry(Idx);
if (Entry)
{
const FName NewCat = FName(*Text.ToString());
if (BatchFlagPtr) { *BatchFlagPtr = true; }
FScopedTransaction Transaction(INVTEXT("New Category"));
Coll->Modify();
Entry->Category = NewCat;
Coll->PostEditChange();
if (BatchFlagPtr) { *BatchFlagPtr = false; }
OnTileCategoryChanged.ExecuteIfBound();
}
}
}
// Switch back to combobox mode
if (CategoryWidgetSwitcher.IsValid())
{
CategoryWidgetSwitcher->SetActiveWidgetIndex(0);
}
})
];
// Set initial combobox selection to match current category
if (CategoryCombo.IsValid())
{
FName CurrentCategory;
if (const UPCGExAssetCollection* Coll = WeakColl.Get())
{
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (Result.IsValid()) { CurrentCategory = Result.Entry->Category; }
}
for (const TSharedPtr<FName>& Option : *CategoryOptions)
{
if (Option.IsValid() && *Option == CurrentCategory)
{
CategoryCombo->SetSelectedItem(Option);
break;
}
}
}
}
const float ContentWidth = TileSize + 16.f;
// Index overlay text
const FText PrimaryIndexText = FText::AsNumber(EntryIndex);
const bool bHasCategoryIndex = (CategoryIndex != INDEX_NONE);
ChildSlot
[
// Selection highlight border (outermost)
SNew(SBorder)
.BorderImage(FAppStyle::GetBrush("Brushes.White"))
.BorderBackgroundColor_Lambda([this]() -> FSlateColor
{
return bIsSelected
? FSlateColor(FLinearColor(0.1f, 0.4f, 0.9f, 1.0f))
: FSlateColor(FLinearColor(0, 0, 0, 0));
})
.Padding(2.f)
[
SNew(SBorder)
.BorderImage(FAppStyle::GetBrush("ToolPanel.GroupBorder"))
.Padding(4.f)
[
SNew(SBox)
.WidthOverride(ContentWidth)
[
SNew(SVerticalBox)
// Top bar: SubCollection checkbox + Weight spinner
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(0, 0, 0, 2)
[
SNew(SHorizontalBox)
// SubCollection checkbox
+ SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
.Padding(0, 0, 4, 0)
[
SNew(SBox)
.ToolTipText(INVTEXT("Sub-collection"))
[
SNew(SCheckBox)
.IsChecked_Lambda([WeakColl, Idx]() -> ECheckBoxState
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return ECheckBoxState::Unchecked; }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid()) { return ECheckBoxState::Unchecked; }
return Result.Entry->bIsSubCollection ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
})
.OnCheckStateChanged_Lambda([this, WeakColl, Idx](ECheckBoxState NewState)
{
UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return; }
FPCGExAssetCollectionEntry* Entry = Coll->EDITOR_GetMutableEntry(Idx);
if (!Entry) { return; }
if (BatchFlagPtr) { *BatchFlagPtr = true; }
FScopedTransaction Transaction(INVTEXT("Toggle SubCollection"));
Coll->Modify();
Entry->bIsSubCollection = (NewState == ECheckBoxState::Checked);
Coll->PostEditChange();
if (BatchFlagPtr) { *BatchFlagPtr = false; }
RefreshThumbnail();
OnTilePropertyChanged.ExecuteIfBound();
})
]
]
+ SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
.Padding(0, 0, 4, 0)
[
SNew(STextBlock)
.Text(INVTEXT("Sub"))
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 7))
.ColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 0.5f)))
]
// Weight
+ SHorizontalBox::Slot()
.FillWidth(1.f)
.VAlign(VAlign_Center)
[
SNew(SBox)
.ToolTipText(INVTEXT("Weight"))
[
SNew(SSpinBox<int32>)
.MinValue(0)
.Delta(1)
.Value_Lambda([WeakColl, Idx]() -> int32
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return 0; }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
return Result.IsValid() ? Result.Entry->Weight : 0;
})
.OnBeginSliderMovement_Lambda([this, WeakColl]()
{
if (BatchFlagPtr) { *BatchFlagPtr = true; }
if (GEditor) { GEditor->BeginTransaction(INVTEXT("Adjust Weight")); }
if (UPCGExAssetCollection* Coll = WeakColl.Get()) { Coll->Modify(); }
})
.OnValueChanged_Lambda([WeakColl, Idx](int32 NewVal)
{
UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return; }
FPCGExAssetCollectionEntry* Entry = Coll->EDITOR_GetMutableEntry(Idx);
if (Entry) { Entry->Weight = NewVal; }
})
.OnEndSliderMovement_Lambda([this, WeakColl](int32)
{
if (UPCGExAssetCollection* Coll = WeakColl.Get()) { Coll->PostEditChange(); }
if (GEditor) { GEditor->EndTransaction(); }
if (BatchFlagPtr) { *BatchFlagPtr = false; }
OnTilePropertyChanged.ExecuteIfBound();
})
.OnValueCommitted_Lambda([this, WeakColl, Idx](int32 NewVal, ETextCommit::Type CommitType)
{
UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return; }
FPCGExAssetCollectionEntry* Entry = Coll->EDITOR_GetMutableEntry(Idx);
if (!Entry) { return; }
if (BatchFlagPtr) { *BatchFlagPtr = true; }
FScopedTransaction Transaction(INVTEXT("Set Weight"));
Coll->Modify();
Entry->Weight = NewVal;
Coll->PostEditChange();
if (BatchFlagPtr) { *BatchFlagPtr = false; }
OnTilePropertyChanged.ExecuteIfBound();
})
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 8))
]
]
]
// Thumbnail with [i|j] overlay
+ SVerticalBox::Slot()
.FillHeight(1.f)
.HAlign(HAlign_Center)
.Padding(0, 2)
[
SNew(SOverlay)
+ SOverlay::Slot()
[
SAssignNew(ThumbnailBox, SBox)
.WidthOverride(TileSize)
.HeightOverride(TileSize)
.Clipping(EWidgetClipping::ClipToBounds)
[
BuildThumbnailWidget()
]
]
// Index tag (top-left)
+ SOverlay::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.Padding(2.f)
[
SNew(SBorder)
.BorderImage(FAppStyle::GetBrush("Brushes.White"))
.BorderBackgroundColor(FLinearColor(0, 0, 0, 0.7f))
.Padding(FMargin(5, 2))
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.AutoWidth()
[
SNew(STextBlock)
.Text(PrimaryIndexText)
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 7))
.ColorAndOpacity(FSlateColor(FLinearColor::White))
]
+ SHorizontalBox::Slot()
.AutoWidth()
[
SNew(STextBlock)
.Text(FText::Format(INVTEXT(" | {0}"), FText::AsNumber(CategoryIndex)))
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 7))
.ColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 0.45f)))
.Visibility(bHasCategoryIndex ? EVisibility::HitTestInvisible : EVisibility::Collapsed)
]
]
]
// Meta badges (top-right)
+ SOverlay::Slot()
.HAlign(HAlign_Right)
.VAlign(VAlign_Top)
.Padding(2.f)
[
SNew(SHorizontalBox)
// Variations badge
+ SHorizontalBox::Slot()
.AutoWidth()
.Padding(1, 0)
[
SNew(SBorder)
.Visibility_Lambda([WeakColl, Idx]() -> EVisibility
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return EVisibility::Collapsed; }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid() || Result.Entry->bIsSubCollection) { return EVisibility::Collapsed; }
const FPCGExFittingVariations& V = Result.Entry->Variations;
const bool bHasVariations =
V.OffsetMin != FVector::ZeroVector || V.OffsetMax != FVector::ZeroVector ||
V.RotationMin != FRotator::ZeroRotator || V.RotationMax != FRotator::ZeroRotator ||
V.ScaleMin != FVector::OneVector || V.ScaleMax != FVector::OneVector;
return bHasVariations ? EVisibility::HitTestInvisible : EVisibility::Collapsed;
})
.BorderImage(FAppStyle::GetBrush("Brushes.White"))
.BorderBackgroundColor(FLinearColor(0.6f, 0.4f, 0.1f, 0.85f))
.Padding(FMargin(3, 1))
[
SNew(STextBlock)
.Text(INVTEXT("V"))
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 6))
.ColorAndOpacity(FSlateColor(FLinearColor::White))
]
]
// Sockets badge
+ SHorizontalBox::Slot()
.AutoWidth()
.Padding(1, 0)
[
SNew(SBorder)
.Visibility_Lambda([WeakColl, Idx]() -> EVisibility
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return EVisibility::Collapsed; }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid() || Result.Entry->bIsSubCollection) { return EVisibility::Collapsed; }
return !Result.Entry->Staging.Sockets.IsEmpty() ? EVisibility::HitTestInvisible : EVisibility::Collapsed;
})
.BorderImage(FAppStyle::GetBrush("Brushes.White"))
.BorderBackgroundColor(FLinearColor(0.1f, 0.5f, 0.6f, 0.85f))
.Padding(FMargin(3, 1))
[
SNew(STextBlock)
.Text_Lambda([WeakColl, Idx]() -> FText
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return FText::GetEmpty(); }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid()) { return FText::GetEmpty(); }
return FText::Format(INVTEXT("S:{0}"), FText::AsNumber(Result.Entry->Staging.Sockets.Num()));
})
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 6))
.ColorAndOpacity(FSlateColor(FLinearColor::White))
]
]
// Tags badge
+ SHorizontalBox::Slot()
.AutoWidth()
.Padding(1, 0)
[
SNew(SBorder)
.Visibility_Lambda([WeakColl, Idx]() -> EVisibility
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return EVisibility::Collapsed; }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid()) { return EVisibility::Collapsed; }
return !Result.Entry->Tags.IsEmpty() ? EVisibility::HitTestInvisible : EVisibility::Collapsed;
})
.BorderImage(FAppStyle::GetBrush("Brushes.White"))
.BorderBackgroundColor(FLinearColor(0.4f, 0.2f, 0.6f, 0.85f))
.Padding(FMargin(3, 1))
[
SNew(STextBlock)
.Text(INVTEXT("T"))
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 6))
.ColorAndOpacity(FSlateColor(FLinearColor::White))
]
]
// PropertyOverrides badge
+ SHorizontalBox::Slot()
.AutoWidth()
.Padding(1, 0)
[
SNew(SBorder)
.Visibility_Lambda([WeakColl, Idx]() -> EVisibility
{
const UPCGExAssetCollection* Coll = WeakColl.Get();
if (!Coll) { return EVisibility::Collapsed; }
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(Idx);
if (!Result.IsValid() || Result.Entry->bIsSubCollection) { return EVisibility::Collapsed; }
return Result.Entry->PropertyOverrides.GetEnabledCount() > 0 ? EVisibility::HitTestInvisible : EVisibility::Collapsed;
})
.BorderImage(FAppStyle::GetBrush("Brushes.White"))
.BorderBackgroundColor(FLinearColor(0.2f, 0.6f, 0.3f, 0.85f))
.Padding(FMargin(3, 1))
[
SNew(STextBlock)
.Text(INVTEXT("P"))
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 6))
.ColorAndOpacity(FSlateColor(FLinearColor::White))
]
]
]
]
// Picker (type-specific: mesh picker, actor class picker, etc.)
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(0, 2)
[
PickerWidget
]
// Category combobox
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(0, 2, 0, 0)
[
SNew(SBorder)
.BorderImage(FAppStyle::GetNoBrush())
.ColorAndOpacity(FLinearColor(1.f, 1.f, 1.f, 0.8f))
.Padding(0)
[
CategoryWidget
]
]
]
]
]
];
}
FReply SPCGExCollectionGridTile::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
{
// If modifier keys or unselected: apply selection immediately
// If already selected without modifiers: defer to mouse-up (preserves multi-select for drag)
if (MouseEvent.IsControlDown() || MouseEvent.IsShiftDown() || !bIsSelected)
{
OnTileClicked.ExecuteIfBound(EntryIndex, MouseEvent);
bPendingClick = false;
}
else
{
bPendingClick = true;
}
return FReply::Handled().DetectDrag(SharedThis(this), EKeys::LeftMouseButton);
}
return FReply::Unhandled();
}
FReply SPCGExCollectionGridTile::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton && bPendingClick)
{
bPendingClick = false;
// Deferred exclusive select — was already selected, user didn't drag
OnTileClicked.ExecuteIfBound(EntryIndex, MouseEvent);
return FReply::Handled();
}
return FReply::Unhandled();
}
FReply SPCGExCollectionGridTile::OnDragDetected(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
bPendingClick = false;
if (OnTileDragDetected.IsBound())
{
return OnTileDragDetected.Execute(EntryIndex, MouseEvent);
}
return FReply::Unhandled();
}
void SPCGExCollectionGridTile::RefreshThumbnail()
{
if (!ThumbnailBox.IsValid()) { return; }
// Check if the visual state has actually changed
const UPCGExAssetCollection* Coll = Collection.Get();
if (Coll && EntryIndex != INDEX_NONE)
{
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(EntryIndex);
if (Result.IsValid())
{
const bool bIsSub = Result.Entry->bIsSubCollection;
const FSoftObjectPath& CurrentPath = Result.Entry->Staging.Path;
if (CurrentPath == CachedStagingPath && bIsSub == bCachedIsSubCollection)
{
return; // Nothing visual changed, skip rebuild
}
}
}
ThumbnailBox->SetContent(BuildThumbnailWidget());
}
TSharedRef<SWidget> SPCGExCollectionGridTile::BuildThumbnailWidget()
{
if (!ThumbnailPool.IsValid())
{
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(INVTEXT("?"))
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 16))
.ColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 0.3f)))
];
}
// Read staging data directly from the collection UObject
const UPCGExAssetCollection* Coll = Collection.Get();
if (!Coll || EntryIndex == INDEX_NONE)
{
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(INVTEXT("?"))
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 16))
.ColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 0.3f)))
];
}
const FPCGExEntryAccessResult Result = Coll->GetEntryRaw(EntryIndex);
if (!Result.IsValid())
{
CachedStagingPath.Reset();
bCachedIsSubCollection = false;
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(INVTEXT("Invalid"))
.Font(FCoreStyle::GetDefaultFontStyle("Italic", 8))
.ColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 0.3f)))
];
}
// Update cache
bCachedIsSubCollection = Result.Entry->bIsSubCollection;
CachedStagingPath = Result.Entry->Staging.Path;
// Subcollection — show collection icon
if (Result.Entry->bIsSubCollection)
{
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(SImage)
.Image(FAppStyle::GetBrush("ClassIcon.DataAsset"))
.DesiredSizeOverride(FVector2D(48, 48))
];
}
// Get asset path from staging data
const FSoftObjectPath& AssetPath = CachedStagingPath;
if (AssetPath.IsNull())
{
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(INVTEXT("No Asset"))
.Font(FCoreStyle::GetDefaultFontStyle("Italic", 8))
.ColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 0.3f)))
];
}
// Check cache first
if (ThumbnailCachePtr)
{
if (TSharedPtr<FAssetThumbnail>* Cached = ThumbnailCachePtr->Find(AssetPath))
{
Thumbnail = *Cached;
FAssetThumbnailConfig ThumbnailConfig;
ThumbnailConfig.bAllowFadeIn = false;
return Thumbnail->MakeThumbnailWidget(ThumbnailConfig);
}
}
// Resolve FAssetData from path and create thumbnail
const IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get();
const FAssetData AssetData = AssetRegistry.GetAssetByObjectPath(AssetPath);
const int32 ThumbnailResolution = FMath::RoundToInt32(TileSize);
Thumbnail = MakeShared<FAssetThumbnail>(AssetData, ThumbnailResolution, ThumbnailResolution, ThumbnailPool);
// Store in cache
if (ThumbnailCachePtr)
{
ThumbnailCachePtr->Add(AssetPath, Thumbnail);
}
if (Thumbnail.IsValid())
{
FAssetThumbnailConfig ThumbnailConfig;
ThumbnailConfig.bAllowFadeIn = true;
return Thumbnail->MakeThumbnailWidget(ThumbnailConfig);
}
return SNullWidget::NullWidget;
}
#pragma endregion