Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1564] Convert property attribution to use tooltips #2081

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[#1564] Convert property attribution to use tooltips
  • Loading branch information
arbron committed Jan 19, 2023
commit 18d5c74b31122c80fa3d2739f43f83a75cfd3dfa
52 changes: 19 additions & 33 deletions dnd5e.css
Original file line number Diff line number Diff line change
Expand Up @@ -562,56 +562,56 @@ h5 {
/* ----------------------------------------- */
/* Property Attribution */
/* ----------------------------------------- */
.property-attribution {
display: none;
position: absolute;
#tooltip.property-attribution {
min-width: 150px;
padding: 3px;
border: 1px solid #000;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(4px);
color: #c9c7b8;
text-align: left;
z-index: 1;
text-align: left !important;
}
.property-attribution table {
#tooltip.property-attribution table {
margin: 0;
border: 0;
font-size: var(--font-size-14);
}
#tooltip.property-attribution table caption {
padding-block: 0.25em 0.5em;
font-size: var(--font-size-16);
}
.property-attribution table tr {
#tooltip.property-attribution table tr {
background-color: inherit;
}
.property-attribution table td {
#tooltip.property-attribution table td {
padding: 3px;
}
.property-attribution table tr.total > td {
#tooltip.property-attribution table tr.total > td {
font-weight: 600;
padding-top: 5px;
border-top: 1px solid #7a7971;
}
.property-attribution table td.attribution-value {
#tooltip.property-attribution table td.attribution-value {
width: 20%;
padding-right: 5px;
text-align: right;
font-weight: 600;
}
.property-attribution table td::before {
#tooltip.property-attribution table td::before {
opacity: 0.6;
}
.property-attribution table td.mode-1::before {
#tooltip.property-attribution table td.mode-1::before {
content: "×";
}
.property-attribution table td.mode-2::before {
#tooltip.property-attribution table td.mode-2::before {
content: "+";
}
.property-attribution table td.mode-2.negative::before {
#tooltip.property-attribution table td.mode-2.negative::before {
content: "−";
margin-right: -1px;
}
.property-attribution table td.mode-3::before {
#tooltip.property-attribution table td.mode-3::before {
content: "↓";
}
.property-attribution table td.mode-4::before {
#tooltip.property-attribution table td.mode-4::before {
content: "↑";
}
/* ----------------------------------------- */
Expand Down Expand Up @@ -828,14 +828,6 @@ h5 {
.dnd5e.sheet.actor .sheet-header .attributes .attribute input.temphp {
width: 48%;
}
.dnd5e.sheet.actor .sheet-header .attributes .attribute .property-attribution {
min-width: 150px;
top: 50px;
font-family: Signika, sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1rem;
}
.dnd5e.sheet.actor h4.box-title {
height: 18px;
line-height: 16px;
Expand Down Expand Up @@ -895,12 +887,6 @@ h5 {
font-weight: 400;
white-space: nowrap;
}
.dnd5e.sheet.actor .attributable {
position: relative;
}
.dnd5e.sheet.actor .attributable:hover .tooltip {
display: block;
}
.dnd5e.sheet.actor .ability-scores {
flex: 0 0 100px;
align-content: flex-start;
Expand Down
18 changes: 0 additions & 18 deletions less/actors.less
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@
input.temphp {
width: 48%;
}

// Attribution Tooltip
.property-attribution {
min-width: 150px;
top: 50px;
font-family: Signika, sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1rem;
}
}
}
}
Expand Down Expand Up @@ -195,14 +185,6 @@
}
}

.attributable {
position: relative;

&:hover .tooltip {
display: block;
}
}

