Skip to content

Commit

Permalink
Add button to show item roll options in item sheet (foundryvtt#14522)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed May 29, 2024
1 parent 522cc1a commit 32da765
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/module/item/base/sheet/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TagSelectorBasic,
} from "@system/tag-selector/index.ts";
import {
createHTMLElement,
ErrorPF2e,
fontAwesomeIcon,
htmlClosest,
Expand Down Expand Up @@ -346,6 +347,18 @@ class ItemSheetPF2e<TItem extends ItemPF2e> extends ItemSheet<TItem, ItemSheetOp
this.#selectedRuleElementType = ruleElementSelect.value;
});

// Add implementation for viewing an item's roll options
const viewRollOptionsElement = htmlQuery(rulesPanel, "a[data-action=view-roll-options]");
viewRollOptionsElement?.addEventListener("click", async () => {
const rollOptions = R.sortBy(this.item.getRollOptions("item").sort(), (o) => o.includes(":"));
const content = await renderTemplate("systems/pf2e/templates/items/roll-options.hbs", { rollOptions });
game.tooltip.dismissLockedTooltips();
game.tooltip.activate(viewRollOptionsElement, {
content: createHTMLElement("div", { innerHTML: content }),
locked: true,
});
});

for (const anchor of htmlQueryAll(rulesPanel, "a[data-action=add-rule-element]")) {
anchor.addEventListener("click", async (event) => {
await this._onSubmit(event); // Submit any unsaved changes
Expand Down
7 changes: 7 additions & 0 deletions src/styles/item/_rules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
margin-right: 0.5em;
}
}

a[data-action] {
flex: 0 0 auto;
line-height: 1.75em;
height: 1.75em;
margin-left: auto;
}
}

.rules {
Expand Down
6 changes: 4 additions & 2 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2438,12 +2438,14 @@
"Hint": {
"Slug": "A stable, human-readable identifier: if set, it will remain in place even if the item is renamed.",
"SourceId": "The UUID of the original compendium item",
"UUID": "A universally unique identifier for this item"
"UUID": "A universally unique identifier for this item",
"RollOptions": "An item roll option's prefix depends on its usage. <em>item:</em> is used most of the time, but <em>parent:</em> is used for the item containing the rule element."
},
"New": "New Rule Element",
"RegenerateSlug": "(Re)generate Slug",
"Remove": "Remove Rule Element",
"Tab": "Rules"
"Tab": "Rules",
"ViewRollOptions": "View Roll Options"
},
"Shield": {
"Base": {
Expand Down
6 changes: 6 additions & 0 deletions static/templates/items/roll-options.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>{{{localize "PF2E.Item.Rules.Hint.RollOptions"}}}</p>
<ul>
{{#each rollOptions as |option|}}
<li>{{option}}</li>
{{/each}}
</ul>
6 changes: 6 additions & 0 deletions static/templates/items/rules-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<a data-action="regenerate-slug" data-tooltip="PF2E.Item.Rules.RegenerateSlug"><i class="fa-solid fa-fw fa-sync-alt"></i></a>
</div>
</div>
<div class="form-group">
<a data-action="view-roll-options" data-tooltip-class="pf2e roll-options" data-tooltip-direction="RIGHT">
{{localize "PF2E.Item.Rules.ViewRollOptions"}}
<i class="fa-solid fa-circle-info"></i>
</a>
</div>
</div>
<div class="rule-element-forms">
{{#each rules.elements as |form|}}
Expand Down

0 comments on commit 32da765

Please sign in to comment.