Updated sounds on edit menu.

This commit is contained in:
Michael Mainguy 2023-08-26 09:48:12 -05:00
parent 6f70e4dfba
commit 4f23023428
3 changed files with 41 additions and 22 deletions

View File

@ -3,28 +3,27 @@ import log from "loglevel";
import {AdvancedDynamicTexture, Control, InputText, VirtualKeyboard} from "@babylonjs/gui"; import {AdvancedDynamicTexture, Control, InputText, VirtualKeyboard} from "@babylonjs/gui";
import {ControllerEventType, Controllers} from "../controllers/controllers"; import {ControllerEventType, Controllers} from "../controllers/controllers";
import {setMenuPosition} from "../util/functions/setMenuPosition"; import {setMenuPosition} from "../util/functions/setMenuPosition";
import {DiaSounds} from "../util/diaSounds";
export type TextEvent = { export type TextEvent = {
text: string; text: string;
} }
export type InputTextViewOptions = {
scene?: Scene;
xr?: WebXRDefaultExperience;
text?: string;
controllers?: Controllers;
}
export class InputTextView { export class InputTextView {
public readonly onTextObservable: Observable<TextEvent> = new Observable<TextEvent>(); public readonly onTextObservable: Observable<TextEvent> = new Observable<TextEvent>();
private readonly text: string = ""; private readonly text: string = "";
private readonly scene: Scene; private readonly scene: Scene;
private sounds: DiaSounds;
private readonly controllers: Controllers; private readonly controllers: Controllers;
private readonly xr: WebXRDefaultExperience; 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.text = text ? text : "";
this.xr = xr; this.xr = xr;
this.controllers = controllers;
this.scene = scene; this.scene = scene;
this.sounds = new DiaSounds(scene);
} }
public show() { public show() {
@ -69,8 +68,23 @@ export class InputTextView {
keyboard.connect(input); keyboard.connect(input);
keyboard.isVisible = true; keyboard.isVisible = true;
keyboard.isEnabled = 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) => { keyboard.onKeyPressObservable.add((key) => {
if (key === '↵') { if (key === '↵') {
this.onTextObservable.notifyObservers({text: input.text}); this.onTextObservable.notifyObservers({text: input.text});
@ -78,9 +92,11 @@ export class InputTextView {
keyboard.dispose(); keyboard.dispose();
advancedTexture.dispose(); advancedTexture.dispose();
inputMesh.dispose(); inputMesh.dispose();
this.sounds.exit.play();
} }
}); });
setMenuPosition(inputMesh, this.scene, new Vector3(0, .4, 0)); setMenuPosition(inputMesh, this.scene, new Vector3(0, .4, 0));
this.sounds.enter.play();
} }
public showWeb() { public showWeb() {

View File

@ -252,7 +252,7 @@ export class EditMenu extends AbstractMenu {
if (mesh?.metadata?.text) { if (mesh?.metadata?.text) {
text = 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.show();
textInput.onTextObservable.addOnce((value) => { textInput.onTextObservable.addOnce((value) => {
@ -264,7 +264,7 @@ export class EditMenu extends AbstractMenu {
} }
private showNewRelic() { 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.show();
inputTextView.onTextObservable.addOnce((value) => { inputTextView.onTextObservable.addOnce((value) => {
const config = this.diagramManager.config.current; const config = this.diagramManager.config.current;

View File

@ -2,19 +2,7 @@ import {Scene, Sound} from "@babylonjs/core";
export class DiaSounds { export class DiaSounds {
private readonly scene: Scene; private readonly scene: Scene;
private readonly _tick: Sound;
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;
}
constructor(scene: Scene) { constructor(scene: Scene) {
this.scene = scene; this.scene = scene;
@ -34,6 +22,7 @@ export class DiaSounds {
length: 1.0 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, { this._bounce = new Sound("bounce", "/assets/sounds/drumsprite.mp3", this.scene, null, {
autoplay: false, autoplay: false,
loop: false, loop: false,
@ -57,6 +46,20 @@ export class DiaSounds {
this._backgroundEffects.push(this.buildSpatialSound("dove", "/assets/sounds/dove.mp3")) 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<Sound> = []; _backgroundEffects: Array<Sound> = [];
public get backgroundEffects(): Array<Sound> { public get backgroundEffects(): Array<Sound> {
return this._backgroundEffects; return this._backgroundEffects;