MV How to align icons on the right side of skills?

Skill icons align left of skill names in the skill selection window, and I need them aligned to the right instead.

I can't seem to find where I can change this in windows.js. Any help?
If you look through the window types in that file, you'll get to find Window_SkillList, "The window for selecting a skill on the skill screen."

You then scroll through its functions until you see the drawItem() method which is clearly the place, as you can see it prints the item name and then its cost. There's no line there for an icon, so it must be a part of drawItemName().

Doing a search for that takes you back up to line 596, where you find drawItemName is a method of Window_Base. And right on lines 601 and 602 you can see it draws the icon followed by the text - so if you want to swap that, just swap those lines.

Note that this will change the formatting for every place that skills are listed. If you only want it in one place, you should copy that code and rename it to Window_SkillList.prototype.drawItemName and then make your changes.

Whether you do that or make it universal, you shouldn't change the actual lines in your rpg_windows.js file. Copy the function and put it in your own *.js, then include that as a plugin.
If you look through the window types in that file, you'll get to find Window_SkillList, "The window for selecting a skill on the skill screen."

You then scroll through its functions until you see the drawItem() method which is clearly the place, as you can see it prints the item name and then its cost. There's no line there for an icon, so it must be a part of drawItemName().

Doing a search for that takes you back up to line 596, where you find drawItemName is a method of Window_Base. And right on lines 601 and 602 you can see it draws the icon followed by the text - so if you want to swap that, just swap those lines.

Note that this will change the formatting for every place that skills are listed. If you only want it in one place, you should copy that code and rename it to Window_SkillList.prototype.drawItemName and then make your changes.

Whether you do that or make it universal, you shouldn't change the actual lines in your rpg_windows.js file. Copy the function and put it in your own *.js, then include that as a plugin.
Thank you. I swore I looked at Window_SkillList, but I must've just been very tired.

I've never made my own plugin before. This is a good learning experience, and trying to make a .js file out of this, I've done what you said, but it doesn't seem to actually work or overwrite anything.

(function() { var parameters = PluginManager.parameters('LZYSMK_SkillIconAlign'); var LzysmkRightIconDraw = Window_Base.prototype.drawItemName; Window_Base.prototype.drawItemName = function(item, x, y, width) { LzysmkRightIconDraw.call(this); width = width || 312; if (item) { var iconBoxWidth = Window_Base._iconWidth + 4; this.resetTextColor(); this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth); this.drawIcon(item.iconIndex, x + 2, y + 2); } };

Am I missing something that makes it actually call my new var when drawItemName is referenced in code?
Am I missing something that makes it actually call my new var when drawItemName is referenced in code?
You have a lot of unnecessary stuff there - I don't know what your knowledge/skill level is, so I mean no insult, but I wonder how much of that is you trying to copy formats that you've seen in other places.

(function() { var parameters = PluginManager.parameters('LZYSMK_SkillIconAlign');
For something this simplistic, there's no reason for you to create an IIFE or define plugin parameters.

Code:
    LzysmkRightIconDraw.call(this);
If this were working correctly, why would you want this? By calling the original function, it would print the skill icon then name...and then your code beneath would print it again.

All you need to do is take this:
Code:
Window_Base.prototype.drawItemName = function(item, x, y, width) {
    width = width || 312;
    if (item) {
        var iconBoxWidth = Window_Base._iconWidth + 4;
        this.resetTextColor();
        this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth);
        this.drawIcon(item.iconIndex, x + 2, y + 2);
    }
};
and paste it into Notepad. Save it as anything_you_want.js and add it in your plugin manager.

Save your project and start a new play test, check that it looks how you want.

Let us know if you still have any issues.

Am I missing something that makes it actually call my new var when drawItemName is referenced in code?
At a quick glance, I'm not sure what that open parenthesis at the very beginning of your code is for, but it never appears to be closed. The same is true for the open brace before "var parameters" so I don't think any of your code is getting run due to the incomplete syntax.
You have a lot of unnecessary stuff there - I don't know what your knowledge/skill level is, so I mean no insult, but I wonder how much of that is you trying to copy formats that you've seen in other places.


For something this simplistic, there's no reason for you to create an IIFE or define plugin parameters.


If this were working correctly, why would you want this? By calling the original function, it would print the skill icon then name...and then your code beneath would print it again.

All you need to do is take this:
Code:
Window_Base.prototype.drawItemName = function(item, x, y, width) {
    width = width || 312;
    if (item) {
        var iconBoxWidth = Window_Base._iconWidth + 4;
        this.resetTextColor();
        this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth);
        this.drawIcon(item.iconIndex, x + 2, y + 2);
    }
};
and paste it into Notepad. Save it as anything_you_want.js and add it in your plugin manager.

Save your project and start a new play test, check that it looks how you want.

Let us know if you still have any issues.


At a quick glance, I'm not sure what that open parenthesis at the very beginning of your code is for, but it never appears to be closed. The same is true for the open brace before "var parameters" so I don't think any of your code is getting run due to the incomplete syntax.
No offense taken, I'm definitely still a beginner, and yeah some pieces are just used from different tutorials on "How to make your first plugin".

Except the strange thing is my first attempt at the plugin was exactly what you just posted as the solution now. I tried it again once more to check, even on a new clean project, and it still doesn't work. Once that didn't work, that's when I started inserting unnecessary stuff like the parameters and var as an act of desperation haha.

My question from before still stands: If I redefine Window_Base.prototype.drawItemName in my own separate plugin, how does RPGmaker know to refer to mine instead of what's already in windows.js? It doesn't seem like it's being called. Or maybe the original windows.js version of the function is just taking priority?.
My question from before still stands: If I redefine Window_Base.prototype.drawItemName in my own separate plugin, how does RPGmaker know to refer to mine instead of what's already in windows.js?
It uses whatever is most recent (furthest down the plugin manager list). There is no way to tell it. However, I'm not smart (I won't blame you here 😛)

Actually looking at the function calls, it's not about what order theyr'e in - the coordinates to print this stuff on the screen is there. So the x and y coordinate arguments getting passed in need to be altered.

I'm writing this on my way out the door to work, so I'm not sure off the top of my head how to figure out the size in pixels of the skill's name. I can help more in a few hours if no one else corrects this.

But if you do something like this, you'll at least see a difference 🤣

Code:
this.drawText(item.name, x + 2, y, width - iconBoxWidth);
this.drawIcon(item.iconIndex, x + + width-iconBoxWidth, y + 2);
It uses whatever is most recent (furthest down the plugin manager list). There is no way to tell it. However, I'm not smart (I won't blame you here 😛)

Actually looking at the function calls, it's not about what order theyr'e in - the coordinates to print this stuff on the screen is there. So the x and y coordinate arguments getting passed in need to be altered.

I'm writing this on my way out the door to work, so I'm not sure off the top of my head how to figure out the size in pixels of the skill's name. I can help more in a few hours if no one else corrects this.

But if you do something like this, you'll at least see a difference 🤣

Code:
this.drawText(item.name, x + 2, y, width - iconBoxWidth);
this.drawIcon(item.iconIndex, x + 2, y + width-iconBoxWidth);
Window_Base has a function called textWidth that uses the contents bitmap's measureTextWidth function to determine how many pixels are needed to display a given string using the current font.

So you can use this.textWidth(item.name)
Alternatively, Bitmap#drawText has an alignment parameter, e.g.
JavaScript:
var w = width - Window_Base._iconWidth;
this.drawText(item.name, x, y, w - 4, "right");
this.drawIcon(item.iconIndex, x + w, y);
(If you were using drawTextEx instead, for text code support, then you'd need to draw, measure width, then redraw. MZ has a core-script method for that; MV doesn't.)
It uses whatever is most recent (furthest down the plugin manager list). There is no way to tell it. However, I'm not smart (I won't blame you here 😛)

Actually looking at the function calls, it's not about what order theyr'e in - the coordinates to print this stuff on the screen is there. So the x and y coordinate arguments getting passed in need to be altered.

I'm writing this on my way out the door to work, so I'm not sure off the top of my head how to figure out the size in pixels of the skill's name. I can help more in a few hours if no one else corrects this.

But if you do something like this, you'll at least see a difference 🤣

Code:
this.drawText(item.name, x + 2, y, width - iconBoxWidth);
this.drawIcon(item.iconIndex, x + + width-iconBoxWidth, y + 2);
So plugging this or the previous attempted code straight into windows.js (which I'm aware is bad practice, it's just for testing purposes) works perfectly as intended. It's when I try making my own separate .js plugin that it doesn't run for some reason. So thank you for the help so far, really appreciate that. As for why the plugin doesn't work, that's a different story I guess.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-align-icons-on-the-right-side-of-skills.152455/