MV Images (like busts) in menu windows - Javascript help

Hello everyone! I start with the warning: I am a noob at Javascript. I barely know what I'm doing.

I have been making a plugin to customize my menus (RPG Maker MV), and while my code is probably shoddy and does stupid things, it's working so far! I am only moving things around and sometimes hiding parts I don't need. So far so good. But how do I go about adding images to menus? I'm specifically thinking about a bust for each actor that you could see in their status window.

I tried to investigate other plugins that do this, like Galv's and SRD's bust plugins, but unlike other times I looked at their code, this time around I have no idea how adding pictures that aren't faces or icons remotely work T_T And it's been very frustrating. I also tried reading the seemingly related core scripts and I'm still very confused.

Could someone be so kind (and... patient) to explain how I should add an image that isn't used in the Database for anything else? Having in mind that my plugin process has been just copying and pasting whatever I could read in the core scripts, and tinkering with it until it looks good? Maybe I just need to come back next weekend with a clearer mind, but some help would be very appreciated @_@

It would also be awesome to learn how to implement plugin commands, with the idea of changing these busts corresponding to each character depending on the story (I'm also going to change their sprites and faces, so...). However, that's a question for later, and I should start with the images haha.

Thank you very much! Regardless of how much help I can get here, I think I shall try again next weekend x)
I am a noob at Javascript. I barely know what I'm doing...I have been making a plugin...It would also be awesome to learn how to implement plugin commands
My personal, somewhat professional advice, is to do some proper tutorials. I like w3schools, starting with the Statements chapter, but there are many options if you Google it (and there are other things like YouTube classes and books and such).

It's less satisfying than moving stuff around in existing code and seeing what happens right away, but you'll actually understand what you're doing. And you'll start to understand the code that you're reading, so you'll be able to figure out answers by reading it.

I haven't looked at SRD's, but Galv's bust plugin is too advanced to hack around and figure stuff out that way - he creates an entire new sprite class for his bust images, with the associated methods.

Briefly, to draw an image that isn't a predefined type (e.g. face, icon, character...) you'd use the Bitmap.blt() function on the contents of a window.
My personal, somewhat professional advice, is to do some proper tutorials. I like w3schools, starting with the Statements chapter, but there are many options if you Google it (and there are other things like YouTube classes and books and such).

It's less satisfying than moving stuff around in existing code and seeing what happens right away, but you'll actually understand what you're doing. And you'll start to understand the code that you're reading, so you'll be able to figure out answers by reading it.

I haven't looked at SRD's, but Galv's bust plugin is too advanced to hack around and figure stuff out that way - he creates an entire new sprite class for his bust images, with the associated methods.

Briefly, to draw an image that isn't a predefined type (e.g. face, icon, character...) you'd use the Bitmap.blt() function on the contents of a window.

Thank you for replying!
My bad, I didn't clarify what I mean by being a Javascript noob x') I know the basics! I completed a two month course on HTML, CSS and Javascript o7. I wouldn't be trying to make plugins (even just moving things around!) if I didn't know at least that much haha. I am not doing things completely at random! But that doesn't mean I understand everything I read in the code.

I'm sure that someone with years of experience in Javascript will have an easier time, but I can't really just... spend years and years trying to find that experience just to add images to my silly menu x) If I can't find the way, then I will give up on it. I just wanted to ask in case someone got it figured out and wanted to try to explain it to me.

