mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-16 05:31:07 +01:00
Added DHContextMenu to pass on the event from clicking a contextmenuitem
This commit is contained in:
parent
9dd05cab33
commit
992afd4d94
4 changed files with 30 additions and 4 deletions
|
|
@ -112,6 +112,7 @@ Hooks.once('init', () => {
|
||||||
CONFIG.Token.rulerClass = DhpTokenRuler;
|
CONFIG.Token.rulerClass = DhpTokenRuler;
|
||||||
|
|
||||||
CONFIG.ui.resources = Resources;
|
CONFIG.ui.resources = Resources;
|
||||||
|
CONFIG.ux.ContextMenu = applications.DhContextMenu;
|
||||||
|
|
||||||
game.socket.on(`system.${SYSTEM.id}`, handleSocketEvent);
|
game.socket.on(`system.${SYSTEM.id}`, handleSocketEvent);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ export { default as DhpArmor } from './sheets/items/armor.mjs';
|
||||||
export { default as DhpChatMessage } from './chatMessage.mjs';
|
export { default as DhpChatMessage } from './chatMessage.mjs';
|
||||||
export { default as DhpEnvironment } from './sheets/environment.mjs';
|
export { default as DhpEnvironment } from './sheets/environment.mjs';
|
||||||
export { default as DhActiveEffectConfig } from './sheets/activeEffectConfig.mjs';
|
export { default as DhActiveEffectConfig } from './sheets/activeEffectConfig.mjs';
|
||||||
|
export { default as DhContextMenu } from './contextMenu.mjs';
|
||||||
|
|
||||||
export * as api from './sheets/api/_modules.mjs';
|
export * as api from './sheets/api/_modules.mjs';
|
||||||
|
|
|
||||||
24
module/applications/contextMenu.mjs
Normal file
24
module/applications/contextMenu.mjs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -222,7 +222,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
useItem: {
|
useItem: {
|
||||||
name: 'DAGGERHEART.Sheets.PC.ContextMenu.UseItem',
|
name: 'DAGGERHEART.Sheets.PC.ContextMenu.UseItem',
|
||||||
icon: '<i class="fa-solid fa-burst"></i>',
|
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: {
|
equip: {
|
||||||
name: 'DAGGERHEART.Sheets.PC.ContextMenu.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);
|
(await game.packs.get('daggerheart.communities'))?.render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async useItem(element, button) {
|
static async useItem(event, button) {
|
||||||
const id = (button ?? element).closest('a').id,
|
const id = button.closest('a').id,
|
||||||
item = this.document.items.get(id);
|
item = this.document.items.get(id);
|
||||||
const wasUsed = await item.use({});
|
const wasUsed = await item.use(event);
|
||||||
if (wasUsed && item.type === 'weapon') {
|
if (wasUsed && item.type === 'weapon') {
|
||||||
Hooks.callAll(SYSTEM.HOOKS.characterAttack, {});
|
Hooks.callAll(SYSTEM.HOOKS.characterAttack, {});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue