Help Fixing Selection Cursor (JIF Grid Inventory)

This is copy-pasted from my post in the plugin's release thread. I figured this would be a more appropriate place to post this. Apologies if it isn't. (maybe plugin requests is more fitting?) Anyways...

So I just installed your plugin and I'm loving it! I only have 1 tiny gripe with it though. It concerns the selection cursor thingy, and how it's 1 pixel too narrow. I tinkered w/ the js file and realized it isn't defined by the plugin, but rather rpg_windows.js. Here's what I'm talking about:
Thingy.png


Notice how the semi-transparent selection cursor is thinner on the right side. This is because the width is 1 pixel short vs the height (35px vs 36px). Here's the portion of code in rpg_windows.js that controls the sizing of the selection cursor:
JavaScript:
Window_Selectable.prototype.itemRect = function(index) {
    var rect = new Rectangle();
    var maxCols = this.maxCols();
    rect.width = this.itemWidth();
    rect.height = this.itemHeight();
    rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
    rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
    return rect;
};
If I change "rect.width = this.itemWidth();" -> "rect.width = this.itemWidth() + 1;" this resolves the issue and I get a perfect square of 36x36 pixels. However, this solution makes pretty much every other part of the game that uses the selection cursor look wonky.

So I thought of 2 possible solutions, but need assistance implementing it since my JS skills are limited.
  1. Introduce a conditional in rpg_windows.js so that if the selection cursor is being used for the items in the inventory (and not anywhere else, not even the category choices right above it like "Items, Weapon, Armor, etc"), then use "rect.width = this.itemWidth() + 1;", otherwise use "rect.width = this.itemWidth();".
  2. Add some code in the plugin's js file itself to use a customized selection cursor size. I've seen this done in SomeFire's SkillTreeSystem.js, which I will include the snippet of code for below.
JavaScript:
Skills_Window.prototype.updateCursor = function() {
    if (this.isCursorVisible()) {
        var rect = this.itemRect(this.index());

        if (SkillTreesSystem.skillCursorMargin) {
            this.setCursorRect(rect.x + this.spacing() / 2, rect.y + this.spacing() / 2,
                rect.width + this.spacing(), rect.height + this.spacing());
        } else
            this.setCursorRect(rect.x + this.spacing(), rect.y + this.spacing(), rect.width, rect.height);
    } else
        this.setCursorRect(0, 0, 0, 0);

For method #1, I'm thinking we could possibly use something like "Window_ItemList" for the conditional, but that's just a hunch.

I would greatly appreciate it if someone could help implement this fix, using any method you see fit. Thanks!

Edit: This is what I've come up with so far. Of course, it doesn't work, but I'm hoping someone can fix the syntax or find the proper conditional statement for me.
JavaScript:
Window_Selectable.prototype.itemRect = function(index) {
    var rect = new Rectangle();
    var maxCols = this.maxCols();
    if (this._Window_ItemList) {
      rect.width = this.itemWidth() + 1;
      rect.height = this.itemHeight();
      rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
      rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
      return rect;
    } else {
    rect.width = this.itemWidth();
    rect.height = this.itemHeight();
    rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
    rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
    return rect;
    }
};
You don't want to change the base classes.
Instead, you want to change the prototype function on the specific window in your example.
I can't promise this will work specifcally bc I'd need to know more about your plugin setup and your project state, but

JavaScript:
Skills_Window.prototype.itemRect = function(index){
    let rect = Window_Selectable.prototype.itemRect.call(this, index)
    rect.width = 36;
    return rect
}

This will call all of the normal code from Window_Selectable.prototype.itemRect, which is what would have happened when the Skills_Window object called it's itemRect.
However, before the rectangle is returned, this changes the width, then returns it. This will change only for this specific window, and not the rest of the game's windows that use Window_Selectable.prototype as their prototype
@standardplayer Thank you! Do I put this in the inventory plugin js or rpg_windows.js? And where should it be placed inside?

Attached is the inventory plugin in question.

Edit: I WORKS PERFECTLY! 😤
I changed Skills_Window to Window_ItemList since that seemed to make more sense. Not sure if it mattered, but it worked on the 1st attempt lol.
As long as it's working as you want, that's good.

Changing it to Window_ItemList means that it will simply replicate all of the functionality from that base window class. When you create a new window, you generally set it's prototype to the closes base class you're going for, so you can benefit from the functionality written in them.

Skills_Window would have been prototyped as one of those classes, but some of the functionality would also have been overwritten.

Either way, again, as long as you have what you need, that's good. Always be careful about editing those rpg window classes directly, though, that can have an effect on any window that uses the class you're editing. Sometimes you won't spot it right away, either, bc a lot of child classes do overwrite those functions on their own constructors. But they leave the bases alone
Yea leaving rpg_windows.js alone was a good call. I put the snippet of code in the JIF_GridInventory.js.

Original thread: https://forums.rpgmakerweb.com/threads/help-fixing-selection-cursor-jif-grid-inventory.123238/