]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/VictoryState.cpp
3516bdeaf5150802642f5022864fe120e3712134
[l2e.git] / src / battle / states / VictoryState.cpp
1 #include "VictoryState.h"
2
3 #include "../Battle.h"
4 #include "../BattleState.h"
5 #include "../Hero.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"
12
13 #include <sstream>
14
15 using app::Application;
16 using app::Input;
17 using graphics::Font;
18 using graphics::Frame;
19 using math::Vector;
20 using std::string;
21 using std::vector;
22
23 namespace battle {
24
25 void VictoryState::OnEnterState(SDL_Surface *screen) {
26         OnResize(screen->w, screen->h);
27         LoadResults();
28 }
29
30 void VictoryState::LoadResults() {
31         lines.clear();
32
33         std::stringstream s;
34         s << "Gets " << battle->ExpReward() << " EXP";
35         lines.push_back(s.str());
36
37         s.str("");
38         s << "Gets " << battle->GoldReward() << " gold";
39         lines.push_back(s.str());
40
41         for (std::vector<Hero>::const_iterator
42                         i(battle->HeroesBegin()), end(battle->HeroesEnd());
43                         i != end; ++i) {
44                 if (i->Health() <= 0) continue;
45                 const common::Hero &hero = i->Master();
46                 s.str("");
47                 s << hero.Name() << " next level " << hero.NextLevel();
48                 lines.push_back(s.str());
49         }
50 }
51
52 void VictoryState::OnExitState(SDL_Surface *screen) {
53
54 }
55
56 void VictoryState::OnResumeState(SDL_Surface *screen) {
57         timer = GraphicsTimers().StartCountdown(1500);
58 }
59
60 void VictoryState::OnPauseState(SDL_Surface *screen) {
61
62 }
63
64
65 void VictoryState::OnResize(int width, int height) {
66         const Vector<int> offset = parent->ScreenOffset();
67
68         const Resources &res = parent->Res();
69         const Frame &frame = *res.selectFrame;
70
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();
76 }
77
78
79 void VictoryState::HandleEvents(const Input &input) {
80         if (timer.Finished()) {
81                 Ctrl().PopState(); // pop self
82         }
83 }
84
85
86 void VictoryState::UpdateWorld(Uint32 deltaT) {
87
88 }
89
90 void VictoryState::Render(SDL_Surface *screen) {
91         parent->RenderBackground(screen);
92         RenderFrame(screen);
93         RenderLines(screen);
94 }
95
96 void VictoryState::RenderFrame(SDL_Surface *screen) {
97         const Frame &frame = *parent->Res().selectFrame;
98         frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
99 }
100
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());
107                         i != end; ++i) {
108                 font.DrawString(i->c_str(), screen, position);
109                 position.Y() += font.CharHeight();
110         }
111 }
112
113 }