RMMV Where is the Window_ShopBuy refresh func that occurs for each cursor move?(SOLVED)

Status
Not open for further replies.

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
Been going over the Window_ShopBuy in order to try and find out where the best place to set a "refresh" for another Window. But I am unsuccesful in finding this. I want to update a window each time I move from one item to another. But the Window_ShopBuy.refresh() only refreshes every time you move from the bottom to the top and vice versa. I.e. pressing the down button at the bottom of the list.

Any help on where to find this, or if there is a better way to update a window?

Best regards,
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,520
Reaction score
1,566
First Language
Spanish
Primarily Uses
RMVXA
the window is always refreshing..... that refresh drives the cursor blink.
what you're talking about, is a redraw, which is not the same thing.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
the window is always refreshing..... that refresh drives the cursor blink.
what you're talking about, is a redraw, which is not the same thing.
Why are you having an attitude?
I am not an advanced programmer, asking for help so I can improve.

I can tell you that the refresh is not constantly refreshing however.
Modifying Window_ShopBuy.prototype.refresh() to the below code doesn't continuously log "hello". It only logs "hello" when I move from the top/bottom to the bottom/top.
JavaScript:
Window_ShopBuy.prototype.refresh = function() {
    this.makeItemList();
    this.createContents();
    this.drawAllItems();
    console.log("hello");
};

I want to call a function every time I move down or up in the list.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
In rpg_windows.js, notice that Window_ShopBuy inherits from Window_Selectable:
JavaScript:
Window_ShopBuy.prototype = Object.create(Window_Selectable.prototype);
Tracing this back, you can discover methods like cursorDown:
JavaScript:
Window_Selectable.prototype.cursorDown = function(wrap) {
    var index = this.index();
    var maxItems = this.maxItems();
    var maxCols = this.maxCols();
    if (index < maxItems - maxCols || (wrap && maxCols === 1)) {
        this.select((index + maxCols) % maxItems);
    }
};
Here we can see that it ultimately calls select to change the index.

With that in mind, consider hooking into the select method of Window_ShopBuy, e.g.
JavaScript:
(function(alias) {
  Window_ShopBuy.prototype.select = function(index) {
    alias.apply(this, arguments);
    // your update code here
  };
})(Window_ShopBuy.prototype.select);
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
In rpg_windows.js, notice that Window_ShopBuy inherits from Window_Selectable:
JavaScript:
Window_ShopBuy.prototype = Object.create(Window_Selectable.prototype);
Tracing this back, you can discover methods like cursorDown:
JavaScript:
Window_Selectable.prototype.cursorDown = function(wrap) {
    var index = this.index();
    var maxItems = this.maxItems();
    var maxCols = this.maxCols();
    if (index < maxItems - maxCols || (wrap && maxCols === 1)) {
        this.select((index + maxCols) % maxItems);
    }
};
Here we can see that it ultimately calls select to change the index.

With that in mind, consider hooking into the select method of Window_ShopBuy, e.g.
JavaScript:
(function(alias) {
  Window_ShopBuy.prototype.select = function(index) {
    alias.apply(this, arguments);
    // your update code here
  };
})(Window_ShopBuy.prototype.select);
Thanks!

Yeah, that rings a bell, I was there before. But upon looking at it, I was rather skeptical. I forgot to write this in my question actually. I've set shop to be the active Scene_Shop.
1634740825717.png

I am very skeptical to change this as it doesn't really seem correct, and this is naturally since I am using the Yanfly.ctb. In essence, I do not understand, at all, how this works :/
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
I am very skeptical to change this as it doesn't really seem correct, and this is naturally since I am using the Yanfly.ctb. In essence, I do not understand, at all, how this works :/
:kaohi: No worries there! An alias/patch approach like I described simply adds extra code to run before and/or after what it already does. It doesn't matter what the method does before patching: it gets invoked as part of the new method definition.

Put another way, these two code snippets function identically:
JavaScript:
(function(alias) {   // IIFE argument (i.e. local variable) is named "alias"
  Window_ShopBuy.prototype.select = function(index) {   // override method
    alias.apply(this, arguments);   // invoke stored method
    // your code here
  };
})(Window_ShopBuy.prototype.select);   // pass current "select" method in as an IIFE argument
JavaScript:
(function() {        // IIFE to hide _Window_ShopBuy_select from the global scope
  var _Window_ShopBuy_select = Window_ShopBuy.prototype.select;   // store current "select" method
  Window_ShopBuy.prototype.select = function(index) {   // override method
    _Window_ShopBuy_select.apply(this, arguments);   // invoke stored method
    // your code here
  };
})();
Overriding and/or storing methods is a big part of why plugin load order matters so much.

Just for interest, I think the code you quoted says something like this:
  • If the party is in battle and Charge Turn Battle mode is active, then:
    • Clear the charge counters for all party members.
  • Then run the select method of Window_Selectable, as it was immediately before Yanfly's CTB plugin loaded.
