MV SRD_WindowUpgrade

Hello peoples,

I got a small issue with the WindowUpgrade plugin and it rather does work nicely,
now I dont know if it should go to support or request, as it could be both probably.

I got a small issue, I like to solve inside or a patch to solve the issue, as there are 2,
1 might be a plugin addon or patch to it in order to work or snippet if it exist.

Issue 1)
The info window can set information and works, but the issue is, if you hold the button (z, ok) for
a slight second longer, the info window closes almost instantly.

is there a way to set the wait a bit longer or what I like best, wait for input (z, ok, any button) to avoid
that it closes directly if you hold the button a slightly longer that is directly closes?

issue 2) (Solved)
this one is more a bugging one (which I like to be solved at most) is that, on the Choice/Question window,
you can set a value/words on them to choose from?

question window can look like:
how are you
------------
choice 1, choice 2, choice 3

this way, you can show horizontally or vertically depending on the setting, as I set it in a vertical way,
the last one (choice 3) is not alligned in the center as I set it like that, but has an offset!

in order to fix that, you place a "comma" on choice 3 and it's fixed, but not entirely, it add a 4th option
which cannot really be target, but you can still select it, removing the selection cursor.

I hope it can be fixed without the comma without the offset as this is crucial on my end.

request/snippet (Solved)
the last question is a snippet to get a timer on the choice/question window, ideally what can work,
is when the times runs out, it "auto presses" the ok/cancel button automaticallly.

I do not know if this is possible as I use an input for text that have it, but with windowUpgrade
when the info/choice/question window, there is no force mode to close it, so auto button press
likes the best way I can think off to force closes the window.

any help on this is enormous, at least issue 2 is most important one, all 3 is perfect.
Huh, I've used WindowUpgrade in my game for a while, but I've somehow never noticed that your second issue happens here too! I guess it's not as noticeable when all the options have different lengths and are in a 2x2 grid, but now I can't unsee it xD

This is a relatively simple fix. Looks like the plugin is parsing arguments incorrectly: it adds a spacebar after each one, resulting in there being an extra space at the very end.

Dumb but simple solution: add an extra space to every option but the last, now they're all misaligned in the same way xD

Actual solution: inside SRD.PluginCommands['setquestionwindowchoices'] replace
JavaScript:
let argString = '';
for (let i = 0; i < args.length; i++) {
    argString += args[i] + ' ';
}
with
JavaScript:
let argString = args.join(' ');

That's specifically for question window choices, but it looks like everything is parsed this way, so analogous fix should prevent extra spaces from being added in other places too.

As for the request, force closing should be the easy part: store a reference to the window object being created, and set it's _closing parameter to true when you want to close it (it already has a callback to make the interpreter move on), plus of course changing the variable that would normally store the chosen option to whatever the default option should be. The thing that requires work would be to create and display that timer.

