From 4f23023428791c4645170c66ae49e7242f8c4623 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Sat, 26 Aug 2023 09:48:12 -0500 Subject: [PATCH] Updated sounds on edit menu. --- src/information/inputTextView.ts | 30 +++++++++++++++++++++++------- src/menus/editMenu.ts | 4 ++-- src/util/diaSounds.ts | 29 ++++++++++++++++------------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/information/inputTextView.ts b/src/information/inputTextView.ts index cff7a34..83df840 100644 --- a/src/information/inputTextView.ts +++ b/src/information/inputTextView.ts @@ -3,28 +3,27 @@ import log from "loglevel"; import {AdvancedDynamicTexture, Control, InputText, VirtualKeyboard} from "@babylonjs/gui"; import {ControllerEventType, Controllers} from "../controllers/controllers"; import {setMenuPosition} from "../util/functions/setMenuPosition"; +import {DiaSounds} from "../util/diaSounds"; export type TextEvent = { text: string; } -export type InputTextViewOptions = { - scene?: Scene; - xr?: WebXRDefaultExperience; - text?: string; - controllers?: Controllers; -} export class InputTextView { public readonly onTextObservable: Observable = new Observable(); private readonly text: string = ""; private readonly scene: Scene; + private sounds: DiaSounds; private readonly controllers: Controllers; private readonly xr: WebXRDefaultExperience; - constructor(text: string, xr: WebXRDefaultExperience, scene: Scene) { + + constructor(text: string, xr: WebXRDefaultExperience, scene: Scene, controllers: Controllers) { this.text = text ? text : ""; this.xr = xr; + this.controllers = controllers; this.scene = scene; + this.sounds = new DiaSounds(scene); } public show() { @@ -69,8 +68,23 @@ export class InputTextView { keyboard.connect(input); keyboard.isVisible = true; keyboard.isEnabled = true; + keyboard.children.forEach((key) => { + key.onPointerEnterObservable.add((eventData, eventState) => { + const gripId = eventState?.userInfo?.pickInfo?.gripTransform?.id; + if (gripId) { + this.controllers.controllerObserver.notifyObservers({ + type: ControllerEventType.PULSE, + gripId: gripId + }); + } + + }, -1, false, this, false); + }); + keyboard.onPointerDownObservable.add(() => { + this.sounds.tick.play(); + }); keyboard.onKeyPressObservable.add((key) => { if (key === '↵') { this.onTextObservable.notifyObservers({text: input.text}); @@ -78,9 +92,11 @@ export class InputTextView { keyboard.dispose(); advancedTexture.dispose(); inputMesh.dispose(); + this.sounds.exit.play(); } }); setMenuPosition(inputMesh, this.scene, new Vector3(0, .4, 0)); + this.sounds.enter.play(); } public showWeb() { diff --git a/src/menus/editMenu.ts b/src/menus/editMenu.ts index a7e2dfe..4be5c16 100644 --- a/src/menus/editMenu.ts +++ b/src/menus/editMenu.ts @@ -252,7 +252,7 @@ export class EditMenu extends AbstractMenu { if (mesh?.metadata?.text) { text = mesh.metadata.text; } - const textInput = new InputTextView(text, this.xr, this.scene); + const textInput = new InputTextView(text, this.xr, this.scene, this.controllers); textInput.show(); textInput.onTextObservable.addOnce((value) => { @@ -264,7 +264,7 @@ export class EditMenu extends AbstractMenu { } private showNewRelic() { - const inputTextView = new InputTextView('test', this.xr, this.scene); + const inputTextView = new InputTextView('test', this.xr, this.scene, this.controllers); inputTextView.show(); inputTextView.onTextObservable.addOnce((value) => { const config = this.diagramManager.config.current; diff --git a/src/util/diaSounds.ts b/src/util/diaSounds.ts index e79de66..8217131 100644 --- a/src/util/diaSounds.ts +++ b/src/util/diaSounds.ts @@ -2,19 +2,7 @@ import {Scene, Sound} from "@babylonjs/core"; export class DiaSounds { private readonly scene: Scene; - - public get tick() { - return new Sound("tick", '/assets/sounds/tick.mp3', this.scene); - } - - private volume: number = 0.8; - private readonly _bounce: Sound; - private readonly _background: Sound; - private readonly _enter: Sound; - - public get enter() { - return this._enter; - } + private readonly _tick: Sound; constructor(scene: Scene) { this.scene = scene; @@ -34,6 +22,7 @@ export class DiaSounds { length: 1.0 }); }); + this._tick = new Sound("tick", '/assets/sounds/tick.mp3', this.scene); this._bounce = new Sound("bounce", "/assets/sounds/drumsprite.mp3", this.scene, null, { autoplay: false, loop: false, @@ -57,6 +46,20 @@ export class DiaSounds { this._backgroundEffects.push(this.buildSpatialSound("dove", "/assets/sounds/dove.mp3")) } + private volume: number = 0.8; + private readonly _bounce: Sound; + private readonly _background: Sound; + private readonly _enter: Sound; + + public get enter() { + return this._enter; + } + + public get tick() { + return this._tick; + + } + _backgroundEffects: Array = []; public get backgroundEffects(): Array { return this._backgroundEffects;