Added DHContextMenu to pass on the event from clicking a contextmenuitem

This commit is contained in:
WBHarry 2025-06-28 12:59:11 +02:00
parent 9dd05cab33
commit 992afd4d94
4 changed files with 30 additions and 4 deletions

View file

@ -112,6 +112,7 @@ Hooks.once('init', () => {
CONFIG.Token.rulerClass = DhpTokenRuler;
CONFIG.ui.resources = Resources;
CONFIG.ux.ContextMenu = applications.DhContextMenu;
game.socket.on(`system.${SYSTEM.id}`, handleSocketEvent);

View file

@ -13,5 +13,6 @@ export { default as DhpArmor } from './sheets/items/armor.mjs';
export { default as DhpChatMessage } from './chatMessage.mjs';
export { default as DhpEnvironment } from './sheets/environment.mjs';
export { default as DhActiveEffectConfig } from './sheets/activeEffectConfig.mjs';
export { default as DhContextMenu } from './contextMenu.mjs';
export * as api from './sheets/api/_modules.mjs';

View file

@ -0,0 +1,24 @@
export default class DhContextMenu extends ContextMenu {
constructor(container, selector, menuItems, options) {
super(container, selector, menuItems, options);
/** @deprecated since v13 until v15 */
this.#jQuery = options.jQuery;
}
#jQuery;
activateListeners(menu) {
menu.addEventListener('click', this.#onClickItem.bind(this));
}
#onClickItem(event) {
event.preventDefault();
event.stopPropagation();
const element = event.target.closest('.context-item');
if (!element) return;
const item = this.menuItems.find(i => i.element === element);
item?.callback(this.#jQuery ? $(this.target) : this.target, event);
this.close();
}
}

View file

@ -222,7 +222,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
useItem: {
name: 'DAGGERHEART.Sheets.PC.ContextMenu.UseItem',
icon: '<i class="fa-solid fa-burst"></i>',
callback: this.constructor.useItem.bind(this)
callback: (element, event) => this.constructor.useItem.bind(this)(event, element)
},
equip: {
name: 'DAGGERHEART.Sheets.PC.ContextMenu.Equip',
@ -640,10 +640,10 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
(await game.packs.get('daggerheart.communities'))?.render(true);
}
static async useItem(element, button) {
const id = (button ?? element).closest('a').id,
static async useItem(event, button) {
const id = button.closest('a').id,
item = this.document.items.get(id);
const wasUsed = await item.use({});
const wasUsed = await item.use(event);
if (wasUsed && item.type === 'weapon') {
Hooks.callAll(SYSTEM.HOOKS.characterAttack, {});
}