From: Daniel Karbach Date: Thu, 7 Feb 2013 06:55:08 +0000 (+0100) Subject: animated victory messages X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=467fd239cfa26ba057fd1959ca8908f618cd9287;p=l2e.git animated victory messages --- diff --git a/src/battle/states/VictoryState.cpp b/src/battle/states/VictoryState.cpp index c1e5ea4..831f08e 100644 --- a/src/battle/states/VictoryState.cpp +++ b/src/battle/states/VictoryState.cpp @@ -100,20 +100,30 @@ void VictoryState::HandleEvents(const Input &input) { ++cursor; timer = GraphicsTimers().StartInterval(150); } else if (input.IsDown(Input::ACTION_A) - && timer.JustHit() - && timer.Iteration() > 3) { - ++cursor; + && timer.JustHit()) { + if (timer.Iteration() > 3) { + ++cursor; + stalling = false; + } else { + stalling = true; + } } else if (input.JustPressed(Input::SHOULDER_LEFT)) { ++cursor; timer = GraphicsTimers().StartInterval(150); } else if (input.IsDown(Input::SHOULDER_LEFT) - && timer.JustHit() - && timer.Iteration() > 3) { - ++cursor; + && timer.JustHit()) { + if (timer.Iteration() > 3) { + ++cursor; + stalling = false; + } else { + stalling = true; + } } - if (!input.IsDown(Input::ACTION_A) + if (timer.JustHit() + && !input.IsDown(Input::ACTION_A) && !input.IsDown(Input::SHOULDER_LEFT)) { timer.Clear(); + stalling = false; } if (cursor >= int(lines.size())) { Ctrl().PopState(); // pop self @@ -140,10 +150,31 @@ void VictoryState::RenderFrame(SDL_Surface *screen) { void VictoryState::RenderLines(SDL_Surface *screen) { // naive implementation const Font &font = *parent->Res().normalFont; + const Vector lineBreak = Vector( + 0, font.CharHeight() * 5 / 4); + const int start = cursor > 7 ? cursor - 8 : 0; Vector position = textPosition; - for (int i = 0; i <= cursor && i < int(lines.size()); ++i) { + + int end = cursor + 1; + + if (start > 0) { + if (timer.Running() && !stalling) { + position += lineBreak; + const int correction = timer.IterationElapsed(); + if (correction > 0) { + // ++start; + position.Y() -= lineBreak.Y() * correction / timer.TargetTime(); + } else { + --end; + } + } + } + + if (end > int(lines.size())) end = lines.size(); + + for (int i = start; i < end; ++i) { font.DrawString(lines[i].c_str(), screen, position); - position.Y() += font.CharHeight(); + position += lineBreak; } } diff --git a/src/battle/states/VictoryState.h b/src/battle/states/VictoryState.h index d14ec76..4dca6e9 100644 --- a/src/battle/states/VictoryState.h +++ b/src/battle/states/VictoryState.h @@ -23,7 +23,8 @@ public: BattleState *parent) : battle(battle) , parent(parent) - , cursor(0) { } + , cursor(0) + , stalling(false) { } public: virtual void HandleEvents(const app::Input &); @@ -52,6 +53,7 @@ private: math::Vector frameSize; math::Vector textPosition; int cursor; + bool stalling; };