]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.cpp
reworked Application's state stack
[l2e.git] / src / battle / BattleState.cpp
index a2c306a2ef7050d1fd9d0a468d768d152962229b..2c5fe8174449ceb899f2bf7f8f634baff60304ba 100644 (file)
@@ -8,6 +8,7 @@
 #include "BattleState.h"
 
 #include "PartyLayout.h"
+#include "states/SelectMoveAction.h"
 #include "../app/Application.h"
 #include "../app/Input.h"
 #include "../geometry/operators.h"
@@ -52,41 +53,25 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        }
 }
 
-void BattleState::ExitState() {
+void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+void BattleState::ResumeState(Application &ctrl, SDL_Surface *screen) {
+       // reset attack choices
+       activeHero = -1;
+       attackChoices.clear();
+       attackChoices.resize(heroes.size());
+       ctrl.PushState(new SelectMoveAction(this));
+}
+
+void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
 
 }
 
 
 void BattleState::HandleInput(const Input &input) {
-       if (moveChoice == -1) {
-               if (input.IsDown(Input::PAD_UP)) {
-                       moveMenu.Select(MoveMenu::CHANGE);
-               } else if (input.IsDown(Input::PAD_DOWN)) {
-                       moveMenu.Select(MoveMenu::RUN);
-               } else {
-                       moveMenu.Select(MoveMenu::ATTACK);
-               }
-
-               if (input.JustPressed(Input::ACTION_A)) {
-                       moveChoice = moveMenu.Selected();
-               }
-       } else {
-               if (input.IsDown(Input::PAD_UP)) {
-                       attackTypeMenu.Select(AttackTypeMenu::MAGIC);
-               } else if (input.IsDown(Input::PAD_RIGHT)) {
-                       attackTypeMenu.Select(AttackTypeMenu::DEFEND);
-               } else if (input.IsDown(Input::PAD_DOWN)) {
-                       attackTypeMenu.Select(AttackTypeMenu::IKARI);
-               } else if (input.IsDown(Input::PAD_LEFT)) {
-                       attackTypeMenu.Select(AttackTypeMenu::ITEM);
-               } else {
-                       attackTypeMenu.Select(AttackTypeMenu::SWORD);
-               }
-
-               if (input.JustPressed(Input::ACTION_A)) {
-                       activeHero = (activeHero + 1) % 4;
-               }
-       }
+
 }
 
 void BattleState::UpdateWorld(float deltaT) {
@@ -94,19 +79,12 @@ void BattleState::UpdateWorld(float deltaT) {
 }
 
 void BattleState::Render(SDL_Surface *screen) {
-       Vector<int> offset(
-                       (screen->w - background->w) / 2,
-                       (screen->h - background->h) / 2);
+       Vector<int> offset(CalculateScreenOffset(screen));
 
        RenderBackground(screen, offset);
        RenderMonsters(screen, offset);
 //     RenderHeroes(screen, offset);
        RenderHeroTags(screen, offset);
-       if (moveChoice == -1) {
-               RenderMoveMenu(screen, offset);
-       } else {
-               RenderAttackTypeMenu(screen, offset);
-       }
 }
 
 void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
@@ -133,9 +111,9 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
 }
 
 void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
-       int uiHeight(background->h / 2), uiOffset(uiHeight);
+       int uiHeight(BackgroundHeight() / 2), uiOffset(uiHeight);
        int tagHeight((uiHeight - attackTypeMenu.IconHeight()) / 2);
-       int tagWidth((background->w - attackTypeMenu.IconWidth()) / 2);
+       int tagWidth((BackgroundWidth() - attackTypeMenu.IconWidth()) / 2);
 
        Point<int> tagPosition[4];
        tagPosition[0] = Point<int>(0, uiOffset);
@@ -144,22 +122,8 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset)
        tagPosition[3] = Point<int>(tagWidth + attackTypeMenu.IconWidth(), uiOffset + tagHeight + attackTypeMenu.IconHeight());
 
        for (vector<HeroTag>::size_type i(0), end(heroTags.size()); i < end; ++i) {
-               heroTags[i].Render(screen, tagWidth, tagHeight, tagPosition[i] + offset, i == activeHero);
+               heroTags[i].Render(screen, tagWidth, tagHeight, tagPosition[i] + offset, (int)i == activeHero);
        }
 }
 
-void BattleState::RenderAttackTypeMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       Point<int> position(
-                       (background->w - attackTypeMenu.Width()) / 2,
-                       (background->h * 3 / 4) - (attackTypeMenu.Height() / 2));
-       attackTypeMenu.Render(screen, position + offset);
-}
-
-void BattleState::RenderMoveMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       Point<int> position(
-                       (background->w - moveMenu.Width()) / 2,
-                       (background->h * 3 / 4) - (moveMenu.Height() / 2));
-       moveMenu.Render(screen, position + offset);
-}
-
 }