-/*
- * SelectMoveAction.cpp
- *
- * Created on: Aug 7, 2012
- * Author: holy
- */
-
#include "SelectMoveAction.h"
#include "RunState.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(Application &c, SDL_Surface *screen) {
- ctrl = &c;
+SelectMoveAction::SelectMoveAction(Battle *battle, BattleState *parent)
+: battle(battle)
+, parent(parent) {
+
}
-void SelectMoveAction::ExitState(Application &c, SDL_Surface *screen) {
- ctrl = 0;
+
+void SelectMoveAction::OnEnterState(SDL_Surface *screen) {
+ OnResize(screen->w, screen->h);
}
-void SelectMoveAction::ResumeState(Application &ctrl, SDL_Surface *screen) {
+void SelectMoveAction::OnExitState(SDL_Surface *screen) {
}
-void SelectMoveAction::PauseState(Application &ctrl, 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::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:
- ctrl->PushState(new SwapHeroes(battle, this));
+ Ctrl().PushState(new SwapHeroes(battle, this));
break;
case MoveMenu::RUN:
- ctrl->ChangeState(new RunState(battle));
+ 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->Width() - battle->GetMoveMenu().Width()) / 2,
- battle->Height() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
- battle->GetMoveMenu().Render(screen, position + offset);
+const Vector<int> &SelectMoveAction::HeroTagPositionAt(int index) const {
+ return parent->HeroTagPositionAt(index);
}
}