X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectItem.cpp;h=0291b739c9c2746b5b17f6f72edf58fabb203f57;hb=00b557a47e47d9410730d47d436f6158a3fb79f5;hp=4f6c7af1eb049b4b6d0492132a823a4f0b0a22e4;hpb=536a8c96ebfec2a2b34f680d3d0b97db8e66d599;p=l2e.git diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 4f6c7af..0291b73 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)) { @@ -86,7 +110,7 @@ void SelectItem::Render(SDL_Surface *screen) { void SelectItem::RenderFrame(SDL_Surface *screen, const Vector &offset) { const Frame *frame(battle->Res().selectFrame); Point position(frame->BorderWidth(), frame->BorderHeight()); - int width(battle->BackgroundWidth() - 2 * frame->BorderWidth()); + int width(battle->Width() - 2 * frame->BorderWidth()); int height(battle->Res().normalFont->CharHeight() * 13); frame->Draw(screen, position + offset, width, height); }