Add 'delay' argument for screen fading operations

new-script-api
scrawl 7 years ago
parent c035548f37
commit d78e822833

@ -317,11 +317,11 @@ namespace MWBase
virtual void pinWindow (MWGui::GuiWindow window) = 0; virtual void pinWindow (MWGui::GuiWindow window) = 0;
/// Fade the screen in, over \a time seconds /// Fade the screen in, over \a time seconds
virtual void fadeScreenIn(const float time, bool clearQueue=true) = 0; virtual void fadeScreenIn(const float time, bool clearQueue=true, float delay=0.f) = 0;
/// Fade the screen out to black, over \a time seconds /// Fade the screen out to black, over \a time seconds
virtual void fadeScreenOut(const float time, bool clearQueue=true) = 0; virtual void fadeScreenOut(const float time, bool clearQueue=true, float delay=0.f) = 0;
/// Fade the screen to a specified percentage of black, over \a time seconds /// Fade the screen to a specified percentage of black, over \a time seconds
virtual void fadeScreenTo(const int percent, const float time, bool clearQueue=true) = 0; virtual void fadeScreenTo(const int percent, const float time, bool clearQueue=true, float delay=0.f) = 0;
/// Darken the screen to a specified percentage /// Darken the screen to a specified percentage
virtual void setBlindness(const int percent) = 0; virtual void setBlindness(const int percent) = 0;

@ -6,12 +6,13 @@
namespace MWGui namespace MWGui
{ {
FadeOp::FadeOp(ScreenFader * fader, float time, float targetAlpha) FadeOp::FadeOp(ScreenFader * fader, float time, float targetAlpha, float delay)
: mFader(fader), : mFader(fader),
mRemainingTime(time), mRemainingTime(time+delay),
mTargetTime(time), mTargetTime(time),
mTargetAlpha(targetAlpha), mTargetAlpha(targetAlpha),
mStartAlpha(0.f), mStartAlpha(0.f),
mDelay(delay),
mRunning(false) mRunning(false)
{ {
} }
@ -26,7 +27,7 @@ namespace MWGui
if (mRunning) if (mRunning)
return; return;
mRemainingTime = mTargetTime; mRemainingTime = mTargetTime + mDelay;
mStartAlpha = mFader->getCurrentAlpha(); mStartAlpha = mFader->getCurrentAlpha();
mRunning = true; mRunning = true;
} }
@ -42,6 +43,12 @@ namespace MWGui
return; return;
} }
if (mRemainingTime > mTargetTime)
{
mRemainingTime -= dt;
return;
}
float currentAlpha = mFader->getCurrentAlpha(); float currentAlpha = mFader->getCurrentAlpha();
if (mStartAlpha > mTargetAlpha) if (mStartAlpha > mTargetAlpha)
{ {
@ -103,19 +110,19 @@ namespace MWGui
mMainWidget->setAlpha(1.f-((1.f-mCurrentAlpha) * mFactor)); mMainWidget->setAlpha(1.f-((1.f-mCurrentAlpha) * mFactor));
} }
void ScreenFader::fadeIn(float time) void ScreenFader::fadeIn(float time, float delay)
{ {
queue(time, 1.f); queue(time, 1.f, delay);
} }
void ScreenFader::fadeOut(const float time) void ScreenFader::fadeOut(const float time, float delay)
{ {
queue(time, 0.f); queue(time, 0.f, delay);
} }
void ScreenFader::fadeTo(const int percent, const float time) void ScreenFader::fadeTo(const int percent, const float time, float delay)
{ {
queue(time, percent/100.f); queue(time, percent/100.f, delay);
} }
void ScreenFader::clear() void ScreenFader::clear()
@ -135,7 +142,7 @@ namespace MWGui
mRepeat = repeat; mRepeat = repeat;
} }
void ScreenFader::queue(float time, float targetAlpha) void ScreenFader::queue(float time, float targetAlpha, float delay)
{ {
if (time < 0.f) if (time < 0.f)
return; return;
@ -147,7 +154,7 @@ namespace MWGui
return; return;
} }
mQueue.push_back(FadeOp::Ptr(new FadeOp(this, time, targetAlpha))); mQueue.push_back(FadeOp::Ptr(new FadeOp(this, time, targetAlpha, delay)));
} }
bool ScreenFader::isEmpty() bool ScreenFader::isEmpty()

