From bd92e6928a7cab2ec5fae904c376bfc3b7dc1462 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Mon, 13 Jan 2025 23:21:58 -0700 Subject: [PATCH] RC-97 | Add Context Menu for embedded weapons --- assets/_credit.txt | 5 ++- assets/icons/edit.svg | 4 ++ assets/icons/roll.svg | 2 +- module/Apps/ActorSheets/HeroSummaryCardV1.mjs | 39 ++++++++++++++++++- templates/Apps/HeroSummaryCardV1/content.hbs | 19 ++++++++- templates/Apps/HeroSummaryCardV1/style.css | 7 +++- templates/css/elements/span.css | 7 ++++ 7 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 assets/icons/edit.svg diff --git a/assets/_credit.txt b/assets/_credit.txt index 19babdc..d2a13c1 100644 --- a/assets/_credit.txt +++ b/assets/_credit.txt @@ -1,2 +1,5 @@ Soetarman Atmodjo: - - icons/roll.svg : Rights Purchased. + - icons/roll.svg (https://thenounproject.com/icon/dice-5195278/) : Rights Purchased. + +SuperNdre: + - icons/edit.svg (https://thenounproject.com/icon/edit-5208207/) : Rights Purchased \ No newline at end of file diff --git a/assets/icons/edit.svg b/assets/icons/edit.svg new file mode 100644 index 0000000..acae8d6 --- /dev/null +++ b/assets/icons/edit.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/icons/roll.svg b/assets/icons/roll.svg index 4d2a61b..51fb7ed 100644 --- a/assets/icons/roll.svg +++ b/assets/icons/roll.svg @@ -1,4 +1,4 @@ - + diff --git a/module/Apps/ActorSheets/HeroSummaryCardV1.mjs b/module/Apps/ActorSheets/HeroSummaryCardV1.mjs index c38b6f4..888ae4d 100644 --- a/module/Apps/ActorSheets/HeroSummaryCardV1.mjs +++ b/module/Apps/ActorSheets/HeroSummaryCardV1.mjs @@ -6,6 +6,7 @@ import { Logger } from "../../utils/Logger.mjs"; const { HandlebarsApplicationMixin } = foundry.applications.api; const { ActorSheetV2 } = foundry.applications.sheets; +const { ContextMenu } = foundry.applications.ui; export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixin(ActorSheetV2)) { @@ -22,7 +23,9 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi window: { resizable: false, }, - actions: {}, + actions: { + editItem: (_event, target) => this._editItem(target), + }, form: { submitOnChange: true, closeOnSubmit: false, @@ -37,6 +40,32 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi // #endregion // #region Lifecycle + async _onRender(context, options) { + await super._onRender(context, options); + + const itemMenuOptions = [ + { + name: `Edit`, + condition: () => this.isEditable, + callback: HeroSummaryCardV1._editItem, + }, + { + name: `Delete`, + condition: () => this.isEditable, + callback: async (el) => { + const itemEl = el.closest(`[data-item-id]`); + if (!itemEl) { return }; + const itemId = itemEl.dataset.itemId; + const item = await fromUuid(itemId); + await item.delete(); + }, + }, + ]; + if (itemMenuOptions.length) { + new ContextMenu(this.element, `.weapon-ctx-menu`, itemMenuOptions, { jQuery: false, fixed: true }); + } + }; + async _preparePartContext(partId, ctx, opts) { ctx = await super._preparePartContext(partId, ctx, opts); ctx.actor = this.document; @@ -135,5 +164,13 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi // #endregion // #region Actions + static async _editItem(target) { + const itemEl = target.closest(`[data-item-id]`); + if (!itemEl) { return }; + const itemId = itemEl.dataset.itemId; + if (!itemId) { return }; + const item = await fromUuid(itemId); + item.sheet.render({ force: true }); + }; // #endregion }; diff --git a/templates/Apps/HeroSummaryCardV1/content.hbs b/templates/Apps/HeroSummaryCardV1/content.hbs index 0c6c508..36414fb 100644 --- a/templates/Apps/HeroSummaryCardV1/content.hbs +++ b/templates/Apps/HeroSummaryCardV1/content.hbs @@ -181,8 +181,23 @@ {{else}} -
- {{ slot.data.name }} +
+ + +
+ {{ slot.data.name }} + + {{#if slot.data.system.traitString}} {{ slot.data.system.traitString }} diff --git a/templates/Apps/HeroSummaryCardV1/style.css b/templates/Apps/HeroSummaryCardV1/style.css index 1f8ef4f..57cabbe 100644 --- a/templates/Apps/HeroSummaryCardV1/style.css +++ b/templates/Apps/HeroSummaryCardV1/style.css @@ -91,13 +91,18 @@ display: grid; grid-template-columns: subgrid; grid-template-rows: subgrid; - overflow-y: auto; thead, tbody, tr { display: contents; } + td { + display: flex; + flex-direction: row; + align-items: center; + gap: 4px; + } .row-alt > * { background: inherit; } diff --git a/templates/css/elements/span.css b/templates/css/elements/span.css index 65a1858..25c1ca9 100644 --- a/templates/css/elements/span.css +++ b/templates/css/elements/span.css @@ -3,6 +3,13 @@ font-size: var(--font-size-10) } + &.ellipses { + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + } + + /* Makes it so that spans are never less than the font size */ &:empty::before { content: "\200b"; }