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
241
Reaction score
136
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,526
Reaction score
1,569
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
241
Reaction score
136
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,984
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
241
Reaction score
136
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,984
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
241
Reaction score
136
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
241
Reaction score
136
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,970
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 Profile Posts

Lots of not good things happening IRL but I'm not gonna let this day end like this. Quote time:
"Success is not final, failure is not fatal: it is the courage to continue that counts." -Winston Churchill

So, keep going, lads. Whatever you do keep going. Until next time.

It's a Spanish devlog don't get scared!. (please)
Q:"Why don't you get a job?"
A: Posting statuses IS my job. It just so happens to not pay and happen periodically over the course of three months.
My new 49" monitor has been dispatched from the warehouse. Will it arrive tomorrow? The day after? I love that we can track packages now, even if it does only tell me when it's left that end and when it's arrived at the local centre. As long as it doesn't end up in Melbourne again, which has happened before ...

Forum statistics

Threads
117,238
Messages
1,105,778
Members
153,402
Latest member
maurosanfi
Top