Skip to content

Commit

Permalink
hide persistent hud when placing a template
Browse files Browse the repository at this point in the history
  • Loading branch information
reonZ committed Oct 5, 2024
1 parent 75845c1 commit dc2ddc0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
51 changes: 31 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Hooks.on("renderSettingsConfig", (app: SettingsConfig, $html: JQuery) => {
Hooks.on("drawMeasuredTemplate", (template: MeasuredTemplatePF2e) => {
if (!template.isPreview) return;

addFadeOuts(true);
addFadeOuts();

HUDS.token.close();
HUDS.persistent.closeSidebar();
Expand All @@ -293,27 +293,30 @@ Hooks.on("drawMeasuredTemplate", (template: MeasuredTemplatePF2e) => {
Hooks.on("destroyMeasuredTemplate", (template: MeasuredTemplatePF2e) => {
if (!template.isPreview) return;

removeFadeOuts(true);
removeFadeOuts();
});

window.addEventListener(
"dragstart",
() => {
addFadeOuts();
window.addEventListener("dragend", () => removeFadeOuts(), { once: true, capture: true });
(event) => {
addFadeOuts(event);
window.addEventListener("dragend", () => removeFadeOuts(event), {
once: true,
capture: true,
});
},
true
);

function addFadeOuts(persistentOnly?: boolean) {
for (const element of getFadingElements(persistentOnly)) {
function addFadeOuts(event?: DragEvent) {
for (const element of getFadingElements(event)) {
element?.classList?.add("pf2e-hud-fadeout");
}
}

function removeFadeOuts(persistentOnly?: boolean) {
function removeFadeOuts(event?: DragEvent) {
setTimeout(() => {
for (const element of getFadingElements(persistentOnly)) {
for (const element of getFadingElements(event)) {
element?.classList?.remove("pf2e-hud-fadeout");
}
}, 500);
Expand All @@ -324,17 +327,25 @@ function refreshSidebar() {
HUDS.persistent.sidebar?.render();
}

function getFadingElements(persistentOnly: boolean = false) {
return persistentOnly
? [...PF2eHudPopup.apps, HUDS.tracker]
: [
HUDS.token.mainElement,
...[HUDS.token, HUDS.persistent].map((x) =>
x.sidebar && x.sidebar.key !== "extras" ? x.sidebar.element : undefined
),
...PF2eHudPopup.apps,
HUDS.tracker,
];
function getFadingElements(event?: DragEvent) {
const elements: Maybe<{ classList: DOMTokenList | undefined }>[] = [
...PF2eHudPopup.apps,
HUDS.tracker,
];

if (event) {
elements.push(HUDS.token.mainElement);

for (const element of [HUDS.token, HUDS.persistent]) {
if (element.sidebar && element.sidebar.key !== "extras") {
elements.push(element.sidebar.element);
}
}
} else {
elements.push(HUDS.persistent);
}

return elements;
}

export { HUDS as hud };
9 changes: 8 additions & 1 deletion styles/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,14 @@ aside.locked-tooltip {

&.pf2e-hud-popup,
&#pf2e-hud-token-main .panel,
&#pf2e-hud-tracker {
&#pf2e-hud-tracker,
#pf2e-hud-persistent-menu,
#pf2e-hud-persistent-portrait,
#pf2e-hud-persistent-portrait .panel,
#pf2e-hud-persistent-main .app,
#hotbar #action-bar,
#hotbar #hotbar-directory-controls,
#hotbar #hotbar-page-controls {
pointer-events: none;
}
}
Expand Down
2 changes: 1 addition & 1 deletion styles/pf2e-hud.css

Large diffs are not rendered by default.

Loading

0 comments on commit dc2ddc0

Please sign in to comment.