-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEditorInterface.cpp
More file actions
2288 lines (2121 loc) · 93.3 KB
/
EditorInterface.cpp
File metadata and controls
2288 lines (2121 loc) · 93.3 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
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
#include "EditorInterface.h"
#include "KEnvironment.h"
#include "imguiimpl.h"
#include "rwrenderer.h"
#include "rwext.h"
#include "GameLauncher.h"
#include "Shape.h"
#include "rw.h"
#include "Image.h"
#include "GuiUtils.h"
#include "LocaleEditor.h"
#include "Encyclopedia.h"
#include "CoreClasses/CKService.h"
#include "CoreClasses/CKDictionary.h"
#include "CoreClasses/CKNode.h"
#include "CoreClasses/CKLogic.h"
#include "CoreClasses/CKGraphical.h"
#include "CoreClasses/CKGroup.h"
#include "CoreClasses/CKHook.h"
#include "GameClasses/CKGameX1.h"
#include "GameClasses/CKGameX2.h"
#include "GameClasses/CKGameOG.h"
#include "EditorUI/IGSceneNodeEditor.h"
#include "EditorUI/IGCloneEditor.h"
#include "EditorUI/IGTextureEditor.h"
#include "EditorUI/IGSoundEditor.h"
#include "EditorUI/IGBeaconEditor.h"
#include "EditorUI/IGGroundEditor.h"
#include "EditorUI/IGEventEditor.h"
#include "EditorUI/IGTriggerEditor.h"
#include "EditorUI/IGHookEditor.h"
#include "EditorUI/IGSquadEditor.h"
#include "EditorUI/IGEventEditor.h"
#include "EditorUI/IGPathfindingEditor.h"
#include "EditorUI/IGMarkerEditor.h"
#include "EditorUI/IGDetectorEditor.h"
#include "EditorUI/IGCinematicEditor.h"
#include "EditorUI/IGCollisionEditor.h"
#include "EditorUI/IGLineEditor.h"
#include "EditorUI/IGCameraEditor.h"
#include "EditorUI/IGCounterEditor.h"
#include "EditorUI/IGMusicEditor.h"
#include "EditorUI/IGSekensEditor.h"
#include "EditorUI/IGAnimationViewer.h"
#include "EditorUI/IGLevelInfoEditor.h"
#include "EditorUI/IGObjectInspector.h"
#include "EditorUI/IGObjectList.h"
#include "EditorUI/IGMisc.h"
#include "EditorUI/IGAbout.h"
#include "EditorUI/EditorWidgets.h"
#include "EditorUI/DictionaryEditors.h"
#include "EditorUI/EditorUtils.h"
#include "EditorUI/ImGuiMemberListener.h"
#include "EditorUI/PropFlagsEditor.h"
#include "EditorUI/GeoUtils.h"
#include <numbers>
#include <optional>
#include "imgui/imgui.h"
#include "imgui/ImGuizmo.h"
#include <SDL2/SDL.h>
#include <nlohmann/json.hpp>
#include <fmt/format.h>
using namespace GuiUtils;
namespace EditorUI {
namespace {
bool IsNodeInvisible(CKSceneNode *node, bool isXXL2) {
return isXXL2 ? ((node->unk1 & 4) && !(node->unk1 & 0x10)) : (node->unk1 & 2);
}
void DrawSceneNode(CKSceneNode *node, const Matrix &transform, Renderer *gfx, ProGeoCache &geocache, ProTexDict *texdict, CCloneManager *clm, bool showTextures, bool showInvisibles, bool showClones, std::map<CSGBranch*, int> &nodeCloneIndexMap, bool isXXL2)
{
for (; node; node = node->next.get()) {
Matrix nodeTransform = node->transform;
nodeTransform.m[0][3] = nodeTransform.m[1][3] = nodeTransform.m[2][3] = 0.0f;
nodeTransform.m[3][3] = 1.0f;
Matrix globalTransform = nodeTransform * transform;
if (showInvisibles || !IsNodeInvisible(node, isXXL2)) {
if (node->isSubclassOf<CClone>() || node->isSubclassOf<CAnimatedClone>()) {
if (showClones) {
//auto it = std::find_if(clm->_clones.begin(), clm->_clones.end(), [node](const kobjref<CSGBranch> &ref) {return ref.get() == node; });
//assert(it != clm->_clones.end());
//size_t clindex = it - clm->_clones.begin();
int clindex = nodeCloneIndexMap.at((CSGBranch*)node);
gfx->setTransformMatrix(globalTransform);
for (uint32_t part : clm->_team.dongs[clindex].bongs)
if (part != 0xFFFFFFFF) {
RwGeometry *rwgeo = clm->_teamDict._bings[part]._clump.atomic.geometry.get();
geocache.getPro(rwgeo, texdict)->draw(showTextures);
}
}
}
else if (node->isSubclassOf<CNode>()) {
gfx->setTransformMatrix(globalTransform);
for (CKAnyGeometry *kgeo = node->cast<CNode>()->geometry.get(); kgeo; kgeo = kgeo->nextGeo.get()) {
CKAnyGeometry *rgeo = kgeo->duplicateGeo ? kgeo->duplicateGeo.get() : kgeo;
if (auto& rwminiclp = rgeo->clump)
if (RwGeometry *rwgeo = rwminiclp->atomic.geometry.get())
if((rwgeo->flags & RwGeometry::RWGEOFLAG_NATIVE) == 0)
geocache.getPro(rwgeo, texdict)->draw(showTextures);
}
}
if (node->isSubclassOf<CSGBranch>())
DrawSceneNode(node->cast<CSGBranch>()->child.get(), globalTransform, gfx, geocache, texdict, clm, showTextures, showInvisibles, showClones, nodeCloneIndexMap, isXXL2);
if (CAnyAnimatedNode *anyanimnode = node->dyncast<CAnyAnimatedNode>())
DrawSceneNode(anyanimnode->branchs.get(), globalTransform, gfx, geocache, texdict, clm, showTextures, showInvisibles, showClones, nodeCloneIndexMap, isXXL2);
}
}
}
Vector3 getRay(const Camera &cam, Window *window) {
const float zNear = 0.1f;
Vector3 xvec = cam.direction.normal().cross(Vector3(0, 1, 0)).normal();
Vector3 yvec = cam.direction.normal().cross(xvec).normal();
float ys = tan(0.45f) * zNear;
yvec *= ys;
xvec *= ys * window->getWidth() / window->getHeight();
yvec *= (1 - window->getMouseY() * 2.0f / window->getHeight());
xvec *= (1 - window->getMouseX() * 2.0f / window->getWidth());
return cam.direction.normal() * zNear - xvec - yvec;
}
bool rayIntersectsSphere(const Vector3 &rayStart, const Vector3 &_rayDir, const Vector3 &spherePos, float sphereRadius) {
Vector3 rayDir = _rayDir.normal();
Vector3 rs2sp = spherePos - rayStart;
float sphereRadiusSq = sphereRadius * sphereRadius;
if (rs2sp.sqlen3() <= sphereRadiusSq)
return true;
float dot = rayDir.dot(rs2sp);
if (dot < 0.0f)
return false;
Vector3 shortPoint = rayStart + rayDir * dot;
float shortDistSq = (spherePos - shortPoint).sqlen3();
return shortDistSq <= sphereRadiusSq;
}
std::optional<Vector3> getRaySphereIntersection(const Vector3 &rayStart, const Vector3 &_rayDir, const Vector3 &spherePos, float sphereRadius) {
Vector3 rayDir = _rayDir.normal();
Vector3 rs2sp = spherePos - rayStart;
float sphereRadiusSq = sphereRadius * sphereRadius;
if (rs2sp.sqlen3() <= sphereRadiusSq)
return rayStart;
float dot = rayDir.dot(rs2sp);
if (dot < 0.0f)
return std::nullopt;
Vector3 shortPoint = rayStart + rayDir * dot;
float shortDistSq = (spherePos - shortPoint).sqlen3();
if (shortDistSq > sphereRadiusSq)
return std::nullopt;
Vector3 ix = shortPoint - rayDir * sqrt(sphereRadiusSq - shortDistSq);
return ix;
}
std::optional<Vector3> getRayTriangleIntersection(const Vector3 &rayStart, const Vector3 &_rayDir, const Vector3 &p1, const Vector3 &p2, const Vector3 &p3) {
Vector3 rayDir = _rayDir.normal();
Vector3 v2 = p2 - p1, v3 = p3 - p1;
Vector3 trinorm = v2.cross(v3).normal(); // order?
if (trinorm == Vector3(0, 0, 0))
return std::nullopt;
float rayDir_dot_trinorm = rayDir.dot(trinorm);
if (rayDir_dot_trinorm < 0.0f)
return std::nullopt;
float p = p1.dot(trinorm);
float alpha = (p - rayStart.dot(trinorm)) / rayDir_dot_trinorm;
if (alpha < 0.0f)
return std::nullopt;
Vector3 sex = rayStart + rayDir * alpha;
Vector3 c = sex - p1;
float d = v2.sqlen3() * v3.sqlen3() - v2.dot(v3) * v2.dot(v3);
//assert(d != 0.0f);
float a = (c.dot(v2) * v3.sqlen3() - c.dot(v3) * v2.dot(v3)) / d;
float b = (c.dot(v3) * v2.sqlen3() - c.dot(v2) * v3.dot(v2)) / d;
if (a >= 0.0f && b >= 0.0f && (a + b) <= 1.0f)
return sex;
else
return std::nullopt;
}
bool isPointInAABB(const Vector3 &point, const Vector3 &highCorner, const Vector3 &lowCorner) {
for (int i = 0; i < 3; i++)
if (point.coord[i] < lowCorner.coord[i] || point.coord[i] > highCorner.coord[i])
return false;
return true;
}
std::optional<Vector3> getRayAABBIntersection(const Vector3 &rayStart, const Vector3 &_rayDir, const Vector3 &highCorner, const Vector3 &lowCorner) {
if (isPointInAABB(rayStart, highCorner, lowCorner))
return rayStart;
Vector3 rayDir = _rayDir.normal();
for (int i = 0; i < 3; i++) {
if (rayDir.coord[i] != 0.0f) {
int j = (i + 1) % 3, k = (i + 2) % 3;
for (const std::pair<const Vector3 &, float>& pe : { std::make_pair(highCorner,1.0f), std::make_pair(lowCorner,-1.0f) }) {
if (rayDir.coord[i] * pe.second > 0)
continue;
float t = (pe.first.coord[i] - rayStart.coord[i]) / rayDir.coord[i];
Vector3 candidate = rayStart + rayDir * t;
if (candidate.coord[j] >= lowCorner.coord[j] && candidate.coord[k] >= lowCorner.coord[k] &&
candidate.coord[j] <= highCorner.coord[j] && candidate.coord[k] <= highCorner.coord[k])
return candidate;
}
}
}
return std::nullopt;
}
}
// Selection classes
struct NodeSelection : UISelection {
static const int ID = 1;
KWeakRef<CKSceneNode> node;
NodeSelection(EditorInterface &ui, Vector3 &hitpos, CKSceneNode *node) : UISelection(ui, hitpos), node(node) {}
int getTypeID() override { return ID; }
bool hasTransform() override { return node.get() != nullptr; }
Matrix getTransform() override {
Matrix mat = node->transform;
for (int i = 0; i < 4; i++)
mat.m[i][3] = (i == 3) ? 1.0f : 0.0f;
return mat;
}
void setTransform(const Matrix &mat) override { node->transform = mat; }
void onSelected() override {
CKSceneNode* node = this->node.get();
ui.selNode = node;
// Find hook attached to node
for (auto& hkclass : ui.kenv.levelObjects.categories[CKHook::CATEGORY].type) {
for (CKObject* obj : hkclass.objects) {
CKHook* hook = obj->dyncast<CKHook>();
if (hook && hook->node.bound) {
if (hook->node.get() == node) {
ui.selectedHook = hook;
ui.viewGroupInsteadOfHook = false;
}
}
}
}
}
std::string getInfo() override {
if (node)
return fmt::format("Node {} ({})", ui.kenv.getObjectName(node.get()), node->getClassName());
else
return "Node removed";
}
void onDetails() override {
ui.selNode = node;
ui.wndShowSceneGraph = true;
}
};
struct BeaconSelection : UISelection {
static const int ID = 2;
int sectorIndex, klusterIndex, bingIndex, beaconIndex;
BeaconSelection(EditorInterface& ui, Vector3& hitpos, int sectorIndex, int klusterIndex, int bingIndex, int beaconIndex) :
UISelection(ui, hitpos), sectorIndex(sectorIndex), klusterIndex(klusterIndex), bingIndex(bingIndex), beaconIndex(beaconIndex) {}
CKBeaconKluster* getKluster() const {
CKSrvBeacon* srvBeacon = ui.kenv.levelObjects.getFirst<CKSrvBeacon>();
if (sectorIndex >= 0 && sectorIndex <= (int)srvBeacon->beaconSectors.size())
if (klusterIndex >= 0 && klusterIndex < (int)srvBeacon->beaconSectors[sectorIndex].beaconKlusters.size())
return srvBeacon->beaconSectors[sectorIndex].beaconKlusters[klusterIndex].get();
return nullptr;
}
SBeacon* getBeaconPtr() const {
if (CKBeaconKluster* kluster = getKluster())
if (bingIndex >= 0 && bingIndex < (int)kluster->bings.size())
if (beaconIndex >= 0 && beaconIndex < (int)kluster->bings[bingIndex].beacons.size())
return &kluster->bings[bingIndex].beacons[beaconIndex];
return nullptr;
}
int getTypeID() override { return ID; }
bool hasTransform() override { return getBeaconPtr() != nullptr; }
Matrix getTransform() override {
Matrix mat = Matrix::getTranslationMatrix(getBeaconPtr()->getPosition());
CKSrvBeacon* srvBeacon = ui.kenv.levelObjects.getFirst<CKSrvBeacon>();
if (auto* beaconInfo = ui.g_encyclo.getBeaconJson(srvBeacon->handlers[bingIndex].handlerId)) {
if (beaconInfo->is_object() && beaconInfo->value<bool>("orientable", false)) {
mat = Matrix::getRotationYMatrix(decode8bitAngle(getBeaconPtr()->params & 255)) * mat;
}
}
return mat;
}
void setTransform(const Matrix &mat) override {
CKSrvBeacon* srvBeacon = ui.kenv.levelObjects.getFirst<CKSrvBeacon>();
if (ui.kenv.version <= maxGameSupportingAdvancedBeaconEditing) {
SBeacon beacon = *getBeaconPtr();
srvBeacon->removeBeacon(sectorIndex, klusterIndex, bingIndex, beaconIndex);
srvBeacon->updateKlusterBounds(srvBeacon->beaconSectors[sectorIndex].beaconKlusters[klusterIndex].get());
srvBeacon->cleanEmptyKlusters(ui.kenv, sectorIndex);
beacon.setPosition(mat.getTranslationVector());
if (auto* beaconInfo = ui.g_encyclo.getBeaconJson(srvBeacon->handlers[bingIndex].handlerId)) {
if (beaconInfo->is_object() && beaconInfo->value<bool>("orientable", false)) {
const float angle = std::atan2(mat._31, mat._11);
beacon.params = (beacon.params & 0xFF00) | (uint8_t)std::round(angle * 128.0f / std::numbers::pi);
}
}
std::tie(klusterIndex, beaconIndex) = srvBeacon->addBeaconToNearestKluster(ui.kenv, sectorIndex, bingIndex, beacon);
std::tie(ui.selBeaconKluster, ui.selBeaconIndex) = std::tie(klusterIndex, beaconIndex); // bad
srvBeacon->updateKlusterBounds(srvBeacon->beaconSectors[sectorIndex].beaconKlusters[klusterIndex].get());
}
else {
auto* beacon = getBeaconPtr();
beacon->setPosition(mat.getTranslationVector());
if (auto* beaconInfo = ui.g_encyclo.getBeaconJson(srvBeacon->handlers[bingIndex].handlerId)) {
if (beaconInfo->is_object() && beaconInfo->value<bool>("orientable", false)) {
const float angle = std::atan2(mat._31, mat._11);
beacon->params = (beacon->params & 0xFF00) | (uint8_t)(int)(angle * 128.0f / std::numbers::pi);
}
}
ui.kenv.levelObjects.getFirst<CKSrvBeacon>()->updateKlusterBounds(getKluster());
}
}
void duplicate() override {
if (!hasTransform()) return;
CKSrvBeacon* srvBeacon = ui.kenv.levelObjects.getFirst<CKSrvBeacon>();
const SBeacon* originalBeacon = getBeaconPtr();
int dupKlusterIndex = klusterIndex;
if (ui.kenv.version > maxGameSupportingAdvancedBeaconEditing) {
dupKlusterIndex = srvBeacon->addKluster(ui.kenv, sectorIndex);
}
srvBeacon->addBeacon(sectorIndex, dupKlusterIndex, bingIndex, *originalBeacon);
srvBeacon->updateKlusterBounds(srvBeacon->beaconSectors[sectorIndex].beaconKlusters[dupKlusterIndex].get());
}
bool remove() override {
if (!hasTransform()) return false;
CKSrvBeacon* srvBeacon = ui.kenv.levelObjects.getFirst<CKSrvBeacon>();
srvBeacon->removeBeacon(sectorIndex, klusterIndex, bingIndex, beaconIndex);
if (ui.kenv.version <= maxGameSupportingAdvancedBeaconEditing) {
srvBeacon->updateKlusterBounds(srvBeacon->beaconSectors[sectorIndex].beaconKlusters[klusterIndex].get());
srvBeacon->cleanEmptyKlusters(ui.kenv, sectorIndex);
}
ui.selBeaconSector = -1;
return true;
}
void onSelected() override {
ui.selBeaconSector = sectorIndex;
ui.selBeaconKluster = klusterIndex;
ui.selBeaconBing = bingIndex;
ui.selBeaconIndex = beaconIndex;
}
std::string getInfo() override {
CKSrvBeacon* srvBeacon = ui.kenv.levelObjects.getFirst<CKSrvBeacon>();
return fmt::format("Beacon {}", ui.g_encyclo.getBeaconName(srvBeacon->handlers[bingIndex].handlerId));
}
void onDetails() override {
onSelected();
ui.wndShowBeacons = true;
}
};
struct GroundSelection : UISelection {
static const int ID = 3;
KWeakRef<CGround> ground;
GroundSelection(EditorInterface &ui, Vector3 &hitpos, CGround *gnd) : UISelection(ui, hitpos), ground(gnd) {}
int getTypeID() override { return ID; }
void onSelected() override { ui.selGround = ground; }
std::string getInfo() override {
return fmt::format("{} {}",
(ground && ground->isSubclassOf<CDynamicGround>()) ? "Dynamic Ground" : "Ground",
ground ? ui.kenv.getObjectName(ground.get()) : "removed");
}
void onDetails() override { onSelected(); ui.wndShowGrounds = true; }
bool hasTransform() override { return ground && ground->editing; }
Matrix getTransform() override { return ground->editing->transform; }
void setTransform(const Matrix& mat) override { ground->setTransform(mat); }
};
struct SquadSelection : UISelection {
static const int ID = 4;
KWeakRef<CKGrpSquadEnemy> squad;
SquadSelection(EditorInterface &ui, Vector3 &hitpos, CKGrpSquadEnemy *squad) : UISelection(ui, hitpos), squad(squad) {}
int getTypeID() override { return ID; }
bool hasTransform() override { return squad.get(); }
Matrix getTransform() override { return squad->mat1; }
void setTransform(const Matrix &mat) override { squad->mat1 = mat; }
void onSelected() override { ui.selectedSquad = squad; }
std::string getInfo() override { return fmt::format("Squad {}", squad ? ui.kenv.getObjectName(squad.get()) : "Removed"); }
void onDetails() override { onSelected(); ui.wndShowSquads = true; }
};
struct X2SquadSelection : UISelection {
static const int ID = 204;
KWeakRef<CKGrpSquadX2> squad;
X2SquadSelection(EditorInterface& ui, Vector3& hitpos, CKGrpSquadX2* squad) : UISelection(ui, hitpos), squad(squad) {}
int getTypeID() override { return ID; }
bool hasTransform() override { return squad.get() && ui.showingChoreography < squad->phases.size(); }
Matrix getTransform() override {
Matrix mmm = squad->phases[ui.showingChoreography].mat;
mmm._14 = 0.0f;
mmm._24 = 0.0f;
mmm._34 = 0.0f;
mmm._44 = 1.0f;
return mmm;
}
void setTransform(const Matrix& mat) override { squad->phases[ui.showingChoreography].mat = mat; }
void onSelected() override { ui.selectedX2Squad = squad; }
std::string getInfo() override { return fmt::format("Squad {}", squad ? ui.kenv.getObjectName(squad.get()) : "Removed"); }
void onDetails() override { onSelected(); ui.wndShowSquads = true; }
};
struct BaseChoreoSpotSelection : UISelection {
static const int ID = 5;
int spotIndex;
BaseChoreoSpotSelection(EditorInterface& ui, Vector3& hitpos, int spotIndex)
: UISelection(ui, hitpos), spotIndex(spotIndex) {}
virtual CKGroup* squadGroup() = 0;
virtual CKChoreoKey* choreoKey() = 0;
virtual Matrix squadMatrix() = 0;
Matrix getTransform() override {
auto& spot = choreoKey()->slots[spotIndex];
Matrix mRot = Matrix::getIdentity();
Vector3 v1 = spot.direction.normal();
Vector3 v3 = v1.cross(Vector3(0.0f, 1.0f, 0.0f));
const Vector3& v4 = spot.position;
std::tie(mRot._11, mRot._12, mRot._13) = std::tie(v1.x, v1.y, v1.z);
std::tie(mRot._31, mRot._32, mRot._33) = std::tie(v3.x, v3.y, v3.z);
std::tie(mRot._41, mRot._42, mRot._43) = std::tie(v4.x, v4.y, v4.z);
return mRot * squadMatrix();
}
void setTransform(const Matrix &mat) override {
Matrix inv = squadMatrix().getInverse4x4();
Matrix spotMat = mat * inv;
auto& spot = choreoKey()->slots[spotIndex];
spot.position = spotMat.getTranslationVector();
spot.direction = Vector3(spotMat._11, spotMat._12, spotMat._13);
}
void duplicate() override {
if (!hasTransform()) return;
auto& slots = choreoKey()->slots;
slots.push_back(slots[spotIndex]);
}
bool remove() override {
if (!hasTransform()) return false;
auto& slots = choreoKey()->slots;
slots.erase(slots.begin() + spotIndex);
return true;
}
std::string getInfo() override {
auto* squad = squadGroup();
return fmt::format("Choreo spot {} from Squad {}", spotIndex, squad ? ui.kenv.getObjectName(squad) : "removed");
}
void onDetails() override { onSelected(); ui.wndShowSquads = true; }
};
struct X1ChoreoSpotSelection : BaseChoreoSpotSelection {
static const int ID = 5;
KWeakRef<CKGrpSquadEnemy> squad;
X1ChoreoSpotSelection(EditorInterface& ui, Vector3& hitpos, CKGrpSquadEnemy* squad, int spotIndex)
: BaseChoreoSpotSelection(ui, hitpos, spotIndex), squad(squad) {}
CKGroup* squadGroup() override { return squad.get(); }
CKChoreoKey* choreoKey() override { return squad->choreoKeys[ui.showingChoreoKey].get(); }
Matrix squadMatrix() override { return squad->mat1; }
int getTypeID() override { return ID; }
bool hasTransform() override {
if (!squad) return false;
if (ui.showingChoreoKey < 0 || ui.showingChoreoKey >= (int)squad->choreoKeys.size()) return false;
if (spotIndex < 0 || spotIndex >= (int)squad->choreoKeys[ui.showingChoreoKey]->slots.size()) return false;
return true;
}
void onSelected() override { ui.selectedSquad = squad; }
};
struct X2ChoreoSpotSelection : BaseChoreoSpotSelection {
static const int ID = 205;
KWeakRef<CKGrpSquadX2> squad;
X2ChoreoSpotSelection(EditorInterface& ui, Vector3& hitpos, CKGrpSquadX2* squad, int spotIndex)
: BaseChoreoSpotSelection(ui, hitpos, spotIndex), squad(squad) {}
CKGroup* squadGroup() override { return squad.get(); }
CKChoreoKey* choreoKey() override { return squad->phases[ui.showingChoreography].choreography->keys[ui.showingChoreoKey].get(); }
Matrix squadMatrix() override {
Matrix mat = squad->phases[ui.showingChoreography].mat;
mat._14 = mat._24 = mat._34 = 0.0f;
mat._44 = 1.0f;
return mat;
}
int getTypeID() override { return ID; }
bool hasTransform() override {
if (!squad) return false;
if (ui.showingChoreography < 0 || ui.showingChoreography >= (int)squad->phases.size()) return false;
auto& phase = squad->phases[ui.showingChoreography];
if (ui.showingChoreoKey < 0 || ui.showingChoreoKey >= (int)phase.choreography->keys.size()) return false;
if (spotIndex < 0 || spotIndex >= (int)phase.choreography->keys[ui.showingChoreoKey]->slots.size()) return false;
return true;
}
void onSelected() override { ui.selectedX2Squad = squad; }
};
struct MarkerSelection : UISelection {
static const int ID = 6;
int markerIndex;
MarkerSelection(EditorInterface &ui, Vector3 &hitpos, int markerIndex) : UISelection(ui, hitpos), markerIndex(markerIndex) {}
CKSrvMarker::Marker* getMarker() const {
auto* srvMarker = ui.kenv.levelObjects.getFirst<CKSrvMarker>();
if (!srvMarker || srvMarker->lists.empty()) return nullptr;
auto& list = srvMarker->lists[0];
if (markerIndex >= 0 && markerIndex < list.size())
return &list[markerIndex];
return nullptr;
}
int getTypeID() override { return ID; }
bool hasTransform() override { return getMarker() != nullptr; }
Matrix getTransform() override {
auto* marker = getMarker();
return Matrix::getRotationYMatrix(decode8bitAngle(marker->orientation1)) * Matrix::getTranslationMatrix(marker->position);
}
void setTransform(const Matrix &mat) override {
auto* marker = getMarker();
marker->position = mat.getTranslationVector();
const float angle = std::atan2(mat._31, mat._11);
marker->orientation1 = (uint8_t)std::round(angle * 128.0f / std::numbers::pi);
marker->orientation2 = 0;
}
void onSelected() override { ui.selectedMarkerIndex = markerIndex; }
std::string getInfo() override {
auto* marker = getMarker();
return fmt::format("Marker {}: {}", markerIndex, marker ? marker->name : "OOB");
}
void onDetails() override { onSelected(); ui.wndShowMarkers = true; }
};
struct HkLightSelection : UISelection {
static const int ID = 7;
CKGrpLight* grpLight;
int lightIndex;
HkLightSelection(EditorInterface& ui, Vector3& hitpos, CKGrpLight* grpLight, int lightIndex) : UISelection(ui, hitpos), grpLight(grpLight), lightIndex(lightIndex) {}
Vector3& position() { return grpLight->node->cast<CNode>()->geometry->cast<CKParticleGeometry>()->pgPoints[lightIndex]; }
CKHook* getHook() {
int i = 0;
for (CKHook* hook = grpLight->childHook.get(); hook; hook = hook->next.get()) {
if (i++ == lightIndex) {
return hook;
}
}
return nullptr;
}
int getTypeID() override { return ID; }
bool hasTransform() override { return true; }
Matrix getTransform() override { return Matrix::getTranslationMatrix(position()); }
void setTransform(const Matrix& mat) override { position() = mat.getTranslationVector(); }
void onSelected() override {
if (CKHook* hook = getHook()) {
ui.selectedHook = hook;
ui.viewGroupInsteadOfHook = false;
}
}
std::string getInfo() override {
if (CKHook* hook = getHook()) {
return fmt::format("Light Hook {} ({})", ui.kenv.getObjectName(hook), lightIndex);
}
return "Light Hook ???";
}
void onDetails() override { onSelected(); ui.wndShowHooks = true; }
};
struct X1DetectorSelection : UISelection {
static const int ID = 8;
enum ShapeType {
BOUNDINGBOX = 0,
SPHERE = 1,
RECTANGLE = 2,
};
ShapeType type;
size_t index;
Vector3 bbCenter, bbHalf;
X1DetectorSelection(EditorInterface& ui, Vector3& hitpos, ShapeType type, size_t index) : UISelection(ui, hitpos), type(type), index(index) {}
CKSrvDetector* getSrvDetector() { return ui.kenv.levelObjects.getFirst<CKSrvDetector>(); }
Vector3& position() {
CKSrvDetector* srvDetector = getSrvDetector();
if (type == BOUNDINGBOX)
return bbCenter;
else if (type == SPHERE)
return srvDetector->spheres[index].center;
else if (type == RECTANGLE)
return srvDetector->rectangles[index].center;
return bbCenter;
}
int getTypeID() override { return ID; }
bool hasTransform() override {
CKSrvDetector* srvDetector = getSrvDetector();
size_t counts[3] = { srvDetector->aaBoundingBoxes.size(), srvDetector->spheres.size(), srvDetector->rectangles.size() };
return index >= 0 && index < counts[type];
}
Matrix getTransform() override {
if (type == BOUNDINGBOX) {
auto& bb = getSrvDetector()->aaBoundingBoxes[index];
bbCenter = (bb.highCorner + bb.lowCorner) * 0.5f;
bbHalf = (bb.highCorner - bb.lowCorner) * 0.5f;
}
return Matrix::getTranslationMatrix(position());
}
void setTransform(const Matrix& mat) override {
position() = mat.getTranslationVector();
if (type == BOUNDINGBOX) {
auto& bb = getSrvDetector()->aaBoundingBoxes[index];
bb.highCorner = bbCenter + bbHalf;
bb.lowCorner = bbCenter - bbHalf;
}
}
void onSelected() override {
ui.selectedShapeType = type;
ui.selectedShapeIndex = index;
}
std::string getInfo() override {
CKSrvDetector* srvDetector = getSrvDetector();
if (type == BOUNDINGBOX)
return "Box Detector " + srvDetector->aabbNames[index];
else if (type == SPHERE)
return "Sphere Detector " + srvDetector->sphNames[index];
else if (type == RECTANGLE)
return "Rectangle Detector " + srvDetector->rectNames[index];
return "Unknown Detector";
}
void onDetails() override { onSelected(); ui.wndShowDetectors = true; }
};
struct X2DetectorSelection : UISelection {
static const int ID = 9;
KWeakRef<CMultiGeometryBasic> geometry;
KWeakRef<CKDetectorBase> detector;
Vector3 bbCenter, bbHalf;
X2DetectorSelection(EditorInterface& ui, Vector3& hitpos, CMultiGeometryBasic* geometry, CKDetectorBase* detector) :
UISelection(ui, hitpos), geometry(geometry), detector(detector) {}
Vector3& position() {
if (std::holds_alternative<AABoundingBox>(geometry->mgShape))
return bbCenter;
else if (auto* sphere = std::get_if<BoundingSphere>(&geometry->mgShape))
return sphere->center;
else if (auto* rect = std::get_if<AARectangle>(&geometry->mgShape))
return rect->center;
return bbCenter;
}
int getTypeID() override { return ID; }
bool hasTransform() override {
return geometry.get() != nullptr;
}
Matrix getTransform() override {
if (auto* bb = std::get_if<AABoundingBox>(&geometry->mgShape)) {
bbCenter = (bb->highCorner + bb->lowCorner) * 0.5f;
bbHalf = (bb->highCorner - bb->lowCorner) * 0.5f;
}
return Matrix::getTranslationMatrix(position());
}
void setTransform(const Matrix& mat) override {
position() = mat.getTranslationVector();
if (auto* bb = std::get_if<AABoundingBox>(&geometry->mgShape)) {
bb->highCorner = bbCenter + bbHalf;
bb->lowCorner = bbCenter - bbHalf;
}
}
void onSelected() override {
ui.selectedX2Detector = detector;
}
std::string getInfo() override {
std::string name = ui.kenv.getObjectName(geometry.get());
if (geometry->mgShape.index() == 0)
return "Box Detector " + name;
else if (geometry->mgShape.index() == 1)
return "Sphere Detector " + name;
else if (geometry->mgShape.index() == 2)
return "Rectangle Detector " + name;
return "Unknown Detector " + name;
}
void onDetails() override { onSelected(); ui.wndShowDetectors = true; }
};
EditorInterface::EditorInterface(KEnvironment & kenv, Window * window, Renderer * gfx, const std::string & gameModule)
: kenv(kenv), g_window(window), gfx(gfx), protexdict(gfx), progeocache(gfx), gndmdlcache(gfx),
launcher(gameModule, kenv.outGamePath, kenv.version)
{
lastFpsTime = SDL_GetTicks() / 1000;
auto loadModel = [](const char *fn) {
auto clp = std::make_unique<RwClump>();
File *dff = GetResourceFile(fn);
rwCheckHeader(dff, 0x10);
clp->deserialize(dff);
delete dff;
return clp;
};
auto origRwVer = HeaderWriter::rwver; // backup Renderware vesion
sphereModel = loadModel("sphere.dff");
swordModel = loadModel("sword.dff");
spawnStarModel = loadModel("SpawnStar.dff");
HeaderWriter::rwver = origRwVer;
g_encyclo.setKVersion(kenv.version);
g_encyclo.window = g_window;
}
EditorInterface::~EditorInterface() = default;
void EditorInterface::prepareLevelGfx()
{
if (kenv.hasClass<CTextureDictionary>()) {
protexdict.reset(kenv.levelObjects.getObject<CTextureDictionary>(0));
str_protexdicts.clear();
str_protexdicts.reserve((size_t)kenv.numSectors);
for (int i = 0; i < (int)kenv.numSectors; i++) {
ProTexDict strptd(gfx, kenv.sectorObjects[i].getObject<CTextureDictionary>(0));
strptd._next = &protexdict;
str_protexdicts.push_back(std::move(strptd));
//printf("should be zero: %i\n", strptd.dict.size());
}
}
nodeCloneIndexMap.clear();
cloneSet.clear();
if (kenv.hasClass<CCloneManager>()) {
if (CCloneManager* cloneMgr = kenv.levelObjects.getFirst<CCloneManager>()) {
if (cloneMgr->_numClones > 0) {
for (int i = 0; i < (int)cloneMgr->_clones.size(); i++)
nodeCloneIndexMap.insert({ cloneMgr->_clones[i].get(), i });
for (auto& dong : cloneMgr->_team.dongs)
cloneSet.insert(dong.bongs);
}
}
}
}
void EditorInterface::iter()
{
// FPS Counter
framesInSecond++;
uint32_t sec = SDL_GetTicks() / 1000;
if (sec != lastFpsTime) {
lastFps = framesInSecond;
framesInSecond = 0;
lastFpsTime = sec;
}
// Camera update and movement
static auto lastTicks = SDL_GetTicks();
const auto nowTicks = SDL_GetTicks();
camera.aspect = (float)g_window->getWidth() / g_window->getHeight();
camera.updateMatrix();
float camspeed = _camspeed * (nowTicks - lastTicks) / 1000.0f;
if (ImGui::GetIO().KeyShift)
camspeed *= 0.5f;
Vector3 camside = camera.direction.cross(Vector3(0, 1, 0)).normal();
Vector3 camuxs = -camside.cross(Vector3(0, 1, 0)).normal();
if (g_window->getKeyDown(SDL_SCANCODE_UP) || g_window->getKeyDown(SDL_SCANCODE_W))
camera.position += (ImGui::GetIO().KeyCtrl ? camuxs : camera.direction) * camspeed;
if (g_window->getKeyDown(SDL_SCANCODE_DOWN) || g_window->getKeyDown(SDL_SCANCODE_S))
camera.position -= (ImGui::GetIO().KeyCtrl ? camuxs : camera.direction) * camspeed;
if (g_window->getKeyDown(SDL_SCANCODE_RIGHT) || g_window->getKeyDown(SDL_SCANCODE_D))
camera.position += camside * camspeed;
if (g_window->getKeyDown(SDL_SCANCODE_LEFT) || g_window->getKeyDown(SDL_SCANCODE_A))
camera.position -= camside * camspeed;
lastTicks = nowTicks;
// Camera rotation
static bool rotating = false;
static int rotStartX, rotStartY;
static Vector3 rotOrigOri;
if (g_window->getKeyDown(SDL_SCANCODE_KP_0) || g_window->getMouseDown(SDL_BUTTON_RIGHT)) {
if (!rotating) {
rotStartX = g_window->getMouseX();
rotStartY = g_window->getMouseY();
rotOrigOri = camera.orientation;
rotating = true;
SDL_CaptureMouse(SDL_TRUE);
}
int dx = g_window->getMouseX() - rotStartX;
int dy = g_window->getMouseY() - rotStartY;
camera.orientation = rotOrigOri + Vector3(-dy * 0.01f, dx*0.01f, 0);
}
else {
rotating = false;
SDL_CaptureMouse(SDL_FALSE);
}
camera.updateMatrix();
// Mouse ray selection
if (g_window->getMousePressed(SDL_BUTTON_LEFT)) {
checkMouseRay();
if (nearestRayHit) {
nearestRayHit->onSelected();
}
}
// Selection operation keys
if (nearestRayHit) {
if (g_window->isAltPressed() && g_window->getKeyPressed(SDL_SCANCODE_C)) {
nearestRayHit->duplicate();
}
if (g_window->getKeyPressed(SDL_SCANCODE_DELETE)) {
bool removed = nearestRayHit->remove();
if (removed) {
rayHits.clear();
nearestRayHit = nullptr;
}
}
}
// ImGuizmo
static int gzoperation = ImGuizmo::TRANSLATE;
if (g_window->getKeyPressed(SDL_SCANCODE_E)) guizmoOperation = 0;
if (g_window->getKeyPressed(SDL_SCANCODE_R)) guizmoOperation = 1;
if (g_window->getKeyPressed(SDL_SCANCODE_T)) guizmoOperation = 2;
if (!ImGuizmo::IsUsing())
gzoperation = (g_window->isCtrlPressed() || guizmoOperation == 1) ? ImGuizmo::ROTATE : ((g_window->isShiftPressed() || guizmoOperation == 2) ? ImGuizmo::SCALE : ImGuizmo::TRANSLATE);
ImGuizmo::BeginFrame();
ImGuizmo::SetRect(0.0f, 0.0f, (float)g_window->getWidth(), (float)g_window->getHeight());
auto* selection = nearestRayHit;
if (selection && selection->hasTransform()) {
static Matrix gzmat = Matrix::getIdentity();
if (!ImGuizmo::IsUsing() || gzoperation == ImGuizmo::TRANSLATE) {
gzmat = selection->getTransform();
}
Matrix originalMat = gzmat;
const float snapAngle = 15.0f;
const float* snap = (gzoperation == ImGuizmo::ROTATE && g_window->isAltPressed()) ? &snapAngle : nullptr;
ImGuizmo::Manipulate(camera.viewMatrix.v, camera.projMatrix.v, (ImGuizmo::OPERATION)gzoperation, ImGuizmo::WORLD, gzmat.v, nullptr, snap);
if (gzmat != originalMat)
selection->setTransform(gzmat);
}
// Menu bar
static bool tbIconsLoaded = false;
static texture_t tbTexture = nullptr;
static texture_t helpTexture = nullptr;
if (!tbIconsLoaded) {
auto [ptr, siz] = GetResourceContent("ToolbarIcons.png");
Image img = Image::loadFromMemory(ptr, siz);
tbTexture = gfx->createTexture(img);
std::tie(ptr, siz) = GetResourceContent("HelpMarker.png");
img = Image::loadFromMemory(ptr, siz);
helpTexture = gfx->createTexture(img);
tbIconsLoaded = true;
}
ImGui::BeginMainMenuBar();
static bool toolbarCollapsed = false;
static float toolbarIconSize = 48.0f;
if (ImGui::ArrowButton("ToolbarCollapse", toolbarCollapsed ? ImGuiDir_Right : ImGuiDir_Down))
toolbarCollapsed = !toolbarCollapsed;
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s toolbar", toolbarCollapsed ? "Show" : "Hide");
ImVec2 respos = ImGui::GetCursorScreenPos();
float reslen = ImGui::GetFrameHeight();
if (ImGui::Button("##ToolbarResizeIcons", ImVec2(reslen, reslen)))
toolbarIconSize = (toolbarIconSize >= 48.0f) ? 32.0f : 48.0f;
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Resize toolbar icons");
ImGui::GetWindowDrawList()->AddCircleFilled(ImVec2(respos.x + reslen * 0.5f, respos.y + reslen * 0.5f), reslen * ((toolbarIconSize >= 48.0f) ? 0.35f : 0.2f), -1);
ImGui::Spacing();
#ifdef XEC_APPVEYOR
ImGui::Text("XXL Editor v" XEC_APPVEYOR " (" __DATE__ ") by AdrienTD, FPS %i", lastFps);
#else
ImGui::Text("XXL Editor Development version, by AdrienTD, FPS: %i", lastFps);
#endif
const char* needhelp = "Need help?";
ImGui::SameLine(ImGui::GetWindowContentRegionMax().x - 13 - ImGui::CalcTextSize(needhelp).x - ImGui::GetStyle().ItemSpacing.x);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().ItemInnerSpacing.y);
ImGui::Image(helpTexture, ImVec2(13, 13));
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().ItemInnerSpacing.y);
ImGui::TextLinkOpenURL(needhelp, "https://github.com/AdrienTD/XXL-Editor/wiki");
ImGui::EndMainMenuBar();
// Toolbar
static int windowOpenCounter = -1;
float BUTTON_SIZE = toolbarIconSize;
static constexpr float CATEGORY_SEPARATION = 3.0f;
static constexpr int TEX_ICONS_PER_ROW = 5;
auto toolbarButton = [&](const char* title, bool* wndShowBoolean, int tid, const char* description = nullptr) {
ImGui::PushID(title);
bool pushed = *wndShowBoolean;
if (pushed)
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
float tx = (float)(tid % TEX_ICONS_PER_ROW) / (float)TEX_ICONS_PER_ROW;
float ty = (float)(tid / TEX_ICONS_PER_ROW) / (float)TEX_ICONS_PER_ROW;
constexpr float delta = 1.0f / (float)TEX_ICONS_PER_ROW;
if (ImGui::ImageButton("button", tbTexture, ImVec2(BUTTON_SIZE, BUTTON_SIZE), ImVec2(tx, ty), ImVec2(tx + delta, ty + delta))) {
*wndShowBoolean = !*wndShowBoolean;
if(*wndShowBoolean)
windowOpenCounter = (windowOpenCounter + 1) & 3;
else
windowOpenCounter = (windowOpenCounter - 1) & 3;
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
float x = ImGui::GetCursorPosX();
ImGui::TextUnformatted(title);
ImGui::SameLine(x + 1.0f);
ImGui::TextUnformatted(title);
ImGui::TextUnformatted(description);
ImGui::EndTooltip();
}
if (pushed)
ImGui::PopStyleColor();
ImGui::PopID();
ImGui::SameLine(0.0f, 2.0f);
};
auto toolbarSeparator = [&]() {
ImVec2 pos = ImGui::GetCursorScreenPos();
ImGui::Dummy(ImVec2(CATEGORY_SEPARATION, 1.0f));
ImGui::SameLine(0.0f, 2.0f);
const float x = std::floor(pos.x + CATEGORY_SEPARATION / 2.0f);
ImGui::GetWindowDrawList()->AddLine(ImVec2(x, pos.y), ImVec2(x, pos.y + BUTTON_SIZE + 4.0f + ImGui::GetTextLineHeightWithSpacing()), 0xFFFFFFFF);
};
const char* groupTitle = nullptr;
float groupStartX = 0.0f;
auto toolbarGroupStart = [&](const char* title) {
ImGui::BeginGroup();
groupTitle = title;
groupStartX = ImGui::GetCursorPosX();
};
auto toolbarGroupEnd = [&]() {
float groupEndX = ImGui::GetCursorPosX() - ImGui::GetStyle().ItemSpacing.x;
float len = ImGui::CalcTextSize(groupTitle).x;
ImGui::NewLine();
ImGui::SetCursorPosX(groupStartX + std::round((groupEndX - groupStartX) * 0.5f - len * 0.5f));
ImGui::TextUnformatted(groupTitle);
ImGui::EndGroup();
ImGui::SameLine(0.0f, 0.0f);
};
if (!toolbarCollapsed) {
ImVec2 minCorner = ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() + 2.0f);
ImVec2 tbSize = ImVec2((float)g_window->getWidth(), BUTTON_SIZE + 16.0f + ImGui::GetTextLineHeightWithSpacing());
ImVec2 maxCorner = ImVec2(minCorner.x + tbSize.x, minCorner.y + tbSize.y);
ImGui::SetNextWindowPos(minCorner, ImGuiCond_Always);
ImGui::SetNextWindowSize(tbSize, ImGuiCond_Always);
ImVec4 bgndcolor = ImGui::GetStyleColorVec4(ImGuiCol_MenuBarBg);
bgndcolor.x *= 0.7f; bgndcolor.y *= 0.7f; bgndcolor.z *= 0.7f; bgndcolor.w = 240.0f / 255.0f;
ImGui::PushStyleColor(ImGuiCol_WindowBg, bgndcolor);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::Begin("Toolbar", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoScrollWithMouse /* | ImGuiWindowFlags_NoBackground*/);
ImGui::PopStyleVar(1);
ImGui::PopStyleColor(1);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f));
toolbarGroupStart("General");
toolbarButton("Main", &wndShowMain, 0, "Load and save level, manage the camera and view");
toolbarButton("Scene graph", &wndShowSceneGraph, 1, "View the Scene Graph and manipulate the Scene Nodes\n - Add new scene nodes\n - Import/export of rendered geometry");
toolbarButton("Beacons", &wndShowBeacons, 2, "Manage beacons\nBeacons are 3D points used to position objects such as:\nbonuses, crates, respawn points, merchant, ...");
toolbarButton("Grounds", &wndShowGrounds, 3, "Manage the Grounds in the sectors\nGrounds are 3D collision models that indicate where entities\nsuch as heroes and enemies can stand and walk on.\nThey also include walls that prevent heroes to pass through.");
toolbarButton("Pathfinding", &wndShowPathfinding, 4, "Manipulate the pathfinding grids and cells.\nPathfinding is used to guide AI-controlled heroes and enemies through the world\nwhile preventing them to access undesired areas such as walls\nusing some form of A* algorithm.");
if (kenv.version <= kenv.KVERSION_XXL2)
toolbarButton("Level properties", &wndShowLevel, 17, "Edit the properties of the current level, such as:\n - Set Asterix spawning position\n - Add new sector\n - Sky color\n - ...");
toolbarGroupEnd();
toolbarSeparator();