X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FVictoryState.cpp;fp=src%2Fbattle%2Fstates%2FVictoryState.cpp;h=3516bdeaf5150802642f5022864fe120e3712134;hb=e1dab8a680a76f8621e967a693dbf2b481ba8f75;hp=0000000000000000000000000000000000000000;hpb=8f4e771181491f1d83ce0c907b8dda0fbbe0ce93;p=l2e.git diff --git a/src/battle/states/VictoryState.cpp b/src/battle/states/VictoryState.cpp new file mode 100644 index 0000000..3516bde --- /dev/null +++ b/src/battle/states/VictoryState.cpp @@ -0,0 +1,113 @@ +#include "VictoryState.h" + +#include "../Battle.h" +#include "../BattleState.h" +#include "../Hero.h" +#include "../../app/Application.h" +#include "../../app/Input.h" +#include "../../common/Hero.h" +#include "../../math/Vector.h" +#include "../../graphics/Font.h" +#include "../../graphics/Frame.h" + +#include + +using app::Application; +using app::Input; +using graphics::Font; +using graphics::Frame; +using math::Vector; +using std::string; +using std::vector; + +namespace battle { + +void VictoryState::OnEnterState(SDL_Surface *screen) { + OnResize(screen->w, screen->h); + LoadResults(); +} + +void VictoryState::LoadResults() { + lines.clear(); + + std::stringstream s; + s << "Gets " << battle->ExpReward() << " EXP"; + lines.push_back(s.str()); + + s.str(""); + s << "Gets " << battle->GoldReward() << " gold"; + lines.push_back(s.str()); + + for (std::vector::const_iterator + i(battle->HeroesBegin()), end(battle->HeroesEnd()); + 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()); + } +} + +void VictoryState::OnExitState(SDL_Surface *screen) { + +} + +void VictoryState::OnResumeState(SDL_Surface *screen) { + timer = GraphicsTimers().StartCountdown(1500); +} + +void VictoryState::OnPauseState(SDL_Surface *screen) { + +} + + +void VictoryState::OnResize(int width, int height) { + const Vector offset = parent->ScreenOffset(); + + const Resources &res = parent->Res(); + const Frame &frame = *res.selectFrame; + + framePosition = offset + frame.BorderSize(); + frameSize = Vector( + parent->Width() - 2 * frame.BorderWidth(), + res.normalFont->CharHeight() * 13); + textPosition = framePosition + frame.BorderSize(); +} + + +void VictoryState::HandleEvents(const Input &input) { + if (timer.Finished()) { + Ctrl().PopState(); // pop self + } +} + + +void VictoryState::UpdateWorld(Uint32 deltaT) { + +} + +void VictoryState::Render(SDL_Surface *screen) { + parent->RenderBackground(screen); + RenderFrame(screen); + RenderLines(screen); +} + +void VictoryState::RenderFrame(SDL_Surface *screen) { + const Frame &frame = *parent->Res().selectFrame; + frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y()); +} + +void VictoryState::RenderLines(SDL_Surface *screen) { + // naive implementation + const Font &font = *parent->Res().normalFont; + Vector position = textPosition; + for (vector::const_iterator + i(lines.begin()), end(lines.end()); + i != end; ++i) { + font.DrawString(i->c_str(), screen, position); + position.Y() += font.CharHeight(); + } +} + +}