Add the ability to be able to prompt users for information from a Dialog/macro
This commit is contained in:
parent
ce9c2de751
commit
8a94558590
9 changed files with 91 additions and 3 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
.dialog-content:not(:only-child) {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.actor--player.style-v1 {
|
.actor--player.style-v1 {
|
||||||
--header-size: 75px;
|
--header-size: 75px;
|
||||||
}
|
}
|
||||||
|
|
@ -35,4 +39,4 @@
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,%22sourceRoot%22:%22%22,%22sources%22:%5B%22../styles/v1/player/root.scss%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;EACC;;AAEA;EACC;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAEA;EACC%22,%22file%22:%22root.css%22%7D */
|
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,%22sourceRoot%22:%22%22,%22sources%22:%5B%22../styles/v1/Dialog.scss%22,%22../styles/v1/player/root.scss%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;EACC;;;ACDD;EACC;;AAEA;EACC;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAEA;EACC%22,%22file%22:%22root.css%22%7D */
|
||||||
|
|
|
||||||
5
.styles/v1/Dialog.css
Normal file
5
.styles/v1/Dialog.css
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
.dialog-content:not(:only-child) {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,%22sourceRoot%22:%22%22,%22sources%22:%5B%22../../styles/v1/Dialog.scss%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;EACC%22,%22file%22:%22Dialog.css%22%7D */
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
.dialog-content:not(:only-child) {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.actor--player.style-v1 {
|
.actor--player.style-v1 {
|
||||||
--header-size: 75px;
|
--header-size: 75px;
|
||||||
}
|
}
|
||||||
|
|
@ -35,4 +39,4 @@
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,%22sourceRoot%22:%22%22,%22sources%22:%5B%22../../styles/v1/player/root.scss%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;EACC;;AAEA;EACC;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAEA;EACC%22,%22file%22:%22index.css%22%7D */
|
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,%22sourceRoot%22:%22%22,%22sources%22:%5B%22../../styles/v1/Dialog.scss%22,%22../../styles/v1/player/root.scss%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;EACC;;;ACDD;EACC;;AAEA;EACC;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAGD;EACC;EACA;EACA;EACA;;AAEA;EACC%22,%22file%22:%22index.css%22%7D */
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export default [
|
||||||
ChatMessage: `readonly`,
|
ChatMessage: `readonly`,
|
||||||
ActiveEffect: `readonly`,
|
ActiveEffect: `readonly`,
|
||||||
Dialog: `readonly`,
|
Dialog: `readonly`,
|
||||||
|
renderTemplate: `readonly`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { PlayerData } from "./documents/Actor/Player/Model.mjs";
|
||||||
|
|
||||||
// Misc Imports
|
// Misc Imports
|
||||||
import "./utils/logger.mjs";
|
import "./utils/logger.mjs";
|
||||||
|
import "./utils/DialogManager.mjs";
|
||||||
import { registerCustomComponents } from "./components/_index.mjs";
|
import { registerCustomComponents } from "./components/_index.mjs";
|
||||||
import { registerHandlebarsHelpers } from "./helpers/_index.mjs";
|
import { registerHandlebarsHelpers } from "./helpers/_index.mjs";
|
||||||
import { registerSettings } from "./settings/_index.mjs";
|
import { registerSettings } from "./settings/_index.mjs";
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,63 @@ export class DialogManager {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the user to provide a simple piece of information, this is primarily
|
||||||
|
* intended to be used within macros so that it can have better info gathering
|
||||||
|
* as needed.
|
||||||
|
*/
|
||||||
|
static async ask(data, opts = {}) {
|
||||||
|
if (!data.question) {
|
||||||
|
throw new Error(`Asking the user for input must contain a question`);
|
||||||
|
}
|
||||||
|
data.inputType ??= `text`;
|
||||||
|
data.initialValue ??= ``;
|
||||||
|
|
||||||
|
opts.title ??= `System Question`;
|
||||||
|
opts.jQuery = true;
|
||||||
|
|
||||||
|
const content = await renderTemplate(
|
||||||
|
`systems/${game.system.id}/templates/Dialogs/ask.hbs`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
DialogManager.createOrFocus(
|
||||||
|
data.question,
|
||||||
|
{
|
||||||
|
content,
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
label: `Confirm`,
|
||||||
|
callback: (html) => {
|
||||||
|
const element = html.find(`.user-input`)[0];
|
||||||
|
let value = element.value;
|
||||||
|
switch (data.inputType) {
|
||||||
|
case `number`:
|
||||||
|
value = parseFloat(value);
|
||||||
|
break;
|
||||||
|
case `checkbox`:
|
||||||
|
value = element.checked;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Logger.debug(`Ask response: ${value} (type: ${typeof value})`);
|
||||||
|
resolve(value);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
label: `Cancel`,
|
||||||
|
callback: () => reject(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
static get size() {
|
static get size() {
|
||||||
return DialogManager.#dialogs.size;
|
return DialogManager.#dialogs.size;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
globalThis.DialogManager = DialogManager;
|
||||||
|
|
|
||||||
3
styles/v1/Dialog.scss
Normal file
3
styles/v1/Dialog.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
.dialog-content:not(:only-child) {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
// Styling version 1
|
// Styling version 1
|
||||||
|
|
||||||
@use "./player/root.scss";
|
@use "./Dialog.scss";
|
||||||
|
|
||||||
|
@use "./player/root.scss";
|
||||||
|
|
|
||||||
12
templates/Dialogs/ask.hbs
Normal file
12
templates/Dialogs/ask.hbs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{question}}
|
||||||
|
</p>
|
||||||
|
<input
|
||||||
|
type="{{inputType}}"
|
||||||
|
value="{{initialValue}}"
|
||||||
|
checked="{{initialValue}}"
|
||||||
|
class="user-input"
|
||||||
|
autofocus
|
||||||
|
>
|
||||||
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue