diff --git a/module/applications/dialogs/_module.mjs b/module/applications/dialogs/_module.mjs index bbffb791..f9b40f3f 100644 --- a/module/applications/dialogs/_module.mjs +++ b/module/applications/dialogs/_module.mjs @@ -7,3 +7,4 @@ export { default as DeathMove } from './deathMove.mjs'; export { default as Downtime } from './downtime.mjs'; export { default as OwnershipSelection } from './ownershipSelection.mjs'; export { default as ResourceDiceDialog } from './resourceDiceDialog.mjs'; +export { default as ActionSelectionDialog } from './actionSelectionDialog.mjs'; diff --git a/module/applications/dialogs/actionSelectionDialog.mjs b/module/applications/dialogs/actionSelectionDialog.mjs new file mode 100644 index 00000000..c029be24 --- /dev/null +++ b/module/applications/dialogs/actionSelectionDialog.mjs @@ -0,0 +1,87 @@ +const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; + +export default class ActionSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) { + constructor(item, event, options={}) { + super(options); + this.#item = item; + this.#event = event; + } + + /* -------------------------------------------- */ + + /** @override */ + static DEFAULT_OPTIONS = { + classes: ['daggerheart', 'dh-style', 'dialog'], + actions: { + choose: ActionSelectionDialog.#onChooseAction + }, + position: { + width: 400 + } + }; + + /* -------------------------------------------- */ + + static PARTS = { + actions: { + template: "systems/daggerheart/templates/dialogs/actionSelect.hbs" + } + }; + + #item; + + get item() { + return this.#item; + } + + #event; + + get event() { + return this.#event; + } + + #action; + + get action() { + return this.#action ?? null; + } + + /* -------------------------------------------- */ + + /** @override */ + get title() { + return game.i18n.localize('DAGGERHEART.CONFIG.SelectAction.selectAction'); + } + + /* -------------------------------------------- */ + + /** @inheritDoc */ + async _prepareContext(options) { + const actions = this.#item.system.actionsList, + itemName = this.#item.name; + return { + ...await super._prepareContext(options), + actions, + itemName + } + } + + static async #onChooseAction(event, button) { + const { actionId } = button.dataset; + this.#action = this.#item.system.actionsList.find(a => a._id === actionId); + Object.defineProperty(this.#event, 'shiftKey', { + get() { + return event.shiftKey; + } + }); + this.close(); + } + + static create(item, event, options) { + return new Promise(resolve => { + const dialog = new this(item, event, options); + dialog.addEventListener("close", () => resolve(dialog.action), { once: true }); + dialog.render({ force: true }); + }); + } +} \ No newline at end of file diff --git a/module/data/fields/actionField.mjs b/module/data/fields/actionField.mjs index bc28943a..a4b97c6a 100644 --- a/module/data/fields/actionField.mjs +++ b/module/data/fields/actionField.mjs @@ -168,9 +168,13 @@ export function ActionMixin(Base) { ({ type } = (await foundry.applications.api.DialogV2.input({ window: { title: 'Select Action Type' }, + classes: ['daggerheart', 'dh-style'], content: await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/actionTypes/actionType.hbs', - { types: CONFIG.DH.ACTIONS.actionTypes } + { + types: CONFIG.DH.ACTIONS.actionTypes, + itemName: parent.parent?.name + } ), ok: { label: game.i18n.format('DOCUMENT.Create', { diff --git a/module/documents/item.mjs b/module/documents/item.mjs index 4bad4fdc..e75547f3 100644 --- a/module/documents/item.mjs +++ b/module/documents/item.mjs @@ -1,3 +1,5 @@ +import ActionSelectionDialog from "../applications/dialogs/actionSelectionDialog.mjs"; + /** * Override and extend the basic Item implementation. * @extends {foundry.documents.Item} @@ -94,41 +96,13 @@ export default class DHItem extends foundry.documents.Item { }); } - async selectActionDialog(prevEvent) { - const content = await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/dialogs/actionSelect.hbs', - { - actions: this.system.actionsList, - itemName: this.name - } - ), - title = game.i18n.localize('DAGGERHEART.CONFIG.SelectAction.selectAction'); - - return foundry.applications.api.DialogV2.prompt({ - window: { title }, - classes: ['daggerheart', 'dh-style'], - content, - ok: { - label: title, - callback: (event, button, dialog) => { - Object.defineProperty(prevEvent, 'shiftKey', { - get() { - return event.shiftKey; - } - }); - return this.system.actionsList.find(a => a._id === button.form.elements.actionId.value); - } - } - }); - } - async use(event) { const actions = new Set(this.system.actionsList); if (actions?.size) { let action = actions.first(); if (actions.size > 1 && !event?.shiftKey) { // Actions Choice Dialog - action = await this.selectActionDialog(event); + action = await ActionSelectionDialog.create(this, event); } if (action) return action.use(event); } diff --git a/styles/less/dialog/actions/action-list.less b/styles/less/dialog/actions/action-list.less index 1f405b5d..3af09c98 100644 --- a/styles/less/dialog/actions/action-list.less +++ b/styles/less/dialog/actions/action-list.less @@ -12,7 +12,35 @@ gap: 5px; .label { + display: flex; + align-items: center; + gap: 10px; font-family: @font-body; + cursor: pointer; + flex: 1; + i { + text-align: center; + width: 30px; + } + } + + input[type="radio"] { + margin-left: auto; + } + + button { + flex: 1; + display: flex; + padding: 6px 40px 6px 6px; + height: fit-content; + img { + width: 30px; + } + span { + font-family: @font-body; + flex: 1; + font-weight: bold; + } } } } diff --git a/templates/actionTypes/actionType.hbs b/templates/actionTypes/actionType.hbs index 1cd912e9..261fcbee 100644 --- a/templates/actionTypes/actionType.hbs +++ b/templates/actionTypes/actionType.hbs @@ -5,8 +5,11 @@ diff --git a/templates/dialogs/actionSelect.hbs b/templates/dialogs/actionSelect.hbs index f2190121..15b8b480 100644 --- a/templates/dialogs/actionSelect.hbs +++ b/templates/dialogs/actionSelect.hbs @@ -5,8 +5,10 @@