From 3aca2860c95bb4d30569a23ab88a5286c3b9b757 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 14 Feb 2013 07:59:24 +0100 Subject: [PATCH] fade out after victory fixes #5 --- src/battle/states/VictoryState.cpp | 18 ++++++++++++++---- src/graphics/ColorFade.cpp | 9 ++++++++- src/graphics/ColorFade.h | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/battle/states/VictoryState.cpp b/src/battle/states/VictoryState.cpp index 59d4495..ddc940b 100644 --- a/src/battle/states/VictoryState.cpp +++ b/src/battle/states/VictoryState.cpp @@ -11,6 +11,7 @@ #include "../../common/GameState.h" #include "../../common/Upgrade.h" #include "../../math/Vector.h" +#include "../../graphics/ColorFade.h" #include "../../graphics/Font.h" #include "../../graphics/Frame.h" @@ -21,6 +22,7 @@ using app::Application; using app::Input; using common::GameState; using common::Upgrade; +using graphics::ColorFade; using graphics::Font; using graphics::Frame; using math::Vector; @@ -201,7 +203,11 @@ void VictoryState::HandleEvents(const Input &input) { stalling = false; } if (cursor >= int(lines.size())) { - Ctrl().PopState(); // pop self + timer.Clear(); + ColorFade *fade = new ColorFade(this, 0, 650); + fade->SetLeadInTime(150); + fade->SetDoublePop(); + Ctrl().PushState(fade); } } @@ -227,7 +233,7 @@ void VictoryState::RenderLines(SDL_Surface *screen) { const Font &font = *parent->Res().normalFont; const Vector lineBreak = Vector( 0, font.CharHeight() * 5 / 4); - const int start = cursor > 7 ? cursor - 8 : 0; + int start = cursor > 7 ? cursor - 8 : 0; Vector position = textPosition; int end = cursor + 1; @@ -238,13 +244,17 @@ void VictoryState::RenderLines(SDL_Surface *screen) { position += lineBreak; const int correction = timer.IterationElapsed(); if (correction > 0) { - // ++start; position.Y() -= lineBreak.Y() * correction / timer.TargetTime(); } } } - if (end > int(lines.size())) end = lines.size(); + if (end > int(lines.size())) { + end = lines.size(); + } + if (start > int(lines.size()) - 9) { + start = lines.size() - 9; + } for (int i = start; i < end; ++i) { font.DrawString(lines[i].c_str(), screen, position); diff --git a/src/graphics/ColorFade.cpp b/src/graphics/ColorFade.cpp index 72bf409..55e14fc 100644 --- a/src/graphics/ColorFade.cpp +++ b/src/graphics/ColorFade.cpp @@ -18,7 +18,8 @@ ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool int , leadInDone(true) , fadeDone(false) , in(in) -, interactive(interactive) { +, interactive(interactive) +, doublePop(false) { } @@ -86,9 +87,15 @@ void ColorFade::HandleEvents(const Input &input) { timer = GraphicsTimers().StartCountdown(leadOut); } else { Ctrl().PopState(); + if (doublePop) { + Ctrl().PopState(); + } } } else { Ctrl().PopState(); + if (doublePop) { + Ctrl().PopState(); + } } } } diff --git a/src/graphics/ColorFade.h b/src/graphics/ColorFade.h index aad9247..6505be1 100644 --- a/src/graphics/ColorFade.h +++ b/src/graphics/ColorFade.h @@ -12,12 +12,21 @@ class ColorFade : public app::State { public: - ColorFade(app::State *slave, Uint32 color, int duration, bool in = false, bool interactive = false); + ColorFade( + app::State *slave, + Uint32 color, + int duration, + bool in = false, + bool interactive = false); virtual ~ColorFade() { } public: - void SetLeadInTime(int ms) { leadIn = ms; if (ms > 0) leadInDone = false; } + void SetLeadInTime(int ms) { + leadIn = ms; + if (ms > 0) leadInDone = false; + } void SetLeadOutTime(int ms) { leadOut = ms; } + void SetDoublePop(bool b = true) { doublePop = b; } public: virtual void HandleEvents(const app::Input &); @@ -48,6 +57,7 @@ private: bool fadeDone; bool in; bool interactive; + bool doublePop; }; -- 2.39.2