Hello,
I'm currently writing a level editor in Monogame 3.7 Desktop GL.
I'd like to intercept window exiting to be able to let the user save his work or cancel exiting.
It is a pretty common feature, maybe not useful for games, but for other tools.
Right now, we can only perform some actions while the game is exiting, but not cancel it.
What would be nice is to have a method to overload that returns true or false, depending on wether the game is authorized to exit.
Thanks in advance.
We could have a flag in the Game.Exiting event argument that you can set to cancel exiting. That's simple to implement and a non-breaking way to implement this feature. Sorry for the extremely late response!
@tomspilman This is easy to implement and I'm up for it, but I'd like your opinion first :)
If we can do it properly and support at least all desktop platforms i guess it is ok.
My concern is that you cannot keep a mobile or console game from shutting down. So this is exclusively a PC feature really.
Yes, we'll just be able to implement this for desktop. I guess this falls in the same bucket as #6392.
For synchronous run loop we simply wrap this code in a while loop with the stop condition that the new flag blocking game exit isn't set.
I'll have to look into async run loop.
@Jjagg: I created a PR for this above (#7096) ... My changes only impact the synchronous loops because it doesn't look like async run loops are supported for the DesktopGL and WindowsDX platforms.
As I mentioned in the PR I'm not sure if that's exactly how we should go about this, but I'm very happy to discuss and modify in order to get this to an acceptable state. Thanks!
Most helpful comment
We could have a flag in the
Game.Exitingevent argument that you can set to cancel exiting. That's simple to implement and a non-breaking way to implement this feature. Sorry for the extremely late response!