MV Refreshing the whole window?

Hey all,

So I've been mucking around with Yanfly's gold window. My code is atrocious (and also works thanks to some forum posters!), but the end result mostly functions:
1717561542977.png

The above example: In the bottom left corner I have this window that keeps the player informed about their resource limits.
I just now added this:

1717561479919.png


The above example: This added info shows up when the player has unspent attribute points. This basically works! But here's the problem:

1717561667512.png


The above example: when the player first gets an attribute point, it doesn't resize the window. You have to do something to refresh it like open the menu. I have some code that makes sure it refreshes, but this only seems to affect the data therein:
JavaScript:
Scene_Map.prototype.updateGoldRefresh = function() {
    if (this._goldWindowValue === $gameParty.gold() && this._currentchemValue === $gameParty.numItems($dataItems[6]) || this._numattValue === $gameParty.numItems($dataItems[2])) return;
    this._goldWindowValue = $gameParty.gold();
    this._messageWindow._goldWindow.refresh();
};
And here's the function that resizes the window but refuses to run until a window refresh:
JavaScript:
Window_Gold.prototype.windowHeight = function() {
if ($gameParty.numItems($dataItems[2]) > 0) {
return this.fittingHeight(3);}
else {
    return this.fittingHeight(2);}
};
I feel like the answer is some kind of full refresh of the UI, but I'm ignorant of what command that might be. Any ideas?
You may have to write it (or rewrite some of your window class).

The default way that windows are drawn is their dimensions are determined in the initialize() method, which is only called when an object is created - e.g. new Window_Gold()
1717565482625.png


That's why just refreshing the window doesn't change it, because that doesn't delete and reinitialize the object.

Similarly, the scenes by default don't have a refresh method that deletes and reinitializes their windows.

You could try calling the move() method inside your refresh() method - this.move(x, y, width, height)
You could try calling the move() method inside your refresh() method - this.move(x, y, width, height)
Makes a lot of sense to me, but it's telling me that "move is not a function."
1717567697676.png

Although I can only get this error if I zero out the variables in the move function, otherwise it complains that they aren't defined.
Because you tried to put it inside a method of the scene - it's a property of the window.

See the last line of your scene refreshing function?
1717568358196.png


You'd add stuff to the Window_Gold.prototype.refresh method.

Code:
Window_Gold.prototype.refresh = function() {
    var x = this.textPadding();
    var width = this.contents.width - this.textPadding() * 2;
    this.move(this.x, this.y, this.width, ($gameParty.numItems($dataItems[2]) > 0 ? this.fittingHeight(3) : this.fittingHeight(2)));
    this.contents.clear();
    this.drawCurrencyValue(this.value(), this.currencyUnit(), x, 0, width);
};

Although I can only get this error if I zero out the variables in the move function, otherwise it complains that they aren't defined.
Right - I just provided the isolated format for calling the function, words like "x, y, width, height" don't mean anything unless you declare them as variables, replace them with numeric values, etc.

I was nonspecific in instructions there, I didn't know if you'd picked up some JS basics during the course of your meddling 😉
I'd suggest replacing this.contents.clear() with this.createContents().

(The contents bitmap is where text is drawn to, but it doesn't auto-resize with the window bounds.)
You'd add stuff to the Window_Gold.prototype.refresh method.
Ah, I got mixed up because there's two functions with "refresh" in the name, you set me straight here.
Right - I just provided the isolated format for calling the function, words like "x, y, width, height" don't mean anything unless you declare them as variables, replace them with numeric values, etc.

I was nonspecific in instructions there, I didn't know if you'd picked up some JS basics during the course of your meddling 😉
I've meddled enough that I had a hunch, but not enough to know the when and why's, heh. I still struggle with a lot of things like when I can use this and when functions seem to be able to pull from other places in the code and when they can't. I'm still just going at this with a lot of brute force like a total oaf :hswt:
I'd suggest replacing this.contents.clear() with this.createContents().
Ah, this actually fixes the thing I was about to bring up which is that it seemed like the text would fail to draw the last line as if the window wasn't big enough, even though it is. But this new command fixes that!

For those curious, here's my ugly code:
JavaScript:
Window_Gold.prototype.refresh = function() {
    var x = this.textPadding();
    var width = this.contents.width - this.textPadding() * 2;
    this.move(this.x, this.y, this.width, ($gameParty.numItems($dataItems[2]) > 0 ? this.fittingHeight(3) : this.fittingHeight(2)));
    this.createContents();
    if ($gameParty.numItems($dataItems[2]) > 0) {this.drawLevelUpEbas(this.numatt(), 0, x, 0, width)};
    if ($gameParty.numItems($dataItems[2]) > 0) {this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, 37, width)} else {this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, 0, width)};
    if ($gameParty.numItems($dataItems[2]) > 0) {this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, 74, width)} else {this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, 37, width)};
};

