1 #include "VictoryState.h"
4 #include "../BattleState.h"
6 #include "../../app/Application.h"
7 #include "../../app/Input.h"
8 #include "../../common/Capsule.h"
9 #include "../../common/GameConfig.h"
10 #include "../../common/GameState.h"
11 #include "../../common/Hero.h"
12 #include "../../math/Vector.h"
13 #include "../../graphics/Font.h"
14 #include "../../graphics/Frame.h"
18 using app::Application;
21 using graphics::Frame;
28 void VictoryState::OnEnterState(SDL_Surface *screen) {
29 OnResize(screen->w, screen->h);
33 void VictoryState::LoadResults() {
37 s << "Gets " << battle->ExpReward() << " EXP";
38 lines.push_back(s.str());
41 s << "Gets " << battle->GoldReward() << " gold";
42 lines.push_back(s.str());
46 for (std::vector<Hero>::const_iterator
47 i(battle->HeroesBegin()), end(battle->HeroesEnd());
49 if (i->Health() <= 0) continue;
50 const common::Hero &hero = i->Master();
52 s << hero.Name() << " next level " << hero.NextLevel();
53 lines.push_back(s.str());
56 if (battle->HasCapsule()) {
57 const Capsule &capsule = battle->GetCapsule();
58 if (capsule.Health() > 0) {
60 s << capsule.Name() << " next level " << capsule.Master().NextLevel();
61 lines.push_back(s.str());
67 s << parent->Game().state->money << " gold";
68 lines.push_back(s.str());
71 void VictoryState::OnExitState(SDL_Surface *screen) {
75 void VictoryState::OnResumeState(SDL_Surface *screen) {
79 void VictoryState::OnPauseState(SDL_Surface *screen) {
84 void VictoryState::OnResize(int width, int height) {
85 const Vector<int> offset = parent->ScreenOffset();
87 const Resources &res = parent->Res();
88 const Frame &frame = *res.selectFrame;
90 framePosition = offset + frame.BorderSize();
91 frameSize = Vector<int>(
92 parent->Width() - 2 * frame.BorderWidth(),
93 res.normalFont->CharHeight() * 13);
94 textPosition = framePosition + frame.BorderSize();
98 void VictoryState::HandleEvents(const Input &input) {
99 if (input.JustPressed(Input::ACTION_A)) {
101 timer = GraphicsTimers().StartInterval(150);
102 } else if (input.IsDown(Input::ACTION_A)
104 && timer.Iteration() > 3) {
106 } else if (input.JustPressed(Input::SHOULDER_LEFT)) {
108 timer = GraphicsTimers().StartInterval(150);
109 } else if (input.IsDown(Input::SHOULDER_LEFT)
111 && timer.Iteration() > 3) {
114 if (!input.IsDown(Input::ACTION_A)
115 && !input.IsDown(Input::SHOULDER_LEFT)) {
118 if (cursor >= int(lines.size())) {
119 Ctrl().PopState(); // pop self
124 void VictoryState::UpdateWorld(Uint32 deltaT) {
128 void VictoryState::Render(SDL_Surface *screen) {
129 parent->RenderBackground(screen);
130 parent->RenderHeroes(screen);
135 void VictoryState::RenderFrame(SDL_Surface *screen) {
136 const Frame &frame = *parent->Res().selectFrame;
137 frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
140 void VictoryState::RenderLines(SDL_Surface *screen) {
141 // naive implementation
142 const Font &font = *parent->Res().normalFont;
143 Vector<int> position = textPosition;
144 for (int i = 0; i <= cursor && i < int(lines.size()); ++i) {
145 font.DrawString(lines[i].c_str(), screen, position);
146 position.Y() += font.CharHeight();