From a23061a8beed13aabe6d92eb2917b5554066a4cd Mon Sep 17 00:00:00 2001 From: WBHarry Date: Fri, 7 Nov 2025 16:43:21 +0100 Subject: [PATCH] Added delete icon to inventory --- lang/en.json | 3 +- module/applications/sheets/actors/party.mjs | 44 ++++++--- module/data/actor/party.mjs | 96 +++++++++---------- module/documents/actor.mjs | 2 +- templates/sheets/actors/party/inventory.hbs | 12 ++- .../partials/inventory-fieldset-items-V2.hbs | 3 + .../global/partials/inventory-item-V2.hbs | 32 ++++--- 7 files changed, 115 insertions(+), 77 deletions(-) diff --git a/lang/en.json b/lang/en.json index 3c6a9770..6120dbc8 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2679,7 +2679,8 @@ "remainingUses": "Uses refresh on {type}", "rightClickExtand": "Right-Click to extand", "companionPartnerLevelBlock": "The companion needs an assigned partner to level up.", - "configureAttribution": "Configure Attribution" + "configureAttribution": "Configure Attribution", + "deleteItem": "Delete Item" } } } diff --git a/module/applications/sheets/actors/party.mjs b/module/applications/sheets/actors/party.mjs index 6188ec48..a622dcec 100644 --- a/module/applications/sheets/actors/party.mjs +++ b/module/applications/sheets/actors/party.mjs @@ -26,6 +26,7 @@ export default class Party extends DHBaseActorSheet { }, actions: { deletePartyMember: Party.#deletePartyMember, + deleteItem: Party.#deleteItem, toggleHope: Party.#toggleHope, toggleHitPoints: Party.#toggleHitPoints, toggleStress: Party.#toggleStress, @@ -468,23 +469,44 @@ export default class Party extends DHBaseActorSheet { } } - static async #deletePartyMember(_event, target) { + static async #deletePartyMember(event, target) { const doc = await getDocFromElement(target.closest('.inventory-item')); - const confirmed = await foundry.applications.api.DialogV2.confirm({ - window: { - title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { - type: game.i18n.localize('TYPES.Actor.adversary'), - name: doc.name - }) - }, - content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: doc.name }) - }); + if (!event.shiftKey) { + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize('TYPES.Actor.adversary'), + name: doc.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: doc.name }) + }); - if (!confirmed) return; + if (!confirmed) return; + } const currentMembers = this.document.system.partyMembers.map(x => x.uuid); const newMemberdList = currentMembers.filter(uuid => uuid !== doc.uuid); await this.document.update({ 'system.partyMembers': newMemberdList }); } + + static async #deleteItem(event, target) { + const doc = await getDocFromElement(target.closest('.inventory-item')); + if (!event.shiftKey) { + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize('TYPES.Actor.party'), + name: doc.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: doc.name }) + }); + + if (!confirmed) return; + } + + this.document.deleteEmbeddedDocuments('Item', [doc.id]); + } } diff --git a/module/data/actor/party.mjs b/module/data/actor/party.mjs index e9199c45..93fb3cde 100644 --- a/module/data/actor/party.mjs +++ b/module/data/actor/party.mjs @@ -1,48 +1,48 @@ -import BaseDataActor from './base.mjs'; -import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs'; - -export default class DhParty extends BaseDataActor { - /**@inheritdoc */ - static defineSchema() { - const fields = foundry.data.fields; - return { - ...super.defineSchema(), - partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }), - notes: new fields.HTMLField(), - gold: new fields.SchemaField({ - coins: new fields.NumberField({ initial: 0, integer: true }), - handfuls: new fields.NumberField({ initial: 1, integer: true }), - bags: new fields.NumberField({ initial: 0, integer: true }), - chests: new fields.NumberField({ initial: 0, integer: true }) - }) - }; - } - - /* -------------------------------------------- */ - - /**@inheritdoc */ - static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/actors/dark-squad.svg'; - - /* -------------------------------------------- */ - - prepareBaseData() { - super.prepareBaseData(); - this.partyMembers = this.partyMembers.filter((p) => !!p); - - // Register this party to all members - if (fromUuidSync(this.parent.uuid) === this.parent) { - for (const member of this.partyMembers) { - member.parties?.add(this.parent); - } - } - } - - _onDelete(options, userId) { - super._onDelete(options, userId); - - // Clear this party from all members that aren't deleted - for (const member of this.partyMembers) { - member.parties?.delete(this.parent); - } - } -} +import BaseDataActor from './base.mjs'; +import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs'; + +export default class DhParty extends BaseDataActor { + /**@inheritdoc */ + static defineSchema() { + const fields = foundry.data.fields; + return { + ...super.defineSchema(), + partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }), + notes: new fields.HTMLField(), + gold: new fields.SchemaField({ + coins: new fields.NumberField({ initial: 0, integer: true }), + handfuls: new fields.NumberField({ initial: 1, integer: true }), + bags: new fields.NumberField({ initial: 0, integer: true }), + chests: new fields.NumberField({ initial: 0, integer: true }) + }) + }; + } + + /* -------------------------------------------- */ + + /**@inheritdoc */ + static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/actors/dark-squad.svg'; + + /* -------------------------------------------- */ + + prepareBaseData() { + super.prepareBaseData(); + this.partyMembers = this.partyMembers.filter(p => !!p); + + // Register this party to all members + if (game.actors.get(this.parent.id) === this.parent) { + for (const member of this.partyMembers) { + member.parties?.add(this.parent); + } + } + } + + _onDelete(options, userId) { + super._onDelete(options, userId); + + // Clear this party from all members that aren't deleted + for (const member of this.partyMembers) { + member.parties?.delete(this.parent); + } + } +} diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index efca9f40..f1fbb3db 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -76,7 +76,7 @@ export default class DhpActor extends Actor { // Configure prototype token settings const prototypeToken = {}; - if (['character', 'companion'].includes(this.type)) + if (['character', 'companion', 'party'].includes(this.type)) Object.assign(prototypeToken, { sight: { enabled: true }, actorLink: true, diff --git a/templates/sheets/actors/party/inventory.hbs b/templates/sheets/actors/party/inventory.hbs index 4d315610..95845197 100644 --- a/templates/sheets/actors/party/inventory.hbs +++ b/templates/sheets/actors/party/inventory.hbs @@ -43,36 +43,40 @@ {{> 'daggerheart.inventory-items' title='TYPES.Item.weapon' type='weapon' + actorType='party' collection=document.itemTypes.weapon isGlassy=true canCreate=true hideResources=true - hideControls=true + hideContextMenu=true }} {{> 'daggerheart.inventory-items' title='TYPES.Item.armor' type='armor' + actorType='party' collection=document.itemTypes.armor isGlassy=true canCreate=true hideResources=true - hideControls=true + hideContextMenu=true }} {{> 'daggerheart.inventory-items' title='TYPES.Item.consumable' type='consumable' + actorType='party' collection=document.itemTypes.consumable isGlassy=true canCreate=true - hideControls=true + hideContextMenu=true }} {{> 'daggerheart.inventory-items' title='TYPES.Item.loot' type='loot' + actorType='party' collection=document.itemTypes.loot isGlassy=true canCreate=true - hideControls=true + hideContextMenu=true }} \ No newline at end of file diff --git a/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs b/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs index 1ef065d5..b0093ab9 100644 --- a/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs +++ b/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs @@ -10,6 +10,7 @@ Parameters: - isGlassy {boolean} : If true, applies the 'glassy' class to the fieldset. - cardView {boolean} : If true and type is 'domainCard', renders using domain card layout. - isActor {boolean} : Passed through to inventory-item partials. +- actorType {boolean} : The actor type of the parent actor - canCreate {boolean} : If true, show createDoc anchor on legend - inVault {boolean} : If true, the domainCard is created with inVault=true - disabled {boolean}: If true, the ActiveEffect is created with disabled=true; @@ -17,6 +18,7 @@ Parameters: - showLabels {boolean} : If true, show label-tags else show simple tags. - hideTooltip {boolean} : If true, disables the tooltip on the item image. - hideControls {boolean} : If true, hides the controls inside inventory-item partials. +- simpleDelete {boolean} : if true, uses only a delete button for controls. - hideDescription {boolean} : If true, hides the item's description. - hideResources {boolean} : If true, hides the item's resources. - showActions {boolean} : If true show feature's actions. @@ -54,6 +56,7 @@ Parameters: {{> 'daggerheart.inventory-item' item=item type=../type + actorType=../actorType hideControls=../hideControls hideContextMenu=../hideContextMenu isActor=../isActor diff --git a/templates/sheets/global/partials/inventory-item-V2.hbs b/templates/sheets/global/partials/inventory-item-V2.hbs index e365fb6a..a85aa347 100644 --- a/templates/sheets/global/partials/inventory-item-V2.hbs +++ b/templates/sheets/global/partials/inventory-item-V2.hbs @@ -4,6 +4,7 @@ Parameters: - type {string} : The type of items in the list - isActor {boolean} : Passed through to inventory-item partials. +- actorType {boolean} : The actor type of the parent actor - categoryAdversary {string} : Category adversary id. - noExtensible {boolean} : If true, the inventory-item-content would be collapsable/extendible else it always be showed - hideLabels {boolean} : If true, hide label-tags else show label-tags. @@ -95,17 +96,24 @@ Parameters: {{/if}} {{else}} - {{#if (eq type 'weapon')}} - - - - {{else if (eq type 'armor')}} - - - - {{else if (eq type 'domainCard')}} + {{#unless (eq actorType 'party')}} + {{#if (eq type 'weapon')}} + + + + {{else if (eq type 'armor')}} + + + + {{/if}} + {{else}} + + + + {{/unless}} + {{#if (eq type 'domainCard')}} @@ -116,7 +124,7 @@ Parameters: {{/if}} - {{#if (hasProperty item "toChat")}} + {{#if (and (hasProperty item "toChat") (not (eq actorType 'party')))}}