/* ----------------------------------------- */
/* Ability Scores */
/* ----------------------------------------- */
Expand Down
17 changes: 9 additions & 8 deletions less/apps.less
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,22 @@ h5 {
/* Property Attribution */
/* ----------------------------------------- */

.property-attribution {
display: none;
position: absolute;
#tooltip.property-attribution {
min-width: 150px;
padding: 3px;
border: 1px solid #000;
border-radius: 3px;
background-color: rgba(0, 0, 0, .8);
backdrop-filter: blur(4px);
color: @colorFaint;
text-align: left;
z-index: 1;
text-align: left !important;
arbron marked this conversation as resolved.
Show resolved Hide resolved

table {
margin: 0;
border: 0;
font-size: var(--font-size-14);

caption {
padding-block: 0.25em 0.5em;
font-size: var(--font-size-16);
}
tr {
background-color: inherit;
}
Expand Down
20 changes: 15 additions & 5 deletions module/applications/actor/base-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ export default class ActorSheet5e extends ActorSheet {
html.find(".item-edit").click(this._onItemEdit.bind(this));

// Property attributions
html.find("[data-attribution]").mouseover(this._onPropertyAttribution.bind(this));
html.find(".attributable").mouseover(this._onPropertyAttribution.bind(this));

// Preparation Warnings
Expand Down Expand Up @@ -1245,18 +1246,27 @@ export default class ActorSheet5e extends ActorSheet {
* @private
*/
async _onPropertyAttribution(event) {
const existingTooltip = event.currentTarget.querySelector("div.tooltip");
const property = event.currentTarget.dataset.property;
if ( existingTooltip || !property ) return;
const element = event.target;
let property = element.dataset.attribution;
if ( !property ) {
property = element.dataset.property;
if ( !property ) return;
foundry.utils.logCompatibilityWarning(
"Defining attributable properties on sheets with the `.attributable` class and `data-property` value"
+ " has been deprecated in favor of a single `data-attribution` value.",
{ since: "DnD5e 2.2", until: "DnD5e 2.4" }
);
}

const rollData = this.actor.getRollData({ deterministic: true });
const title = game.i18n.localize(element.dataset.attributionCaption);
let attributions;
switch ( property ) {
case "attributes.ac":
attributions = this._prepareArmorClassAttribution(rollData); break;
}
if ( !attributions ) return;
const html = await new PropertyAttribution(this.actor, attributions, property).renderTooltip();
event.currentTarget.insertAdjacentElement("beforeend", html[0]);
new PropertyAttribution(this.actor, attributions, property, {title}).renderTooltip(element);
}

/* -------------------------------------------- */
Expand Down
10 changes: 5 additions & 5 deletions module/applications/property-attribution.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ export default class PropertyAttribution extends Application {

/**
* Render this view as a tooltip rather than a whole window.
* @returns {jQuery} HTML of the rendered tooltip.
* @param {HTMLElement} element The element to which the tooltip should be attached.
*/
async renderTooltip() {
async renderTooltip(element) {
const data = this.getData(this.options);
let html = await this._renderInner(data);
html[0].classList.add("tooltip");
return html;
const text = (await this._renderInner(data))[0].outerHTML;
game.tooltip.activate(element, { text, cssClass: "property-attribution" });
}

/* -------------------------------------------- */
Expand All @@ -60,6 +59,7 @@ export default class PropertyAttribution extends Application {
else if ( typeof property === "object" && Number.isNumeric(property.value) ) total = property.value;
const sources = foundry.utils.duplicate(this.attributions);
return {
caption: this.options.title,
sources: sources.map(entry => {
if ( entry.label.startsWith("@") ) entry.label = this.getPropertyLabel(entry.label.slice(1));
if ( (entry.mode === CONST.ACTIVE_EFFECT_MODES.ADD) && (entry.value < 0) ) {
Expand Down
3 changes: 2 additions & 1 deletion templates/actors/character-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
<a class="config-button" data-action="armor" data-tooltip="{{localize 'DND5E.ArmorConfig'}}">
<i class="fas fa-cog"></i>
</a>
<div class="attribute-value attributable" data-property="attributes.ac">
<div class="attribute-value" data-attribution="attributes.ac"
data-attribution-caption="DND5E.ArmorClass" data-tooltip-direction="DOWN">
<span>{{system.attributes.ac.value}}</span>
</div>
<footer class="attribute-footer">
Expand Down
3 changes: 2 additions & 1 deletion templates/actors/npc-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
<a class="config-button" data-action="armor" title="{{localize 'DND5E.ArmorConfig'}}">
<i class="fas fa-cog"></i>
</a>
<div class="attribute-value attributable" data-property="attributes.ac">
<div class="attribute-value" data-attribution="attributes.ac"
data-attribution-caption="DND5E.ArmorClass" data-tooltip-direction="DOWN">
<span>{{system.attributes.ac.value}}</span>
</div>
<footer class="attribute-footer">
Expand Down
15 changes: 7 additions & 8 deletions templates/apps/property-attribution.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="property-attribution">
<table>
<table>
{{#if caption}}<caption>{{caption}}</caption>{{/if}}
{{#each sources as |source|}}
<tr>
<td class="attribution-value mode-{{source.mode}}{{#if source.negative}} negative{{/if}}">
Expand All @@ -8,9 +8,8 @@
<td class="attribution-label">{{source.label}}</td>
</tr>
{{/each}}
<tr class="total">
<td class="attribution-value">{{total}}</td>
<td class="attribution-label">{{localize "DND5E.PropertyTotal"}}</td>
</tr>
</table>
</div>
<tr class="total">
<td class="attribution-value">{{total}}</td>
<td class="attribution-label">{{localize "DND5E.PropertyTotal"}}</td>
</tr>
</table>