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;
}
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_UNUSED_PARAM;
@ -122,7 +131,8 @@ void oneshotBindingInit()
_rb_define_module_function(module, "textinput", oneshotTextInput);
_rb_define_module_function(module, "reset_obscured", oneshotResetObscured);
_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, "setwinpos", oneshotSetWindowPos);
_rb_define_module_function(module, "getwinpos", oneshotGetWindowPos);

View file

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

View file

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

View file

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

View file

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

View file

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