MV [REQ] Keep current window state upon refresh

When the game window is refreshed, either by the user pressing F5 or calling a refresh with a script call, it will reset to the default windowed mode. This can be annoying for players who have resized the window in any way (including playing in full screen).

I'm requesting a plugin that can refresh the game completely while keeping the window the same size. I hope this is something that is feasible to do, because it would be pretty neat and a nice quality-of-life thing!

I also currently have my game set to just reload the window whenever the player goes back to the (evented) title screen, so although I can work around this issue by setting up a new game with DataManager.setupNewGame(); if a plugin like this is simple enough it would certainly kill two birds with one stone for me.
you can change the F5 command as I did it with "Game Over" scene
as the code is what I use to disable it, you can use to alter the F5 key function.

JavaScript:
        const _SM_onKeyDown = SceneManager.onKeyDown;
            SceneManager.onKeyDown = function(event) {
                if (event.code !== "F5") location.reload();
                    _SM_onKeyDown.call(this, event);
            }

this make it so, it reload the window, but keep the window intact.
no matter what size the window is, as game over is fade out, it is more abruptly,
but it refresh the window, alone, not reset the config part, but it does clear
the cache which I needed for 1 of my plugins to function correctly.

this might work for you.
Wait a minute, but doesn't the window keep its size after pressing F5?
Because mine does.
Wait a minute, but doesn't the window keep its size after pressing F5?
Because mine does.
Mine does the same thing as the OP. I start my game, press Maximize to stretch the window out, then press F5. The window returns to its default size.

I don't really get why he expects his players to be pressing F5, why do you need to restart the game like that? But I can confirm the behavior.
Hmmm, maybe there's a plugin I'm not aware? But my window stay unchanged after refreshing.

As for why the play needs that, maybe they need to return to the title screen. My game also needs that because I use the escape button to do other things and removed in-game menu. And I'm a bit lazy to add a new function.
Hmmm, maybe there's a plugin I'm not aware? But my window stay unchanged after refreshing.
Seems like that plugin is exactly what OP needs here - if you're able to identify it, this would be really helpful.
I don't have one. I tried a new project. Actually the window only exits full screen mode, but the size doesn't change.

Unless the OP want a config option that saves.


Edit*
Well, after reading the document of nw.js, it seems if you give the window a proper id, it will save the position and size after you close the game. But not with fullscreen, not without touching the code or the engine.

JSON:
{
    "name": "Your App Name",
    "main": "www/index.html",
    "js-flags": "--expose-gc",
    "window": {
        "id":"nameyourgamewindowblahblah",
        "title": "",
        "toolbar": false,
        "width": 816,
        "height": 624,
        "icon": "www/icon/icon.png"
    }
}
you can change the F5 command as I did it with "Game Over" scene
as the code is what I use to disable it, you can use to alter the F5 key function.

JavaScript:
        const _SM_onKeyDown = SceneManager.onKeyDown;
            SceneManager.onKeyDown = function(event) {
                if (event.code !== "F5") location.reload();
                    _SM_onKeyDown.call(this, event);
            }

this make it so, it reload the window, but keep the window intact.
no matter what size the window is, as game over is fade out, it is more abruptly,
but it refresh the window, alone, not reset the config part, but it does clear
the cache which I needed for 1 of my plugins to function correctly.

this might work for you.
I added that as a plugin and it now reloads the window every time I press any key lol. In addition, it doesn't actually keep the window size, it totally resets it like normal.

I don't really get why he expects his players to be pressing F5, why do you need to restart the game like that?
It is useful for getting to the title screen fast. For instance, to reload a save quickly if you are in a spot where you can't access the menu like within a battle. Rather than closing out of the game and opening it again, you can just press F5 and return to the title quickly.

There is also the fact that using the reload script is easier than using setupnewgame and transferring to the title screen and then getting rid of anything lingering from other plugins, but that's more of a secondary goal for something like this since I recognize it is just taking my workload and dropping it on someone else.

Well, after reading the document of nw.js, it seems if you give the window a proper id, it will save the position and size after you close the game. But not with fullscreen, not without touching the code or the engine.
It doesn't appear that this saves the size, just the position of the window.
Are you sure you don't have a scrip that resize the window?
Because I double checked, a new project never did that.
Mine does the same thing as the OP.

Are you sure you don't have a scrip that resize the window?
Mine also functions this way.

And while I'm not home to test on a new project, I'm 99% sure this is normal behavior for new projects.
Did you update NWJS, utunnel?
I double checked, a new project never did that.
You've been told by, like, four people in this thread that it does 🤣

Just to make sure you're actually testing what the thread is talking about:
- Start a playtest
- Click the Maximize button on the window
- Press F5

It will go back to the original window dimensions.
You've been told by, like, four people in this thread that it does 🤣
Oh, I think I found it.
You are all using Community_basic, right?
Because I never changed the default window size. lol
Oh, I think I found it.
You are all using Community_basic, right?
No.

This has nothing to do with changing the window's size in the game.


Just to make sure you're actually testing what the thread is talking about:
- Start a playtest
- Click the Maximize button on the window
- Press F5

It will go back to the original window dimensions.
1720065362451.png

I have the same problem as the OP only if I fill these two lines.
If I leave them blank, F5 doesn't reset the size.
By the way, I didn't upgrade nw.js for the new project, but maybe their profiles are somewhat shared.
Oh shoot, you're 100% right. I tested with my game, not my test project. That doesn't use Community Basic, but it does have other plugins changing the dimensions.

In a blank MV test project, with the default window dimensions, pressing F5 has no effect. I apologize for the confusion.
Okay, interesting. I'm using YEP_CoreEngine to change the resolution. Never touched Community Basics. It does seem like, with it disabled, refresh does actually keep the window size and position except in the case that it is in full screen or the F3 mode that keeps the window size the same within the larger window.

So I guess the next step is, how do we solve that? I definitely don't want to change the resolution of my game to default or stop using the core engine.
Spoiler: YEP Code
JavaScript:
Yanfly.updateResolution = function() {
  var resizeWidth = Yanfly.Param.ScreenWidth - window.innerWidth;
  var resizeHeight = Yanfly.Param.ScreenHeight - window.innerHeight;
  if (!Imported.ScreenResolution) {
    window.moveBy(-1 * resizeWidth / 2, -1 * resizeHeight / 2);
    window.resizeBy(resizeWidth, resizeHeight);
  }
};


YEP_CoreEngine uses this code to switch off auto-resize:

Imported.ScreenResolution = true;

So you just need to edit the plugin or create a new one with that line, put it below YEP_CoreEngine.
if that fixed it, you can just rule it out that line for the same effect.
as it would be faster and cleaner ^^
Alright so if I comment out that whole bit of code I get an error that Yanfly.updateResolution is not a function. If I comment out the part with the conditional, it works exactly like it does without the plugin at all except with the defined resolution. The full screen and F3 modes are the only things that will reset. This is a good step in the right direction though.

I think having a full-screen toggle option would work well for this issue, but if I recall the one I used had some issues with other plugins I'm using and that's why I ended up removing it. It would say the game was full screen when it wasn't and you had to toggle the option on and off, stuff like that. Maybe there are some different/better ones out there.

Imported.ScreenResolution = true;
I couldn't find this line in the core engine. Were you saying that making a plugin with just that line is what I would have had to do if I didn't comment stuff out?
No it doesn't have that line, it checks for that line.
You need to add it. Either by adding a new plugin or editing the original, or use an in game event.

Original thread: https://forums.rpgmakerweb.com/threads/req-keep-current-window-state-upon-refresh.169992/