diff --git a/daggerheart.mjs b/daggerheart.mjs index 1c4c2a85..3150aa11 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -165,6 +165,8 @@ Hooks.on('ready', async () => { if(!(ui.compendiumBrowser instanceof applications.ui.ItemBrowser)) ui.compendiumBrowser = new applications.ui.ItemBrowser(); + ui.presetTemplates = new applications.ui.PresetTemplates(); + registerCountdownHooks(); socketRegistration.registerSocketHooks(); registerRollDiceHooks(); diff --git a/module/applications/ui/_module.mjs b/module/applications/ui/_module.mjs index 815fc4e7..b29ebc9b 100644 --- a/module/applications/ui/_module.mjs +++ b/module/applications/ui/_module.mjs @@ -2,5 +2,6 @@ export { default as DhChatLog } from './chatLog.mjs'; export { default as DhCombatTracker } from './combatTracker.mjs'; export * as DhCountdowns from './countdowns.mjs'; export { default as DhFearTracker } from './fearTracker.mjs'; +export { default as PresetTemplates } from './presetTemplates.mjs'; export { default as DhHotbar } from './hotbar.mjs'; export { ItemBrowser } from './itemBrowser.mjs'; diff --git a/module/applications/ui/presetTemplates.mjs b/module/applications/ui/presetTemplates.mjs new file mode 100644 index 00000000..15a26911 --- /dev/null +++ b/module/applications/ui/presetTemplates.mjs @@ -0,0 +1,72 @@ +const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; + +/** + * + * @extends ApplicationV2 + * @mixes HandlebarsApplication + */ + +export default class PresetTemplates extends HandlebarsApplicationMixin(ApplicationV2) { + constructor(options = {}) { + super(options); + } + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + id: 'presetTemplates', + classes: [], + tag: 'div', + window: { + frame: true, + title: 'Preset Templates', + positioned: true, + resizable: true, + minimizable: true + }, + actions: { + }, + position: { + width: 222, + height: 222 + // top: "200px", + // left: "120px" + } + }; + + /** @override */ + static PARTS = { + resources: { + root: true, + template: 'systems/daggerheart/templates/ui/presetTemplates.hbs' + } + }; + + /* -------------------------------------------- */ + /* Rendering */ + /* -------------------------------------------- */ + + /** @override */ + async _prepareContext(_options) { + // Return the data for rendering + return { }; + } + + /** @override */ + async _preFirstRender(context, options) { + options.position = + game.user.getFlag(CONFIG.DH.id, 'app.presetTemplates.position') ?? PresetTemplates.DEFAULT_OPTIONS.position; + } + + /** @override */ + async _preRender(context, options) { + } + + _onPosition(position) { + game.user.setFlag(CONFIG.DH.id, 'app.presetTemplates.position', position); + } + + async close(options = {}) { + if (!options.allowed) return; + else super.close(options); + } +} diff --git a/module/canvas/placeables/templateLayer.mjs b/module/canvas/placeables/templateLayer.mjs index 56b25bc8..364308dc 100644 --- a/module/canvas/placeables/templateLayer.mjs +++ b/module/canvas/placeables/templateLayer.mjs @@ -92,6 +92,25 @@ export default class DhTemplateLayer extends foundry.canvas.layers.TemplateLayer static handlePreset(event, active) { console.log("Preset handling goes here, event, active is: ", event, active); + if (active) { + ui.presetTemplates.open(); + // if (CONFIG.ux.TemplateManager.getActivePreview()) { + // return; + // } + // const { width, height } = game.canvas.scene.dimensions; + // const data = { + // x: width / 2, + // y: height / 2, + // t: 'circle', + // distance: 30, + // fillColor: '#FF0000' + // }; + + // CONFIG.ux.TemplateManager.createPreview(data); + } else { + ui.presetTemplates.close(); + // CONFIG.ux.TemplateManager.cancelActivePreview(event); + } } _onDragLeftStart(event) { diff --git a/module/documents/templateManager.mjs b/module/documents/templateManager.mjs index cf15c2e3..091ee4e6 100644 --- a/module/documents/templateManager.mjs +++ b/module/documents/templateManager.mjs @@ -5,6 +5,11 @@ export default class DhTemplateManager { #activePreview; + + getActivePreview() { + return this.#activePreview; + } + /** * Create a template preview, deactivating any existing ones. * @param {object} data @@ -29,6 +34,7 @@ export default class DhTemplateManager { canvas.app.view.addEventListener('wheel', this.#activePreview.events.wheel, true); canvas.app.view.addEventListener('contextmenu', this.#activePreview.events.contextmenu); + return this.#activePreview; } /** @@ -102,4 +108,11 @@ export default class DhTemplateManager { canvas.scene.createEmbeddedDocuments('MeasuredTemplate', [this.#activePreview.document.toObject()]); this.#activePreview = undefined; } + + cancelActivePreview(event) { + if (this.#activePreview) { + this.#cancelTemplate(event); + this.#activePreview = undefined; + } + } } diff --git a/templates/ui/presetTemplates.hbs b/templates/ui/presetTemplates.hbs new file mode 100644 index 00000000..a0510c82 --- /dev/null +++ b/templates/ui/presetTemplates.hbs @@ -0,0 +1,3 @@ +
+ Preset Template stuff. +
\ No newline at end of file