]> git.localhorst.tv Git - l2e.git/commitdiff
fade out after victory
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 14 Feb 2013 06:59:24 +0000 (07:59 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 15 Feb 2013 15:29:40 +0000 (16:29 +0100)
fixes #5

src/battle/states/VictoryState.cpp
src/graphics/ColorFade.cpp
src/graphics/ColorFade.h

index 59d4495f68c5d4c0c4ef7349b229016235dc83f2..ddc940b4c4d04bcb0ca0bd9e4b4517d09ecdbcb9 100644 (file)
@@ -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<int> lineBreak = Vector<int>(
                        0, font.CharHeight() * 5 / 4);
-       const int start = cursor > 7 ? cursor - 8 : 0;
+       int start = cursor > 7 ? cursor - 8 : 0;
        Vector<int> 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);
index 72bf40978791cfb1d0bad8143eda8d241fc98506..55e14fc811d87e2427a4ef0443259a3da996d1da 100644 (file)
@@ -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();
+                       }
                }
        }
 }
index aad9247e09ac40ee61ec9a6519f1ca31b313fd2f..6505be186bc1179768722e0ec076a90247777e01 100644 (file)
@@ -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;
 
 };