]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/VictoryState.cpp
added simple victory state
[l2e.git] / src / battle / states / VictoryState.cpp
diff --git a/src/battle/states/VictoryState.cpp b/src/battle/states/VictoryState.cpp
new file mode 100644 (file)
index 0000000..3516bde
--- /dev/null
@@ -0,0 +1,113 @@
+#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();
+       }
+}
+
+}