]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SelectMoveAction.cpp
extracted battle logic into a class
[l2e.git] / src / battle / states / SelectMoveAction.cpp
index 54f0f297661f2654ef49ffb82ed463b07ec57c98..79aa8b949feab80f216c93bb2e02466c83f2b086 100644 (file)
-/*
- * SelectMoveAction.cpp
- *
- *  Created on: Aug 7, 2012
- *      Author: holy
- */
-
 #include "SelectMoveAction.h"
 
+#include "RunState.h"
 #include "SelectAttackType.h"
+#include "SwapHeroes.h"
 #include "../BattleState.h"
 #include "../MoveMenu.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
-#include "../../geometry/operators.h"
+#include "../../math/Vector.h"
 
+using app::Application;
 using app::Input;
-using geometry::Point;
-using geometry::Vector;
+using math::Vector;
 
 namespace battle {
 
-void SelectMoveAction::EnterState(app::Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+SelectMoveAction::SelectMoveAction(Battle *battle, BattleState *parent)
+: battle(battle)
+, parent(parent) {
+
+}
+
+
+void SelectMoveAction::OnEnterState(SDL_Surface *screen) {
+       OnResize(screen->w, screen->h);
 }
 
-void SelectMoveAction::ExitState() {
-       ctrl = 0;
+void SelectMoveAction::OnExitState(SDL_Surface *screen) {
+
 }
 
+void SelectMoveAction::OnResumeState(SDL_Surface *screen) {
+
+}
+
+void SelectMoveAction::OnPauseState(SDL_Surface *screen) {
+
+}
 
-void SelectMoveAction::Resize(int width, int height) {
 
+void SelectMoveAction::OnResize(int width, int height) {
+       position = parent->ScreenOffset() + Vector<int>(
+                       (parent->Width() - parent->GetMoveMenu().Width()) / 2,
+                       parent->Height() - parent->GetMoveMenu().Height() - parent->GetMoveMenu().Height() / 2);
 }
 
 
-void SelectMoveAction::HandleInput(const app::Input &input) {
+void SelectMoveAction::HandleEvents(const Input &input) {
        if (input.IsDown(Input::PAD_UP)) {
-               battle->GetMoveMenu().Select(MoveMenu::CHANGE);
+               parent->GetMoveMenu().Select(MoveMenu::CHANGE);
        } else if (input.IsDown(Input::PAD_DOWN)) {
-               battle->GetMoveMenu().Select(MoveMenu::RUN);
+               parent->GetMoveMenu().Select(MoveMenu::RUN);
        } else {
-               battle->GetMoveMenu().Select(MoveMenu::ATTACK);
+               parent->GetMoveMenu().Select(MoveMenu::ATTACK);
        }
 
        if (input.JustPressed(Input::ACTION_A)) {
-               switch (battle->GetMoveMenu().Selected()) {
+               switch (parent->GetMoveMenu().Selected()) {
                        case MoveMenu::ATTACK:
-                               ctrl->ChangeState(new SelectAttackType(battle));
+                               Ctrl().ChangeState(new SelectAttackType(battle, parent));
                                battle->NextHero();
                                break;
                        case MoveMenu::CHANGE:
-                               // TODO: switch to change state
+                               Ctrl().PushState(new SwapHeroes(battle, this));
                                break;
                        case MoveMenu::RUN:
-                               // TODO: switch to run state
+                               Ctrl().ChangeState(new RunState(parent));
                                break;
                }
        }
 }
 
-void SelectMoveAction::UpdateWorld(float deltaT) {
+void SelectMoveAction::UpdateWorld(Uint32 deltaT) {
 
 }
 
 void SelectMoveAction::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       battle->RenderBackground(screen, offset);
-       battle->RenderMonsters(screen, offset);
-       battle->RenderHeroTags(screen, offset);
-       RenderMenu(screen, offset);
+       parent->RenderBackground(screen);
+       parent->RenderMonsters(screen);
+       parent->RenderHeroTags(screen);
+       RenderMenu(screen);
+}
+
+void SelectMoveAction::RenderMenu(SDL_Surface *screen) {
+       parent->GetMoveMenu().Render(screen, position);
+}
+
+
+const Resources &SelectMoveAction::Res() const {
+       return parent->Res();
+}
+
+const Vector<int> &SelectMoveAction::ScreenOffset() const {
+       return parent->ScreenOffset();
+}
+
+const HeroTag &SelectMoveAction::HeroTagAt(int index) const {
+       return parent->HeroTagAt(index);
 }
 
-void SelectMoveAction::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       Point<int> position(
-                       (battle->BackgroundWidth() - battle->GetMoveMenu().Width()) / 2,
-                       (battle->BackgroundHeight() * 3 / 4) - (battle->GetMoveMenu().Height() / 2));
-       battle->GetMoveMenu().Render(screen, position + offset);
+const Vector<int> &SelectMoveAction::HeroTagPositionAt(int index) const {
+       return parent->HeroTagPositionAt(index);
 }
 
 }