#include "SelectAttackType.h"
+#include "SelectIkari.h"
+#include "SelectItem.h"
+#include "SelectMoveAction.h"
+#include "SelectSpell.h"
+#include "SelectTarget.h"
#include "../AttackChoice.h"
#include "../BattleState.h"
#include "../../app/Application.h"
#include "../../app/Input.h"
+#include "../../common/Item.h"
#include "../../geometry/operators.h"
#include <stdexcept>
using app::Application;
using app::Input;
+using common::Item;
using geometry::Point;
using geometry::Vector;
}
void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+ if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
+ battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
+ battle->NextHero();
+ }
+ if (battle->AttackSelectionDone()) {
+ // pass through
+ ctrl.PopState();
+ }
}
void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
}
-void SelectAttackType::HandleInput(const Input &input) {
+void SelectAttackType::HandleEvents(const Input &input) {
if (input.IsDown(Input::PAD_UP)) {
battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
} else if (input.IsDown(Input::PAD_RIGHT)) {
battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
}
+ Hero &hero(battle->ActiveHero());
+ AttackChoice &ac(hero.GetAttackChoice());
if (input.JustPressed(Input::ACTION_A)) {
- battle->SetAttackType(battle->GetAttackTypeMenu().Selected());
switch (battle->GetAttackTypeMenu().Selected()) {
case AttackChoice::SWORD:
- battle->NextHero();
+ if (hero.HasWeapon()) {
+ if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
+ ac.SetType(AttackChoice::SWORD);
+ battle->NextHero();
+ break;
+ } else {
+ ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
+ }
+ } else {
+ ac.Selection().SetSingle();
+ }
+ ac.Selection().Reset();
+ ctrl->PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
break;
case AttackChoice::MAGIC:
- // TODO: switch to spell select
+ if (battle->ActiveHero().CanUseMagic()) {
+ ctrl->PushState(new SelectSpell(battle, this));
+ }
break;
case AttackChoice::DEFEND:
+ ac.SetType(AttackChoice::DEFEND);
battle->NextHero();
break;
case AttackChoice::IKARI:
- // TODO: switch to ikari attack select
+ ctrl->PushState(new SelectIkari(battle, this));
break;
case AttackChoice::ITEM:
- // TODO: switch to item select
+ ctrl->PushState(new SelectItem(battle, this));
break;
default:
throw std::logic_error("selected invalid attack type");
}
+ } else if (input.JustPressed(Input::ACTION_B)) {
+ ac.Reset();
+ battle->PreviousHero();
+ if (battle->BeforeFirstHero()) {
+ ctrl->ChangeState(new SelectMoveAction(battle));
+ } else {
+ battle->ActiveHero().GetAttackChoice().Reset();
+ }
}
if (battle->AttackSelectionDone()) {
- // TODO: switch to battle animation instead
ctrl->PopState();
}
}
void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
Point<int> position(
- (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2,
- (battle->BackgroundHeight() * 3 / 4) - (battle->GetAttackTypeMenu().Height() / 2));
+ (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
+ battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
battle->GetAttackTypeMenu().Render(screen, position + offset);
}