forked from guitarfreak/PropertyWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropertyWatcher.cpp
2227 lines (1811 loc) · 79.1 KB
/
PropertyWatcher.cpp
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Info:
https://forums.unrealengine.com/t/a-sample-for-calling-a-ufunction-with-reflection/276416/9
https://ikrima.dev/ue4guide/engine-programming/uobject-reflection/uobject-reflection/
void UObject::ParseParms( const TCHAR* Parms )
https://www.cnblogs.com/LynnVon/p/14794664.html
https://github.com/ocornut/imgui/issues/718
https://forums.unrealengine.com/t/using-clang-to-compile-on-windows/17478/51
Not Important:
- handle right clip copy and paste
- export import everything with json
try to use unreal serialization functions in properties.
- favourites can be selected and deleted with del
- selection happens on first cell background?
- Sorting
- make tool for stepping timesteps, pause, continue, maybe speed up gamespeed
- idea: could filter everything if we do a complete full pre pass by asking all children if they have the searched item
- Better line trace.
- make save and restore functions for window settings
- super bonus: hide things that have changed from base object like in details viewer in unreal
- ability to modify contains like array and map, add/remove/insert and so on
- look at EFieldIterationFlags
- Metadata: use keys: Category, UIMin, UIMax
maybe: tooltip, sliderexponent?
- add ability to categorise any table column, right now we hardcoded class categories,
but could make it dynamic and then use metadata categories
- metadata categories, Property->MetaDataMap
- add hot keys for enabling filter, classes, functions
- call functions in watchItemPaths like Manager.SubObject.CallFunc:GetCurrentThing.Member
- Make it easier to add unique struct handlings, make it so code is not so spread out.
- unreal engine clang compile test
Easy to implement:
- add ctrl+shift+alt + numbers for menu navigation
- ctrl+123 to switch between tabs
- make value was updated animations
- make background transparent mode, overlay style
- if search input already focused, ctrl+f should select everything
Things to handle:
- WorldOutline, Actor components, widget tree
Problems:
- classes left navigation doesnt work
- blueprint functions have wrong parameters in property cpp type
- Delegates don't get inlined?
global settings to change float text input to sliders, and also global settings for drag change speed
crash on weakpointerget when bp selected camera search for private and disable classes
***
- print container preview up to property value region size, the more you open the column the more you see
- Fix blueprint struct members that have _C_0 and so on
- make mode that diffs current values of object with default class variables.
- compare categories from widgets and actors and see how they are composed
- for call functions dynamically we could use all our widgets for input and then store the result in a input
we could then display it with drawItem, all the information is in the properties of the function, including the result property
- draw widget tree
- add option to auto push nodes on left side so you can see more and the padding isnt so big on big trees
- clamp property name text to right and clip left so right side
of text is always visible, which is more important
- Button to clear custom storage like inlining
- handle UberGaphFrame functions
- Class pointer members maybe do default object.
- column texts as value or string to distinguish between text and value filtering.
***
Todo before release:
- search should be able to do structvar.membervar = 5
- better search: maybe make a mode "hide non value types" that hides a list of things like delegates that you never want to see
maybe 2 search boxes, second for permanent stuff like hiding delegates, first one for quick searches.
- search jump to next result
- detached watch windows
- custom draw functions for data
- add right click "draw as" (rect, whatever)
- manipulator widget based on data like position, show in world
- simple function calling
Make functions expandable in tree form, and leafs are arguments and return value
- simple delegate calling
- fix maps with touples
- auto complete for watch window members
- property path by member value
- make path with custom getter-> instead of array index look at object and test for name or something
- make custom path by dragging from a value, that should make link to parent node with that value being looked for
- try imgui viewports
***
Server comm widget console explorer thing:
- client ask server what vars there are, server answers.
- if text box empty all names are listed
- double click, when server answers list things
imgui on server?
maybe server could give answer for vars as json string
like you ask him for stuff and he gets the var/struct and returns the thing as string
maybe explorer for member vars
Another idea: Make server send snapshot of object that you want to look at, server serializes it and client stores it
allow overscroll in tables, so we dont jump up when we clamp
make memory snapshot
Bugs:
- Error when inlining this PlayerController.AcknowledgedPawn.PlayerState.PawnPrivate.Controller.PlayerInput.DebugExecBindings in watch tab
and setting inline stack to 2
Structs don't inline correctly in watch window as first item.
*/
#if !UE_SERVER
#define PROPERTY_WATCHER_INTERNAL
#include "PropertyWatcher.h"
#undef PROPERTY_WATCHER_INTERNAL
#include "imgui.h"
#include "imgui_internal.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Engine/StaticMeshActor.h"
#include "GameFramework/PlayerController.h"
#include "UObject/Stack.h"
#include "Engine/Level.h"
#include "Misc/ExpressionParser.h"
#include "Internationalization/Regex.h"
//using namespace PropertyWatcher;
#if WITH_EDITORONLY_DATA
#define MetaData_Available true
#else
#define MetaData_Available false
#endif
namespace PropertyWatcher {
void PropertyWatcher::Update(FString WindowName, TArray<PropertyItemCategory>& CategoryItems, TArray<MemberPath>& WatchedMembers, UWorld* World, bool* IsOpen, bool* WantsToSave, bool* WantsToLoad) {
*WantsToSave = false;
*WantsToLoad = false;
// For convenience
TArray<PropertyItem> Items;
for (auto& It : CategoryItems)
Items.Append(It.Items);
ImGui::SetNextWindowSize(ImVec2(430, 450), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(Ansi(*("Property Watcher: " + WindowName)), IsOpen, ImGuiWindowFlags_MenuBar)) { ImGui::End(); return; }
static ImVec2 FramePadding = ImVec2(ImGui::GetStyle().FramePadding.x, 2);
if (ImGui::BeginMenuBar()) {
defer{ ImGui::EndMenuBar(); };
if (ImGui::BeginMenu("Settings")) {
defer{ ImGui::EndMenu(); };
ImGui::SetNextItemWidth(150);
ImGui::DragFloat2("Item Padding", &FramePadding[0], 0.1f, 0.0, 20.0f, "%.0f");
if (ImGui::IsItemClicked(ImGuiMouseButton_Right))
FramePadding = ImVec2(ImGui::GetStyle().FramePadding.x, 2);
}
if (ImGui::BeginMenu("Help")) {
defer{ ImGui::EndMenu(); };
ImGui::Text(HelpText);
}
}
// Top region.
static bool ListFunctionsOnObjectItems = true;
static bool EnableClassCategoriesOnObjectItems = true;
static bool SearchFilterActive = false;
static char SearchString[100];
SimpleSearchParser SearchParser;
{
// Search.
bool SelectAll = false;
if (ImGui::IsKeyDown(ImGuiMod_Ctrl) && ImGui::IsKeyPressed(ImGuiKey_F)) {
SelectAll = true;
ImGui::SetKeyboardFocusHere();
}
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 280);
int Flags = ImGuiInputTextFlags_AutoSelectAll;
ImGui::InputTextWithHint("##SearchEdit", "Search Properties (Ctrl+F)", SearchString, IM_ARRAYSIZE(SearchString), Flags);
ImGui::SameLine();
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) {
ImGui::BeginTooltip(); defer{ ImGui::EndTooltip(); };
ImGui::Text(SearchBoxHelpText);
}
ImGui::SameLine();
ImGui::Checkbox("Filter", &SearchFilterActive);
ImGuiAddon::QuickTooltip("Enable filtering of rows that didn't pass the search in the search box.");
ImGui::SameLine();
ImGui::Checkbox("Classes", &EnableClassCategoriesOnObjectItems);
ImGuiAddon::QuickTooltip("Enable sorting of actor member variables by classes with subsections.");
ImGui::SameLine();
ImGui::Checkbox("Functions", &ListFunctionsOnObjectItems);
ImGuiAddon::QuickTooltip("Show functions in actor items.");
ImGui::Spacing();
static TArray<FString> ColumnNames = { "name", "value", "metadata", "type", "cpptype", "class", "category", "address", "size" };
SearchParser.ParseExpression(SearchString, ColumnNames);
// Debug show commands
if (false)
{
int i = -1;
for (auto It : SearchParser.Commands) {
i++;
if (i > 0) {
ImGui::SameLine();
ImGui::Text(",");
ImGui::SameLine();
}
ImGui::Text(Ansi(*It.ToString()));
}
}
}
if (ImGui::BeginTabBar("MyTabBar", ImGuiTabBarFlags_None))
{
defer{ ImGui::EndTabBar(); };
bool AddressHoveredThisFrame = false;
static void* HoveredAddress = 0;
static bool DrawHoveredAddresses = false;
defer{ DrawHoveredAddresses = AddressHoveredThisFrame; };
const char* Tabs[] = { "Objects", "Actors", "Watch" };
for (int TabIndex = 0; TabIndex < IM_ARRAYSIZE(Tabs); TabIndex++)
{
FString CurrentTab = Tabs[TabIndex];
static TArray<PropertyItem> ActorItems;
static bool UpdateActorsEveryFrame = false;
static bool SearchAroundPlayer = false;
static float ActorsSearchRadius = 5;
static bool DrawOverlapSphere = false;
if (ImGui::BeginTabItem(Tabs[TabIndex]))
{
defer{ ImGui::EndTabItem(); };
if (CurrentTab == "Watch") {
if (ImGui::Button("Clear All"))
WatchedMembers.Empty();
ImGui::SameLine();
if (ImGui::Button("Save"))
*WantsToSave = true;
ImGui::SameLine();
if (ImGui::Button("Load"))
*WantsToLoad = true;
} else if (CurrentTab == "Actors") {
static TArray<bool> CollisionChannelsActive;
static bool InitActors = true;
if (InitActors) {
InitActors = false;
int NumCollisionChannels = StaticEnum<ECollisionChannel>()->NumEnums();
for (int i = 0; i < NumCollisionChannels; i++)
CollisionChannelsActive.Push(false);
}
if (World->GetCurrentLevel()) {
ImGui::Text("Current World: %s, ", Ansi(*World->GetName()));
ImGui::SameLine();
ImGui::Text("Current Level: %s", Ansi(*World->GetCurrentLevel()->GetName()));
ImGui::Spacing();
}
bool UpdateActors = UpdateActorsEveryFrame;
if (UpdateActorsEveryFrame) ImGui::BeginDisabled();
if (ImGui::Button("Update Actors"))
UpdateActors = true;
ImGui::SameLine();
if (ImGui::Button("x", ImVec2(ImGui::GetFrameHeight(), 0)))
ActorItems.Empty();
if (UpdateActorsEveryFrame) ImGui::EndDisabled();
ImGui::SameLine();
ImGui::Checkbox("Update actors every frame", &UpdateActorsEveryFrame);
ImGui::SameLine();
ImGui::Checkbox("Search around player", &SearchAroundPlayer);
ImGui::Spacing();
bool DoRaytrace = false;
{
if (!SearchAroundPlayer) ImGui::BeginDisabled();
if (ImGui::Button("Set Channels"))
ImGui::OpenPopup("SetChannelsPopup");
if (ImGui::BeginPopup("SetChannelsPopup")) {
for (int i = 0; i < CollisionChannelsActive.Num(); i++) {
FString Name = StaticEnum<ECollisionChannel>()->GetNameStringByIndex(i);
ImGui::Selectable(Ansi(*Name), &CollisionChannelsActive[i], ImGuiSelectableFlags_DontClosePopups);
}
ImGui::Separator();
if (ImGui::Button("Clear All"))
for (auto& It : CollisionChannelsActive)
It = false;
ImGui::EndPopup();
}
static bool RaytraceReady = false;
ImGui::SameLine();
if (ImGui::Button("Do Mouse Trace")) {
ImGui::OpenPopup("PopupMouseTrace");
RaytraceReady = true;
}
if (ImGui::BeginPopup("PopupMouseTrace")) {
ImGui::Text("Click on screen to trace object.");
ImGui::EndPopup();
} else {
if (RaytraceReady) {
RaytraceReady = false;
DoRaytrace = true;
}
}
ImGui::SetNextItemWidth(150);
ImGui::InputFloat("Search radius in meters", &ActorsSearchRadius, 1.0, 1.0, "%.1f");
ImGui::SameLine();
ImGui::Checkbox("Draw Search sphere", &DrawOverlapSphere);
if (!SearchAroundPlayer) ImGui::EndDisabled();
}
{
APlayerController* PlayerController = World->GetFirstPlayerController();
TArray<TEnumAsByte<EObjectTypeQuery>> traceObjectTypes;
for (int i = 0; i < CollisionChannelsActive.Num(); i++) {
bool Active = CollisionChannelsActive[i];
if (Active)
traceObjectTypes.Add(UEngineTypes::ConvertToObjectType((ECollisionChannel)i));
}
FVector SpherePos = PlayerController->GetPawn()->GetActorTransform().GetLocation();
if (UpdateActors) {
ActorItems.Empty();
if (SearchAroundPlayer) {
TArray<AActor*> ResultActors;
{
//UClass* seekClass = AStaticMeshActor::StaticClass();
UClass* seekClass = 0;
TArray<AActor*> ignoreActors = {};
UKismetSystemLibrary::SphereOverlapActors(World, SpherePos, ActorsSearchRadius * 100, traceObjectTypes, seekClass, ignoreActors, ResultActors);
}
for (auto It : ResultActors) {
if (!It) continue;
ActorItems.Push(MakeObjectItem(It));
}
} else {
ULevel* CurrentLevel = World->GetCurrentLevel();
if (CurrentLevel) {
for (auto& Actor : CurrentLevel->Actors) {
if (!Actor) continue;
ActorItems.Push(MakeObjectItem(Actor));
}
}
}
}
if (DrawOverlapSphere)
DrawDebugSphere(World, SpherePos, ActorsSearchRadius * 100, 20, FColor::Purple, false, 0.0f);
if (DoRaytrace) {
FHitResult HitResult;
bool Result = PlayerController->GetHitResultUnderCursorForObjects(traceObjectTypes, true, HitResult);
if (Result) {
AActor* HitActor = HitResult.GetActor();
if (HitActor)
ActorItems.Push(MakeObjectItem(HitActor));
}
}
}
}
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, FramePadding); defer{ ImGui::PopStyleVar(); };
ImVec2 TabItemSize = ImVec2(0, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing());
ImGuiTableFlags TableFlags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders |
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SortTristate;
if (CurrentTab == "Actors")
TableFlags |= ImGuiTableFlags_Sortable;
if (ImGui::BeginTable("table", 10, TableFlags, TabItemSize)) {
enum MyItemColumnID {
ColumnID_PropertyName,
ColumnID_PropertyCPPType,
ColumnID_Address,
ColumnID_Size,
};
int FlagSort = CurrentTab == "Actors" ? ImGuiTableColumnFlags_DefaultSort : ImGuiTableColumnFlags_NoSort;
int FlagNoSort = ImGuiTableColumnFlags_NoSort;
int FlagDefault = ImGuiTableColumnFlags_WidthStretch;
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Property Name", FlagDefault | ImGuiTableColumnFlags_NoHide, 0.0, ColumnID_PropertyName);
ImGui::TableSetupColumn("Property Value", FlagDefault | FlagNoSort);
ImGui::TableSetupColumn("Metadata", FlagNoSort | ImGuiTableColumnFlags_DefaultHide | ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("(?)").x);
ImGui::TableSetupColumn("Property Type", FlagDefault | FlagNoSort | ImGuiTableColumnFlags_DefaultHide);
ImGui::TableSetupColumn("CPP Type", FlagDefault, 0.0, ColumnID_PropertyCPPType);
ImGui::TableSetupColumn("Owner Class", FlagDefault | FlagNoSort | ImGuiTableColumnFlags_DefaultHide);
ImGui::TableSetupColumn("Category", FlagDefault | FlagNoSort | ImGuiTableColumnFlags_DefaultHide);
ImGui::TableSetupColumn("Adress", FlagDefault | ImGuiTableColumnFlags_DefaultHide, 0.0, ColumnID_Address);
ImGui::TableSetupColumn("Size", FlagDefault | ImGuiTableColumnFlags_DefaultHide, 0.0, ColumnID_Size);
ImGui::TableSetupColumn("Remove", (CurrentTab == "Watch" ? 0 : ImGuiTableColumnFlags_Disabled) | ImGuiTableColumnFlags_WidthFixed, ImGui::GetFrameHeight());
ImGui::TableHeadersRow();
TArray<FString> CurrentPath;
TreeState State = {};
State.SearchFilterActive = SearchFilterActive;
State.DrawHoveredAddress = DrawHoveredAddresses;
State.HoveredAddress = HoveredAddress;
State.CurrentWatchItemIndex = -1;
State.EnableClassCategoriesOnObjectItems = EnableClassCategoriesOnObjectItems;
State.ListFunctionsOnObjectItems = ListFunctionsOnObjectItems;
State.SearchParser = SearchParser;
defer{
if (State.AddressWasHovered) {
State.AddressWasHovered = false;
AddressHoveredThisFrame = true;
HoveredAddress = State.HoveredAddress;
};
};
if (CurrentTab == "Objects") { // @ObjectsTable
for (auto& Category : CategoryItems) {
bool MakeCategorySection = !Category.Name.IsEmpty();
TreeNodeState NodeState = {};
if (MakeCategorySection)
BeginSection(Category.Name, NodeState, State, -1, ImGuiTreeNodeFlags_DefaultOpen);
if (NodeState.IsOpen || !MakeCategorySection)
for (auto& Item : Category.Items)
DrawItemRow(State, Item, CurrentPath);
if (MakeCategorySection)
EndSection(NodeState, State);
}
} else if (CurrentTab == "Actors") { // @ActorsTable
// Sorting.
{
static ImGuiTableSortSpecs* s_current_sort_specs = NULL;
auto SortFun = [](const void* lhs, const void* rhs) -> int {
PropertyItem* a = (PropertyItem*)lhs;
PropertyItem* b = (PropertyItem*)rhs;
for (int n = 0; n < s_current_sort_specs->SpecsCount; n++) {
const ImGuiTableColumnSortSpecs* sort_spec = &s_current_sort_specs->Specs[n];
int delta = 0;
switch (sort_spec->ColumnUserID)
{
case ColumnID_PropertyName: delta = (strcmp(Ansi(*((UObject*)a->Ptr)->GetName()), Ansi(*((UObject*)b->Ptr)->GetName()))); break;
case ColumnID_PropertyCPPType: delta = (strcmp(Ansi(*a->GetCPPType()), Ansi(*b->GetCPPType()))); break;
case ColumnID_Address: delta = ((int64)a->Ptr - (int64)b->Ptr); break;
case ColumnID_Size: delta = (a->GetSize() - b->GetSize()); break;
default: IM_ASSERT(0); break;
}
if (delta > 0)
return (sort_spec->SortDirection == ImGuiSortDirection_Ascending) ? +1 : -1;
if (delta < 0)
return (sort_spec->SortDirection == ImGuiSortDirection_Ascending) ? -1 : +1;
}
return ((int64)a->Ptr - (int64)b->Ptr);
};
if (ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs()) {
if (sorts_specs->SpecsDirty) {
s_current_sort_specs = sorts_specs; // Store in variable accessible by the sort function.
if (ActorItems.Num() > 1)
qsort(ActorItems.GetData(), (size_t)ActorItems.Num(), sizeof(ActorItems[0]), SortFun);
s_current_sort_specs = NULL;
sorts_specs->SpecsDirty = false;
}
}
}
for (auto& Item : ActorItems)
DrawItemRow(State, Item, CurrentPath);
} else if (CurrentTab == "Watch") { // @WatchTable
int MemberIndexToDelete = -1;
bool MoveHappened = false;
int MoveIndexFrom = -1;
int MoveIndexTo = -1;
FString NewPathName;
int i = 0;
for (auto& Member : WatchedMembers) {
State.CurrentWatchItemIndex = i++;
State.WatchItemGotDeleted = false;
State.RenameHappened = false;
State.PathStringPtr = &Member.PathString;
bool Found = Member.UpdateItemFromPath(Items);
if (!Found) {
Member.CachedItem.Ptr = 0;
Member.CachedItem.Prop = 0;
}
DrawItemRow(State, Member.CachedItem, CurrentPath);
if (State.WatchItemGotDeleted)
MemberIndexToDelete = State.CurrentWatchItemIndex;
if (State.MoveHappened) {
MoveHappened = true;
MoveIndexFrom = State.MoveFrom;
MoveIndexTo = State.MoveTo;
}
}
if (MemberIndexToDelete != -1)
WatchedMembers.RemoveAt(MemberIndexToDelete);
if (MoveHappened)
WatchedMembers.Swap(MoveIndexFrom, MoveIndexTo);
}
ImGui::EndTable();
ImGui::Text("Item count: %d", State.ItemDrawCount);
}
}
}
}
ImRect TargetRect(ImGui::GetWindowContentRegionMin(), ImGui::GetWindowContentRegionMax());
TargetRect.Translate(ImGui::GetWindowPos());
TargetRect.Translate(ImVec2(0, ImGui::GetScrollY()));
if (ImGui::BeginDragDropTargetCustom(TargetRect, ImGui::GetHoveredID())) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("PropertyWatcherMember")) {
char* Payload = (char*)payload->Data;
MemberPath Member;
Member.PathString = Payload;
WatchedMembers.Push(Member);
}
}
}
void PropertyWatcher::DrawItemRow(TreeState& State, PropertyItem Item, TArray<FString>& CurrentMemberPath, int StackIndex) {
if (State.ItemDrawCount > 100000) // @Todo: Random safety measure against infinite recursion, do better.
return;
TMap<FName, FString> ColumnTexts;
bool ItemIsSearched;
{
ColumnTexts.Add("name", GetColumnCellText(State, Item, "name", &CurrentMemberPath, &StackIndex)); // Default.
// Cache the cell texts that we need for the text search.
for (auto Command : State.SearchParser.Commands)
if (Command.Type == SimpleSearchParser::Command_Test && !ColumnTexts.Find(Command.Tst.Column))
ColumnTexts.Add(Command.Tst.Column, GetColumnCellText(State, Item, Command.Tst.Column, &CurrentMemberPath, &StackIndex));
ItemIsSearched = State.SearchParser.ApplyTests(ColumnTexts);
}
auto FindOrGetColumnText = [&State, &Item, &ColumnTexts, &CurrentMemberPath, &StackIndex](FName ColumnName) -> FString {
if (const FString* Result = ColumnTexts.Find(ColumnName))
return *Result;
else
return GetColumnCellText(State, Item, ColumnName);
};
// Item is skipped.
if (State.SearchFilterActive && !ItemIsSearched && !Item.CanBeOpened())
return;
// Misc setup.
State.ItemDrawCount++;
CurrentMemberPath.Push(Item.GetDisplayName());
if (StackIndex == 0) {
if (!Item.NameIDOverwrite.IsEmpty())
// Usefull if you want to add an object to the object table, that
// has an unstable pointer and name. Not used anywhere else yet.
ImGui::PushID(Ansi(*Item.NameIDOverwrite));
else
ImGui::PushID(Item.Ptr);
} else
ImGui::PushID(Ansi(*Item.GetDisplayName()));
TreeNodeState NodeState;
// Executed after all members are drawn.
defer{
CurrentMemberPath.Pop();
ImGui::PopID();
EndTreeNode(NodeState, State);
};
// @Column(name): Property name
{
if (!Item.IsValid()) ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
defer{ if (!Item.IsValid()) ImGui::PopStyleColor(1); };
{
NodeState = {};
NodeState.HasBranches = Item.CanBeOpened();
NodeState.ItemInfo = VisitedPropertyInfo::FromItem(Item);
if (ItemIsSearched) {
NodeState.PushTextColor = true;
NodeState.TextColor = ImVec4(1, 0.5f, 0, 1);
}
BeginTreeNode("##Object", FindOrGetColumnText("name"), NodeState, State, StackIndex, 0);
}
bool NodeIsMarkedAsInlined = false;
// Right click popup for inlining.
{
// Do tree push to get right bool from storage when node is open or closed.
if (!NodeState.IsOpen) { ImGui::TreePush("##Object"); };
defer{ if (!NodeState.IsOpen) { ImGui::TreePop(); } };
auto StorageIDIsInlined = ImGui::GetID("IsInlined");
auto StorageIDInlinedStackDepth = ImGui::GetID("InlinedStackDepth");
auto Storage = ImGui::GetStateStorage();
NodeIsMarkedAsInlined = Storage->GetBool(StorageIDIsInlined);
int InlinedStackDepth = Storage->GetInt(StorageIDInlinedStackDepth, 0);
TreeNodeSetInline(NodeState, State, CurrentMemberPath.Num(), StackIndex, NodeIsMarkedAsInlined, InlinedStackDepth);
if (ImGui::IsItemClicked(ImGuiMouseButton_Right))
ImGui::OpenPopup("ItemPopup");
if (ImGui::BeginPopup("ItemPopup")) {
if (ImGui::Checkbox("Inlined", &NodeIsMarkedAsInlined))
Storage->SetBool(StorageIDIsInlined, NodeIsMarkedAsInlined);
ImGui::SameLine();
ImGui::BeginDisabled(!NodeIsMarkedAsInlined);
if (ImGui::SliderInt("Stack Depth", &InlinedStackDepth, 0, 9))
Storage->SetInt(StorageIDInlinedStackDepth, InlinedStackDepth);
ImGui::EndDisabled();
ImGui::EndPopup();
}
}
// Drag to watch window.
if (StackIndex > 0 && Item.Type != PointerType::Function) {
if (ImGui::BeginDragDropSource()) {
FString PathString = FString::Join(CurrentMemberPath, TEXT("."));
const char* String = Ansi(*PathString);
ImGui::SetDragDropPayload("PropertyWatcherMember", String, PathString.Len() + 1);
ImGui::Text("Add to watch list:");
ImGui::Text(String);
ImGui::EndDragDropSource();
}
}
// Drag to move watch item. Only available when top level watch list item.
if (State.CurrentWatchItemIndex != -1 && StackIndex == 0) {
if (ImGui::BeginDragDropSource()) {
ImGui::SetDragDropPayload("PropertyWatcherMoveIndex", &State.CurrentWatchItemIndex, sizeof(int));
ImGui::Text("Move Item: %d", State.CurrentWatchItemIndex);
ImGui::EndDragDropSource();
}
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* Payload = ImGui::AcceptDragDropPayload("PropertyWatcherMoveIndex")) {
if (Payload->Data) {
State.MoveHappened = true;
State.MoveFrom = *(int*)Payload->Data;
State.MoveTo = State.CurrentWatchItemIndex;
}
}
ImGui::EndDragDropTarget();
}
// Handle watch list item path editing.
if (State.PathStringPtr) {
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0)); defer{ ImGui::PopStyleColor(1); };
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetFrameHeight());
FString StringID = FString::Printf(TEXT("##InputPathText %d"), State.CurrentWatchItemIndex);
static TArray<char> StringBuffer;
StringBuffer.Empty();
StringBuffer.Append(Ansi(**State.PathStringPtr), State.PathStringPtr->Len() + 1);
if (ImGuiAddon::InputText(Ansi(*StringID), StringBuffer, ImGuiInputTextFlags_EnterReturnsTrue))
(*State.PathStringPtr) = FString(StringBuffer);
}
}
if (NodeIsMarkedAsInlined) {
ImGui::SameLine();
ImGui::Text("*");
}
}
// Draw other columns if visible.
// @Todo: Should check row and not tree node for visibility.
if (!ImGui::IsItemVisible()) {
ImGui::TableSetColumnIndex(ImGui::TableGetColumnCount() - 1);
} else {
// @Column(value): Property Value
if (ImGui::TableNextColumn()) {
ImGui::SetNextItemWidth(-FLT_MIN);
if (Item.IsValid())
DrawPropertyValue(Item);
}
// @Column(metadata): Metadata
if (ImGui::TableNextColumn() && Item.Prop) {
FString MetaDataText = FindOrGetColumnText("metadata");
if (MetaDataText.Len()) {
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (MetaData_Available)
ImGui::TextUnformatted(Ansi(*MetaDataText));
else
ImGui::TextUnformatted("Data not available in shipping builds.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::IsItemHovered();
}
}
// @Column(type): Property Type
if (ImGui::TableNextColumn()) {
if (Item.IsValid()) {
{
ImVec4 cText = ImVec4(0, 0, 0, 0);
GetItemColor(Item, cText);
ImGui::PushStyleColor(ImGuiCol_Text, cText); defer{ ImGui::PopStyleColor(); };
ImGui::Bullet();
}
ImGui::SameLine();
ImGui::Text(Ansi(*FindOrGetColumnText("type")));
}
}
// @Column(cpptype): CPP Type
if (ImGui::TableNextColumn())
ImGui::Text(Ansi(*FindOrGetColumnText("cpptype")));
// @Column(class): Owner Class
if (ImGui::TableNextColumn())
ImGui::Text(Ansi(*FindOrGetColumnText("class")));
// @Column(category): Metadata Category
if (ImGui::TableNextColumn())
ImGui::Text(Ansi(*FindOrGetColumnText("category")));
// @Column(address): Adress
if (ImGui::TableNextColumn()) {
if (State.DrawHoveredAddress && Item.Ptr == State.HoveredAddress)
ImGui::TextColored(ImVec4(1, 0.5f, 0, 1), Ansi(*FindOrGetColumnText("address")));
else
ImGui::Text(Ansi(*FindOrGetColumnText("address")));
if (ImGui::IsItemHovered()) {
State.AddressWasHovered = true;
State.HoveredAddress = Item.Ptr;
}
}
// @Column(size): Size
if (ImGui::TableNextColumn())
ImGui::Text(Ansi(*FindOrGetColumnText("size")));
// Close Button
if (ImGui::TableNextColumn())
if (State.CurrentWatchItemIndex != -1 && StackIndex == 0)
if (ImGui::Button("x", ImVec2(ImGui::GetFrameHeight(), 0)))
State.WatchItemGotDeleted = true;
}
// Draw leaf properties.
if (NodeState.IsOpen) {
bool PushAddressesStack = State.ForceToggleNodeOpenClose || State.ForceInlineChildItems;
if (PushAddressesStack)
State.VisitedPropertiesStack.Push(VisitedPropertyInfo::FromItem(Item));
DrawItemChildren(State, Item, CurrentMemberPath, StackIndex);
if (PushAddressesStack)
State.VisitedPropertiesStack.Pop();
}
}
void PropertyWatcher::DrawItemChildren(TreeState& State, PropertyItem Item, TArray<FString>& CurrentMemberPath, int StackIndex) {
check(Item.Ptr); // Do we need this check here? Can't remember.
if (Item.Prop &&
(Item.Prop->IsA(FWeakObjectProperty::StaticClass()) ||
Item.Prop->IsA(FLazyObjectProperty::StaticClass()) ||
Item.Prop->IsA(FSoftObjectProperty::StaticClass()))) {
UObject* Obj = 0;
bool IsValid = GetObjFromObjPointerProp(Item, Obj);
if (IsValid) {
auto NewItem = MakeObjectItem(Obj);
return DrawItemChildren(State, NewItem, CurrentMemberPath, StackIndex + 1);
}
}
bool ItemIsObjectProp = Item.Prop && Item.Prop->IsA(FObjectProperty::StaticClass());
bool ItemIsObject = ItemIsObjectProp || Item.Type == PointerType::Object;
// Members.
{
TArray<PropertyItem> Members;
Item.GetMembers(&Members);
SectionHelper SectionHelper;
if (State.EnableClassCategoriesOnObjectItems && ItemIsObject) {
for (auto& Member : Members)
SectionHelper.Names.Push(((FField*)(Member).Prop)->Owner.GetName());
SectionHelper.Init();
}
if (!SectionHelper.Enabled) {
for (auto It : Members)
DrawItemRow(State, It, CurrentMemberPath, StackIndex + 1);
} else {
for (int SectionIndex = 0; SectionIndex < SectionHelper.GetSectionCount(); SectionIndex++) {
int MemberStartIndex, MemberEndIndex;
FString CurrentSectionName = SectionHelper.GetSectionInfo(SectionIndex, MemberStartIndex, MemberEndIndex);
TreeNodeState NodeState = {};
NodeState.OverrideNoTreePush = true;
BeginSection(CurrentSectionName, NodeState, State, StackIndex, SectionIndex == 0 ? ImGuiTreeNodeFlags_DefaultOpen : 0);
if (NodeState.IsOpen)
for (int MemberIndex = MemberStartIndex; MemberIndex < MemberEndIndex; MemberIndex++)
DrawItemRow(State, Members[MemberIndex], CurrentMemberPath, StackIndex + 1);
EndSection(NodeState, State);
}
}
}
// Functions.
if (State.ListFunctionsOnObjectItems && Item.Ptr && ItemIsObject) {
TArray<UFunction*> Functions = GetObjectFunctionList((UObject*)Item.Ptr);
if (Functions.Num()) {
TreeNodeState FunctionSection = {};
BeginSection("Functions", FunctionSection, State, StackIndex, 0);
defer{ EndSection(FunctionSection, State); };
if (FunctionSection.IsOpen) {
SectionHelper SectionHelper;
if (State.EnableClassCategoriesOnObjectItems) {
for (auto& Function : Functions)
SectionHelper.Names.Push(Function->GetOuterUClass()->GetName());
SectionHelper.Init();
}
if (!SectionHelper.Enabled) {
for (auto It : Functions)
DrawItemRow(State, MakeFunctionItem(Item.Ptr, It), CurrentMemberPath, StackIndex + 1);
} else {
for (int SectionIndex = 0; SectionIndex < SectionHelper.GetSectionCount(); SectionIndex++) {
int MemberStartIndex, MemberEndIndex;
FString CurrentSectionName = SectionHelper.GetSectionInfo(SectionIndex, MemberStartIndex, MemberEndIndex);
TreeNodeState NodeState = {};
NodeState.OverrideNoTreePush = true;
BeginSection(CurrentSectionName, NodeState, State, StackIndex, SectionIndex == 0 ? ImGuiTreeNodeFlags_DefaultOpen : 0);
if (NodeState.IsOpen)
for (int MemberIndex = MemberStartIndex; MemberIndex < MemberEndIndex; MemberIndex++)
DrawItemRow(State, MakeFunctionItem(Item.Ptr, Functions[MemberIndex]), CurrentMemberPath, StackIndex + 1);
EndSection(NodeState, State);
}
}
}
}
}
}
FString PropertyWatcher::GetColumnCellText(TreeState& State, PropertyItem& Item, FName ColumnName, TArray<FString>* CurrentMemberPath, int* StackIndex) {
FString Result = "";
if (ColumnName == "name") {
if (CurrentMemberPath && StackIndex) {
bool TopLevelWatchListItem = State.CurrentWatchItemIndex != -1 && (*StackIndex) == 0;
bool PathIsEditable = TopLevelWatchListItem && State.PathStringPtr;
if (!PathIsEditable) {
FString StrName = Item.GetDisplayName();
if (State.ForceInlineChildItems) {
TArray<FString> InlinedMemberPath = *CurrentMemberPath;
for (int i = 0; i < State.InlineMemberPathIndexOffset; i++) {
if (InlinedMemberPath.Num())
InlinedMemberPath.RemoveAt(0);
}
InlinedMemberPath.Push(StrName);
Result = FString::Join(InlinedMemberPath, TEXT("."));
} else
Result = StrName;
}
}
} else if (ColumnName == "value") {
Result = GetValueStringFromItem(Item);
} else if (ColumnName == "metadata" && Item.Prop) {
#if MetaData_Available
if (const TMap<FName, FString>* MetaData = Item.Prop->GetMetaDataMap()) {
TArray<FName> Keys;
MetaData->GenerateKeyArray(Keys);
int i = 0;
for (auto Key : Keys) {
if (i != 0) Result.Append("\n\n");
i++;
const FString* Value = MetaData->Find(Key);
Result.Append(FString::Printf(TEXT("%s:\n\t"), *Key.ToString()));
Result.Append(*Value);
}
}
#endif
} else if (ColumnName == "type") {
Result = Item.GetPropertyType();
} else if (ColumnName == "cpptype") {
Result = Item.GetCPPType();
} else if (ColumnName == "class") {
if (Item.Prop) {
FFieldVariant Owner = ((FField*)Item.Prop)->Owner;
Result = Owner.GetName();
} else if (Item.Type == PointerType::Function) {
UClass* Class = ((UFunction*)Item.StructPtr)->GetOuterUClass();
if (Class)
Result = Class->GetName();
}
} else if (ColumnName == "category") {
Result = GetItemMetadataCategory(Item);
} else if (ColumnName == "address") {
Result = FString::Printf(TEXT("%p"), Item.Ptr);
} else if (ColumnName == "size") {
int Size = Item.GetSize();
if (Size != -1)
Result = FString::Printf(TEXT("%d B"), Size);
}
return Result;