@ -14,7 +14,7 @@ namespace MWGui
public: public:
typedef std::shared_ptr<FadeOp> Ptr; typedef std::shared_ptr<FadeOp> Ptr;
FadeOp(ScreenFader * fader, float time, float targetAlpha); FadeOp(ScreenFader * fader, float time, float targetAlpha, float delay);
bool isRunning(); bool isRunning();
@ -28,6 +28,7 @@ namespace MWGui
float mTargetTime; float mTargetTime;
float mTargetAlpha; float mTargetAlpha;
float mStartAlpha; float mStartAlpha;
float mDelay;
bool mRunning; bool mRunning;
}; };
@ -38,16 +39,16 @@ namespace MWGui
void update(float dt); void update(float dt);
void fadeIn(const float time); void fadeIn(const float time, float delay=0);
void fadeOut(const float time); void fadeOut(const float time, float delay=0);
void fadeTo(const int percent, const float time); void fadeTo(const int percent, const float time, float delay=0);
void clear(); void clear();
void setFactor (float factor); void setFactor (float factor);
void setRepeat(bool repeat); void setRepeat(bool repeat);
void queue(float time, float targetAlpha); void queue(float time, float targetAlpha, float delay);
bool isEmpty(); bool isEmpty();
void clearQueue(); void clearQueue();

@ -40,7 +40,6 @@ namespace MWGui
TrainingWindow::TrainingWindow() TrainingWindow::TrainingWindow()
: WindowBase("openmw_trainingwindow.layout") : WindowBase("openmw_trainingwindow.layout")
, mFadeTimeRemaining(0)
, mTimeAdvancer(0.05f) , mTimeAdvancer(0.05f)
{ {
getWidget(mTrainingOptions, "TrainingOptions"); getWidget(mTrainingOptions, "TrainingOptions");
@ -183,7 +182,7 @@ namespace MWGui
mTimeAdvancer.run(2); mTimeAdvancer.run(2);
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.25); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.25);
mFadeTimeRemaining = 0.5; MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.25, false, 0.25);
} }
void TrainingWindow::onTrainingProgressChanged(int cur, int total) void TrainingWindow::onTrainingProgressChanged(int cur, int total)
@ -204,13 +203,5 @@ namespace MWGui
{ {
checkReferenceAvailable(); checkReferenceAvailable();
mTimeAdvancer.onFrame(dt); mTimeAdvancer.onFrame(dt);
if (mFadeTimeRemaining <= 0)
return;
mFadeTimeRemaining -= dt;
if (mFadeTimeRemaining <= 0)
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.25);
} }
} }

@ -39,8 +39,6 @@ namespace MWGui
MyGUI::Button* mCancelButton; MyGUI::Button* mCancelButton;
MyGUI::TextBox* mPlayerGold; MyGUI::TextBox* mPlayerGold;
float mFadeTimeRemaining;
WaitDialogProgressBar mProgressBar; WaitDialogProgressBar mProgressBar;
TimeAdvancer mTimeAdvancer; TimeAdvancer mTimeAdvancer;
}; };

@ -1788,25 +1788,25 @@ namespace MWGui
updateVisible(); updateVisible();
} }
void WindowManager::fadeScreenIn(const float time, bool clearQueue) void WindowManager::fadeScreenIn(const float time, bool clearQueue, float delay)
{ {
if (clearQueue) if (clearQueue)
mScreenFader->clearQueue(); mScreenFader->clearQueue();
mScreenFader->fadeOut(time); mScreenFader->fadeOut(time, delay);
} }
void WindowManager::fadeScreenOut(const float time, bool clearQueue) void WindowManager::fadeScreenOut(const float time, bool clearQueue, float delay)
{ {
if (clearQueue) if (clearQueue)
mScreenFader->clearQueue(); mScreenFader->clearQueue();
mScreenFader->fadeIn(time); mScreenFader->fadeIn(time, delay);
} }
void WindowManager::fadeScreenTo(const int percent, const float time, bool clearQueue) void WindowManager::fadeScreenTo(const int percent, const float time, bool clearQueue, float delay)
{ {
if (clearQueue) if (clearQueue)
mScreenFader->clearQueue(); mScreenFader->clearQueue();
mScreenFader->fadeTo(percent, time); mScreenFader->fadeTo(percent, time, delay);
} }
void WindowManager::setBlindness(const int percent) void WindowManager::setBlindness(const int percent)

@ -344,11 +344,11 @@ namespace MWGui
virtual void pinWindow (MWGui::GuiWindow window); virtual void pinWindow (MWGui::GuiWindow window);
/// Fade the screen in, over \a time seconds /// Fade the screen in, over \a time seconds
virtual void fadeScreenIn(const float time, bool clearQueue); virtual void fadeScreenIn(const float time, bool clearQueue, float delay);
/// Fade the screen out to black, over \a time seconds /// Fade the screen out to black, over \a time seconds
virtual void fadeScreenOut(const float time, bool clearQueue); virtual void fadeScreenOut(const float time, bool clearQueue, float delay);
/// Fade the screen to a specified percentage of black, over \a time seconds /// Fade the screen to a specified percentage of black, over \a time seconds
virtual void fadeScreenTo(const int percent, const float time, bool clearQueue); virtual void fadeScreenTo(const int percent, const float time, bool clearQueue, float delay);
/// Darken the screen to a specified percentage /// Darken the screen to a specified percentage
virtual void setBlindness(const int percent); virtual void setBlindness(const int percent);

Loading…
Cancel
Save