diff --git a/src/module/dialog/itemBrowserDialog.mjs b/src/module/dialog/itemBrowserDialog.mjs new file mode 100644 index 00000000..c5db0023 --- /dev/null +++ b/src/module/dialog/itemBrowserDialog.mjs @@ -0,0 +1,132 @@ +import {Equipment} from "../documents/equipment.mjs"; + +const { + ApplicationV2, + HandlebarsApplicationMixin +} = foundry.applications.api + +export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) { + + static DEFAULT_OPTIONS = { + classes: ['dsa41', 'dialog', 'item-browser'], + tag: "form", + position: { + width: 640, + height: 480 + }, + window: { + resizable: true, + }, + actions: { + buy: ItemBrowserDialog.#buy + } + } + + static PARTS = { + form: { + template: 'systems/DSA_4-1/templates/dialog/item-browser-dialog.hbs', + } + } + + /** + * @type {Actor} + * @private + */ + _actor = null + /** + * + * @type {[Equipment]} + * @private + */ + _items = [] + + constructor(actor) { + super(); + this._actor = actor + // load compendium data + this._items = [] + } + + static async #buy(event, target) { + + } + + _canDragDrop(event, options) { + return game.user.isGM + } + + _canDrag(event, options) { + return true + } + + /** + * An event that occurs when a drag workflow begins for a draggable item on the sheet. + * @param {DragEvent} event The initiating drag start event + * @returns {Promise} + * @protected + */ + async _onDragStart(event) { + const target = event.currentTarget; + let dragData; + + if (target.dataset.itemId) { + dragData = { + type: "Item", + uuid: target.dataset.itemId + } + } + + // Set data transfer + if (!dragData) return; + event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); + } + + async _prepareContext(options) { + const context = await super._prepareContext(options) + context.items = this._items + return context + } + + async _onRender(context, options) { + + if (this._items.length === 0) { + const compendia = [ + game.packs.get('DSA_4-1.Armor'), + game.packs.get('DSA_4-1.Weapons'), + game.packs.get('DSA_4-1.Ammunition'), + game.packs.get('DSA_4-1.Items') + ] + + for (const c of compendia) { + const it = await c.getDocuments() + it.forEach((item) => { + const uuid = item.uuid + const e = new Equipment(item) + this._items.push({ + img: item.img, + uuid, + type: item.type, + name: item.name, + price: e.system.price, + weight: e.system.weight, + category: e.system.category.join(", ") + }) + console.log("importing ", item.name) + }) + console.log("done importing from ", c) + } + this.render({parts: ["form"]}) + } + + new foundry.applications.ux.DragDrop.implementation({ + dropSelector: ".window-content", + dragSelector: ".item", + permissions: { + drag: this._canDrag.bind(this) + }, + callbacks: { + dragstart: this._onDragStart.bind(this), + } + }).bind(this.element) + } +} \ No newline at end of file diff --git a/src/module/setup/config.mjs b/src/module/setup/config.mjs index 53a2dfd8..e8778dd1 100644 --- a/src/module/setup/config.mjs +++ b/src/module/setup/config.mjs @@ -20,6 +20,7 @@ import {Talent} from "../data/talent.mjs"; import {Character} from "../documents/character.mjs"; import {currency} from "../handlebar-helpers/currency.mjs"; import {DeityDataModel} from "../data/deity.mjs"; +import {ItemBrowserDialog} from "../dialog/itemBrowserDialog.mjs"; function initGlobalAccess() { @@ -30,6 +31,7 @@ function initGlobalAccess() { Wunde, RestingDialog, BattleDialog, + ItemBrowserDialog, Talent, displayCurrency: currency } diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index 02c13ac1..aaba9861 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -14,6 +14,8 @@ import {RestingDialog} from "../dialog/restingDialog.mjs"; import {LiturgyDialog} from "../dialog/liturgyDialog.mjs"; import {TalentDialog} from "../dialog/talentDialog.mjs"; import {AttributeDialog} from "../dialog/attributeDialog.mjs"; +import {ItemBrowserDialog} from "../dialog/itemBrowserDialog.mjs"; +import * as EquipmentDocument from "../documents/equipment.mjs"; const {HandlebarsApplicationMixin, DocumentSheetV2} = foundry.applications.api const {ActorSheetV2} = foundry.applications.sheets @@ -51,6 +53,8 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) { rest: CharacterSheet.#startResting, removeEffect: CharacterSheet.#removeEffect, rollDamage: CharacterSheet.#rollDamage, + openItemBrowser: CharacterSheet.#openItemBrowser, + newItem: CharacterSheet.#addNewItem } } @@ -250,6 +254,19 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) { } + static async #openItemBrowser(event, target) { + new ItemBrowserDialog(this.document).render(true) + } + + static async #addNewItem(event, target) { + let item = new EquipmentDocument.Equipment({ + name: "Neuer Gegenstand", + type: "Equipment", + }) + const items = await this.document.createEmbeddedDocuments("Item", [item]) + items[0].sheet.render(true) + } + _configureRenderOptions(options) { super._configureRenderOptions(options) diff --git a/src/style/organisms/_item-browser-dialog.scss b/src/style/organisms/_item-browser-dialog.scss new file mode 100644 index 00000000..75ad7ea2 --- /dev/null +++ b/src/style/organisms/_item-browser-dialog.scss @@ -0,0 +1,57 @@ +.dsa41.dialog.item-browser { + + .window-content [data-application-part] { + + display: grid; + grid-template-columns: 240px 1fr; + height: 100%; + gap: 16px; + + aside { + width: 240px; + } + + .scrollable-table { + + display: grid; + grid-template-rows: 32px 1fr; + overflow: hidden; + + .header { + display: grid; + grid-template-columns: 64px 1fr 120px 120px 120px; + gap: 4px; + background-color: rgba(0, 0, 0, 0.3); + + * { + font-weight: bold; + line-height: 32px; + vertical-align: middle; + } + } + + .scroll-y { + overflow-x: hidden; + overflow-y: auto; + + border: 1px inset #ccc; + + .item { + display: grid; + grid-template-columns: 64px 1fr 120px 120px 120px; + gap: 4px; + + &:nth-child(odd) { + background-color: rgba(0, 0, 0, 0.1); + } + } + + } + + + } + + } + + +} \ No newline at end of file diff --git a/src/style/styles.scss b/src/style/styles.scss index e78462f6..070b26d5 100644 --- a/src/style/styles.scss +++ b/src/style/styles.scss @@ -35,4 +35,5 @@ @use "organisms/battle-dialog"; @use "organisms/liturgy-sheet"; @use "organisms/dialog"; -@use "organisms/deity-sheet"; \ No newline at end of file +@use "organisms/deity-sheet"; +@use "organisms/item-browser-dialog"; \ No newline at end of file diff --git a/src/templates/actor/character/tab-equipment.hbs b/src/templates/actor/character/tab-equipment.hbs index 68cb7693..d72a93a0 100644 --- a/src/templates/actor/character/tab-equipment.hbs +++ b/src/templates/actor/character/tab-equipment.hbs @@ -16,6 +16,8 @@

Inventar

+ +
{{> "systems/DSA_4-1/templates/ui/partial-equipment-button.hbs" equipments}}
diff --git a/src/templates/dialog/item-browser-dialog.hbs b/src/templates/dialog/item-browser-dialog.hbs new file mode 100644 index 00000000..d09860f6 --- /dev/null +++ b/src/templates/dialog/item-browser-dialog.hbs @@ -0,0 +1,46 @@ +
+ + + +
+
+ + Name + Kategorie + Preis + Gewicht +
+
+ {{#each items}} +
+ {{this.name}} + {{this.name}} + {{this.category}} + {{currency this.price}} + {{weight this.weight}} +
+ {{/each}} +
+
+ +
\ No newline at end of file