X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectItem.cpp;h=22369f304252d6cf7ff82cae5e86bc738ebe2621;hb=04b582180c8f86f50f08f5141a2514a1fcda3e01;hp=4f6c7af1eb049b4b6d0492132a823a4f0b0a22e4;hpb=536a8c96ebfec2a2b34f680d3d0b97db8e66d599;p=l2e.git diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 4f6c7af..22369f3 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -8,15 +8,18 @@ #include "SelectItem.h" #include "SelectAttackType.h" +#include "SelectTarget.h" #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" +#include "../../common/Item.h" #include "../../geometry/Point.h" #include "../../geometry/operators.h" #include "../../graphics/Frame.h" using app::Application; using app::Input; +using common::Item; using geometry::Point; using geometry::Vector; using graphics::Frame; @@ -32,7 +35,11 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) { } void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) { - + if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) { + battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM); + battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected()); + ctrl.PopState(); + } } void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) { @@ -45,13 +52,30 @@ void SelectItem::Resize(int width, int height) { } -void SelectItem::HandleInput(const Input &input) { +void SelectItem::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { - // TODO: switch to target select if (battle->GetItemMenu().SelectedIsEnabled()) { - battle->SetAttackType(AttackChoice::ITEM); - battle->NextHero(); - ctrl->PopState(); + const Item *item(battle->GetItemMenu().Selected()); + battle->ActiveHeroAttackChoice().Selection().Reset(); + if (item->GetTargetingMode().TargetsAlly()) { + battle->ActiveHeroAttackChoice().Selection().SelectHeroes(); + } else { + battle->ActiveHeroAttackChoice().Selection().SelectEnemies(); + } + if (item->GetTargetingMode().TargetsAll()) { + battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM); + // TODO: remove item from inventory + battle->ActiveHeroAttackChoice().SetItem(item); + battle->NextHero(); + ctrl->PopState(); + } else { + if (item->GetTargetingMode().TargetsSingle()) { + battle->ActiveHeroAttackChoice().Selection().SetSingle(); + } else { + battle->ActiveHeroAttackChoice().Selection().SetMultiple(); + } + ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().itemTargetCursor)); + } } } if (input.JustPressed(Input::ACTION_B)) {