-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModalWindow.cs
More file actions
141 lines (110 loc) · 4.18 KB
/
ModalWindow.cs
File metadata and controls
141 lines (110 loc) · 4.18 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
using StereoKit;
using System;
using System.Collections.Generic;
using System.Text;
namespace JumbliVR
{
static class ModalWindow
{
static bool isActive = false;
public delegate void Notify();
static public event Notify ?Activated;
static public event Notify ?Closed;
static public Action ?modalConfirmAction;
static public Action ?modalDraw;
static private Pose pose = new Pose();
static private string message = "";
static private Object? textStyle;
public enum ButtonsToAdd
{
None = 0,
Close,
ConfirmCancel
}
static private ButtonsToAdd buttonsToAdd;
static public void SetWindowHeight(float y)
{
pose.position.y = y;
}
static public float GetWindowHeight()
{
return pose.position.y;
}
static public void ActivateWithConfirmCancelButtons(Action confirmAction, string messageToDisplay = "", Object ?textStyleForWindow = null, Action ?customDraw = null)
{
modalConfirmAction = confirmAction;
Activate(messageToDisplay, textStyleForWindow, customDraw);
buttonsToAdd = ButtonsToAdd.ConfirmCancel;
}
static public void ActivateWithCloseButton(string messageToDisplay = "", Object ?textStyleForWindow = null, Action ?customDraw = null)
{
Activate(messageToDisplay, textStyleForWindow, customDraw);
buttonsToAdd = ButtonsToAdd.Close;
}
static public void Activate(string messageToDisplay, Object ?textStyleForWindow = null, Action ?customDraw = null)
{
modalDraw = customDraw;
Activated?.Invoke();
message = messageToDisplay;
buttonsToAdd = ButtonsToAdd.None;
pose = Utils.GetPopupPose(Vec3.Zero);
if (Vec3.Distance(pose.position, Input.Head.position) > 1 ||
Vec3.Dot((Input.Head.position - pose.position).Normalized, Input.Head.Forward) < .8f)
{
pose.position = Input.Head.position + Input.Head.Forward * .5f;
pose.orientation = Quat.LookAt(pose.position, Input.Head.position);
}
textStyle = textStyleForWindow;
isActive = true;
}
public delegate void ActionRef<T1, T2>(T1 arg1, ref T2 arg2);
// Call backs to allow standard header / footer / stlying / positioning
static ActionRef<string, Pose>? beginWindow;
static public Action<string>? EndWindow;
const string windowName = "ModalWindow";
internal static ActionRef<string, Pose>? BeginWindow { get => beginWindow; set => beginWindow = value; }
static public void Draw()
{
if (isActive == false)
return;
UI.WindowBegin(windowName, ref pose, UIWin.Body, UIMove.Exact);
BeginWindow?.Invoke(windowName, ref pose);
UI.LayoutReserve(V.XY(.2f, .0001f));
// Draw content
if (textStyle != null)
UI.PushTextStyle((TextStyle)textStyle);
if (message != "")
UI.Label(message);
if (modalDraw != null)
modalDraw?.Invoke();
if (textStyle != null)
UI.PopTextStyle();
// Add standard buttons
switch (buttonsToAdd)
{
case ButtonsToAdd.Close:
if (UI.Button("Close"))
Close();
break;
case ButtonsToAdd.ConfirmCancel:
if (UI.Button("Cancel"))
Close();
UI.SameLine();
UI.Space(.01f);
if (UI.Button("Confirm"))
{
modalConfirmAction?.Invoke();
Close();
}
break;
}
EndWindow?.Invoke(windowName);
UI.WindowEnd();
}
static public void Close()
{
isActive= false;
Closed?.Invoke();
}
}
}