--- /dev/null
+#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 <sstream>
+
+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<Hero>::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<int> offset = parent->ScreenOffset();
+
+ const Resources &res = parent->Res();
+ const Frame &frame = *res.selectFrame;
+
+ framePosition = offset + frame.BorderSize();
+ frameSize = Vector<int>(
+ 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<int> position = textPosition;
+ for (vector<string>::const_iterator
+ i(lines.begin()), end(lines.end());
+ i != end; ++i) {
+ font.DrawString(i->c_str(), screen, position);
+ position.Y() += font.CharHeight();
+ }
+}
+
+}
--- /dev/null
+#ifndef BATTLE_VICTORYSTATE_H_
+#define BATTLE_VICTORYSTATE_H_
+
+namespace battle {
+ class Battle;
+ class BattleState;
+}
+
+#include "../../app/State.h"
+#include "../../math/Vector.h"
+
+#include <string>
+#include <vector>
+
+namespace battle {
+
+class VictoryState
+: public app::State {
+
+public:
+ VictoryState(
+ Battle *battle,
+ BattleState *parent)
+ : battle(battle)
+ , parent(parent) { }
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(Uint32 deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
+ virtual void OnEnterState(SDL_Surface *screen);
+ virtual void OnExitState(SDL_Surface *screen);
+ virtual void OnResumeState(SDL_Surface *screen);
+ virtual void OnPauseState(SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
+private:
+ void LoadResults();
+ void RenderFrame(SDL_Surface *screen);
+ void RenderLines(SDL_Surface *screen);
+
+private:
+ Battle *battle;
+ BattleState *parent;
+ app::Timer<Uint32> timer;
+ std::vector<std::string> lines;
+ math::Vector<int> framePosition;
+ math::Vector<int> frameSize;
+ math::Vector<int> textPosition;
+
+};
+
+}
+
+#endif