Add window fade-out on exit

This commit is contained in:
Vinyl Darkscratch 2017-04-04 02:31:08 -07:00
parent 640ecd46f9
commit 7274072a2d
6 changed files with 39 additions and 2 deletions

View File

@ -64,6 +64,15 @@ RB_METHOD(oneshotAllowExit)
return Qnil; return Qnil;
} }
RB_METHOD(oneshotExiting)
{
RB_UNUSED_PARAM;
bool exiting;
rb_get_args(argc, argv, "b", &exiting RB_ARG_END);
shState->oneshot().setExiting(exiting);
return Qnil;
}
RB_METHOD(oneshotShake) RB_METHOD(oneshotShake)
{ {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
@ -122,7 +131,8 @@ void oneshotBindingInit()
_rb_define_module_function(module, "textinput", oneshotTextInput); _rb_define_module_function(module, "textinput", oneshotTextInput);
_rb_define_module_function(module, "reset_obscured", oneshotResetObscured); _rb_define_module_function(module, "reset_obscured", oneshotResetObscured);
_rb_define_module_function(module, "obscured_cleared?", oneshotObscuredCleared); _rb_define_module_function(module, "obscured_cleared?", oneshotObscuredCleared);
_rb_define_module_function(module, "allow_exit", oneshotAllowExit); _rb_define_module_function(module, "allow_exit", oneshotAllowExit);
_rb_define_module_function(module, "exiting", oneshotExiting);
_rb_define_module_function(module, "shake", oneshotShake); _rb_define_module_function(module, "shake", oneshotShake);
_rb_define_module_function(module, "setwinpos", oneshotSetWindowPos); _rb_define_module_function(module, "setwinpos", oneshotSetWindowPos);
_rb_define_module_function(module, "getwinpos", oneshotGetWindowPos); _rb_define_module_function(module, "getwinpos", oneshotGetWindowPos);

View File

@ -25,11 +25,13 @@ begin
# Make scene object (title screen) # Make scene object (title screen)
$scene = Scene_Title.new $scene = Scene_Title.new
Oneshot.allow_exit false Oneshot.allow_exit false
Oneshot.exiting false
# Call main method as long as $scene is effective # Call main method as long as $scene is effective
while $scene != nil while $scene != nil
$scene.main $scene.main
end end
# Fade out # Fade out
Oneshot.exiting true
Graphics.transition(20) Graphics.transition(20)
Oneshot.allow_exit true Oneshot.allow_exit true
rescue Errno::ENOENT rescue Errno::ENOENT

View File

@ -232,6 +232,9 @@ struct RGSSThreadData
/* Set when F12 is released */ /* Set when F12 is released */
AtomicFlag rqResetFinish; AtomicFlag rqResetFinish;
/* True if we're currently exiting */
AtomicFlag exiting;
/* True if exiting is allowed */ /* True if exiting is allowed */
AtomicFlag allowExit; AtomicFlag allowExit;

View File

@ -816,6 +816,8 @@ void Graphics::transition(int duration,
simpleShader.setProg(prog); simpleShader.setProg(prog);
} }
if (p->threadData->exiting) SDL_SetWindowOpacity(p->threadData->window, 1.0f - prog);
/* Draw the composed frame to a buffer first /* Draw the composed frame to a buffer first
* (we need this because we're skipping PingPong) */ * (we need this because we're skipping PingPong) */
FBO::bind(p->transBuffer.fbo); FBO::bind(p->transBuffer.fbo);

View File

@ -232,7 +232,7 @@ struct OneshotPrivate
std::string txtYes; std::string txtYes;
std::string txtNo; std::string txtNo;
//Allow exiting game bool exiting;
bool allowExit; bool allowExit;
//Alpha texture data for portions of window obscured by screen edges //Alpha texture data for portions of window obscured by screen edges
@ -500,6 +500,7 @@ Oneshot::Oneshot(RGSSThreadData &threadData) :
p->winY = 0; p->winY = 0;
p->winPosChanged = false; p->winPosChanged = false;
p->allowExit = true; p->allowExit = true;
p->exiting = false;
/******************** /********************
* USERNAME/DOCS PATH * USERNAME/DOCS PATH
@ -763,6 +764,11 @@ bool Oneshot::obscuredCleared() const
return p->obscuredCleared; return p->obscuredCleared;
} }
bool Oneshot::exiting() const
{
return p->exiting;
}
bool Oneshot::allowExit() const bool Oneshot::allowExit() const
{ {
return p->allowExit; return p->allowExit;
@ -774,6 +780,18 @@ void Oneshot::setYesNo(const char *yes, const char *no)
p->txtNo = no; p->txtNo = no;
} }
void Oneshot::setExiting(bool exiting)
{
if (p->exiting != exiting) {
p->exiting = exiting;
if (exiting) {
threadData.exiting.set();
} else {
threadData.exiting.clear();
}
}
}
void Oneshot::setAllowExit(bool allowExit) void Oneshot::setAllowExit(bool allowExit)
{ {
if (p->allowExit != allowExit) { if (p->allowExit != allowExit) {

View File

@ -104,10 +104,12 @@ public:
const std::vector<uint8_t> &obscuredMap() const; const std::vector<uint8_t> &obscuredMap() const;
bool obscuredCleared() const; bool obscuredCleared() const;
bool allowExit() const; bool allowExit() const;
bool exiting() const;
//Mutators //Mutators
void setYesNo(const char *yes, const char *no); void setYesNo(const char *yes, const char *no);
void setWindowPos(int x, int y); void setWindowPos(int x, int y);
void setExiting(bool exiting);
void setAllowExit(bool allowExit); void setAllowExit(bool allowExit);
void resetObscured(); void resetObscured();