There doesn't seem to be resources for people at my level (that is, low, but not zero) that explain RPG Maker's code step by step (or, if there are, I don't know them). I did try to follow tutorial videos on this topic that I found, but things started going over my head by chapter 3 or 4, haha.

That said, I went to search the Bitmap.blt() function and while I tried some stuff, nothing is working. I just can't wrap my head around it, and I can't find info online that I can understand OTL
If you have some grounding in programming, I shouldn't think it would take years to become more familiar with JavaScript, but you know how your brain works better than I do.

There doesn't seem to be resources for people at my level (that is, low, but not zero) that explain RPG Maker's code step by step (or, if there are, I don't know them).
You can try looking up Trihan's Jump Into JavaScript posts, but those are primarily explaining in English what each function does. It's kind of assumed that if you need to understand them in more detail, like what's going on inside the function, that you can read the code.

That said, I went to search the Bitmap.blt() function and while I tried some stuff, nothing is working.
Well, you don't show anything you tried so I can't really help just based off "nothing is working" 😛

But if you look up any of the existing draw functions, like Window_Base.prototype.drawFace, you can see the example of how it loads the desired image file from disk, gets the coordinates to draw (which in your case would be the entire dimensions of the bust), then uses blt() on the window's contents at the bottom.
I'm back with the tinkering, hello.
You can try looking up Trihan's Jump Into JavaScript posts, but those are primarily explaining in English what each function does. It's kind of assumed that if you need to understand them in more detail, like what's going on inside the function, that you can read the code.
I did look it up, but (unless it isn't this one post I found), all the links are to rpgmaker.net, so they're all broken : (

Well, you don't show anything you tried so I can't really help just based off "nothing is working" 😛

But if you look up any of the existing draw functions, like Window_Base.prototype.drawFace, you can see the example of how it loads the desired image file from disk, gets the coordinates to draw (which in your case would be the entire dimensions of the bust), then uses blt() on the window's contents at the bottom.
Well then, I will show what I did, but be aware that there are lots of things I don't understand x')

First I will say that I did manage to include an icon in the Gold Window. I think I looked at Yanfly's core engine plugin to figure that one out. I found the drawIcon() function, so I searched it in the core files and found the parameters it used.

JavaScript:
Window_Base.prototype.drawIcon = function(iconIndex, x, y) {
    var bitmap = ImageManager.loadSystem('IconSet');
    var pw = Window_Base._iconWidth;
    var ph = Window_Base._iconHeight;
    var sx = iconIndex % 16 * pw;
    var sy = Math.floor(iconIndex / 16) * ph;
    this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
};

But this was already made! So it was easy for me to use, I only had to know iconIndex (which I set with a plugin parameter) x, and y. For this status window bust I'd have to write a new function similar to this one, right? But the problem is, I don't really understand fully what's going on inside this one x')

I understand that it creates a bitmap object? and for that it uses ImageManager.loadSystem('name of file'). I noticed there are several like this, loadSystem, loadPicture, loadFace... all in rpg_managers.js. They ask for a filename, and a hue. That part is alright. I understand they all have to do with each folder. (I wonder what I'd have to use if I wanted to let the parameter load a file instead of writing the path here? but that would be for later...)
Then there's all the pw, ph, sx and sy that I don't understand much. They are all used for the next function, this.contents.blt(), (why contents?). So I go search that... and I find this in rpg_core.js

JavaScript:
@method blt
 * @param {Bitmap} source The bitmap to draw
 * @param {Number} sx The x coordinate in the source
 * @param {Number} sy The y coordinate in the source
 * @param {Number} sw The width of the source image
 * @param {Number} sh The height of the source image
 * @param {Number} dx The x coordinate in the destination
 * @param {Number} dy The y coordinate in the destination
 * @param {Number} [dw=sw] The width to draw the image in the destination
 * @param {Number} [dh=sh] The height to draw the image in the destination
 */
Bitmap.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
    dw = dw || sw;
    dh = dh || sh;
    if (sx >= 0 && sy >= 0 && sw > 0 && sh > 0 && dw > 0 && dh > 0 &&
            sx + sw <= source.width && sy + sh <= source.height) {
        this._context.globalCompositeOperation = 'source-over';
        this._context.drawImage(source._canvas, sx, sy, sw, sh, dx, dy, dw, dh);
        this._setDirty();
    }
};

Well, that explains some, sx and sy. But what is pw and ph? Width and height of... what? Aren't many parameters missing from drawIcon? (but it works fine). Then my head is kinda exploding from that if alone, I don't get what this._context.globalCompositeOperation is doing, nor this._context.drawImage, nor this._setDirty().

So that's where I'm at. What am I supposed to do here? Include a new drawThing() somewhere? What should I even write to make it work? I tried to write this code for Window_Status, which obviously doesn't work (it doesn't do anything) but honestly I made it last week and I don't fully understand what I was doing myself lmao

JavaScript:
//I copied this from bitmap lol
Window_Status.prototype.bltImage = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
    dw = dw || sw;
    dh = dh || sh;
    if (sx >= 0 && sy >= 0 && sw > 0 && sh > 0 && dw > 0 && dh > 0 &&
        sx + sw <= source.width && sy + sh <= source.height) {
        this._context.globalCompositeOperation = 'source-over';
        this._context.drawImage(source._image, sx, sy, sw, sh, dx, dy, dw, dh);
        this._setDirty();
    }
};