The first issue is present in all windows (the same thing happens if you hold 'Z' too long when selecting a menu, it will end up clicking on the first option there. Changing that would probably require some significant modifications to how windows in the game work.
Huh, I've used WindowUpgrade in my game for a while, but I've somehow never noticed that your second issue happens here too! I guess it's not as noticeable when all the options have different lengths and are in a 2x2 grid, but now I can't unsee it xD
sorry for that, I was playing with choices/question when I saw it 🙂

as I tried your way to replace, it got even weirder, so I removed the space
inside that worked kinda, but for single words, .join didn't work really,
specially not with "what am I", as removing the space, will glue this together.

as I use a visual timer, I couldn't figure out the force closing part,
I dont mind making a another visiual timer as choosing an option is by
variable, so closing the window forcefull is harder and didn't found a way
to do so.

I hope you can give an example on it? as I dont get SRD coding really.
but while I use Galv_variableBar as timer, I also use SRD_TimerUpgrade.

Galv plugin is the visual per obstacle that works nicely, just need a way for
question window as I have an imput form for the other part that has an
included "force switch" that cancel in the input form.

a similair way would be idea for the choice/question window that turns on,
the most ideal way is "setQuestionTimerSwitch x y" and or "setChoiceTimerSwitch x y"
so if the time expire, switch is flipped ON to close it, and switch goes OFF
in the event as well, which would be ideal.

x = being the timer set (frames)
y = being the switch (id)

it would be a great if you know a way for that (can be an addon as a feature)
as it might be helpfull for other players looking for it.

EDIT:
solved the spacing issue (issue 2) with replacing the split funtion with
JavaScript:
//in choices where it set the split
const choices = argString.trim().split(/\s*,\s*/);

// in setQuestion where it split
$gameSystem.wu_info.questionWindowChoices = argString.trim().split(/\s*,\s*/);

when adding "trim()", it removes the space on the last entry which fixes issue 2.
.join didn't work really,
What did it do? Crash the game, or just still keep a space at the end? If the latter, there's a good chance there actually was an extra space in the input. At least for me it seems to work fine. But I guess trimming/any other way of removing it should work just as well.
I hope you can give an example on it?
If you replace
JavaScript:
scene.addWindow(win);
win.setCloseCallback(function () {
    scene.removeChild(win);
    this.setWaitMode('');
}.bind(this));
with
JavaScript:
scene.addWindow(win);
let timeout = setTimeout(() => win.close(), 5000);
win.setCloseCallback(function () {
    clearTimeout(timeout);
    scene.removeChild(win);
    this.setWaitMode('');
}.bind(this));
it will close the window after 5 seconds.

If you want to also set a switch when the time runs out, add that to the timeout like so:
JavaScript:
let timeout = setTimeout(function () {
    win.close();
    $gameSwitches.setValue(42, true);
}, 5000);
I did try with the switch but didn't owrk out, setValue
is something would be harder 😛

as I use galv_variable, I need to bound those, which is with with
a variable value, so 5000 can be changed to $gameVariables.value(x)
to do the trick nicely.

as that is bound to a switch (forceStop) and timer switch (2), I can use
either 1 or both, but I need to bound it to the forceTimer switch as when
the timer runs out, it closes, so I can add that (and will test to see if it works).

the .join add the first value to the next command (so double words)
or just add the first one to the bottom in a kinda loop? which the cursor
dissapear on the length, like 5 entries sees it like 10 entries which is weird,
the trim().split removes the space and works much better in my case.

to come backa bit, you code should be as followed:
JavaScript:
scene.addWindow(win);
let varId = $gameVariables.value(x);
let timeout = setTimeout(function () {
    win.close();
    $gameSwitches.setValue(42, true);
}, varId);
win.setCloseCallback(function () {
    clearTimeout(timeout);
    scene.removeChild(win);
    this.setWaitMode('');
}.bind(this));

like this?
if it is, I'm going to set it to see if it does the job and report back 🙂

EDIT:
test it, but it semi works, so variable need to be off, but the switch only
might work which I need to test.

as adding variable, 600 = 10 seconds, to fast for the time out.

Edit2:
setting a new variable for timeout seems to work nicely, but I need to set a switch
check in order to not close the other windows, otherwise it is skipped directly.
but it's almost working, will check a few things 🙂

Edit3:
this seems the work without skipping if the number is higher than 0.
otherwise, it skip the question windows before, as the new variable
for time out (x1000) this does the job nicely.
JavaScript:
  let vTimeout = $gameVariables.value(25); // 1000 = 1 second
    let timeout = setTimeout(function() {
        if(vTimeout > 0)
        win.close();
        $gameSwitches.setValue(1, true);
    }, vTimeout);

@Mac15001900
thank you for your sample and direction to make this part work outstanding.
which solve 2 issues so far, just a small way for the issue one.

if you found a nice way, let me know =)
or just add the first one to the bottom in a kinda loop
Did you replace the entire segment I posted, as in replaced those 4 lines with one? That behaviour does sound like you only replaced the one line where it's initialised.
as adding variable, 600 = 10 seconds, to fast for the time out.
setTimout takes milliseconds as an argument, so 600 will only get you a 0.6s delay. But otherwise yeah, that code looks good.
I guess you could also do let varId = $gameVariables.value(x) * 1000 / 60; if you want to specify it in frames.
I edit my post before I saw yours, I can test that vTimeout = the variable ID.
as varId already was defined, so I defined it to the variable ID.
if that works too, than it's even cleaner 🙂
bump to find a solution on issue 1 🙂
bump, still looking for a way on issue 1 please 🙂
final bump on first issue 🙂 (if there is an easy way).
bumping this again for issue part 1.
as holding button skips everything, I really need that they cannot skip
it to fast, either with delay or "when pressing" ok again to continue.
bumping again for issue 1 please =)

is it even possible to solve it? when you press the button, it doesn't continue
unless you press the button again?

Original thread: https://forums.rpgmakerweb.com/threads/srd_windowupgrade.152602/