X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectItem.cpp;h=86f11c25bf3e79547671a9cb507ce85c974a2c94;hb=65158353d1ecbed0032752863c6c4eb96b1a084a;hp=97dd63fc33a53d90c32882ba37bba7e2f462d3c0;hpb=d872d756e64b8f1f57cba64ae19f479f8eab3927;p=l2e.git diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 97dd63f..86f11c2 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -13,34 +13,33 @@ #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; namespace battle { -void SelectItem::EnterState(Application &c, SDL_Surface *screen) { +void SelectItem::OnEnterState(Application &c, SDL_Surface *screen) { ctrl = &c; } -void SelectItem::ExitState(Application &c, SDL_Surface *screen) { +void SelectItem::OnExitState(Application &c, SDL_Surface *screen) { ctrl = 0; } -void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) { - if (battle->ActiveHeroTargets().HasSelected()) { +void SelectItem::OnResumeState(Application &ctrl, SDL_Surface *screen) { + if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) { + battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::ITEM); + battle->ActiveHero().GetAttackChoice().SetItem(battle->ItemMenu().Selected()); ctrl.PopState(); } } -void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) { +void SelectItem::OnPauseState(Application &ctrl, SDL_Surface *screen) { } @@ -50,49 +49,46 @@ 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)) { - if (battle->GetItemMenu().SelectedIsEnabled()) { - const Item *item(battle->GetItemMenu().Selected()); - battle->ActiveHeroTargets().Reset(); + if (battle->ItemMenu().SelectedIsEnabled()) { + AttackChoice &ac(battle->ActiveHero().GetAttackChoice()); + const Item *item(battle->ItemMenu().Selected()); + ac.Selection().Reset(); if (item->GetTargetingMode().TargetsAlly()) { - battle->ActiveHeroTargets().SelectHeroes(); + ac.Selection().SelectHeroes(); } else { - battle->ActiveHeroTargets().SelectEnemies(); + ac.Selection().SelectMonsters(); } if (item->GetTargetingMode().TargetsAll()) { - battle->SetAttackType(AttackChoice::ITEM); - // TODO: remove item from inventory - battle->ActiveHeroAttackChoice().SetItem(item); + ac.SetType(AttackChoice::ITEM); + ac.SetItem(item); battle->NextHero(); ctrl->PopState(); } else { if (item->GetTargetingMode().TargetsSingle()) { - battle->ActiveHeroTargets().SetSingle(); + ac.Selection().SetSingle(); } else { - battle->ActiveHeroTargets().SetMultiple(); + ac.Selection().SetMultiple(); } - ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().itemTargetCursor)); + ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().itemTargetCursor)); } -// battle->SetAttackType(AttackChoice::ITEM); -// battle->NextHero(); -// ctrl->PopState(); } } if (input.JustPressed(Input::ACTION_B)) { ctrl->PopState(); // return control to parent } if (input.JustPressed(Input::PAD_UP)) { - battle->GetItemMenu().PreviousRow(); + battle->ItemMenu().PreviousRow(); } if (input.JustPressed(Input::PAD_RIGHT)) { - battle->GetItemMenu().NextItem(); + battle->ItemMenu().NextItem(); } if (input.JustPressed(Input::PAD_DOWN)) { - battle->GetItemMenu().NextRow(); + battle->ItemMenu().NextRow(); } if (input.JustPressed(Input::PAD_LEFT)) { - battle->GetItemMenu().PreviousItem(); + battle->ItemMenu().PreviousItem(); } } @@ -110,15 +106,15 @@ 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()); + Vector position(frame->BorderSize()); + int width(battle->Width() - 2 * frame->BorderWidth()); int height(battle->Res().normalFont->CharHeight() * 13); frame->Draw(screen, position + offset, width, height); } void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector &offset) { const Resources &res(battle->Res()); - Point position( + Vector position( 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(), 2 * res.selectFrame->BorderHeight()); res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset); @@ -126,10 +122,10 @@ void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector &offset) void SelectItem::RenderMenu(SDL_Surface *screen, const Vector &offset) { const Resources &res(battle->Res()); - Point position( + Vector position( 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(), 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight()); - battle->GetItemMenu().Draw(screen, position + offset); + battle->ItemMenu().Draw(screen, position + offset); } }