From b0585c83791f70479624ceb599228f38865a869a Mon Sep 17 00:00:00 2001 From: Haxxer Date: Sat, 3 Sep 2022 22:00:39 +0100 Subject: [PATCH] Added clear all items, better handling of image, added text editor for description --- languages/en.json | 11 ++-- src/API/api.js | 8 +++ .../components/CustomDialog.svelte | 4 +- .../components/PriceSelector.svelte | 2 +- .../text-editor-dialog-shell.svelte | 44 +++++++++++++++ .../text-editor-dialog/text-editor-dialog.js | 56 +++++++++++++++++++ .../trade-merchant-item-dialog-shell.svelte | 4 +- .../item-pile-config/item-pile-config.svelte | 40 ++++++++++--- .../merchant-app/MerchantLeftPane.svelte | 28 ++++++---- .../MerchantPopulateItemsTab.svelte | 50 +++++++++++++++-- src/helpers/pile-utilities.js | 13 ++++- src/helpers/utilities.js | 6 +- src/stores/item-pile-store.js | 8 ++- src/stores/merchant-store.js | 8 ++- src/styles/styles.scss | 11 +++- templates/text-editor.html | 13 +++++ 16 files changed, 260 insertions(+), 46 deletions(-) create mode 100644 src/applications/dialogs/text-editor-dialog/text-editor-dialog-shell.svelte create mode 100644 src/applications/dialogs/text-editor-dialog/text-editor-dialog.js create mode 100644 templates/text-editor.html diff --git a/languages/en.json b/languages/en.json index ecd351ac..99f7c117 100644 --- a/languages/en.json +++ b/languages/en.json @@ -106,7 +106,8 @@ "ClickRoll": "Click roll to start", "RolledTimes": "Rolled {rolls} times", "KeepRolled": "Keep rolled", - "AddAll": "Add All Items" + "AddAll": "Add All Items", + "ClearAllItems": "Clear All Actor Items" }, "Errors": { "DisallowedItemDrop": "You cannot drop \"{type}\" items", @@ -152,11 +153,9 @@ "Content": "This will reset all of the history of players having taken their share from this pile.

Are you sure you want to do this?", "Confirm": "Reset Sharing Data" }, - "SwitchCurrencyType": { - "Title": "Switching Currency Type", - "Header": "Are you sure?", - "Content1": "Are you sure you want to switch currency type?", - "Content2": "This will reset the existing currency setup." + "ClearAllItems": { + "Title": "Clear All Actor Items", + "Content": "This will clear all of the actor's items, are you sure you want to do this?" } }, "Applications": { diff --git a/src/API/api.js b/src/API/api.js index ca8b6d3e..d91c3d07 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -939,6 +939,14 @@ const API = { }, + getActorItems(actor) { + return PileUtilities.getActorItems(actor); + }, + + getActorCurrencies(actor) { + return PileUtilities.getActorCurrencies(actor); + }, + updateTokenHud() { return ItemPileSocket.executeForEveryone(ItemPileSocket.HANDLERS.RERENDER_TOKEN_HUD); }, diff --git a/src/applications/components/CustomDialog.svelte b/src/applications/components/CustomDialog.svelte index c8f69ed2..29975520 100644 --- a/src/applications/components/CustomDialog.svelte +++ b/src/applications/components/CustomDialog.svelte @@ -14,7 +14,9 @@ {#if icon}

{/if} -

{header}

+ {#if header} +

{header}

+ {/if} {#if Array.isArray(content)} {#each content as part}

{@html part}

diff --git a/src/applications/components/PriceSelector.svelte b/src/applications/components/PriceSelector.svelte index 746a469c..7977f681 100644 --- a/src/applications/components/PriceSelector.svelte +++ b/src/applications/components/PriceSelector.svelte @@ -17,7 +17,7 @@ $: cantAfford = $prices.length > 0 && !$prices[$selectedPriceGroup]?.maxQuantity && item.store.recipient && !standalone; $: cantAffordMultiplePrices = cantAfford && !$prices.filter(group => group.maxQuantity).length; - $: label.text = (standalone && $prices.length > 1 ? " " : "") + ($prices[$selectedPriceGroup]?.basePriceString ?? "Free"); + $: label.text = (standalone && $prices.length > 1 ? " " : "") + ($prices[$selectedPriceGroup]?.free ? "Free" : $prices[$selectedPriceGroup]?.basePriceString); diff --git a/src/applications/dialogs/text-editor-dialog/text-editor-dialog-shell.svelte b/src/applications/dialogs/text-editor-dialog/text-editor-dialog-shell.svelte new file mode 100644 index 00000000..d34f148f --- /dev/null +++ b/src/applications/dialogs/text-editor-dialog/text-editor-dialog-shell.svelte @@ -0,0 +1,44 @@ + + + + + +
+ + + +
+ + +
+ +
+ +
\ No newline at end of file diff --git a/src/applications/dialogs/text-editor-dialog/text-editor-dialog.js b/src/applications/dialogs/text-editor-dialog/text-editor-dialog.js new file mode 100644 index 00000000..d1215d89 --- /dev/null +++ b/src/applications/dialogs/text-editor-dialog/text-editor-dialog.js @@ -0,0 +1,56 @@ +import CONSTANTS from "../../../constants/constants.js"; + +export default class TextEditorDialog extends FormApplication { + + constructor(text, options) { + super(); + this.text = text; + this.resolve = options.resolve; + } + + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("ITEM-PILES.Applications.DropItem.Title"), + template: `${CONSTANTS.PATH}templates/text-editor.html`, + width: 430, + height: 350, + classes: ["item-piles-app"], + resizable: true + }) + } + + async getData(options) { + const data = super.getData(options); + data.text = this.text; + return data; + } + + static getActiveApps(id) { + return Object.values(ui.windows).filter(app => app.id === `item-pile-text-editor-${id}`); + } + + async _updateObject(event, formData) { + this.resolve(formData.text); + return this.close(); + } + + async close(options) { + this.resolve(null); + return super.close(options); + } + + static async show(text, options = {}) { + const apps = options.id ? this.getActiveApps(options.id) : []; + if (apps.length) { + for (let app of apps) { + app.render(false, { focus: true }); + } + return; + } + return new Promise((resolve) => { + options.resolve = resolve; + new this(text, options).render(true, { focus: true }); + }) + } + +} \ No newline at end of file diff --git a/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog-shell.svelte b/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog-shell.svelte index e47facf5..b37deec7 100644 --- a/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog-shell.svelte +++ b/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog-shell.svelte @@ -50,7 +50,7 @@ } $: maxMerchantItemQuantity = $sellerPileData.infiniteQuantity ? Infinity : $itemMaxQuantityStore; - $: maxItemQuantity = $prices[$selectedPriceGroup].maxQuantity; + $: maxItemQuantity = $prices[$selectedPriceGroup]?.maxQuantity ?? Infinity; $: maxItemPurchaseQuantity = Math.min(maxItemQuantity, maxMerchantItemQuantity); function submit() { @@ -81,7 +81,7 @@
+ style="display:flex; justify-content:flex-end; align-items: center; text-align: right;"> {#if maxItemQuantity}
{localize("ITEM-PILES.Applications.TradeMerchantItem.Quantity")} diff --git a/src/applications/item-pile-config/item-pile-config.svelte b/src/applications/item-pile-config/item-pile-config.svelte index 241cb8b6..a8d8e545 100644 --- a/src/applications/item-pile-config/item-pile-config.svelte +++ b/src/applications/item-pile-config/item-pile-config.svelte @@ -3,10 +3,13 @@ import { localize } from '@typhonjs-fvtt/runtime/svelte/helper'; import FilePicker from "../components/FilePicker.svelte"; + import { TJSDialog } from '@typhonjs-fvtt/runtime/svelte/application'; import CONSTANTS from "../../constants/constants.js"; import * as SharingUtilities from "../../helpers/sharing-utilities.js"; import * as Helpers from "../../helpers/helpers.js"; + import TextEditorDialogShell from "../dialogs/text-editor-dialog/text-editor-dialog-shell.svelte"; + import PriceModifiersEditor from "../editors/price-modifiers-editor/price-modifiers-editor.js"; import CurrenciesEditor from "../editors/currencies-editor/currencies-editor.js"; import ItemFiltersEditor from "../editors/item-filters-editor/item-filters-editor.js"; @@ -19,6 +22,8 @@ from "../editors/item-type-price-modifiers-editor/item-type-price-modifiers-editor.js"; import * as PileUtilities from "../../helpers/pile-utilities.js"; import { ApplicationShell } from "@typhonjs-fvtt/runtime/svelte/component/core"; + import { writable } from "svelte/store"; + import TextEditorDialog from "../dialogs/text-editor-dialog/text-editor-dialog.js"; const { application } = getContext('external'); @@ -30,6 +35,10 @@ let pileData = PileUtilities.getActorFlagData(pileActor); let deleteWhenEmptySetting = localize(Helpers.getSetting(SETTINGS.DELETE_EMPTY_PILES) ? "Yes" : "No"); + let pileEnabled = writable(pileData.enabled); + + $: pileData.enabled = $pileEnabled; + let hasOverrideCurrencies = typeof pileData?.overrideCurrencies === "object"; let hasOverrideItemFilters = typeof pileData?.overrideItemFilters === "object"; @@ -127,15 +136,28 @@ }).render(true); } + async function showDescriptionDialog() { + return TextEditorDialog.show(pileData.description, { id: "item-pile-text-editor-" + pileActor.id }).then((result) => { + pileData.description = result || ""; + }); + } + function requestSubmit() { form.requestSubmit(); } - let tabs = [ - { value: "mainsettings", label: "ITEM-PILES.Applications.ItemPileConfig.Main.Title", highlight: !pileData.enabled }, - { value: "merchant", label: "ITEM-PILES.Applications.ItemPileConfig.Merchant.Title" }, - { value: "othersettings", label: "ITEM-PILES.Applications.ItemPileConfig.Other.Title" }, - ]; + let tabs = []; + $: { + tabs = [ + { + value: "mainsettings", + label: "ITEM-PILES.Applications.ItemPileConfig.Main.Title", + highlight: !$pileEnabled + }, + { value: "merchant", label: "ITEM-PILES.Applications.ItemPileConfig.Merchant.Title" }, + { value: "othersettings", label: "ITEM-PILES.Applications.ItemPileConfig.Other.Title" } + ] + } let activeTab = "mainsettings"; @@ -163,10 +185,10 @@ - {#if !pileData.enabled} + {#if !$pileEnabled}
{/if} - +
@@ -193,7 +215,7 @@