]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/VictoryState.cpp
stop lines in victory state from crossing the frame
[l2e.git] / src / battle / states / VictoryState.cpp
index dca0bf2ee3da96bc727be6ee793c8fd58246007b..a0b09ceb5b93d7996c71317f88765b80cce45bad 100644 (file)
@@ -5,6 +5,7 @@
 #include "../Hero.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
+#include "../../common/Capsule.h"
 #include "../../common/GameConfig.h"
 #include "../../common/GameState.h"
 #include "../../common/Hero.h"
@@ -40,6 +41,8 @@ void VictoryState::LoadResults() {
        s << "Gets " << battle->GoldReward() << " gold";
        lines.push_back(s.str());
 
+       lines.push_back("");
+
        for (std::vector<Hero>::const_iterator
                        i(battle->HeroesBegin()), end(battle->HeroesEnd());
                        i != end; ++i) {
@@ -50,6 +53,15 @@ void VictoryState::LoadResults() {
                lines.push_back(s.str());
        }
 
+       if (battle->HasCapsule()) {
+               const Capsule &capsule = battle->GetCapsule();
+               if (capsule.Health() > 0) {
+                       s.str("");
+                       s << capsule.Name() << " next level " << capsule.Master().NextLevel();
+                       lines.push_back(s.str());
+               }
+       }
+
        lines.push_back("");
        s.str("");
        s << parent->Game().state->money << " gold";
@@ -88,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
@@ -128,10 +150,30 @@ void VictoryState::RenderFrame(SDL_Surface *screen) {
 void VictoryState::RenderLines(SDL_Surface *screen) {
        // naive implementation
        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;
        Vector<int> position = textPosition;
-       for (int i = 0; i <= cursor && i < int(lines.size()); ++i) {
+
+       int end = cursor + 1;
+
+       if (start > 0) {
+               if (timer.Running() && !stalling) {
+                       --end;
+                       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();
+
+       for (int i = start; i < end; ++i) {
                font.DrawString(lines[i].c_str(), screen, position);
-               position.Y() += font.CharHeight();
+               position += lineBreak;
        }
 }