Window_Status.prototype.drawBlock3 = function(y) {
    this.drawParameters(48, y);
    this.drawEquipments(432, y);
    //test
    var bitmap = ImageManager.loadSystem('Busto Fendi');
    // I think s is source and d is destination. width, height, x and y
    var sw = 475;
    var sh = 753;
    var sx = 0;
    var sy = 0;
    var dx =  0;
    var dy = 0;
    var dw = sw;
    var dh = sh;

    this.bltImage(bitmap, sx, sy, sw, sh, dx, dy, dw, dh);
    
};

Anyway I hope this clarifies where I'm at! Hopefully this will make it easier to help me add an image to this menu hahah
Then there's all the pw, ph, sx and sy that I don't understand much.
Which parts don't you understand? They're all described above the function definition in the code that you quoted.

JavaScript:
@method blt
 * @param {Bitmap} source The bitmap to draw
 * @param {Number} sx The x coordinate in the source
 * @param {Number} sy The y coordinate in the source
 * @param {Number} sw The width of the source image
 * @param {Number} sh The height of the source image
 * @param {Number} dx The x coordinate in the destination
 * @param {Number} dy The y coordinate in the destination
 * @param {Number} [dw=sw] The width to draw the image in the destination
 * @param {Number} [dh=sh] The height to draw the image in the destination
 */

They are all used for the next function, this.contents.blt(), (why contents?).
Because contents is the bitmap property of a window that actually displays what you see.

Code:
/**
 * The bitmap used for the window contents.
 *
 * @property contents
 * @type Bitmap
 */
Object.defineProperty(Window.prototype, 'contents', {
    get: function() {
        return this._windowContentsSprite.bitmap;
    },
    set: function(value) {
        this._windowContentsSprite.bitmap = value;
    },
    configurable: true
});

Well, that explains some, sx and sy. But what is pw and ph? Width and height of... what?
The names of variables passed as arguments have nothing to do with how those parameters are named in the actual function.

It makes no difference whether this example uses 4, 3, declares variables named apple, orange, or whatever else. They're still used inside the function in the order they were input.

1729292221166.png


Aren't many parameters missing from drawIcon?
Yes, but if the code checks for them to exist and doesn't try to reference them when they're not, then that doesn't matter. It's moderately common to have functions with optional arguments.

So that's where I'm at. What am I supposed to do here?
Load an image, then put it in your window.

Your code has a number of problems. For one, why on Earth are you making up your own bltImage() function? Especially when it's a direct copy of the existing blt() function. What's the point of that?

The image doesn't work because you're calling this.bltImage() - you saw in the example you looked at that the bitmap to receive the image was this.contents so why would you write yours as just this, which is a Window_Status object? That has no visual properties to be seen.

