-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathUI.ts
More file actions
215 lines (173 loc) · 5.19 KB
/
Copy pathUI.ts
File metadata and controls
215 lines (173 loc) · 5.19 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
import Event from "SpectaclesInteractionKit.lspkg/Utils/Event"
import {Conversions} from "./Conversions"
import {LoopController} from "./LoopController"
@component
export class UI extends BaseScriptComponent {
@input
camObj: SceneObject
@input
homeUI: SceneObject
@input
duringPathCreationUI: SceneObject
@input
goToStartUI: SceneObject
@input
goToStartUiDistance: Text
@input
endSessionUI: SceneObject
@input
pfbLoopUi: ObjectPrefab
@input
backplateSo: SceneObject
@input
warningTutorialUI: SceneObject
@input
tutorialUI: SceneObject
@input
tutorialAnimationPlayer: AnimationPlayer
@input
tutorialText: Text
get createPathClicked() {
return this.createPathClickedEvent.publicApi()
}
get resetPathClicked() {
return this.resetPathClickedEvent.publicApi()
}
get finishPathClicked() {
return this.finishPathClickedEvent.publicApi()
}
get loopPathClicked() {
return this.loopPathClickedEvent.publicApi()
}
get tutorialComplete() {
return this.tutorialCompleteEvent.publicApi()
}
get endSessionClicked() {
return this.endSessionClickedEvent.publicApi()
}
private createPathClickedEvent: Event = new Event()
private resetPathClickedEvent: Event = new Event()
private finishPathClickedEvent: Event = new Event()
private loopPathClickedEvent: Event = new Event()
private tutorialCompleteEvent: Event = new Event()
private endSessionClickedEvent: Event = new Event()
private warningTr = null
private tutorialTr = null
private homeTr = null
private duringPathCreationUiTr: Transform = null
private goToStartUiTr: Transform = null
private endSessionUiTr: Transform = null
private currentActiveTr: Transform = null
private tutorialStepCount: number = 0
private loopUiController: LoopController | undefined
onAwake() {
this.warningTr = this.warningTutorialUI.getTransform()
this.tutorialTr = this.tutorialUI.getTransform()
this.homeTr = this.homeUI.getTransform()
this.duringPathCreationUiTr = this.duringPathCreationUI.getTransform()
this.goToStartUiTr = this.goToStartUI.getTransform()
this.endSessionUiTr = this.endSessionUI.getTransform()
this.hide(this.tutorialTr)
this.hide(this.homeTr)
this.hide(this.duringPathCreationUiTr)
this.hide(this.goToStartUiTr)
this.hide(this.endSessionUiTr)
}
showHomeUi() {
this.tryHideCurrentActive()
this.currentActiveTr = this.homeTr
this.show(this.currentActiveTr)
}
showTutorialUi() {
this.tryHideCurrentActive()
this.tutorialStepCount = 0
this.currentActiveTr = this.warningTr
this.show(this.currentActiveTr)
}
showDuringPathCreationUi() {
this.tryHideCurrentActive()
this.currentActiveTr = this.duringPathCreationUiTr
this.show(this.currentActiveTr)
}
showEndSessionUi() {
this.tryHideCurrentActive()
this.currentActiveTr = this.endSessionUiTr
this.show(this.currentActiveTr)
}
showGoToStartUi(distance: number) {
this.tryHideCurrentActive()
const pathDistFt = Conversions.cmToFeet(distance)
this.goToStartUiDistance.text = pathDistFt.toFixed(1) + "'"
this.currentActiveTr = this.goToStartUiTr
this.show(this.currentActiveTr)
}
initLoopUi(startTr: Transform) {
if (!this.loopUiController) {
this.loopUiController = this.pfbLoopUi.instantiate(null).getComponent("ScriptComponent") as LoopController
}
this.loopUiController.start(startTr)
}
showLoopUi() {
this.loopUiController.show()
}
hideLoopUi() {
this.loopUiController.hide()
}
hideUi() {
this.tryHideCurrentActive()
this.currentActiveTr = null
}
onProgressTutorial() {
if (this.tutorialStepCount === 0) {
this.tryHideCurrentActive()
this.currentActiveTr = this.tutorialTr
this.show(this.currentActiveTr)
} else if (this.tutorialStepCount === 1) {
this.tutorialAnimationPlayer.setClipEnabled("Sprint_Layer", false)
this.tutorialAnimationPlayer.setClipEnabled("Loop_Layer", true)
this.tutorialText.text = "MAKE A LOOP"
} else if (this.tutorialStepCount === 2) {
this.hide(this.tutorialTr)
this.tutorialCompleteEvent.invoke()
}
this.tutorialStepCount += 1
}
onCreatePathButton() {
this.hide(this.homeTr)
this.createPathClickedEvent.invoke()
}
onFinishCreatePathButton() {
this.hide(this.duringPathCreationUiTr)
if (this.loopUiController.getIsInLoopZone()) {
this.loopUiController.onLock()
this.loopPathClickedEvent.invoke()
} else {
this.finishPathClickedEvent.invoke()
}
}
onResetCreatePathButton() {
this.hide(this.duringPathCreationUiTr)
this.resetPathClickedEvent.invoke()
}
onStopWalkingButton() {
this.hide(this.endSessionUiTr)
this.endSessionClickedEvent.invoke()
}
private hide(tr: Transform) {
const localPos = tr.getLocalPosition()
localPos.y = 10000
tr.setLocalPosition(localPos)
this.backplateSo.enabled = false
}
private show(tr: Transform) {
const localPos = tr.getLocalPosition()
localPos.y = -5
tr.setLocalPosition(localPos)
this.backplateSo.enabled = true
}
private tryHideCurrentActive() {
if (this.currentActiveTr) {
this.hide(this.currentActiveTr)
}
}
}