X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FVictoryState.cpp;h=ddc940b4c4d04bcb0ca0bd9e4b4517d09ecdbcb9;hb=3aca2860c95bb4d30569a23ab88a5286c3b9b757;hp=dca0bf2ee3da96bc727be6ee793c8fd58246007b;hpb=acc322b16b5f31cfbc350d4fccb457c7730287fd;p=l2e.git diff --git a/src/battle/states/VictoryState.cpp b/src/battle/states/VictoryState.cpp index dca0bf2..ddc940b 100644 --- a/src/battle/states/VictoryState.cpp +++ b/src/battle/states/VictoryState.cpp @@ -3,23 +3,35 @@ #include "../Battle.h" #include "../BattleState.h" #include "../Hero.h" +#include "../Resources.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" +#include "../../common/Upgrade.h" #include "../../math/Vector.h" +#include "../../graphics/ColorFade.h" #include "../../graphics/Font.h" #include "../../graphics/Frame.h" +#include #include using app::Application; using app::Input; +using common::GameState; +using common::Upgrade; +using graphics::ColorFade; using graphics::Font; using graphics::Frame; using math::Vector; +using std::left; +using std::right; +using std::setfill; +using std::setw; using std::string; +using std::stringstream; using std::vector; namespace battle { @@ -30,29 +42,106 @@ void VictoryState::OnEnterState(SDL_Surface *screen) { } void VictoryState::LoadResults() { + const Resources &res = parent->Res(); lines.clear(); - std::stringstream s; - s << "Gets " << battle->ExpReward() << " EXP"; + stringstream s; + s << res.victoryGetsText << ' ' + << battle->ExpReward() << ' ' + << res.victoryExpText << '.'; lines.push_back(s.str()); s.str(""); - s << "Gets " << battle->GoldReward() << " gold"; + s << res.victoryGetsText << ' ' + << battle->GoldReward() << ' ' + << res.victoryGoldText << '.'; lines.push_back(s.str()); - for (std::vector::const_iterator - i(battle->HeroesBegin()), end(battle->HeroesEnd()); + lines.push_back(""); + + GameState &state = *parent->Game().state; + vector upgrade; + battle->ApplyRewards(state, upgrade); + for (vector::const_iterator + i(upgrade.begin()), end(upgrade.end()); i != end; ++i) { - if (i->Health() <= 0) continue; - const common::Hero &hero = i->Master(); - s.str(""); - s << hero.Name() << " next level " << hero.NextLevel(); - lines.push_back(s.str()); + LoadResult(*i, lines); } + s.str(""); + s << state.money << ' ' << res.victoryGoldText; + string goldStr = s.str(); + lines.push_back(""); s.str(""); - s << parent->Game().state->money << " gold"; + s << right << setw(28) << setfill(' ') << goldStr; + lines.push_back(s.str()); +} + +void VictoryState::LoadResult( + const Upgrade &u, + vector &lines) { + const Resources &res = parent->Res(); + stringstream s; + switch (u.GetType()) { + case Upgrade::LEVEL_UP: + s << left << setw(6) << setfill(' ') << u.Name() + << res.victoryLevelUpText << '.'; + break; + case Upgrade::MAX_HEALTH: + s << res.victoryMHPText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::MAX_MAGIC: + s << res.victoryMMPText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::ATTACK: + s << res.victoryATPText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::DEFENSE: + s << res.victoryDFPText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::STRENGTH: + s << res.victorySTRText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::AGILITY: + s << res.victoryAGLText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::INTELLIGENCE: + s << res.victoryINTText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::GUT: + s << res.victoryGUTText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::MAGIC_RESISTANCE: + s << res.victoryMGRText << ' ' + << res.victoryUpgradeText << ' ' + << u.Amount() << '.'; + break; + case Upgrade::LEVEL_NEXT: + s << setw(7) << setfill(' ') + << left << u.Name() << ' ' + << res.victoryNextLevelText + << ' ' << u.Amount(); + break; + default: + s << "unknown upgrade type " << u.GetType(); + } lines.push_back(s.str()); } @@ -88,23 +177,37 @@ 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 + timer.Clear(); + ColorFade *fade = new ColorFade(this, 0, 650); + fade->SetLeadInTime(150); + fade->SetDoublePop(); + Ctrl().PushState(fade); } } @@ -128,10 +231,34 @@ 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); + 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) { + --end; + position += lineBreak; + const int correction = timer.IterationElapsed(); + if (correction > 0) { + position.Y() -= lineBreak.Y() * correction / timer.TargetTime(); + } + } + } + + 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); - position.Y() += font.CharHeight(); + position += lineBreak; } }