-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathMinimapHighlightManager.ts
More file actions
127 lines (112 loc) · 4.13 KB
/
Copy pathMinimapHighlightManager.ts
File metadata and controls
127 lines (112 loc) · 4.13 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
import {Interactable} from "SpectaclesInteractionKit.lspkg/Components/Interaction/Interactable/Interactable"
import {LensConfig} from "SpectaclesInteractionKit.lspkg/Utils/LensConfig"
import {UpdateDispatcher} from "SpectaclesInteractionKit.lspkg/Utils/UpdateDispatcher"
import {NavigationDataComponent} from "SpectaclesNavigationKit.lspkg/NavigationDataComponent/NavigationDataComponent"
import {CustomLocationPlacesImageDisplay} from "./CustomLocationPlacesImageDisplay"
import {PanelManager} from "./PanelManager"
/**
* Manages a highlight ring and icon on the minimized map to alert the user to anything that might disrupt their
* navigation.
*/
@component
export class MinimapHighlightManager extends BaseScriptComponent {
private defaultColor: vec4
@input private navigationComponent: NavigationDataComponent
@input private mapInteractables: Interactable[]
@input private display: Image
@input private customLocationImage: CustomLocationPlacesImageDisplay
@input private panelControl: PanelManager
@input private promptDisplay: Image
@input
@allowUndefined
private audio?: AudioComponent
@input
@widget(new ColorWidget())
private promptColor: vec4
@input
@widget(new ColorWidget())
private localizedColor: vec4
@input
private promptTexture: Texture
@input
private noInternetTexture: Texture
@input
private localizedTexture: Texture
private isHovered = false
private isPrompting = false
private justVisited = 0
private isTransitioning = false
private onAwake(): void {
this.createEvent("OnStartEvent").bind(() => this.start())
}
private start(): void {
this.defaultColor = this.display.mainPass.baseColor
this.panelControl.onMinimized.add((mini) => {
this.isTransitioning = false
this.promptDisplay.sceneObject.enabled = mini && this.customLocationImage.isPromptAvailable
this.updateDisplay()
})
this.panelControl.onTransitionStarted.add(() => {
this.isTransitioning = true
this.updateDisplay()
})
this.mapInteractables.forEach((m) => {
m.onHoverEnter.add(() => {
this.isHovered = true
this.updateDisplay()
})
m.onHoverExit.add(() => {
this.isHovered = false
this.updateDisplay()
})
})
this.customLocationImage.onPromptAvailable.add((place) => {
this.isPrompting = !isNull(place)
this.updateDisplay()
})
const updateDispatcher: UpdateDispatcher = LensConfig.getInstance().updateDispatcher
const update = updateDispatcher.createUpdateEvent("UpdateEvent")
update.bind(() => {
if (this.justVisited > 0) {
this.justVisited -= getDeltaTime()
} else {
this.updateDisplay()
update.enabled = false
}
})
this.navigationComponent.onArrivedAtPlace(() => {
this.justVisited = 5
update.enabled = true
this.audio?.play(1)
this.updateDisplay()
})
this.promptDisplay.sceneObject.enabled = false
this.updateDisplay()
}
private updateDisplay(): void {
this.promptDisplay.sceneObject.enabled = false
if (!this.panelControl.isMinimized || this.isTransitioning) {
this.display.sceneObject.enabled = false
} else if (this.isHovered) {
this.display.mainPass.baseColor = this.defaultColor
this.display.sceneObject.enabled = true
} else if (!global.deviceInfoSystem.isInternetAvailable()) {
this.promptDisplay.sceneObject.enabled = true
this.promptDisplay.mainPass.baseTex = this.noInternetTexture
this.display.mainPass.baseColor = this.promptColor
this.display.sceneObject.enabled = true
} else if (this.justVisited > 0) {
this.display.mainPass.baseColor = this.localizedColor
this.promptDisplay.mainPass.baseTex = this.localizedTexture
this.promptDisplay.sceneObject.enabled = true
this.display.sceneObject.enabled = true
} else if (this.isPrompting) {
this.promptDisplay.sceneObject.enabled = true
this.promptDisplay.mainPass.baseTex = this.promptTexture
this.display.mainPass.baseColor = this.promptColor
this.display.sceneObject.enabled = true
} else {
this.display.sceneObject.enabled = false
}
}
}