1 #include "VictoryState.h"
4 #include "../BattleState.h"
6 #include "../../app/Application.h"
7 #include "../../app/Input.h"
8 #include "../../common/GameConfig.h"
9 #include "../../common/GameState.h"
10 #include "../../common/Hero.h"
11 #include "../../math/Vector.h"
12 #include "../../graphics/Font.h"
13 #include "../../graphics/Frame.h"
17 using app::Application;
20 using graphics::Frame;
27 void VictoryState::OnEnterState(SDL_Surface *screen) {
28 OnResize(screen->w, screen->h);
32 void VictoryState::LoadResults() {
36 s << "Gets " << battle->ExpReward() << " EXP";
37 lines.push_back(s.str());
40 s << "Gets " << battle->GoldReward() << " gold";
41 lines.push_back(s.str());
43 for (std::vector<Hero>::const_iterator
44 i(battle->HeroesBegin()), end(battle->HeroesEnd());
46 if (i->Health() <= 0) continue;
47 const common::Hero &hero = i->Master();
49 s << hero.Name() << " next level " << hero.NextLevel();
50 lines.push_back(s.str());
55 s << parent->Game().state->money << " gold";
56 lines.push_back(s.str());
59 void VictoryState::OnExitState(SDL_Surface *screen) {
63 void VictoryState::OnResumeState(SDL_Surface *screen) {
67 void VictoryState::OnPauseState(SDL_Surface *screen) {
72 void VictoryState::OnResize(int width, int height) {
73 const Vector<int> offset = parent->ScreenOffset();
75 const Resources &res = parent->Res();
76 const Frame &frame = *res.selectFrame;
78 framePosition = offset + frame.BorderSize();
79 frameSize = Vector<int>(
80 parent->Width() - 2 * frame.BorderWidth(),
81 res.normalFont->CharHeight() * 13);
82 textPosition = framePosition + frame.BorderSize();
86 void VictoryState::HandleEvents(const Input &input) {
87 if (input.JustPressed(Input::ACTION_A)) {
89 timer = GraphicsTimers().StartInterval(150);
90 } else if (input.IsDown(Input::ACTION_A)
92 && timer.Iteration() > 3) {
94 } else if (input.JustPressed(Input::SHOULDER_LEFT)) {
96 timer = GraphicsTimers().StartInterval(150);
97 } else if (input.IsDown(Input::SHOULDER_LEFT)
99 && timer.Iteration() > 3) {
102 if (!input.IsDown(Input::ACTION_A)
103 && !input.IsDown(Input::SHOULDER_LEFT)) {
106 if (cursor >= int(lines.size())) {
107 Ctrl().PopState(); // pop self
112 void VictoryState::UpdateWorld(Uint32 deltaT) {
116 void VictoryState::Render(SDL_Surface *screen) {
117 parent->RenderBackground(screen);
118 parent->RenderHeroes(screen);
123 void VictoryState::RenderFrame(SDL_Surface *screen) {
124 const Frame &frame = *parent->Res().selectFrame;
125 frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
128 void VictoryState::RenderLines(SDL_Surface *screen) {
129 // naive implementation
130 const Font &font = *parent->Res().normalFont;
131 Vector<int> position = textPosition;
132 for (int i = 0; i <= cursor && i < int(lines.size()); ++i) {
133 font.DrawString(lines[i].c_str(), screen, position);
134 position.Y() += font.CharHeight();