From efda25bf7e170507165a594004d51668ca4b1029 Mon Sep 17 00:00:00 2001 From: Budzyn <43236231+budzyn0@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:10:04 +0200 Subject: [PATCH] ref. #258, #268 Quick fixes and enhancements for tooltips (#271) * ref. #258, #268 Quick fixes and enhancements for tooltips * Removed doing so many "unless" in templates and instead using a simple javascript function to handle behaviour of tooltips and titles. * Update changelog --- CHANGELOG.md | 5 + lang/en.json | 7 +- module/actor/actor.js | 6 +- module/settings.js | 17 +- module/sheets/base-actor-sheet.js | 91 ++++++- .../actor/partials/custom-skills-partial.html | 242 ++++++++++-------- templates/actor/partials/sanity-agent.html | 50 ++-- templates/actor/parts/gear-tab.html | 24 +- templates/actor/parts/header.html | 4 +- templates/actor/parts/motivations-tab.html | 1 + templates/actor/parts/skills-tab.html | 6 +- templates/item/item-motivation-sheet.html | 74 +++--- 12 files changed, 325 insertions(+), 202 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0416b..af29087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,14 @@ ## Version 1.6.2 - 2025-xx-xx +### **Features:** + +- [#258](https://github.com/deltagreen-foundryvtt/delta-green-foundry-vtt-system/issues/258) - Added a keybind option for hovering tooltips and option to hide all. + ### **Bug Fixes:** - [#274] () - Automated fail marking now works after dice so nice resolve roll. +- [#268] () - Removed unnecessary tooltips. ## Version 1.6.1 - 2025-09-09 diff --git a/lang/en.json b/lang/en.json index e36837f..6884ba5 100644 --- a/lang/en.json +++ b/lang/en.json @@ -395,8 +395,11 @@ "DG.Settings.charactersheet.program": "The Program", "DG.Settings.sortskills.name": "Sort Skills By Column?", "DG.Settings.sortskills.hint": "Checked sorts by column. Unchecked sorts by row.", - "DG.Settings.hideSkillTooltips.name": "Hide Skill Tooltips", - "DG.Settings.hideSkillTooltips.hint": "Do not display skill tooltips in Agent sheets.", + "DG.Settings.skillTooltipDisplay.name": "Display tooltips", + "DG.Settings.skillTooltipDisplay.hint": "Choose when to display skill tooltips in Agent sheets.", + "DG.Settings.skillTooltipDisplay.hover": "On hover (default)", + "DG.Settings.skillTooltipDisplay.never": "Never", + "DG.Settings.skillTooltipDisplay.hoverShift": "On hover + Shift", "DG.Settings.keepSanityPrivate.name": "Keep Sanity Private", "DG.Settings.keepSanityPrivate.hint": "Hide sanity from players in both Agent sheets and rolls.", "DG.Settings.skillImprovementFormula.name": "Default Skill Improvement Roll", diff --git a/module/actor/actor.js b/module/actor/actor.js index c8d79c4..5a86091 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -10,8 +10,6 @@ export default class DeltaGreenActor extends Actor { super.prepareData(); const actorData = this; - const { system } = actorData; - const { flags } = actorData; // console.log('actor.js prepareData'); // console.log(this); @@ -86,7 +84,7 @@ export default class DeltaGreenActor extends Actor { proficiency: 99 - system.sanity.value, cannotBeImprovedByFailure: true, failure: false, - }; + }; if (system.skills.ritual.proficiency > 99) { system.skills.ritual.proficiency = 99; @@ -179,7 +177,7 @@ export default class DeltaGreenActor extends Actor { proficiency: 99 - system.sanity.value, cannotBeImprovedByFailure: true, failure: false, - }; + }; if (system.skills.ritual.proficiency > 99) { system.skills.ritual.proficiency = 99; diff --git a/module/settings.js b/module/settings.js index e9f7b11..2e3ad25 100644 --- a/module/settings.js +++ b/module/settings.js @@ -313,13 +313,20 @@ export default function registerSystemSettings() { default: false, }); - game.settings.register("deltagreen", "hideSkillTooltips", { - name: game.i18n.localize("DG.Settings.hideSkillTooltips.name"), - hint: game.i18n.localize("DG.Settings.hideSkillTooltips.hint"), + game.settings.register("deltagreen", "skillTooltipDisplay", { + name: game.i18n.localize("DG.Settings.skillTooltipDisplay.name"), + hint: game.i18n.localize("DG.Settings.skillTooltipDisplay.hint"), scope: "client", config: true, - type: Boolean, - default: false, + type: String, + choices: { + hover: game.i18n.localize("DG.Settings.skillTooltipDisplay.hover"), + never: game.i18n.localize("DG.Settings.skillTooltipDisplay.never"), + hoverShift: game.i18n.localize( + "DG.Settings.skillTooltipDisplay.hoverShift", + ), + }, + default: "hover", onChange: () => { foundry.applications.instances.forEach((app) => { if (app instanceof DGActorSheet) { diff --git a/module/sheets/base-actor-sheet.js b/module/sheets/base-actor-sheet.js index 7b1227c..f3033c2 100644 --- a/module/sheets/base-actor-sheet.js +++ b/module/sheets/base-actor-sheet.js @@ -83,13 +83,13 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { this._sortSkills(); this._sortCustomSkills(); - // Wether to hide skill tooltips - context.hideSkillTooltips = game.settings.get( + // Skill tooltip display setting + context.skillTooltipDisplay = game.settings.get( "deltagreen", - "hideSkillTooltips", + "skillTooltipDisplay", ); - if (!context.hideSkillTooltips) { + if (context.skillTooltipDisplay !== "never") { // Setup tooltips this._prepareSkillTooltips(); } @@ -158,6 +158,8 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { li.setAttribute("draggable", true); li.addEventListener("dragstart", handler, false); }); + + this._tooltipsSettings(this.element); } /** @override - Add buttons to the header controls. */ @@ -1356,4 +1358,85 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { const currentVal = foundry.utils.getProperty(targetDoc, prop); targetDoc.update({ [prop]: !currentVal }); } + + /** + * Require Shift while hovering to show tooltips. + * Supports either data-tooltip (preferred, may contain HTML) or title (plain text). + */ + _tooltipsSettings(root) { + const mode = game.settings.get("deltagreen", "skillTooltipDisplay"); + + // If not explicitly hoverShift or never, do nothing. + if (mode !== "hoverShift" && mode !== "never") return; + + // Query elements with either data-tooltip OR title + const nodes = root.querySelectorAll("[data-tooltip],[title]"); + + // If mode is "never": strip native attributes so no tooltips (native or custom) can appear. + if (mode === "never") { + nodes.forEach((el) => { + if (el.dataset.shiftTooltipInstalled === "true") return; + el.removeAttribute("data-tooltip"); + el.removeAttribute("title"); + el.dataset.shiftTooltipInstalled = "true"; + }); + return; + } + + // mode === "hoverShift": install Shift-to-show behavior using Foundry's tooltip + nodes.forEach((el) => { + if (el.dataset.shiftTooltipInstalled === "true") return; + + // Prefer data-tooltip, else use title + let html = el.getAttribute("data-tooltip"); + let isHtml = true; + + if (!html) { + const title = el.getAttribute("title"); + if (title) { + html = foundry.utils.escapeHTML(title); // treat title as plain text + isHtml = false; + } + } + + if (!html) return; // nothing usable + + // Remove native attributes so default tooltips don’t trigger + el.removeAttribute("data-tooltip"); + el.removeAttribute("title"); + el.dataset.shiftTooltipInstalled = "true"; + + // Always pass through { html } so
etc. render + const opts = isHtml ? { html } : { text: html }; + + const show = () => game.tooltip.activate(el, opts); + const hide = () => game.tooltip.deactivate(); + + const onKey = (ev) => { + if (ev.key !== "Shift") return; + if (!document.body.contains(el)) { + window.removeEventListener("keydown", onKey); + window.removeEventListener("keyup", onKey); + return; + } + if (ev.type === "keydown") show(); + else hide(); + }; + + const onEnter = (ev) => { + if (ev.shiftKey) show(); + window.addEventListener("keydown", onKey); + window.addEventListener("keyup", onKey); + }; + + const onLeave = () => { + hide(); + window.removeEventListener("keydown", onKey); + window.removeEventListener("keyup", onKey); + }; + + el.addEventListener("pointerenter", onEnter, { passive: true }); + el.addEventListener("pointerleave", onLeave, { passive: true }); + }); + } } diff --git a/templates/actor/partials/custom-skills-partial.html b/templates/actor/partials/custom-skills-partial.html index fd0df26..002a57f 100644 --- a/templates/actor/partials/custom-skills-partial.html +++ b/templates/actor/partials/custom-skills-partial.html @@ -1,125 +1,141 @@
- {{#each actor.system.sortedCustomSkills as |skill| }} - {{#if_eq type "typeSkill" }} + {{#each actor.system.sortedCustomSkills as |skill| }} + {{#if_eq type "typeSkill" }} -
-
- - - - {{#if_eq skill.actorType "agent" }} - - {{/if_eq}} -
- -
+
+
+ + + + {{#if_eq skill.actorType "agent" }} + + {{/if_eq}} +
+ +
- {{/if_eq}} + {{/if_eq}} - {{#if_eq type "training" }} + {{#if_eq type "training" }} -
-
- {{#if_not_eq (localize (concat 'DG.Attributes.' skill.key)) (concat "DG.Attributes." skill.key) }} - - {{else}} - {{#if_not_eq (localize (concat 'DG.Skills.' skill.key)) (concat "DG.Skills." skill.key) }} - - {{else}} - - {{/if_not_eq}} - {{/if_not_eq}} - -
- - -
-
-
+
+
+ {{#if_not_eq (localize (concat 'DG.Attributes.' skill.key)) (concat "DG.Attributes." skill.key) }} + + {{else}} + {{#if_not_eq (localize (concat 'DG.Skills.' skill.key)) (concat "DG.Skills." skill.key) }} + + {{else}} + + {{/if_not_eq}} + {{/if_not_eq}} + +
+ + +
+
+
- {{/if_eq}} + {{/if_eq}} - {{/each}} + {{/each}}
diff --git a/templates/actor/partials/sanity-agent.html b/templates/actor/partials/sanity-agent.html index 3a84228..fa8cbe0 100644 --- a/templates/actor/partials/sanity-agent.html +++ b/templates/actor/partials/sanity-agent.html @@ -1,27 +1,27 @@ -{{#if (keepSanityPrivate)}} - -/ -
-
???
-
+{{#if (keepSanityPrivate) }} + + / +
+
???
+
{{else}} - -/ -
-
{{numberFormat actor.system.sanity.max decimals=0 sign=false}}
-
+ + / +
+
{{numberFormat actor.system.sanity.max decimals=0 sign=false}}
+
{{/if}} diff --git a/templates/actor/parts/gear-tab.html b/templates/actor/parts/gear-tab.html index 0a2457c..39e290a 100644 --- a/templates/actor/parts/gear-tab.html +++ b/templates/actor/parts/gear-tab.html @@ -266,11 +266,15 @@ + title="Edit Item"> + + + title="Delete Item"> + + {{/each}} @@ -341,11 +345,15 @@ + title="Edit Item"> + + + title="Delete Item"> + + @@ -425,11 +433,15 @@ + title="Edit Item"> + + + title="Delete Item"> + + diff --git a/templates/actor/parts/header.html b/templates/actor/parts/header.html index 1adbb5f..370199b 100644 --- a/templates/actor/parts/header.html +++ b/templates/actor/parts/header.html @@ -4,13 +4,13 @@