This repository has been archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Dialog system design and stubs * Update design * Tweaks * Simplify design * Add implementation * Add test * Move design doc * Handle dialog failure
- Loading branch information
1 parent
951ed9e
commit aad0178
Showing
8 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Dialogs | ||
|
||
Goal: Display a message to a single user, and return a response. | ||
|
||
## Architecture | ||
|
||
Create a new method on the `User` object: | ||
|
||
```ts | ||
class User { | ||
/** | ||
* Present the user with a modal dialog, and resolve with the response. | ||
* @param text A message presented to the user. | ||
* @param acceptInput Whether or not the dialog should include a text input field. | ||
*/ | ||
public prompt(text: string, acceptInput?: boolean): Promise<DialogResponse> { } | ||
} | ||
|
||
type DialogResponse = { | ||
submitted: boolean; | ||
text?: string; | ||
}; | ||
``` | ||
|
||
## Network | ||
|
||
The network messages getting sent to clients might look like this: | ||
|
||
```ts | ||
export type ShowDialog = Payload & { | ||
type: 'show-dialog'; | ||
text: string; | ||
acceptInput?: boolean; | ||
}; | ||
|
||
export type DialogResponse = Payload & { | ||
type: 'dialog-response'; | ||
submitted: boolean; | ||
text?: string; | ||
} | ||
``` | ||
## Sync layer considerations | ||
None. Since the messages are going to and coming from a single client, no synchronization is necessary. | ||
## Client implementation | ||
The dialog should have a per-client implementation, so it can match the aesthetic of the host client. As such, I | ||
propose adding a new factory type to the `InitializeAPI` call: | ||
```cs | ||
public interface IDialogFactory { | ||
void ShowDialog(string text, bool allowInput, Action<bool,string> callback); | ||
} | ||
``` | ||
General recommendation is that these dialogs are queued, so only one is visible at a time, but different clients | ||
may have different solutions to this problem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import * as MRE from '@microsoft/mixed-reality-extension-sdk'; | ||
|
||
import { Test } from '../test'; | ||
|
||
export default class PromptTest extends Test { | ||
public expectedResultDescription = "Display a text prompt to a user"; | ||
|
||
public async run(root: MRE.Actor): Promise<boolean> { | ||
let success = true; | ||
|
||
const noTextButton = MRE.Actor.Create(this.app.context, { | ||
actor: { | ||
name: 'noTextButton', | ||
parentId: root.id, | ||
transform: { local: { position: { x: -1, y: 1, z: -1 } } }, | ||
collider: { geometry: { shape: 'box', size: { x: 0.5, y: 0.2, z: 0.01 } } }, | ||
text: { | ||
contents: "Click for message", | ||
height: 0.1, | ||
anchor: MRE.TextAnchorLocation.MiddleCenter, | ||
justify: MRE.TextJustify.Center | ||
} | ||
} | ||
}); | ||
noTextButton.setBehavior(MRE.ButtonBehavior).onClick(user => { | ||
user.prompt(`Hello ${user.name}!`) | ||
.catch(err => { | ||
console.error(err); | ||
success = false; | ||
this.stop(); | ||
}); | ||
}); | ||
|
||
const textButton = MRE.Actor.Create(this.app.context, { | ||
actor: { | ||
name: 'textButton', | ||
parentId: root.id, | ||
transform: { local: { position: { x: 1, y: 1, z: -1 } } }, | ||
collider: { geometry: { shape: 'box', size: { x: 0.5, y: 0.2, z: 0.01 } } }, | ||
text: { | ||
contents: "Click for prompt", | ||
height: 0.1, | ||
anchor: MRE.TextAnchorLocation.MiddleCenter, | ||
justify: MRE.TextJustify.Center | ||
} | ||
} | ||
}); | ||
textButton.setBehavior(MRE.ButtonBehavior).onClick(user => { | ||
user.prompt("Who's your favorite musician?", true) | ||
.then(res => { | ||
textButton.text.contents = | ||
`Click for prompt\nLast response: ${res.submitted ? res.text : "<cancelled>"}`; | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
success = false; | ||
this.stop(); | ||
}); | ||
}); | ||
|
||
await this.stoppedAsync(); | ||
return success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters