MV Editing drawActorIcons()

Hi, I'd like to create a duplicate function of drawActorIcons(), except backward. As in, instead of having the state icons grow from left to right, I'd like it to show from right to left. This is the default code:
JavaScript:
Window_Base.prototype.drawActorIcons = function(actor, x, y, width) {
    width = width || 144;
    var icons = actor.allIcons().slice(0, Math.floor(width / Window_Base._iconWidth));
    for (var i = 0; i < icons.length; i++) {
        this.drawIcon(icons[i], x + Window_Base._iconWidth * i, y + 2);
    }
};
Make the x coordinate decrease with i, e.g. (untested):
JavaScript:
this.drawIcon(icons[i], x + width - Window_Base._iconWidth * (i + 1), y + 2);
I think the rest is OK as-is: you can copy the whole method into a .js file, edit that line, then import as a plugin. Remember to save to apply Plugin Manager changes before testing~
It works, although I just noticed that the state turn counters don't show for some reason...
Edit: Actually, I got them to appear now, but they are in the old location:
1635877290141.png

Edit2: Aha! I think I need to change this...
JavaScript:
Window_Base.prototype.processDrawIcon = function(iconIndex, textState) {
    this.drawIcon(iconIndex, textState.x + 2, textState.y + 2);
    textState.x += Window_Base._iconWidth + 4;
};
...no wait, maybe this...
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);
};
Turn counter display is not a core script feature. For YEP_BuffsStatesCore ("BSC") it looks like the relevant methods are drawStateTurns and drawStateCounter on Window_Base. (Similar for buffs.)

For this override, you could make a copy of Window_Base.prototype.drawActorIconsTurns with the following changes (untested):
  • Find this line: var shownMax = Math.floor(ww / iw);
    Add this immediately after: wx += ww - iw;

  • Find both lines like this: wx += iw;
    Replace them with this: wx -= iw;
I think this should load after BSC, and the suggestion from my previous post should load before BSC. Hopefully that all works out as intended! 😅

[Edit: corrected wx += ww; to wx += ww - iw;, explanation in follow-up post.]
@caethyril Thanks for all the help!
Edit: Almost got it, the only issue is that the state counter is too far to the right by 32px (1 icon's width).
1635884469872.png


Edit2: SOLVED! I fixed it by using wx += ww - iw; instead.
1635885230643.png
Oops! Try wx += ww - iw; instead of wx += ww;. (I'll edit my previous post.)

Explanation: the coordinates are for the top-left of the icon area, so the starting offset should be one icon-width (iw) less than the full icon area width (ww).

Original thread: https://forums.rpgmakerweb.com/threads/editing-drawactoricons.141703/