As a side note, you should not have non-URL-compliant characters in your filenames (such as the space in "Busto Fendi"). That can cause the files to not load and crash your game when the project is deployed.
Hello, I'm back trying again. o/
Which parts don't you understand? They're all described above the function definition in the code that you quoted.
Yes, that's what I said later : )
Because contents is the bitmap property of a window that actually displays what you see.

Code:
/**
 * The bitmap used for the window contents.
 *
 * @property contents
 * @type Bitmap
 */
Object.defineProperty(Window.prototype, 'contents', {
    get: function() {
        return this._windowContentsSprite.bitmap;
    },
    set: function(value) {
        this._windowContentsSprite.bitmap = value;
    },
    configurable: true
});
Thank you for bringing this up. However, and again, because I'm a noob (I guess that's why), this goes way over my head x) Same way that I don't understand why "this" is always used, but I used it just by looking at and imitating the other functions. In this case, I guess I simply didn't look well, and missed the "contents" part.

Not asking for you to explain further though! I'm just explaining why I make the mistakes I make. I barely understand what I do, which is why I try not to touch what I don't understand lmao
Your code has a number of problems. For one, why on Earth are you making up your own bltImage() function? Especially when it's a direct copy of the existing blt() function. What's the point of that?
Why on Earth XD? Well, that's most likely because I tried using it as it was (Bitmap.prototype.bltImage()) and the game crashed and said it wasn't defined (I remember something along those lines). I'm sure it must have been because I had to call it in a specific way and I didn't know how, so I copied it (transforming it into "Window_Status.prototype.") to see if it worked. It didn't, lol! But it didn't crash again. Maybe not progress, but also not-not progress?

The image doesn't work because you're calling this.bltImage() - you saw in the example you looked at that the bitmap to receive the image was this.contents so why would you write yours as just this, which is a Window_Status object? That has no visual properties to be seen.

As a side note, you should not have non-URL-compliant characters in your filenames (such as the space in "Busto Fendi"). That can cause the files to not load and crash your game when the project is deployed.
I most likely missed it. Again, I don't even understand why it needs to use this, or this.contents, so it makes sense that I didn't know which one to use. I'm merely making a franken-code and seeing if it walks x) Still, I appreciate it, even if I'm just parroting, I'm thankful for how to correctly parrot things, haha.

With all this in mind, I tried again. Funnily, the first step worked! The image is visible (poorly placed, but that's for me to fix next). There is one big inconvenient, though... it only shows up the second time I open the status menu, and not the first. I assume it doesn't have time to load, say "I'm ready, you can show the menu" and so it doesn't show up. But I don't know how to fix that or what to investigate next.

I will show my code next in case you can see the problem.


JavaScript:
//a new function that is heavily referenced from drawFace
Window_Status.prototype.drawBust = function(filename, x, y) {
    var bitmap = ImageManager.loadSystem(filename, 0);
    //source width and height
    var sw = 475;
    var sh = 753;
    //source x and y
    var sx = 0;
    var sy = 0;
    //destination x and y
    var dx = x;
    var dy = y;
    this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
};

//I chose drawBlock3 for no real reason. I could make a new block
Window_Status.prototype.drawBlock3 = function(y) {
    this.drawParameters(48, y);
    this.drawEquipments(432, y);
    //test
    this.drawBust('bustofendi', 0, 0)
};

Sorry for the long post and thank you for the patience o7. There are lots of problems after I fix this one thing too, but progress is progress haha.

EDIT: I got help somewhere else and managed to preload the image, so now it works the first time : ) I called this function in my plugin:

JavaScript:
ImageManager.reserveSystem('bustofendi')

Now, I will work in my next step, which will probably be... to associate different images to different actors so it only shows up depending on which one you open. I will investigate on my own first! Is it okay if I double post whenever I need to ask again about it? (better than an entire new post, I assume?)

Original thread: https://forums.rpgmakerweb.com/threads/images-like-busts-in-menu-windows-javascript-help.172569/