Naturally I don't know the shorthand ways to do stuff like in my if statements so it's very overlong I'm sure. Probably the most obnoxious thing is that I'm drawing text shifted to the next line by using raw pixel numbers instead of referencing something like... text height of the previous line somehow. :LZSangel: But anyway, it works! Thanks to you both!
Naturally I don't know the shorthand ways to do stuff like in my ifstatements so it's very overlong I'm sure.
One thing you can always do is combine all those ifs into one like so:
JavaScript:
if ($gameParty.numItems($dataItems[2]) > 0) {
    this.drawLevelUpEbas(this.numatt(), 0, x, 0, width);
    this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, 37, width);
    this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, 74, width)
} else {
    this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, 0, width)
    this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, 37, width);
}
Making this a bit more readable. Though in this specific case it can indeed be shortened using ternary operators, like so:
JavaScript:
let extraLine = $gameParty.numItems($dataItems[2]) > 0;
if (extraLine) this.drawLevelUpEbas(this.numatt(), 0, x, 0, width);  
this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, extraLine ? 37 : 0, width);
this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, extraLine ? 74 : 37, width);
I had no idea ternary operators could be used inside a function like that, mostly outside.
good to know as well, learned another thing 😀

but the last but is really clean indeed.

(I'm gonna save bother, as it might come in handy for a reminder 😀 )

@Mac15001900 you made 2 mistakes as so I correct both of them here.
as in both code (2nd line, you use "}" which throws an errors 😀

JavaScript:
if ($gameParty.numItems($dataItems[2]) > 0) {
    this.drawLevelUpEbas(this.numatt(), 0, x, 0, width);
    this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, 37, width);
    this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, 74, width)
} else {
    this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, 0, width)
    this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, 37, width);
}

and the other one
JavaScript:
let extraLine = $gameParty.numItems($dataItems[2]) > 0;
if (extraLine) this.drawLevelUpEbas(this.numatt(), 0, x, 0, width);   
this.drawChemicalsValue(this.currentchem(), this.maxChem(), 0, x, extraLine ? 37 : 0, width);
this.drawCurrencyValue(this.value(), this.maxValue(), this.currencyUnit(), x, extraLine ? 74 : 37, width);
2nd line, you use "}"
Good catch! It really blended in there xD
Makes me wish for a proper JavaScript syntax highlighting on the forum (which would have made it rather obvious).
I've fixed it in the post.
I had no idea ternary operators could be used inside a function like that
You can use a ternary operator any place the code expects there to be a value.

It doesn't matter if it's an argument getting passed to a function, a comparison, the right hand of an assignment operator.

Any place you could type, say, 5, you could replace that with a ternary statement.
Good catch! It really blended in there xD
Makes me wish for a proper JavaScript syntax highlighting on the forum (which would have made it rather obvious).
use VS Code, I spotted it there, but it was a nice blending, same for ")" to many.
but inbuild code checker on the forum when doing it is also a great idea "+ 1" on it.

I keep learning new things here too.
use VS Code, I spotted it there,
Of course, any decent text editor will highlight a mismatched bracket for you, but it'd be nice to have those kind of features on the forum (like in Github's code preview).

Original thread: https://forums.rpgmakerweb.com/threads/refreshing-the-whole-window.169273/