From 599a25c9717f0df8296af5264fde66027805254f Mon Sep 17 00:00:00 2001 From: jkl Date: Sun, 21 Dec 2025 06:39:42 +0100 Subject: [PATCH] Icons size fix --- js/plugins/IconScaler.js | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 js/plugins/IconScaler.js diff --git a/js/plugins/IconScaler.js b/js/plugins/IconScaler.js new file mode 100644 index 0000000..3256b4a --- /dev/null +++ b/js/plugins/IconScaler.js @@ -0,0 +1,41 @@ +/*: + * @target MZ + * @plugindesc Automatically scales icons in text (\I[x]) to match the current font size. + * @author 1x1x1x1 + * + * @help + * This plugin overrides the default processDrawIcon function. + * Instead of drawing icons at 32x32, it detects the current line height + * (font size) and scales the icon down to fit perfectly inline. + */ + +(() => { + Window_Base.prototype.processDrawIcon = function(iconIndex, textState) { + if (textState.drawing) { + const iconWidth = ImageManager.iconWidth; + const iconHeight = ImageManager.iconHeight; + const bitmap = ImageManager.loadSystem("IconSet"); + const pw = iconWidth; + const ph = iconHeight; + const sx = (iconIndex % 16) * pw; + const sy = Math.floor(iconIndex / 16) * ph; + + // Calculate the scale based on the text line height + // We subtract 2 pixels for a little breathing room/padding + const targetSize = textState.height - 2; + + // Center the icon vertically in the line + const yOffset = (textState.height - targetSize) / 2; + + this.contents.blt( + bitmap, + sx, sy, pw, ph, // Source coordinates (32x32) + textState.x, // Destination X + textState.y + yOffset,// Destination Y (centered) + targetSize, targetSize // Destination Size (Scaled) + ); + } + // Advance the text cursor by the width of the scaled icon + padding + textState.x += textState.height; + }; +})(); \ No newline at end of file