X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectAttackType.cpp;h=351ad1c3584337d85a4d6b4baa3bc20a7a8fc3bb;hb=65158353d1ecbed0032752863c6c4eb96b1a084a;hp=786277d764900f036dbfffca578d3eacfd0db114;hpb=536a8c96ebfec2a2b34f680d3d0b97db8e66d599;p=l2e.git diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 786277d..351ad1c 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -11,37 +11,42 @@ #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 "../../geometry/operators.h" +#include "../../common/Item.h" #include using app::Application; using app::Input; -using geometry::Point; +using common::Item; using geometry::Vector; namespace battle { -void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) { +void SelectAttackType::OnEnterState(Application &c, SDL_Surface *screen) { ctrl = &c; } -void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) { +void SelectAttackType::OnExitState(Application &c, SDL_Surface *screen) { ctrl = 0; } -void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) { +void SelectAttackType::OnResumeState(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::OnPauseState(Application &ctrl, SDL_Surface *screen) { } @@ -51,7 +56,7 @@ void SelectAttackType::Resize(int width, int height) { } -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)) { @@ -64,12 +69,24 @@ void SelectAttackType::HandleInput(const Input &input) { battle->GetAttackTypeMenu().Select(AttackChoice::SWORD); } + Hero &hero(battle->ActiveHero()); + AttackChoice &ac(hero.GetAttackChoice()); if (input.JustPressed(Input::ACTION_A)) { switch (battle->GetAttackTypeMenu().Selected()) { case AttackChoice::SWORD: - // TODO: switch to target select - battle->SetAttackType(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: if (battle->ActiveHero().CanUseMagic()) { @@ -77,7 +94,7 @@ void SelectAttackType::HandleInput(const Input &input) { } break; case AttackChoice::DEFEND: - battle->SetAttackType(AttackChoice::DEFEND); + ac.SetType(AttackChoice::DEFEND); battle->NextHero(); break; case AttackChoice::IKARI: @@ -90,15 +107,16 @@ void SelectAttackType::HandleInput(const Input &input) { throw std::logic_error("selected invalid attack type"); } } else if (input.JustPressed(Input::ACTION_B)) { - battle->SetAttackType(AttackChoice::UNDECIDED); + 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(); } } @@ -116,9 +134,9 @@ void SelectAttackType::Render(SDL_Surface *screen) { } void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector &offset) { - Point position( - (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2, - battle->BackgroundHeight() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2); + Vector position( + (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2, + battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2); battle->GetAttackTypeMenu().Render(screen, position + offset); }