Reduce Action Selection click number & Style Action Type Dialog (#408)

* Reduce Action Selection click number & Style Action Type Dialog

* fixes

* Action Select buttons color
This commit is contained in:
Dapoulp 2025-07-25 19:13:21 +02:00 committed by GitHub
parent 26e3c38aa9
commit 3f95740b7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 228 additions and 684 deletions

View file

@ -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';

View file

@ -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 });
});
}
}

View file

@ -236,7 +236,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
if (!this.action.effects) return;
const index = button.dataset.index,
effectId = this.action.effects[index]._id;
this.constructor.removeElement.bind(this)(event);
this.constructor.removeElement.bind(this)(event, button);
this.action.item.deleteEmbeddedDocuments('ActiveEffect', [effectId]);
}

View file

@ -2,37 +2,44 @@ export const actionTypes = {
attack: {
id: 'attack',
name: 'DAGGERHEART.ACTIONS.TYPES.attack.name',
icon: 'fa-swords'
icon: 'fa-khanda',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.attack.tooltip'
},
healing: {
id: 'healing',
name: 'DAGGERHEART.ACTIONS.TYPES.healing.name',
icon: 'fa-kit-medical'
icon: 'fa-kit-medical',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.healing.tooltip'
},
damage: {
id: 'damage',
name: 'DAGGERHEART.ACTIONS.TYPES.damage.name',
icon: 'fa-bone-break'
},
summon: {
id: 'summon',
name: 'DAGGERHEART.ACTIONS.TYPES.summon.name',
icon: 'fa-ghost'
},
effect: {
id: 'effect',
name: 'DAGGERHEART.ACTIONS.TYPES.effect.name',
icon: 'fa-person-rays'
},
macro: {
id: 'macro',
name: 'DAGGERHEART.ACTIONS.TYPES.macro.name',
icon: 'fa-scroll'
icon: 'fa-heart-crack',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.damage.tooltip'
},
beastform: {
id: 'beastform',
name: 'DAGGERHEART.ACTIONS.TYPES.beastform.name',
icon: 'fa-paw'
icon: 'fa-paw',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.beastform.tooltip'
},
summon: {
id: 'summon',
name: 'DAGGERHEART.ACTIONS.TYPES.summon.name',
icon: 'fa-ghost',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.summon.tooltip'
},
effect: {
id: 'effect',
name: 'DAGGERHEART.ACTIONS.TYPES.effect.name',
icon: 'fa-person-rays',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.effect.tooltip'
},
macro: {
id: 'macro',
name: 'DAGGERHEART.ACTIONS.TYPES.macro.name',
icon: 'fa-scroll',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.macro.tooltip'
}
};

View file

@ -168,9 +168,14 @@ export function ActionMixin(Base) {
({ type } =
(await foundry.applications.api.DialogV2.input({
window: { title: 'Select Action Type' },
position: { width: 300 },
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', {

View file

@ -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);
}