-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNode.cs
1323 lines (1093 loc) · 47.5 KB
/
Node.cs
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
using StereoKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
public class Node
{
public struct NodeModel
{
public string name;
public string filename;
public NodeModel(string inName, string inFilename)
{
name = inName;
filename = inFilename;
}
}
public struct Relative
{
public int id;
public string name;
public Color color;
public Vec2 textSize;
public Vec3 textPosition;
public Quat textOrientation;
public Relative(int inId, Color inColor, string inName = "")
{
id = inId;
name = inName;
color = inColor;
textSize = new Vec2();
textPosition = new Vec3();
textOrientation = new Quat();
}
}
public static int maxNodeId = 0;
public struct State
{
public int id;
public string name;
public Color color;
public string notes;
public float nodeScale;
public string modelFilename;
public string spriteFilename;
public string musicFilename;
public State(int inId, string inName, string inModelFilename = "")
{
id = inId;
name = inName;
color = Color.White;
notes = "";
nodeScale = 1;
modelFilename = inModelFilename;
spriteFilename = "";
musicFilename = "";
}
}
public bool forceDraw = false;
public SortedDictionary<int, State> states = new SortedDictionary<int,State>();
public int activeStateKey = 1;
public int maxStateKey=1;
public bool isLocation;
public bool isPortal;
public int destinationId;
public int id;
public Dictionary<int, Relative> relatives;
public int parent;
public int locationId;
public bool moveable;
public bool movesWithParent;
public Pose pose;
public Model model;
public bool visibleAtStart=true;
public bool visible;
public bool available=true;
public Sprite sprite;
public string defaultName;
public float health;
private Vec3 parentDragPoint;
private float calculatedScale=1f;
private Vec3 dimensions = Vec3.One;
public float radius=1;
public Actions actions;
private Vec3 assetDimensions = Vec3.One;
public bool inFocus;
public bool propertiesDisplayed;
public bool grabbed;
float _hue = 0;
float _saturation = 0;
float _value = 1;
static public int activeNodeId;
private int advancedStartAt=0;
private enum EditState
{
ready,
editingTitle,
linkingParent,
editingDescription,
editingLink
}
public enum ActionType
{
ChangeState,
ChangeScore,
ChangeHealth,
ChangeVisibility,
Pickup,
UseAnObject
}
public struct Action
{
public int id;
public int useNodeid;
public string name;
public List<ActionStep> steps;
public List<int> applicableStates;
public Action(int inId, string inName="")
{
id = inId;
useNodeid = 0;
name = inName;
steps = new List<ActionStep>();
applicableStates = new List<int>();
}
}
public struct ActionStep
{
public ActionType type;
public int nodeId;
public float value;
public string text;
public ActionStep(ActionType inType)
{
type = inType;
nodeId = 0;
value = 0;
text = "";
}
}
public enum MoreInfoState
{
collapsed,
expanded,
editActions
}
public MoreInfoState moreInfoState = MoreInfoState.collapsed;
private int editingLinkId;
private EditState editState;
public string GetDefaultName()
{
string result;
if (isLocation)
{
result = "location #" + id;
}
else
{
result = "Node #" + id;
}
return result;
}
public Node(string serialisedData)
{
init();
UnSerialise(serialisedData);
if (activeState.spriteFilename == "")
OnLoadModel(activeState.modelFilename);
else
OnLoadImage(activeState.spriteFilename);
Node.maxNodeId = Math.Max(Node.maxNodeId, id);
visible = visibleAtStart;
}
public Node(bool inIsLocation, string inName, Pose inPose, bool inIsPortal = false, string inModelFilename="sphere.obj")
{
try {
Node.maxNodeId++;
id = Node.maxNodeId;
isLocation = inIsLocation;
isPortal = inIsPortal;
pose = inPose;
inName = GetDefaultName();
if (isLocation)
Main.LocationNames[id] = inName;
defaultName = inName;
// States
states.Add(maxStateKey, new Node.State(maxStateKey, inName, inModelFilename));
ChangeActiveState(maxStateKey, false);
maxStateKey++;
visibleAtStart = true;
relatives = new Dictionary<int, Relative>();
locationId = Main.locationId;
health = 100;
parentDragPoint = Vec3.Zero;
editState = EditState.ready;
OnLoadModel(activeState.modelFilename);
destinationId = 0;
init();
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
}
~Node()
{
//Log.Info("Node" + states[activeStateKey].name + "Exiting");
}
private void init()
{
try {
actions = new Actions(this);
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
}
public void ChangeActiveState(int newKey, bool updateBeforeChange)
{
try {
if (updateBeforeChange)
states[activeStateKey] = activeState;
activeStateKey = newKey;
activeState = states[activeStateKey];
if (activeState.modelFilename != "")
OnLoadStandardModel(activeState.modelFilename);
if (activeState.spriteFilename != "")
OnLoadStandardImage(activeState.spriteFilename);
if (isLocation)
Main.PlayMusicForLocation();
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
}
private Vec2 titleSize;
private Matrix titlePosition;
private bool draw = false;
private Pose moreInfoPose = new Pose();
private Pose moreInfoWindowPose = new Pose();
private Vec2 notesSize = new Vec2(.2f,.055f);
private int sinx;
public State activeState;
private Bounds scaledBounds;
private Matrix modeTransform = new Matrix();
public void Draw()
{
try {
UI.PushId("" + id);
draw = Vec3.Dot((pose.position - Input.Head.position).Normalized, Input.Head.Forward) > 0 || forceDraw;
forceDraw = false;
titleSize = Text.Size(activeState.name, Main.titleStyle);
actionCooldown = Math.Max(0, actionCooldown - Main.deltaTime);
Controller c = Input.Controller(Handed.Right);
if (c.IsX1Pressed)
{
Renderer.Screenshot("G:\\IdeaEngine\\scrshot" + Time.Elapsedf + ".jpg", Input.Head.position, Input.Head.Forward, 1920, 1080);
sinx++;
}
if (draw)
{
if (activeState.spriteFilename == "")
{
calculatedScale = (.12f * activeState.nodeScale) / Math.Max(Math.Max(model.Bounds.dimensions.x, model.Bounds.dimensions.y), model.Bounds.dimensions.z);
dimensions = model.Bounds.dimensions * calculatedScale;
scaledBounds = model.Bounds * calculatedScale;
dimensions.x = MathF.Max(.05f, dimensions.x);
dimensions.y = MathF.Max(.05f, dimensions.y);
dimensions.z = MathF.Max(.05f, dimensions.z);
modeTransform = Matrix.TRS(pose.position, pose.orientation, calculatedScale * .9f);
modeTransform.Translation = modeTransform.Transform(model.Bounds.center * -1);
model.Draw(modeTransform, activeState.color);
}
else
{
calculatedScale = .12f * activeState.nodeScale;
dimensions = Vec3.One * calculatedScale;
dimensions.z = .05f;
scaledBounds = new Bounds(Vec3.Zero,dimensions);
sprite.Draw(Matrix.TRS(pose.position + pose.Up * (calculatedScale/2) + pose.Right * (calculatedScale / 2) * -1
, pose.orientation, calculatedScale *
V.XYZ(sprite.NormalizedDimensions.x, sprite.NormalizedDimensions.y,1)), activeState.color);
}
radius = MathF.Max(dimensions.x, dimensions.y);
radius = MathF.Max(radius, dimensions.z);
radius /= 2;
titlePosition = Matrix.TRS(pose.position +
pose.Up * ((dimensions.y /2) + titleSize.y / 2 + .03f)
, pose.orientation, 1f);
Text.Add(activeState.name, titlePosition, Main.titleStyle, TextAlign.Center, TextAlign.Center);
moreInfoPose.position = pose.position +
pose.Forward * ((dimensions.z / 2) + .02f) +
pose.Up * ((dimensions.y / -2) + -.00f);
moreInfoPose.orientation = pose.orientation;
if (moreInfoState == MoreInfoState.expanded && Node.activeNodeId != id)
moreInfoState = MoreInfoState.collapsed;
switch (moreInfoState)
{
case MoreInfoState.collapsed:
if (Main.editingNodeId == id && Main.editingNodeDescription == "MoreInfo")
Main.ResetEditingMode();
if (CheckIfMoreWindowRequired()) {
UI.WindowBegin("MoreInfo", ref moreInfoPose, UIWin.Empty);
if (states.Count > 1 && Main.menuState == Main.MenuState.EditNodes)
{
Text.Add("State: " + activeStateKey,
Matrix.Identity, Main.titleStyle, TextAlign.BottomCenter, TextAlign.TopCenter);
}
if (isPortal)
{
string destinationName = "New location";
if (destinationId > 0)
{
if (Main.LocationNames.ContainsKey(destinationId))
destinationName = Main.LocationNames[destinationId];
}
if (UI.Button("Go to\n" + destinationName))
{
Main.GoToLocation(destinationId);
destinationId = Main.locationId; // Update in case a new node was created
}
}
else
{
if (UI.Button("More"))
{
moreInfoState = MoreInfoState.expanded;
moreInfoWindowPose.position = moreInfoPose.position + (moreInfoPose.orientation * Vec3.Forward) * .02f;
moreInfoWindowPose.orientation = moreInfoPose.orientation;
Main.editingNodeId = id;
Main.editingNodeDescription = "MoreInfo";
Node.activeNodeId = id;
}
}
UI.WindowEnd();
}
break;
case MoreInfoState.expanded:
UI.WindowBegin("MoreInfo", ref moreInfoWindowPose, UIWin.Body);
notesSize = Text.Size(activeState.notes, Main.generalTextStyle);
if (Main.menuState == Main.MenuState.EditNodes)
notesSize.x = MathF.Max(.25f, notesSize.x);
else
notesSize.x = MathF.Max(.1f, notesSize.x);
notesSize.y = MathF.Max(.01f, notesSize.y + .003f);
if (Main.menuState == Main.MenuState.EditNodes)
UI.Label("Type notes here. The box will expand to fit the width and height");
UI.LayoutReserve(notesSize);
Mesh.Cube.Draw(Material.Unlit,
Matrix.TRS(UI.LayoutLast.center + Vec3.Forward * .001f, Quat.Identity, UI.LayoutLast.dimensions + V.XYZ(.01f,.01f,0)),
Color.White);
Text.Add(activeState.notes, Matrix.T(UI.LayoutLast.center + Vec3.Forward * .002f), notesSize,
TextFit.Clip, Main.generalTextStyle,
TextAlign.Center, TextAlign.TopLeft);
actions.Draw();
UI.HSeparator();
if (UI.Button("Close"))
moreInfoState = MoreInfoState.collapsed;
if (Main.menuState == Main.MenuState.EditNodes)
{
Main.keyboardInput.Update(id + "notes", true, UI.LayoutAt, Quat.Identity, -.04f, ref activeState.notes);
forceDraw = true;
}
UI.WindowEnd();
break;
case MoreInfoState.editActions:
actions.EditActions(ref moreInfoWindowPose);
break;
}
}
DrawLines();
propertiesDisplayed = false;
if (Main.menuState == Main.MenuState.EditNodes)
{
if (inFocus || editState != EditState.ready)
MakeEditable();
}
UI.PopId();
if (isLocation)
{
if (activeState.musicFilename != "")
if (Main.musicInst.IsPlaying == false)
Main.PlayMusicForLocation();
}
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
}
private bool CheckIfMoreWindowRequired()
{
try {
if (Main.editingNodeId > -1 && Main.menuState == Main.MenuState.EditNodes)
if (Main.editingNodeId != id || Main.editingNodeDescription != "MoreInfo")
return false;
if (Main.menuState == Main.MenuState.EditNodes ||
activeState.notes.Length > 0 || isPortal)
return true;
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
return actions.DoActionsExist(activeStateKey);
}
private Vec3 newPoint = new Vec3();
private Vec3 lineDirection = new Vec3();
public Vec3 ClosestPoint(Vec3 lineSource)
{
try {
if (Main.menuState == Main.MenuState.Play && visible == false)
return Vec3.Zero;
lineDirection = (lineSource - pose.position).Normalized;
newPoint = pose.position + lineDirection * radius;
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
return newPoint;
}
public void DrawLines()
{
Vec3 p1;
Vec3 p2;
Vec3 toPlayer;
Vec3 alongLine;
bool reverseText;
char directionInd;
Relative relative;
string text;
Vec3 lineButtonPosition;
int removeKey = -1;
List<int> keys = new List<int>(relatives.Keys);
try
{
foreach (int key in keys)
{
if (Main.Nodes.ContainsKey(key))
{
relative = relatives[key];
p1 = ClosestPoint(Main.Nodes[key].pose.position) + Vec3.Up * .04f * ((id < relative.id) ? 1f : -1f);
p2 = Main.Nodes[key].ClosestPoint(pose.position);
if (Vec3.Dot((p2 - p1).Normalized, (pose.position - Main.Nodes[key].pose.position).Normalized) < 0)
{
if (p2.Length != 0)
{
p2 += Vec3.Up * .04f * ((id < relative.id) ? 1f : -1f);
alongLine = (p2 - p1).Normalized;
reverseText = Vec3.Dot(Input.Head.Right, alongLine) > 0;
toPlayer = (pose.position - Input.Head.position).Normalized;
relative.textPosition = p1 + (alongLine * (Vec3.Distance(p1, p2) / 2));
relative.textOrientation = Quat.LookAt(p1, p2, Vec3.Cross(alongLine, toPlayer)) * Quat.FromAngles(0, -90, reverseText ? 0 : 180);
directionInd = reverseText ? '>' : '<';
text = "\n\r" + directionInd + " " + relative.name + " " + directionInd;
Lines.Add(p1, p2, relative.color, .005f);
Text.Add(text, Matrix.TRS(relative.textPosition, relative.textOrientation, Vec3.One * 1f),
Main.titleStyle, TextAlign.Center, TextAlign.Center, 0, -.005f);
relative.textSize = Text.Size(text);
lineButtonPosition = relative.textPosition + (relative.textSize.y / 2) * (relative.textOrientation * Vec3.Up);
if (Main.menuState == Main.MenuState.EditNodes)
{
if (editState == EditState.ready)
{
if (Vec3.Distance(Input.Hand(Handed.Right).pinchPt, lineButtonPosition) < .5f)
{
if (EditButton("editLink", ChangeEditMode.setEditMode, lineButtonPosition, false, "M", true, relative.textOrientation))
{
editState = EditState.editingLink;
editingLinkId = key;
actionCooldown = 1f;
}
}
if (Vec3.Distance(Input.Hand(Handed.Right).pinchPt, p1) < .5f)
{
if (EditButton("deleteLink", ChangeEditMode.ignoreEditMode, p1 + Vec3.Up * .03f, false, "J", true, relative.textOrientation))
{
removeKey = key;
actionCooldown = 1f;
}
}
}
if (editState == EditState.editingLink && editingLinkId == key)
{
Main.keyboardInput.Update(id + "link" + key, false, lineButtonPosition, relative.textOrientation, -.04f, ref relative.name);
forceDraw = true;
if (EditButton("editLink", ChangeEditMode.clearEditMode, lineButtonPosition, false, "H", true, relative.textOrientation))
{
ChangeActiveState(activeStateKey, true);
editState = EditState.ready;
actionCooldown = 1f;
}
}
}
relatives[key] = relative;
}
}
}
else
relatives.Remove(key);
}
if (removeKey >= 0)
relatives.Remove(removeKey);
}
catch (Exception ex)
{
Log.Err(ex.Source + ":" + ex.Message);
}
}
private Color lineColour = new Color(.2f, .2f, .2f, 1);
private float actionCooldown = 0;
private int linkingHand;
public void MakeEditable()
{
try {
if (Main.editingNodeId == -1)
AddHandle("Model Handle" + id);
bool actioned = false;
for (int i = 0; i < 2; i++)
{
Hand hand = Input.Hand(i);
if (editState == EditState.linkingParent && linkingHand == i)
{
if (hand.IsPinched == false)
{
editState = EditState.ready;
Main.ResetEditingMode();
if (Main.selectedNodes[i] != -1 && Main.selectedNodes[i] != id)
{
relatives[Main.selectedNodes[i]] = new Relative(Main.selectedNodes[i], lineColour, "");
}
}
else
{
Lines.Add(parentDragPoint, hand.pinchPt, lineColour, .005f);
}
}
}
if (editState == EditState.ready)
{
parentDragPoint = pose.position + pose.Right * ((dimensions.x / 2) + .03f);
if (EditButton("linkNode", ChangeEditMode.setEditMode, parentDragPoint, true, "N", false, Quat.Identity))
{
actioned = true;
editState = EditState.linkingParent;
}
}
Vec3 position = titlePosition.Pose.position + pose.Up * (titleSize.y + .02f);
if (editState == EditState.ready)
{
if (EditButton("editTitle", ChangeEditMode.setEditMode, position, false, "M", false, Quat.Identity))
{
actioned = true;
editState = EditState.editingTitle;
actionCooldown = 1f;
if (activeState.name == Main.nameMe)
activeState.name = "";
}
}
else
{
if (editState == EditState.editingTitle)
{
if (activeState.name == defaultName)
activeState.name = "";
Main.keyboardInput.Update(id + "title", false, position, Quat.Identity, -.04f, ref activeState.name);
forceDraw = true;
if (isLocation)
{
Main.LocationNames[id] = activeState.name;
}
if (EditButton("editTitle", ChangeEditMode.clearEditMode, position, false, "H", false, Quat.Identity))
{
if (activeState.name == "")
activeState.name = GetDefaultName();
ChangeActiveState(activeStateKey, true);
actioned = true;
editState = EditState.ready;
actionCooldown = 1f;
}
}
}
if (actioned)
Default.SoundClick.Play(parentDragPoint);
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
}
public enum ChangeEditMode
{
ignoreEditMode,
setEditMode,
clearEditMode
}
public bool EditButton(string description, ChangeEditMode editMode, Vec3 target, bool needsPinch, string icon, bool ovedrideOrientation, Quat inOrientation)
{
bool activated = false;
try {
if (Main.editingNodeId > -1)
if (Main.editingNodeId != id || Main.editingNodeDescription != description)
return false;
if (ovedrideOrientation == false)
inOrientation = pose.orientation;
if (actionCooldown > 0 || draw == false)
return false;
float distance;
bool Highlight = false;
//
// Drag point
//
for (int i = 0; i < 2; i++)
{
Hand hand = Input.Hand(i);
distance = Vec3.Distance(needsPinch ? hand.pinchPt : hand[FingerId.Index, JointId.Tip].position, target);
if (Highlight == false)
Highlight = distance < .05f;
if (needsPinch)
{
if (hand.IsJustPinched && Highlight)
{
activated = true;
linkingHand = i;
}
}
else
{
if (distance < .01f)
{
activated = true;
}
}
}
Text.Add(icon, Matrix.TRS(target,
inOrientation, Highlight ? 1.1f : 1f), Main.iconTextStyle, TextAlign.Center, TextAlign.Center);
if (activated)
{
switch (editMode)
{
case ChangeEditMode.clearEditMode:
Main.ResetEditingMode();
break;
case ChangeEditMode.setEditMode:
Main.editingNodeId = id;
Main.editingNodeDescription = description;
break;
case ChangeEditMode.ignoreEditMode:
break;
default:
break;
}
}
}
catch (Exception ex) { Log.Err(ex.Source + ":" + ex.Message); }
return activated;
}
public Pose propertiesPose;
private Pose workPose2;
private bool rotateOnly = false;
private enum PropertyState
{
TopLevel,
BrowsingShapes,
BrowsingImages,
LoadingAsset,
SelectColour,
BrowsingDestinations,
BrowsingMusic,
Advanced
}
private PropertyState propertyState = PropertyState.TopLevel;
public Vec2 MaxPropertyWidth = new Vec2(.15f, .001f);
public void AddHandle(string name)
{
try {
if (draw)
Mesh.Cube.Draw(Material.UIBox, Matrix.TRS(pose.position, pose.orientation, dimensions));
Bounds b = new Bounds(dimensions);
grabbed = UI.Handle(name, ref pose, b);
if (draw)
{
propertiesPose.position = pose.position +
(pose.Right * ((dimensions.x / 2f) + (MaxPropertyWidth.x/2) + .01f) * -1) +
(pose.Up * (dimensions.y / 2f + .04f)) +
(pose.Forward * dimensions.z * .5f);
propertiesPose.orientation = pose.orientation;
bool showColours=false;
UI.WindowBegin("Properties", ref propertiesPose, UIWin.Empty);
UI.LayoutReserve(MaxPropertyWidth);
propertiesDisplayed = true;
int counter = 0;
switch (propertyState)
{
case PropertyState.TopLevel:
//UI.Toggle(rotateOnly?"Rotate only":"Move enabled", ref rotateOnly);
if (isPortal)
{
if (UI.Button("Set destination"))
{
propertyState = PropertyState.BrowsingDestinations;
}
}
if (isLocation)
{
if (UI.Button("Set Music"))
{
propertyState = PropertyState.BrowsingMusic;
}
}
if (UI.Button("Select 3d Model"))
{
propertyState = PropertyState.BrowsingShapes;
}
if (UI.Button("Select 2d Image") && !Platform.FilePickerVisible)
{
propertyState = PropertyState.BrowsingImages;
}
if (UI.Button("Change Color"))
propertyState = PropertyState.SelectColour;
if (UI.Button("Advanced"))
propertyState = PropertyState.Advanced;
break;
case PropertyState.Advanced:
if (UI.Button("<"))
propertyState = PropertyState.TopLevel;
UI.SameLine();
UI.Toggle((visibleAtStart ? "Visible at start" : "Hidden at start"), ref visibleAtStart);
Text.Add("Create multiple states for a node,\nthen add buttons and logic in [More]\nallowing users to cause state changes.",
Matrix.Identity, Main.generalTextStyle,TextAlign.BottomLeft, TextAlign.TopLeft, .07f, 0.00f);
State[] aStates = states.Values.ToArray();
int lineCount = 0;
if (advancedStartAt >= states.Count)
advancedStartAt = Math.Max(0, advancedStartAt - 3);
if (actionCooldown == 0)
{
foreach (State s in aStates)
{
if (lineCount >= advancedStartAt && lineCount < advancedStartAt + 3) {
if (UI.Button("Show state " + s.id))
ChangeActiveState(s.id, true);
if (states.Count > 1)
{
UI.SameLine();
if (UI.Button("Delete state " + s.id))
{
ChangeActiveState(activeStateKey, true); // update data first, we may then delete this one
actionCooldown = .5f;
states.Remove(s.id);
ChangeActiveState(states.Keys.ToArray()[0], false);
}
}
}
lineCount++;
}
if (advancedStartAt > 0) {
if (UI.Button("< Previous"))
{
advancedStartAt -= 3;
advancedStartAt = Math.Max(0, advancedStartAt);
}
}
if (lineCount > advancedStartAt + 3)
{
if (advancedStartAt > 0)
UI.SameLine();
if (UI.Button("Next >"))
advancedStartAt += 3;
}
if (UI.Button("Duplicate current state"))
{
State newState = new State(); // create new
newState = activeState; // copy active
newState.id = maxStateKey; // update id
states[maxStateKey] = newState;
ChangeActiveState(maxStateKey, true);
maxStateKey++;
actionCooldown = .5f;
}
}
break;
case PropertyState.BrowsingMusic:
if (UI.Button("<"))
propertyState = PropertyState.TopLevel;
UI.SameLine();
if (UI.Button("Open music...") && !Platform.FilePickerVisible)
{
Platform.FilePicker(PickerMode.Open, OnLoadMusic, OnCancelLoad,
".wav", ".mp3");
propertyState = PropertyState.LoadingAsset;
}
if (UI.Button("No music"))
{
activeState.musicFilename = "";
Main.StopMusic();
}
foreach (Node.NodeModel nodeModel in Main.standardMusic)
{
if (UI.Button(nodeModel.name))
OnLoadStandardMusic(nodeModel.filename);
if (counter < 2)
UI.SameLine();
counter++;
counter %= 3;
}
break;
case PropertyState.BrowsingShapes:
if (UI.Button("<"))
propertyState = PropertyState.TopLevel;
UI.SameLine();
if (UI.Button("Open model...") && !Platform.FilePickerVisible)
{
Platform.FilePicker(PickerMode.Open, OnLoadModel, OnCancelLoad,
".gltf", ".glb", ".obj", ".stl", ".ply");
propertyState = PropertyState.LoadingAsset;
}
foreach (Node.NodeModel nodeModel in Main.standardModels)
{
if (UI.Button(nodeModel.name))
OnLoadStandardModel(nodeModel.filename);
if (counter < 2)
UI.SameLine();
counter++;
counter %= 3;
}
break;
case PropertyState.BrowsingImages:
if (UI.Button("<"))
propertyState = PropertyState.TopLevel;
UI.SameLine();
if (UI.Button("Open image...") && !Platform.FilePickerVisible)
{
Platform.FilePicker(PickerMode.Open, OnLoadImage, OnCancelLoad,
".jpg", ".png", ".tga", ".bmp", ".psd", ".gif", ".hdr", ".pic");
propertyState = PropertyState.LoadingAsset;
}
foreach (Node.NodeModel nodeModel in Main.standardImages)
{
if (UI.Button(nodeModel.name))
OnLoadStandardImage(nodeModel.filename);
if (counter < 2)
UI.SameLine();