Add hotbar settings (reposition, button size/gap)
This commit is contained in:
parent
4dc7b8541f
commit
27c5fccba0
9 changed files with 177 additions and 8 deletions
39
module/settings/hotbarButtonGap.mjs
Normal file
39
module/settings/hotbarButtonGap.mjs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { __ID } from "../consts.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
|
||||
const key = `hotbarButtonGap`;
|
||||
|
||||
export function hotbarButtonGap() {
|
||||
|
||||
const prevented = Hooks.call(`${__ID}.preventSetting`, key);
|
||||
if (!prevented) {
|
||||
Logger.log(`Preventing setting "${key}" from being registered`);
|
||||
return;
|
||||
};
|
||||
|
||||
// #region Registration
|
||||
Logger.log(`Registering setting: ${key}`);
|
||||
document.body.classList.add(`${__ID}-${key}`);
|
||||
game.settings.register(__ID, key, {
|
||||
name: `OFT.setting.${key}.name`,
|
||||
hint: `OFT.setting.${key}.hint`,
|
||||
scope: `user`,
|
||||
type: new foundry.data.fields.NumberField({
|
||||
min: 0,
|
||||
max: 16,
|
||||
step: 1,
|
||||
}),
|
||||
default: 8,
|
||||
config: true,
|
||||
requiresReload: false,
|
||||
onChange: (newValue) => {
|
||||
document.body.style.setProperty(`--hotbar-button-gap`, `${newValue}px`);
|
||||
},
|
||||
});
|
||||
// #endregion Registration
|
||||
|
||||
// #region Implementation
|
||||
const buttonGap = game.settings.get(__ID, key);
|
||||
document.body.style.setProperty(`--hotbar-button-gap`, `${buttonGap}px`);
|
||||
// #endregion Implementation
|
||||
};
|
||||
39
module/settings/hotbarButtonSize.mjs
Normal file
39
module/settings/hotbarButtonSize.mjs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { __ID } from "../consts.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
|
||||
const key = `hotbarButtonSize`;
|
||||
|
||||
export function hotbarButtonSize() {
|
||||
|
||||
const prevented = Hooks.call(`${__ID}.preventSetting`, key);
|
||||
if (!prevented) {
|
||||
Logger.log(`Preventing setting "${key}" from being registered`);
|
||||
return;
|
||||
};
|
||||
|
||||
// #region Registration
|
||||
Logger.log(`Registering setting: ${key}`);
|
||||
document.body.classList.add(`${__ID}-${key}`);
|
||||
game.settings.register(__ID, key, {
|
||||
name: `OFT.setting.${key}.name`,
|
||||
hint: `OFT.setting.${key}.hint`,
|
||||
scope: `user`,
|
||||
type: new foundry.data.fields.NumberField({
|
||||
min: 45,
|
||||
max: 75,
|
||||
step: 5,
|
||||
}),
|
||||
default: 60, // this is the value Foundry uses
|
||||
config: true,
|
||||
requiresReload: false,
|
||||
onChange: (newValue) => {
|
||||
document.body.style.setProperty(`--hotbar-size`, `${newValue}px`);
|
||||
},
|
||||
});
|
||||
// #endregion Registration
|
||||
|
||||
// #region Implementation
|
||||
const hotbarSize = game.settings.get(__ID, key);
|
||||
document.body.style.setProperty(`--hotbar-size`, `${hotbarSize}px`);
|
||||
// #endregion Implementation
|
||||
};
|
||||
45
module/settings/repositionHotbar.mjs
Normal file
45
module/settings/repositionHotbar.mjs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { __ID } from "../consts.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
|
||||
const key = `repositionHotbar`;
|
||||
|
||||
export function repositionHotbar() {
|
||||
|
||||
const prevented = Hooks.call(`${__ID}.preventSetting`, key);
|
||||
if (!prevented) {
|
||||
Logger.log(`Preventing setting "${key}" from being registered`);
|
||||
return;
|
||||
};
|
||||
|
||||
// #region Registration
|
||||
Logger.log(`Registering setting: ${key}`);
|
||||
game.settings.register(__ID, key, {
|
||||
name: `OFT.setting.${key}.name`,
|
||||
hint: `OFT.setting.${key}.hint`,
|
||||
scope: `user`,
|
||||
type: Boolean,
|
||||
default: true,
|
||||
config: true,
|
||||
requiresReload: true,
|
||||
});
|
||||
// #endregion Registration
|
||||
|
||||
// #region Implementation
|
||||
if (game.settings.get(__ID, key)) {
|
||||
Logger.debug(`setting:${key} | Repositioning hotbar`);
|
||||
document.body.classList.add(`oft-${key}`);
|
||||
|
||||
const container = document.createElement(`div`);
|
||||
container.id = `oft-repositionHotbar-container`;
|
||||
|
||||
const playersPlaceholder = document.getElementById(`players`);
|
||||
const hotbarPlaceholder = document.getElementById(`hotbar`);
|
||||
|
||||
container.insertAdjacentElement(`afterbegin`, hotbarPlaceholder);
|
||||
container.insertAdjacentElement(`afterbegin`, playersPlaceholder);
|
||||
|
||||
const uiPosition = document.getElementById(`ui-left-column-1`);
|
||||
uiPosition.insertAdjacentElement(`beforeend`, container);
|
||||
};
|
||||
// #endregion Implementation
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue