RMMV Problem with the Window_ItemCategory choices. (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
Hi!

I am trying to set up the shop window and by extension the sell window. And the way I find a design that might work is to have a 2x2 selector for the category, but upon doing this it just looks like this:
1635072992789.png
JavaScript:
Window_ItemCategory.prototype.maxCols = function() {
    return 2;
};

Window_ItemCategory.prototype.numVisibleRows = function() {
    return 2;
};

I haven't really changed/added mor than these functions in regards to the category window. Apart from just sizing it.

You can move around in the four areas just fine, but two categories are missing, and they are not visible nor can they be found. It just looks exactly this way regardless of where you move the cursor. Any idea if this is fixable? :/

EDIT:
I am having a similar, probably related-ish, situation with the Window_ShopNumber. The width is set to the above window, they share the same x-value. But the width is determined by some type of padding rules. But I do not know where to find these settings.
1635073605601.png
JavaScript:
Scene_Shop.prototype.createNumberWindow = function() {
    var wx = this._actorWindow.x;
    var wy = this._commandWindow.y + this._commandWindow.height;
    var wh = this._buyWindow.height;
    var ww = this._actorWindow.width;
    this._numberWindow = new Window_ShopNumber(wx, wy, wh, ww);
    this._numberWindow.hide();
    this._numberWindow.setHandler('ok',     this.onNumberOk.bind(this));
    this._numberWindow.setHandler('cancel', this.onNumberCancel.bind(this));
    this.addWindow(this._numberWindow);
};

Best regards,
Bishiba
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
I haven't tested, but what you've described sounds like the right approach. However...
I haven't really changed/added mor than these functions in regards to the category window. Apart from just sizing it.
From the screenshot I'm guessing you resized it to half the original width? You should manually recreate the contents bitmap after resizing, e.g.
JavaScript:
this.width = Graphics.boxWidth / 2;
this.createContents();
Alternatively, in this case you could call this.refresh(), since Window_Command's refresh invokes createContents. :kaophew:

I am having a similar, probably related-ish, situation with the Window_ShopNumber. The width is set to the above window, they share the same x-value. But the width is determined by some type of padding rules. But I do not know where to find these settings.
The width of Window_ShopNumber is determined by one of its own methods, its constructor does not expect a "width" argument:
JavaScript:
Window_ShopNumber.prototype.initialize = function(x, y, height) {
    var width = this.windowWidth();
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._item = null;
    this._max = 1;
    this._price = 0;
    this._number = 1;
    this._currencyUnit = TextManager.currencyUnit;
    this.createButtons();
};

Window_ShopNumber.prototype.windowWidth = function() {
    return 456;
};
It seems to use a lot of hard-coded values for spacing etc, I assume that's why it's set up like that. :kaoslp:
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
The solution:

In rpg_windows.js you'll find both lines:
JavaScript:
Window_ItemCategory.prototype.windowWidth = function() {
    return Graphics.boxWidth;

Window_ShopNumber.prototype.windowWidth = function() {
    return 456;
};
};
Essentially a way for them to save on passing in arguments. The same goes for the Window_Number.
All you need to do for Window_ShopNumber is this:
JavaScript:
Window_ShopNumber.prototype.initialize = function(x, y, height, width) {//Write the full function and add "width" to initialize.
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    width = width || this.windowWidth(); //If "width" has been parsed as an argument set it to "width", otherwise set it to default.
    this._item = null;
    this._max = 1;
    this._price = 0;
    this._number = 1;
    this._currencyUnit = TextManager.currencyUnit;
    this.createButtons();
};

However, Window_ItemCategory is a bit more tricky as it uses a superclass, so if you're gonna use the same approach I believe you'd need to change each called function all the way to the Window_Command superclass. The approach I used, is quicker and more efficient. But doesn't seem to work. I guess when the this is called, it probably refers to the superclass rather than the new window.
But I don't know. It feels shoddy adding a private variable just for this. But perhaps this is the best approach?
Code:
Scene_Shop.prototype.createCategoryWindow = function() {
    this._userWidth = this._commandWindow.width; //Setting the width of the category window.
    //Original code in this function
}

Window_ItemCategory.prototype.windowWidth = function() {//Change the function of the windowWidth for Window_ItemCategory.
    return this._userWidth ? this._userWidth : Graphics.boxWidth;
};

Any thoughts on this approach?

I haven't tested, but what you've described sounds like the right approach. However...

From the screenshot I'm guessing you resized it to half the original width? You should manually recreate the contents bitmap after resizing, e.g.
JavaScript:
this.width = Graphics.boxWidth / 2;
this.createContents();
Alternatively, in this case you could call this.refresh(), since Window_Command's refresh invokes createContents. :kaophew:


The width of Window_ShopNumber is determined by one of its own methods, its constructor does not expect a "width" argument:
JavaScript:
Window_ShopNumber.prototype.initialize = function(x, y, height) {
    var width = this.windowWidth();
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._item = null;
    this._max = 1;
    this._price = 0;
    this._number = 1;
    this._currencyUnit = TextManager.currencyUnit;
    this.createButtons();
};

Window_ShopNumber.prototype.windowWidth = function() {
    return 456;
};
It seems to use a lot of hard-coded values for spacing etc, I assume that's why it's set up like that. :kaoslp:
What do you think of my approach?

FYI:
It's not half, but close. It is actually command Window and the window just to the right of it. And it is gonna be the actor window.
Then I just placed the category on top of the command and actor window whilst hiding those windows as they are not relevant whilst in the sell screen.
Then the status screen will still be showing on the right hand side of the screen.

Update:
I changed the way I do the category window based on @caethyril 's suggestion regarding invoking the refresh() function. That works. But now I want to add an alias function to it so I can add the new code to the existing function. But it doesn't seem to work. Can you spot what I am doing wrong?
JavaScript:
(function(alias) {
    Scene_Shop.prototype.createCategoryWindow = function(index) {
        alias.apply(this, arguments);
            this._categoryWindow.copyFormat(this._commandWindow);
            this._categoryWindow.width += this._actorWindow.width;
            this._categoryWindow.refresh();
    };
})(Scene_Shop.prototype.createCategoryWindow);

The error is 1635080669581.png
so my guess is that it doesn't get the function properly for some reason.

Update 2:
Very, very confused now...
1635081244168.png
*************************************************************************************************************
The below is from the console "sources" section. In the rpg_scenes.js.
1635081228547.png
*************************************************************************************************************
This is the return you get from asking for the function in the console.
1635081336337.png
1635081228547.png
*************************************************************************************************************

I've removed any mention of Scene_Shop.prototype.createCategoryWindow from any and all of my plugins, even removed them as comments... Saved, reloaded...

Why wouldn't it read the createCategory function?
 
Last edited by a moderator:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ

@bishiba, please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.

I've merged your posts this time~

Seems OK. Since Window_ShopNumber is only used on one scene by default, you might consider simply overriding its windowWidth method with a new value.

If you decide to resize the window after construction instead, then my previous advice stands: you'd need to recreate/refresh the window contents afterwards to match the new window size.

However, Window_ItemCategory is a bit more tricky as it uses a superclass, so if you're gonna use the same approach I believe you'd need to change each called function all the way to the Window_Command superclass.
JavaScript's prototype model works by traversing the inheritance chain from one "class" to its super: the first instance of the named method that is found is the one that is used. Prototype chain traversal does not change the execution context (i.e. this). More details here:
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
[dpost]@bishiba[/dpost]I've merged your posts this time~

Seems OK. Since Window_ShopNumber is only used on one scene by default, you might consider simply overriding its windowWidth method with a new value.

If you decide to resize the window after construction instead, then my previous advice stands: you'd need to recreate/refresh the window contents afterwards to match the new window size.


JavaScript's prototype model works by traversing the inheritance chain from one "class" to its super: the first instance of the named method that is found is the one that is used. Prototype chain traversal does not change the execution context (i.e. this). More details here:
Alright, I'll refrain from doing it again :)

If you read my updated post above your answer, that be great. Because I do not understand how, but the Scene_Shop.prototype.createCategoryWindow doesn't get read properly. And it was working just before I added the alias function. And even though I've removed the function and what not, it still becomes undefined.

I guess I am just gonna have the entire function in the plugin instead of using an alias then... Don't know what happened at all tbh.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
I'm not sure what the problem is either. :kaoswt: I just tried something similar and it worked for me with no errors:
JavaScript:
(function(alias) {
    Scene_Shop.prototype.createCategoryWindow = function() {
        alias.apply(this, arguments);
        this._categoryWindow.width -= 100;
        this._categoryWindow.refresh();
    };
})(Scene_Shop.prototype.createCategoryWindow);
I removed the reference to _actorWindow because by default that window gets defined after createCategoryWindow runs. [Edit: actually, like you say, it's not there at all by default. :kaoslp:] If you wanted to include it, you could alias a different method instead, e.g. Scene_Shop#create.

You say the change persisted after reverting your plugin edits...that should never happen. :kaoswt2: Did you close and restart your game between tests?

Otherwise, maybe you somehow had an invisible character like a zero-width space messing things up? The forum trims out characters like that so I can't tell for sure just by scanning your posted code.

It's also possible that you accidentally edited your project's core scripts while browsing (I've done that before). You can refresh them by copying the relevant rpg_*.js files from a new project (or, equivalently, from the NewData folder in your RPG Maker MV install folder).
 
Last edited:

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
232
Reaction score
130
First Language
Swedish
Primarily Uses
N/A
I'm not sure what the problem is either. :kaoswt: I just tried something similar and it worked for me with no errors:
JavaScript:
(function(alias) {
    Scene_Shop.prototype.createCategoryWindow = function() {
        alias.apply(this, arguments);
        this._categoryWindow.width -= 100;
        this._categoryWindow.refresh();
    };
})(Scene_Shop.prototype.createCategoryWindow);
I removed the reference to _actorWindow because by default that window gets defined after createCategoryWindow runs. If you wanted to include it, you could alias a different method instead, e.g. Scene_Shop#create.

You say the change persisted after reverting your plugin edits...that should never happen. :kaoswt2: Did you close and restart your game between tests?

Otherwise, maybe you somehow had an invisible character like a zero-width space messing things up? The forum trims out characters like that so I can't tell for sure just by scanning your posted code.

It's also possible that you accidentally edited your project's core scripts while browsing (I've done that before). You can refresh them by copying the relevant rpg_*.js files from a new project (or, equivalently, from the NewData folder in your RPG Maker MV install folder).
Yeah, I was thinking about the possibility that I had changed the source code. But the truth is that I have a long clipboard history active, and I never closed any of the project files. So I actually used ctrlz to revert any changes in all of the source codes. But I had not changed anything...

Yes, I did restart the game and launch it again. But as expected it didn't change anything :/

I guess I never actually turned off my plugin, but I even have a word search function that searches all open code windows. Searched for relevant terms and I honestly do not understand what could've happened. But either way, I suppose it doesn't matter much that the full function is in the plugin.

Probably there's some line somewhere in my plugin that ruins it. But I just don't understand how the entire function disappeared :/ I guess I might've changed the way the superclass is inherited.

The _actorWindow is not included at all by default:
JavaScript:
Scene_Shop.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createHelpWindow();
    this.createGoldWindow();
    this.createCommandWindow();
    this.createDummyWindow();
    this.createNumberWindow();
    this.createStatusWindow();
    this.createBuyWindow();
    this.createCategoryWindow();
    this.createSellWindow();
};
I don't know if this is what you meant, but the actor window is just a custom window, currently it is nothing but a window that I do not know how to implement yet xD

But at least now I've solved it at least. Now on to the next issue :p

Thanks! :)
 

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

"Yeah. It's been a rough road lately. But that's the thing about the Rangers. It doesn't matter how hard it gets, or how many of them fall. They never stop fighting. The Rangers NEVER stop fighting".

Angela Deth, you are a hero of mine. Sorry for my first run of Wasteland 3.
We must press on. For all those we couldn't save. For all those we might yet save.
FirestormNeos wrote on DarkPlasmaBall's profile.
asking this here instead of the thread in question to avoid derailing it, but I'm curious; is there a particular reason you'd include a "Terms of Use" for an RPG Maker game? Like, are there multiplayer features for the game you're working on?
The holidays are upon us! Everyone search for safety from the grocery store music!
I don't understand people sometime. Walking to work today came across someone walking the opposite way in a nice suit, I politely move to the side into the shrubbery so he doesn't have to get his suit dirty and say "good morning" as he passes me, he turns around glaring daggers and asks "why are you talking to me?" like he's bloody offended by me wishing him a good morning or something. Just, why?

Forum statistics

Threads
117,138
Messages
1,104,892
Members
153,202
Latest member
EnderMon
Top