X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectTarget.cpp;h=f9507a17024966158efca526d50193961bd2c8b4;hb=087783315ac5955c17bb3b051c9351f321653df6;hp=25838571162f0aa45e58ff88012063ce0024ade6;hpb=8a6225176cd0946363ac2d8219d54a13009de675;p=l2e.git diff --git a/src/battle/states/SelectTarget.cpp b/src/battle/states/SelectTarget.cpp index 2583857..f9507a1 100644 --- a/src/battle/states/SelectTarget.cpp +++ b/src/battle/states/SelectTarget.cpp @@ -1,57 +1,77 @@ -/* - * SelectTarget.cpp - * - * Created on: Aug 9, 2012 - * Author: holy - */ - #include "SelectTarget.h" #include "SelectAttackType.h" #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" -#include "../../geometry/operators.h" -#include "../../geometry/Point.h" +#include "../../math/Vector.h" using app::Application; using app::Input; -using geometry::Point; -using geometry::Vector; +using math::Vector; using std::vector; namespace battle { -void SelectTarget::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; +SelectTarget::SelectTarget( + Battle *battle, + SelectAttackType *parent, + TargetSelection *selection, + const graphics::Sprite *cursorIcon) +: battle(battle) +, parent(parent) +, selection(selection) +, cursorIcon(cursorIcon) +, flipFlop(true) { + +} + + +void SelectTarget::OnEnterState(SDL_Surface *screen) { + OnResize(screen->w, screen->h); } -void SelectTarget::ExitState(Application &c, SDL_Surface *screen) { - ctrl = 0; +void SelectTarget::OnExitState(SDL_Surface *screen) { + } -void SelectTarget::ResumeState(Application &ctrl, SDL_Surface *screen) { +void SelectTarget::OnResumeState(SDL_Surface *screen) { } -void SelectTarget::PauseState(Application &ctrl, SDL_Surface *screen) { +void SelectTarget::OnPauseState(SDL_Surface *screen) { } -void SelectTarget::Resize(int width, int height) { +void SelectTarget::OnResize(int width, int height) { + Vector offset(parent->ScreenOffset()); + cursorOffset = Vector(cursorIcon->Width() / -2, cursorIcon->Height()) + offset; + // offset the indicator by 1/8th to the right and top + indicatorOffset = cursorOffset + Vector(cursorIcon->Width() / 8, cursorIcon->Height() / -8); + monsterPositions.clear(); + monsterPositions.reserve(battle->NumMonsters()); + for (int i(0), end(battle->NumMonsters()); i < end; ++i) { + monsterPositions.push_back(battle->MonsterAt(i).Position()); + } + + heroPositions.clear(); + heroPositions.reserve(battle->NumHeroes()); + for (int i(0), end(battle->NumHeroes()); i < end; ++i) { + heroPositions.push_back(parent->HeroTagPositionAt(i) + parent->HeroTagAt(i).HeroOffset()); + } } void SelectTarget::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (selection->CurrentIsSelected()) { - ctrl->PopState(); // return control to parent + Ctrl().PopState(); // return control to parent } else { selection->Select(); if (selection->SelectSingle()) { - ctrl->PopState(); // return control to parent + Ctrl().PopState(); // return control to parent } } } @@ -60,7 +80,7 @@ void SelectTarget::HandleEvents(const Input &input) { selection->Unselect(); } else { selection->UnselectAll(); - ctrl->PopState(); // return control to parent + Ctrl().PopState(); // return control to parent } } @@ -78,40 +98,30 @@ void SelectTarget::HandleEvents(const Input &input) { } } -void SelectTarget::UpdateWorld(float deltaT) { +void SelectTarget::UpdateWorld(Uint32 deltaT) { } void SelectTarget::Render(SDL_Surface *screen) { - Vector offset(battle->CalculateScreenOffset(screen)); parent->Render(screen); - RenderCursors(screen, offset); + RenderCursors(screen); } -void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector &offset) { - // TODO: this should be related to the enemy's width - Vector cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height()); - // offset the indicator by 1/8th to the right and top - Vector indicatorOffset(cursorOffset + Vector(cursorIcon->Width() / 8, cursorIcon->Height() / -8)); - vector > positions; - if (selection->TargetsEnemies()) { - for (vector >::const_iterator i(battle->MonsterPositions().begin()), end(battle->MonsterPositions().end()); i != end; ++i) { - positions.push_back(*i); - } - } else { - for (int i(0), end(battle->NumHeroes()); i < end; ++i) { - positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset()); - } - } +void SelectTarget::RenderCursors(SDL_Surface *screen) { + vector > &positions = selection->TargetsMonsters() + ? monsterPositions + : heroPositions; + if (flipFlop) { - for (vector >::size_type i(0); i < positions.size(); ++i) { + for (vector >::size_type i(0), end(positions.size()); + i != end; ++i) { if (selection->IsSelected(i)) { - cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset); + cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset); } } } flipFlop = !flipFlop; - cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset); + cursorIcon->DrawTopRight(screen, positions[selection->Current()] + cursorOffset); } }