I'm unsure why Yanfly didn't store/invoke the Window_ShopBuy version of that method (probably just an oversight); regardless, it doesn't seem to directly conflict with anything on the shop scene.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
:kaohi: No worries there! An alias/patch approach like I described simply adds extra code to run before and/or after what it already does. It doesn't matter what the method does before patching: it gets invoked as part of the new method definition.

Put another way, these two code snippets function identically:
JavaScript:
(function(alias) {   // IIFE argument (i.e. local variable) is named "alias"
  Window_ShopBuy.prototype.select = function(index) {   // override method
    alias.apply(this, arguments);   // invoke stored method
    // your code here
  };
})(Window_ShopBuy.prototype.select);   // pass current "select" method in as an IIFE argument
JavaScript:
(function() {        // IIFE to hide _Window_ShopBuy_select from the global scope
  var _Window_ShopBuy_select = Window_ShopBuy.prototype.select;   // store current "select" method
  Window_ShopBuy.prototype.select = function(index) {   // override method
    _Window_ShopBuy_select.apply(this, arguments);   // invoke stored method
    // your code here
  };
})();
Overriding and/or storing methods is a big part of why plugin load order matters so much.

Just for interest, I think the code you quoted says something like this:
  • If the party is in battle and Charge Turn Battle mode is active, then:
    • Clear the charge counters for all party members.
  • Then run the select method of Window_Selectable, as it was immediately before Yanfly's CTB plugin loaded.
I'm unsure why Yanfly didn't store/invoke the Window_ShopBuy version of that method (probably just an oversight); regardless, it doesn't seem to directly conflict with anything on the shop scene.
Going through it right now. Trying it with a different function at the moment. Doesn't seem to work, any ideas?
JavaScript:
(function() {        // IIFE to hide _Game_Party_gainItem from the global scope
  var _Game_Party_gainItem = Game_Party.prototype.gainItem;   // store current "gainItem" method
  Game_Party.prototype.gainItem = function(item, amount, includeEquip) {   // override method
    _Game_Party_gainItem.apply(this, arguments);   // invoke stored method
    // your code here
    console.log("Hello there :)")
  };
})();
Best regards,

EDIT: Seems all I had to do was place the function at the end of the .js and it worked.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
In rpg_windows.js, notice that Window_ShopBuy inherits from Window_Selectable:
JavaScript:
Window_ShopBuy.prototype = Object.create(Window_Selectable.prototype);
Tracing this back, you can discover methods like cursorDown:
JavaScript:
Window_Selectable.prototype.cursorDown = function(wrap) {
    var index = this.index();
    var maxItems = this.maxItems();
    var maxCols = this.maxCols();
    if (index < maxItems - maxCols || (wrap && maxCols === 1)) {
        this.select((index + maxCols) % maxItems);
    }
};
Here we can see that it ultimately calls select to change the index.

With that in mind, consider hooking into the select method of Window_ShopBuy, e.g.
JavaScript:
(function(alias) {
  Window_ShopBuy.prototype.select = function(index) {
    alias.apply(this, arguments);
    // your update code here
  };
})(Window_ShopBuy.prototype.select);
So... That means that because Window_EquipItem.prototype inherits from Window_ItemList.prototype, does that mean that there is no update per cursor move? Because I want to update StatusWindow everytime the EquipItem cursor changes item...

JavaScript:
Window_EquipItem.prototype = Object.create(Window_ItemList.prototype);

And I assume that since the EquipItem does have a select function, I can't overwrite it since it gets it frm the Selectable Window. So the best way to do it, I guess, would be with the below code? It does work, just wondering if this is a way to do it that you think is best.
JavaScript:
(function(alias) {   // IIFE argument (i.e. local variable) is named "alias"
  Window_EquipItem.prototype.select = function(index) {   // override method
    alias.apply(this, arguments);   // invoke stored method
    // your code here
    console.log(22);
  };
})(Window_EquipItem.prototype.select);   // pass current "select" method in as an IIFE argument

Figured it out now, thanks for the responses on this thread and the other Caethyril! :D
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,115
Reaction score
5,968
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I'm just so close to replacing LUK with a different stat, maybe DEX but we'll see.
Slapped together a title screen and working on some dungeon clutter + portraits for Dubhghaill and Einar. Usual CW for minor body horror wrt Einar
QVLJIgD.png

OaPcYUy.png

r55FiUJ.png

EIgO94y.png
cT1V4nb.png
>studying for months for an exam
>does exam
>waits 3 months for the results to come out
>me trying to login, incorrect password
>I get recovery password
>me trying to login, incorrect password

What the heck. As a son of a Karen, I'm going to file a few complaints.

Forum statistics

Threads
117,145
Messages
1,104,938
Members
153,214
Latest member
jzu1999
Top