X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectAttackType.cpp;h=b4f5dcc73f69a071bc4877d682dc27d2c52da2c4;hb=0b11a24a8b08c49d6e4301573602fb6d01e7a8c8;hp=4bac0bbe50cf1d8ebf7a827f042e14588bd304cb;hpb=2147d00bbcb43f5cb4499091f646057cb6944cb3;p=l2e.git diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 4bac0bb..b4f5dcc 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -1,10 +1,3 @@ -/* - * SelectAttackType.cpp - * - * Created on: Aug 7, 2012 - * Author: holy - */ - #include "SelectAttackType.h" #include "SelectIkari.h" @@ -16,43 +9,48 @@ #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" -#include "../../geometry/operators.h" +#include "../../common/Item.h" +#include "../../math/Vector.h" #include using app::Application; using app::Input; -using geometry::Point; -using geometry::Vector; +using common::Item; +using math::Vector; namespace battle { -void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; +void SelectAttackType::OnEnterState(SDL_Surface *screen) { + OnResize(screen->w, screen->h); } -void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) { - ctrl = 0; +void SelectAttackType::OnExitState(SDL_Surface *screen) { + } -void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) { +void SelectAttackType::OnResumeState(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(); + Ctrl().PopState(); } } -void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) { +void SelectAttackType::OnPauseState(SDL_Surface *screen) { } -void SelectAttackType::Resize(int width, int height) { - +void SelectAttackType::OnResize(int width, int height) { + Vector offset(battle->ScreenOffset()); + Vector position( + (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2, + battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2); + menuOffset = offset + position; } @@ -69,64 +67,71 @@ void SelectAttackType::HandleEvents(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: detect single/multiple/all attack mode - battle->ActiveHero().GetAttackChoice().Selection().SetSingle(); - battle->ActiveHero().GetAttackChoice().Selection().Reset(); - ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHero().GetAttackChoice().Selection(), battle->Res().weaponTargetCursor)); + 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()) { - ctrl->PushState(new SelectSpell(battle, this)); + Ctrl().PushState(new SelectSpell(battle, this)); } break; case AttackChoice::DEFEND: - battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::DEFEND); + ac.SetType(AttackChoice::DEFEND); battle->NextHero(); break; case AttackChoice::IKARI: - ctrl->PushState(new SelectIkari(battle, this)); + Ctrl().PushState(new SelectIkari(battle, this)); break; case AttackChoice::ITEM: - ctrl->PushState(new SelectItem(battle, this)); + Ctrl().PushState(new SelectItem(battle, this)); break; default: throw std::logic_error("selected invalid attack type"); } } else if (input.JustPressed(Input::ACTION_B)) { - battle->ActiveHero().GetAttackChoice().Reset(); + ac.Reset(); battle->PreviousHero(); if (battle->BeforeFirstHero()) { - ctrl->ChangeState(new SelectMoveAction(battle)); + Ctrl().ChangeState(new SelectMoveAction(battle)); } else { battle->ActiveHero().GetAttackChoice().Reset(); } } if (battle->AttackSelectionDone()) { - ctrl->PopState(); + Ctrl().PopState(); } } -void SelectAttackType::UpdateWorld(float deltaT) { +void SelectAttackType::UpdateWorld(Uint32 deltaT) { } void SelectAttackType::Render(SDL_Surface *screen) { - Vector offset(battle->CalculateScreenOffset(screen)); - battle->RenderBackground(screen, offset); - battle->RenderMonsters(screen, offset); - battle->RenderHeroTags(screen, offset); - RenderMenu(screen, offset); + battle->RenderBackground(screen); + battle->RenderMonsters(screen); + battle->RenderHeroTags(screen); + RenderMenu(screen); } -void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector &offset) { - Point position( - (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2, - battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2); - battle->GetAttackTypeMenu().Render(screen, position + offset); +void SelectAttackType::RenderMenu(SDL_Surface *screen) { + battle->GetAttackTypeMenu().Render(screen, menuOffset); } }