@Eliaquim Thanks for your help and sorry for the delay in my reply. How you describes it, it works perfectly fine. I have another question and I do hope that you may be able to answer it.
My problem is that if I add the following code inside my window derived from the Window_Command class it add icons before the command name but from the beginning of the icons sprite sheet, and not what icon I wanna have.
JavaScript:
drawItem(index) {
super.drawItem(index);
this.drawIcon(index, this.itemRect(index).x + 20, this.itemRect(index).y + 4);
}
My question is if you know a way to specify, using this method, to draw specific icons via the addCommand method.
Hi!
The reason for it to draw the icons at the beginning of the icon sprite sheet is that you are inserting the
command index into the argument of the
icon index in the draw icon method.
JavaScript:
Window_Base.prototype.drawIcon = function(iconIndex, x, y) {
const bitmap = ImageManager.loadSystem("IconSet");
const pw = ImageManager.iconWidth;
const ph = ImageManager.iconHeight;
const sx = (iconIndex % 16) * pw;
const sy = Math.floor(iconIndex / 16) * ph;
this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
};
And since you are calling the
drawIcon method after the
super.drawItem(index), there is no way that the icon can be drawn before the command like in the screenshot I showed to you above.
It will overlap the first letters of the command text.
You can try setting
this.itemRect(index).x - ImageManager.iconWidth to draw the icon before the command text, but maybe it will go off the content
You can find a way to draw it after, calculating the
command name text width and setting the draw icon X coordinate to star on any value from there.
But as I can see, if you want to use the
drawIcon method, you will need to overwrite the
drawItem function, to first draw the icon, then start drawing the command text after the icon.
Also, you have to find a way to get the icon id you want for each command. I suggest you create an array property on your window or build it with plugin parameters. Then you get the icon id based on the command index:
JavaScript:
const iconArray = [13, 45, 30]
drawItem(index) {
super.drawItem(index); // You will have to overwrite the function for that.
const iconId = iconArray[index] //
this.drawIcon(iconId, this.itemRect(index).x + 20, this.itemRect(index).y + 4);
}