MZ Update Image when Index is In Use

Hey ya'll ! Been a while

I'm working on Window_MenuBase, specifically the following function:

Spoiler: Window_MenuStatus.prototype.drawItemImage
Window_MenuStatus.prototype.drawItemImage = function(index) {
const actor = this.actor(index);
const rect = this.itemRect(index);
let width;
let height;

this.setBackgroundType(2);

// Background Image Setup
const isPending = this._pendingIndex === index;
// const backgroundImage = isPending ? "flyerB_trans" : "flyerB_trans_" + String(index);
const backgroundImage = "flyerB_trans_" + String(index);
const bgShadow = "flyerB_shadow";
const bgWidth = rect.width * 92/100;
let bgHeight = rect.height * 95/100;
const bgX = rect.x + rect.width * 2/100;/
const bgY = rect.y + rect.height - bgHeight;
const offSet = 4;
// Draw the background image BEFORE actor images
this.drawBackgroundImage(bgShadow, bgX + offSet, bgY + offSet, bgWidth, bgHeight); // draw Shadow first
this.drawBackgroundImage(backgroundImage, bgX, bgY, bgWidth, bgHeight);

// Actor Image Processing
let mPicture = ExMenuScreenBase.getImageName(actor.actorId());
if (mPicture && showStandingPicture) {
width = rect.width - 2;
height = rect.height - 2;
let x = rect.x - 10;// + 10;// - 18;// + 1;
let y = rect.y + 20;
let sx = (Number(mPicture.x) + menuWindowPictureX) * -1;
let sy = (Number(mPicture.y) + menuWindowPictureY) * -1;
let scaleX = Number(mPicture.scaleX) / 100;
let scaleY = Number(mPicture.scaleY) / 100;

// Global Scaling
scaleX *= menuWindowPictureScale / 100;
scaleY *= menuWindowPictureScale / 100;

this.drawStandingPicture(String(mPicture.imageName), x, y, width, height, sx, sy, scaleX, scaleY);
}
this.changePaintOpacity(true);
};


I've already figured out how to update the background image if the index is OK'd (thats the commented out `const backgroundImage = isPending` line; when doing formation changes).

What i'm struggling with is when the cursor simply on an index (in red here)

1740861504171.png


Triggering the image change. I initially thought hooking into `select` but I haven't been successful, as the imagge only updates on OK still lol.

SOLVED:

See fix explanation below:

Spoiler: Solved: Code
So as I suspected and you pointed to, i def had to alias `select` however i needed to prevent the crash, quick fix was:

const Nowis_337_Window_MenuStatus_prototype_select = Window_MenuStatus.prototype.select;
Window_MenuStatus.prototype.select = function(index){
Nowis_337_Window_MenuStatus_prototype_select.call(this, index);
if (this._index >= 0) this.refresh();
}

and for the actuual background image:

const isCurrent = this._index === index;
const backgroundImage = isCurrent ? "flyerB_trans" : "flyerB_trans_" + String(index);
If I understand correctly, you're trying to have the image change when you move the cursor to highlight the character but without pressing 'ok'?
If I understand correctly, you're trying to have the image change when you move the cursor to highlight the character but without pressing 'ok'?
Correct
Code:
const isPending = this._pendingIndex === index || index == this.index();
You can try this to flag the image change while index is pending (used for formation change) or when the selection cursor highlights the character.

If the images are not refreshing when you move the cursor around, might have to tack on a 'refresh' with the select function:
Code:
const Alias_Window_MenuStatus_prototype_select = Window_MenuStatus.prototype.select;
Window_MenuStatus.prototype.select = function(index){
    Alias_Window_MenuStatus_prototype_select.call(this, index);
    this.refresh();

}
@Nowis-337

I Tried that earlier but ran into this error:

1740867314592.png


the issuue is less the flag, as this error occuurs regardless. But i do still need help determining the proper flag as well. The isPending was for when OK does happen and its keepingg an actor selected for formation changges



EDIT: I GOT ITTTTT

So as I suspected and you pointed to, i def had to alias `select` however i needed to prevent the crash, quick fix was:

const Nowis_337_Window_MenuStatus_prototype_select = Window_MenuStatus.prototype.select;
Window_MenuStatus.prototype.select = function(index){
Nowis_337_Window_MenuStatus_prototype_select.call(this, index);
if (this._index >= 0) this.refresh();
}

and for the actuual background image:

const isCurrent = this._index === index;
const backgroundImage = isCurrent ? "flyerB_trans" : "flyerB_trans_" + String(index);

We're good to go!
This thread is closed due to being reported as solved. If you need this thread reopened, report it to let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/update-image-when-index-is-in-use.175916/