]> git.localhorst.tv Git - l2e.git/blobdiff - src/menu/SelectHero.cpp
added hero selection state + status stub
[l2e.git] / src / menu / SelectHero.cpp
diff --git a/src/menu/SelectHero.cpp b/src/menu/SelectHero.cpp
new file mode 100644 (file)
index 0000000..723414f
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * SelectHero.cpp
+ *
+ *  Created on: Oct 22, 2012
+ *      Author: holy
+ */
+
+#include "SelectHero.h"
+
+#include "HeroStatus.h"
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+#include "../common/Hero.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Sprite.h"
+
+using app::Input;
+using geometry::Vector;
+
+namespace menu {
+
+SelectHero::SelectHero(PartyMenu *parent, Callback cb, int cursor)
+: parent(parent)
+, callback(cb)
+, cursor(cursor) {
+
+}
+
+
+void SelectHero::OnEnterState(SDL_Surface *) {
+       cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
+}
+
+void SelectHero::OnExitState(SDL_Surface *) {
+
+}
+
+void SelectHero::OnResumeState(SDL_Surface *) {
+
+}
+
+void SelectHero::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void SelectHero::OnResize(int width, int height) {
+
+}
+
+
+void SelectHero::HandleEvents(const Input &input) {
+       if (input.JustPressed(Input::ACTION_A)) {
+               callback(parent, cursor);
+       }
+       if (input.JustPressed(Input::ACTION_B)) {
+               Ctrl().PopState();
+       }
+
+       if (input.JustPressed(Input::PAD_UP)) {
+               SelectUp();
+       } else if (input.JustPressed(Input::PAD_RIGHT)) {
+               SelectRight();
+       } else if (input.JustPressed(Input::PAD_DOWN)) {
+               SelectDown();
+       } else if (input.JustPressed(Input::PAD_LEFT)) {
+               SelectLeft();
+       }
+}
+
+void SelectHero::SelectUp() {
+       cursor = (cursor + 2) % parent->Game().state->partySize;
+       cursorBlink.Restart();
+}
+
+void SelectHero::SelectRight() {
+       cursor = (cursor + 1) % parent->Game().state->partySize;
+       cursorBlink.Restart();
+}
+
+void SelectHero::SelectDown() {
+       cursor = (cursor + 2) % parent->Game().state->partySize;
+       cursorBlink.Restart();
+}
+
+void SelectHero::SelectLeft() {
+       cursor = (cursor + 3) % parent->Game().state->partySize;
+       cursorBlink.Restart();
+}
+
+
+common::GameConfig &SelectHero::Game() {
+       return parent->Game();
+}
+
+const common::GameConfig &SelectHero::Game() const {
+       return parent->Game();
+}
+
+Resources &SelectHero::Res() {
+       return parent->Res();
+}
+
+const Resources &SelectHero::Res() const {
+       return parent->Res();
+}
+
+
+void SelectHero::UpdateWorld(float deltaT) {
+
+}
+
+
+void SelectHero::Render(SDL_Surface *screen) {
+       parent->Render(screen);
+       if (cursorBlink.Iteration() % 2 == 0) {
+               RenderCursor(screen);
+       }
+}
+
+void SelectHero::RenderCursor(SDL_Surface *screen) const {
+       const HeroStatus &status(parent->GetHeroStatus(cursor));
+       Vector<int> position(
+                       0, Game().state->party[cursor]->BattleSprite()->Height());
+       position += status.Position() + parent->StatusOffset();
+       Res().heroCursor->Draw(screen, position);
+}
+
+}