X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectItem.cpp;h=b64311640020055369f1d692726799c324d3d302;hb=a3ba4dc677ad7c92eeb78b20b642241563605c9d;hp=22369f304252d6cf7ff82cae5e86bc738ebe2621;hpb=e27fcf693589ede18b753d5f64f9dfecfe6344bd;p=l2e.git diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 22369f3..b643116 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -13,85 +13,82 @@ #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 math::Vector; using graphics::Frame; namespace battle { -void SelectItem::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; +void SelectItem::OnEnterState(SDL_Surface *screen) { + } -void SelectItem::ExitState(Application &c, SDL_Surface *screen) { - ctrl = 0; +void SelectItem::OnExitState(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::OnResumeState(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(SDL_Surface *screen) { } -void SelectItem::Resize(int width, int height) { +void SelectItem::OnResize(int width, int height) { } void SelectItem::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { - if (battle->GetItemMenu().SelectedIsEnabled()) { - const Item *item(battle->GetItemMenu().Selected()); - battle->ActiveHeroAttackChoice().Selection().Reset(); + if (battle->ItemMenu().SelectedIsEnabled()) { + AttackChoice &ac(battle->ActiveHero().GetAttackChoice()); + const Item *item(battle->ItemMenu().Selected()); + ac.Selection().Reset(); if (item->GetTargetingMode().TargetsAlly()) { - battle->ActiveHeroAttackChoice().Selection().SelectHeroes(); + ac.Selection().SelectHeroes(); } else { - battle->ActiveHeroAttackChoice().Selection().SelectEnemies(); + ac.Selection().SelectMonsters(); } if (item->GetTargetingMode().TargetsAll()) { - battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM); - // TODO: remove item from inventory - battle->ActiveHeroAttackChoice().SetItem(item); + ac.SetType(AttackChoice::ITEM); + ac.SetItem(item); battle->NextHero(); - ctrl->PopState(); + Ctrl().PopState(); } else { if (item->GetTargetingMode().TargetsSingle()) { - battle->ActiveHeroAttackChoice().Selection().SetSingle(); + ac.Selection().SetSingle(); } else { - battle->ActiveHeroAttackChoice().Selection().SetMultiple(); + ac.Selection().SetMultiple(); } - ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().itemTargetCursor)); + Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().itemTargetCursor)); } } } if (input.JustPressed(Input::ACTION_B)) { - ctrl->PopState(); // return control to parent + 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(); } } @@ -109,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); @@ -125,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); } }