1 #include "VictoryState.h"
4 #include "../BattleState.h"
6 #include "../../app/Application.h"
7 #include "../../app/Input.h"
8 #include "../../common/Hero.h"
9 #include "../../math/Vector.h"
10 #include "../../graphics/Font.h"
11 #include "../../graphics/Frame.h"
15 using app::Application;
18 using graphics::Frame;
25 void VictoryState::OnEnterState(SDL_Surface *screen) {
26 OnResize(screen->w, screen->h);
30 void VictoryState::LoadResults() {
34 s << "Gets " << battle->ExpReward() << " EXP";
35 lines.push_back(s.str());
38 s << "Gets " << battle->GoldReward() << " gold";
39 lines.push_back(s.str());
41 for (std::vector<Hero>::const_iterator
42 i(battle->HeroesBegin()), end(battle->HeroesEnd());
44 if (i->Health() <= 0) continue;
45 const common::Hero &hero = i->Master();
47 s << hero.Name() << " next level " << hero.NextLevel();
48 lines.push_back(s.str());
52 void VictoryState::OnExitState(SDL_Surface *screen) {
56 void VictoryState::OnResumeState(SDL_Surface *screen) {
57 timer = GraphicsTimers().StartCountdown(1500);
60 void VictoryState::OnPauseState(SDL_Surface *screen) {
65 void VictoryState::OnResize(int width, int height) {
66 const Vector<int> offset = parent->ScreenOffset();
68 const Resources &res = parent->Res();
69 const Frame &frame = *res.selectFrame;
71 framePosition = offset + frame.BorderSize();
72 frameSize = Vector<int>(
73 parent->Width() - 2 * frame.BorderWidth(),
74 res.normalFont->CharHeight() * 13);
75 textPosition = framePosition + frame.BorderSize();
79 void VictoryState::HandleEvents(const Input &input) {
80 if (timer.Finished()) {
81 Ctrl().PopState(); // pop self
86 void VictoryState::UpdateWorld(Uint32 deltaT) {
90 void VictoryState::Render(SDL_Surface *screen) {
91 parent->RenderBackground(screen);
96 void VictoryState::RenderFrame(SDL_Surface *screen) {
97 const Frame &frame = *parent->Res().selectFrame;
98 frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
101 void VictoryState::RenderLines(SDL_Surface *screen) {
102 // naive implementation
103 const Font &font = *parent->Res().normalFont;
104 Vector<int> position = textPosition;
105 for (vector<string>::const_iterator
106 i(lines.begin()), end(lines.end());
108 font.DrawString(i->c_str(), screen, position);
109 position.Y() += font.CharHeight();