diff --git a/classes/MaskLayer.js b/classes/MaskLayer.js index ce6446c..8f9affa 100644 --- a/classes/MaskLayer.js +++ b/classes/MaskLayer.js @@ -26,6 +26,7 @@ export default class MaskLayer extends InteractionLayer { }; this.DEFAULTS = { visible: false, + blurEnable: true, blurQuality: 2, blurRadius: 5, }; @@ -34,8 +35,9 @@ export default class MaskLayer extends InteractionLayer { static get layerOptions() { //@ts-ignore return mergeObject(super.layerOptions, { + // ToDo: is ugly hack still needed? // Ugly hack - render at very high zindex and then re-render at layer init with layerZindex value - zIndex: 2147483647, + zIndex: game.settings.get('simplefog', 'zIndex') }); } @@ -67,13 +69,19 @@ export default class MaskLayer extends InteractionLayer { this.setTint(this.getTint()); this.setAlpha(this.getAlpha(), true); - // Filters this.blur = new PIXI.filters.BlurFilter(); this.blur.padding = 0; this.blur.repeatEdgePixels = true; this.blur.blur = this.getSetting("blurRadius"); this.blur.quality = this.getSetting("blurQuality"); + // Filters + if (this.getSetting("blurEnable")) { + this.baseLayer.filters = [this.blur]; + } else { + this.baseLayer.filters = []; + } + //So you can hit escape on the keyboard and it will bring up the menu this._controlled = {}; @@ -83,7 +91,6 @@ export default class MaskLayer extends InteractionLayer { this.baseLayer.mask = this.maskSprite; this.setFill(); - this.baseLayer.filters = [this.blur]; // Allow zIndex prop to function for items on this layer this.sortableChildren = true; @@ -162,7 +169,7 @@ export default class MaskLayer extends InteractionLayer { simplefogLogDebug('MaskLayer.renderStack') // If history is blank, do nothing if (history === undefined) { - this.visible = this.getSetting("autoFog"); + this.visible = game.settings.get('simplefog', 'autoEnableSceneFog'); return; } // If history is zero, reset scene fog @@ -435,4 +442,8 @@ export default class MaskLayer extends InteractionLayer { this.addChild(this.fogSprite); } + + refreshZIndex() { + canvas.simplefog.zIndex = game.settings.get('simplefog', 'zIndex'); + } } diff --git a/classes/SimplefogConfig.js b/classes/SimplefogConfig.js index 8fec96a..9d77622 100644 --- a/classes/SimplefogConfig.js +++ b/classes/SimplefogConfig.js @@ -31,24 +31,13 @@ export default class SimplefogConfig extends FormApplication { playerTint: hexToWeb(canvas.simplefog.getSetting('playerTint')), transition: canvas.simplefog.getSetting('transition'), transitionSpeed: canvas.simplefog.getSetting('transitionSpeed'), + blurEnable: canvas.simplefog.getSetting('blurEnable'), blurRadius: canvas.simplefog.getSetting('blurRadius'), blurQuality: canvas.simplefog.getSetting('blurQuality'), autoVisibility: canvas.simplefog.getSetting('autoVisibility'), - autoFog: canvas.simplefog.getSetting('autoFog'), autoVisGM: canvas.simplefog.getSetting('autoVisGM'), vThreshold: Math.round(canvas.simplefog.getSetting('vThreshold') * 100), - layerZindex: canvas.simplefog.getSetting('layerZindex'), fogTextureFilePath: canvas.simplefog.getSetting('fogTextureFilePath'), - confirmDisablingFog: canvas.simplefog.getSetting( 'confirmDisablingFog'), - enableHotkeys: canvas.simplefog.getSetting('enableHotkeys'), - hotKeyTool: canvas.simplefog.getSetting('hotKeyTool'), - hotKeyToolOptions: { - brush: "Brush", - grid: "Grid", - polygon: "Polygon", - box: "Box", - ellipse: "Ellipse" - }, versionNotification: canvas.simplefog.getSetting('versionNotification') }; } @@ -77,9 +66,6 @@ export default class SimplefogConfig extends FormApplication { } }); - // If zIndex was changed - canvas.simplefog.zIndex = canvas.simplefog.getSetting('layerZindex'); - // If save button was clicked, close app if (event.submitter?.name === 'submit') { Object.values(ui.windows).forEach((val) => { diff --git a/classes/SimplefogHUDControlLayer.js b/classes/SimplefogHUDControlLayer.js index 9e2e686..4d019fb 100644 --- a/classes/SimplefogHUDControlLayer.js +++ b/classes/SimplefogHUDControlLayer.js @@ -12,9 +12,6 @@ export default class SimplefogHUDControlLayer extends InteractionLayer { static get layerOptions() { //@ts-ignore - return mergeObject(super.layerOptions, { - // Ugly hack - render at very high zindex (but one below simplefog) and then re-render at zindex below simplefog - zIndex: 2147483646, - }); + return super.layerOptions } } diff --git a/classes/SimplefogLayer.js b/classes/SimplefogLayer.js index 2753661..37db0c5 100644 --- a/classes/SimplefogLayer.js +++ b/classes/SimplefogLayer.js @@ -201,6 +201,16 @@ export default class SimplefogLayer extends MaskLayer { canvas[this.layername].visible = data.flags[this.layername].visible; } // React to composite history change + if (hasProperty(data, `flags.${this.layername}.blurEnable`)) { + + if (this.baseLayer !== undefined) { + if (this.getSetting("blurEnable")) { + this.baseLayer.filters = [this.blur]; + } else { + this.baseLayer.filters = []; + } + } + } if (hasProperty(data, `flags.${this.layername}.blurRadius`)) { canvas[this.layername].blur.blur = this.getSetting('blurRadius'); } @@ -730,6 +740,7 @@ export default class SimplefogLayer extends MaskLayer { async draw() { simplefogLogDebug('SimplefogLayer.draw') super.draw(); + simplefogLogDebug('SimplefogLayer.draw - this', this) this.addChild(this.boxPreview); this.addChild(this.ellipsePreview); this.addChild(this.polygonPreview); diff --git a/js/controls.js b/js/controls.js index cce7de6..f3bafbe 100644 --- a/js/controls.js +++ b/js/controls.js @@ -148,7 +148,7 @@ function setBrushControlPos() { */ function toggleSimpleFog() { simplefogLogDebug('controls.toggleSimpleFog') - if (canvas.simplefog.getSetting("confirmDisablingFog") && canvas.simplefog.getSetting("visible")) { + if (game.settings.get('simplefog', 'confirmFogDisable') && canvas.simplefog.getSetting("visible")) { let dg = Dialog.confirm({ title: game.i18n.localize('SIMPLEFOG.disableFog'), content: game.i18n.localize('SIMPLEFOG.confirmDisableFog'), @@ -175,7 +175,6 @@ function cancelToggleSimpleFog(result = undefined) { ui.controls.render(); } - // Reset position when brush controls are rendered or sceneNavigation changes Hooks.on('renderBrushControls', setBrushControlPos); Hooks.on('renderSceneNavigation', setBrushControlPos); diff --git a/js/helpers.js b/js/helpers.js index 2d99628..2154bf3 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -132,7 +132,7 @@ export function addSimplefogControlToggleListener() { } let controlName = getNewControlName(); - let toolName = canvas.simplefog.getSetting('hotKeyTool'); + let toolName = game.settings.get('simplefog', 'toolHotKeys'); $('li.scene-control[data-control=' + controlName + ']')?.click(); setTimeout(function(){$('ol.sub-controls.active li.control-tool[data-tool=' + toolName + ']')?.click();}, 500); @@ -143,7 +143,7 @@ export function addSimplefogControlToggleListener() { * @returns bool */ function areHotkeysEnabled() { - return canvas.simplefog.getSetting('enableHotkeys'); + return game.settings.get('simplefog', 'enableHotKeys'); } /** diff --git a/js/simplefog.js b/js/simplefog.js index 44e8f0a..4cb2f5e 100644 --- a/js/simplefog.js +++ b/js/simplefog.js @@ -15,6 +15,56 @@ Hooks.once('init', () => { game.settings.register('simplefog', cfg.name, cfg.data); }); + // Register global config settings + game.settings.register('simplefog', 'confirmFogDisable', { + name: 'Confirm Disabling of Scene Simplefog', + hint: 'When enabled, a confirmation dialog will be displayed before Simplefog can be toggled off for a scene', + scope: 'world', + config: true, + default: true, + type: Boolean + }); + game.settings.register('simplefog', 'autoEnableSceneFog', { + name: 'Auto Enable Scene Fog', + hint: 'When enabled, Simplefog will automatically be enabled for a scene when it is first created.', + scope: 'world', + config: true, + default: true, + type: Boolean + }); + game.settings.register('simplefog', 'enableHotKeys', { + name: 'Enable Simplefog Hotkeys', + hint: 'When enabled, you will be able to quickly swap to the Simplefog control by using Ctrl+S and toggle the opacity using the hotkey \'T\'', + scope: 'world', + config: true, + default: false, + type: Boolean + }); + game.settings.register('simplefog', 'toolHotKeys', { + name: 'Hotkey Tool', + hint: 'When Hotkeys is enabled, define which tool will be selected by using Ctrl+S', + scope: 'world', + config: true, + default: 'brush', + type: String, + choices: { + 'brush': 'Brush', + 'grid': 'Grid', + 'polygon': 'Polygon', + 'box': 'Box', + 'ellipse': 'Ellipse', + } + }); + game.settings.register('simplefog', 'zIndex', { + name: 'Simplefog Z-Index', + hint: 'The z-index determines the order in which various layers are rendered within the Foundry canvas. A higher number will be rendered on top of lower numbered layers (and the objects on that layer). This allows for the adjustment of the z-index to allow for Simple Fog to be rendered above/below other layers; particularly ones added by other modules. Going below 200 will intermingle with Foundry layers such as the foreground image (200), tokens (100), etc... (Default: 220)', + scope: 'world', + config: true, + default: 220, + type: Number, + onChange: SimplefogLayer.refreshZIndex + }); + if (isNewerVersion(game.version, "10")) { CONFIG.Canvas.layers.simplefog = {group: "interface", layerClass: SimplefogLayer}; CONFIG.Canvas.layers.simplefogHUDControls = {group: "interface", layerClass: SimplefogHUDControlLayer}; @@ -85,8 +135,10 @@ Hooks.once('ready', () => { SimplefogMigrations.check(); // Fix simplefog zIndex - canvas.simplefog.zIndex = canvas.simplefog.getSetting('layerZindex'); - canvas.simplefogHUDControls.zIndex = canvas.simplefog.getSetting('layerZindex') - 1; + + canvas.simplefog.refreshZIndex() + // ToDo: why is this set below??? + //canvas.simplefogHUDControls.zIndex = canvas.simplefog.getSetting('layerZindex') - 1; // Move object hud to tokens layer game.canvas.controls.hud.setParent(game.canvas.simplefogHUDControls) diff --git a/lang/en.json b/lang/en.json index 8d1282e..7cae42a 100644 --- a/lang/en.json +++ b/lang/en.json @@ -8,6 +8,7 @@ "SIMPLEFOG.opacity": "Opacity", "SIMPLEFOG.playerFogSettings": "Player Fog Settings", "SIMPLEFOG.filterSettings": "Filter Settings", + "SIMPLEFOG.blurEnable": "Enable Reveal Blur", "SIMPLEFOG.blurRadius": "Blur Radius", "SIMPLEFOG.blurQuality": "Blur Quality", "SIMPLEFOG.blurQualityDesc": "Higher blur quality improves the appearance of the blur effect, but may cause slower performance.", diff --git a/templates/scene-config.html b/templates/scene-config.html index 4ebdbcc..40cbb0a 100644 --- a/templates/scene-config.html +++ b/templates/scene-config.html @@ -38,7 +38,11 @@
{{ localize 'SIMPLEFOG.autoFogNotes' }}
-{{ localize 'SIMPLEFOG.hotkeyNotes' }}
-{{ localize 'SIMPLEFOG.hotKeyToolNotes' }}
-{{ localize 'SIMPLEFOG.confirmDisablingFogNotes' }}
-{{localize 'SIMPLEFOG.configurableZindexNotes'}}
-