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
243
Reaction score
137
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,527
Reaction score
1,570
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
243
Reaction score
137
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,986
Reaction score
2,304
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
243
Reaction score
137
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,986
Reaction score
2,304
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
243
Reaction score
137
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
243
Reaction score
137
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,116
Reaction score
5,971
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

aww man, color hex code #C4C4C4 doesn't work for the tint value in this scene I need something darker, which stinks just because I liked that one it was my favorite plastic explosive three times...#696969 (nice) should work better (WHY IS MY BRAIN LIKE THIS)
Tell it to me straight, doc. If I've been trying to piece together a "shorter" game to learn stuff outside of game jams... am I just running away from my WIP? :v
Well, I've got a party tomorrow, and my friends are coming over. I wanted to work a bit on the Fandom Scouts assets so I can be ready when that update arrives... in other news, Pizza Time Horror is getting a second teaser, and it shows Cabaret Helen's last performance before the location closed.
Also who used to be scared of Chuck E as a kid? I was! Now I love him!
The new cards and what they do:

(I am clearly not a youtuber... Haha)

Forum statistics

Threads
117,282
Messages
1,106,104
Members
153,460
Latest member
janekste
Top