(Mouse) click message box to close

By default, a mouse click anywhere on the screen closes a currently opened message box but this makes it difficult to implement stuff like on-screen buttons for additional functionality (using yanfly’s picture common events for example).

I have such buttons in my game for a custom menu as well as for opening yanfly’s message backlog plugin. It’s useful for a mouse-only VN game. It all works fine except for the fact that when you press a button it also counts towards the message box so you end up closing the current message box as well.

I was wondering if someone was willing to make a plugin where the mouse click to close message only works if you click inside/on the actual message box?

Ideally it should also be compatible with Yanfly’s core and message core plugins, and be flexible with different screen resolutions and message box sizes.
@Parallax Panda Place the following into a .js file and add it as a plugin to your project. See if that works.

Code:
Window_Message.prototype.isTouchedInsideFrame = function() {
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    return x >= 0 && y >= 0 && x < this.width && y < this.height;
};

Window_Message.prototype.isTriggered = function() {
    return (Input.isRepeated('ok') || Input.isRepeated('cancel') ||
            this.isTouchedInsideFrame());
};
@Ossra Thank you. I'll try it out right away though... this might sound a bit stupid but how do I make a .JS file out of it?
@Parallax Panda Nab and toss the following file into your plugin folder. Then add the file to your project via the Plugin Manager.
@Ossra Thank you very much! You're very helpful (I managed to learn how to convert it into a .js file now as well).

Unfortunately it didn't work very well. What happened was;

a) one click in the message box counted as an infinite number of clicks and the message box messages just kept closing after that, even though i only clicked once.

b) yanfly's common picture events became unclickable. Basically, anything outside of the message box counted as nothing which is part of what I wanted but the ideas was to have the picture common events act as triggers for script calls for things such as the message backlog and custom menu I made.
@Parallax Panda Oop, I forgot a bit of code. Give the following a try :

Code:
Window_Message.prototype.isTouchedInsideFrame = function() {
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    return x >= 0 && y >= 0 && x < this.width && y < this.height;
};

Window_Message.prototype.isTriggered = function() {
    return (Input.isRepeated('ok') || Input.isRepeated('cancel') ||
            (this.isTouchedInsideFrame() && TouchInput.isRepeated()));
};
@Ossra
Ooh, nice! That fixed the first issue so now one click doesn't click forever. 😍

There is still one issue remaining for me, which is that clicks outside of the message box doesn't register at all. It's tricky because that's probably how you wrote the plugin to be but I think Yanfly's Common Event Pictures plugin is tied to the same kind of mouse input(?) and just deactivating it outside of the box means that the plugin won't work.

I'm not sure if this would require a more complex solution since I don't want clicking outside of the message box to affect it, but I do want to be able to activate common events thorough Yanfly's plugin.

Original thread: https://forums.rpgmakerweb.com/threads/mouse-click-message-box-to-close.115568/