As the token square is already busy due to the border, the status effect indicators get hidden. Move them entirely to the right of the token, so they don't conflict anymore. Do it only for PCs, as NPC tokens do not have the border and the GM will probably have their token UI open more often, which would hide the status effect indicators.
59 lines
2.5 KiB
JavaScript
59 lines
2.5 KiB
JavaScript
import * as MillsFabula from "./mills_fabula.mjs";
|
|
|
|
const TokenUiSettings = Object.freeze({
|
|
Enabled: "uiAdjustEnabled",
|
|
})
|
|
|
|
Hooks.once("setup", () => {
|
|
game.settings.register(MillsFabula.id, TokenUiSettings.Enabled, {
|
|
name: "MF.TokenUiAdjust.Settings.Enabled.Name",
|
|
hint: "MF.TokenUiAdjust.Settings.Enabled.Hint",
|
|
type: Boolean,
|
|
config: true,
|
|
scope: "world",
|
|
requiresReload: true,
|
|
default: true,
|
|
})
|
|
|
|
if (!game.settings.get(MillsFabula.id, TokenUiSettings.Enabled)) {
|
|
return;
|
|
}
|
|
|
|
/** Padding above and below the token, percentage of a grid square. */
|
|
const top_bot_padding = 5;
|
|
/** Padding left and right the token, percentage of a grid square. */
|
|
const left_right_padding = 5;
|
|
|
|
Hooks.on("drawToken", (drawn_token) => {
|
|
/*
|
|
* Drawing attribute bars and nameplates are handled by private functions called
|
|
* after the `drawToken` hook. That means that we cannot change their position in this hook.
|
|
*
|
|
* We could update them in the `refreshToken` hook, which works, but is called a lot more than
|
|
* necessary and needs a view update (move the view) from the canvas to show the updates.
|
|
*
|
|
* Instead : we can replace the draw functions handling the bars and nameplate.
|
|
* They are still useful, so make of copy bound to the drawn token so that we can call them
|
|
* in our replacement function, then make the changes that we need.
|
|
*/
|
|
let base_drawBar = drawn_token._drawBar.bind(drawn_token);
|
|
drawn_token._drawBar = (number, bar, data) => {
|
|
const token_height = drawn_token.getSize().height
|
|
const padding = drawn_token.scene.grid.size * top_bot_padding/100;
|
|
base_drawBar(number, bar, data)
|
|
bar.position.set(0, token_height + padding + number * bar.height)
|
|
}
|
|
|
|
let base_refreshNameplate = drawn_token._refreshNameplate.bind(drawn_token);
|
|
drawn_token._refreshNameplate = () => {
|
|
const token_width = drawn_token.getSize().width;
|
|
const padding = drawn_token.scene.grid.size * top_bot_padding/100;
|
|
base_refreshNameplate()
|
|
drawn_token.nameplate.position.set(token_width/2, -(padding + drawn_token.nameplate.height))
|
|
}
|
|
|
|
if (drawn_token.document.hasPlayerOwner)
|
|
drawn_token.effects.position.x += drawn_token.getSize().width +
|
|
drawn_token.scene.grid.size * (left_right_padding/100);
|
|
})
|
|
})
|