X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectTarget.cpp;h=dc8c1239145f9a7cfbd95828a2c16612eea25e27;hb=0b11a24a8b08c49d6e4301573602fb6d01e7a8c8;hp=800c2335e53460cda706440e1ae0bcefc7de8858;hpb=d97b7038c28058a76e7214e0dce0394fd8b67cff;p=l2e.git diff --git a/src/battle/states/SelectTarget.cpp b/src/battle/states/SelectTarget.cpp index 800c233..dc8c123 100644 --- a/src/battle/states/SelectTarget.cpp +++ b/src/battle/states/SelectTarget.cpp @@ -14,7 +14,7 @@ using std::vector; namespace battle { void SelectTarget::OnEnterState(SDL_Surface *screen) { - + OnResize(screen->w, screen->h); } void SelectTarget::OnExitState(SDL_Surface *screen) { @@ -31,7 +31,22 @@ void SelectTarget::OnPauseState(SDL_Surface *screen) { void SelectTarget::OnResize(int width, int height) { + Vector offset(battle->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->MaxMonsters()); + for (int i(0), end(battle->MaxMonsters()); 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(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset()); + } } @@ -74,34 +89,25 @@ 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 math::Vector &offset) { - 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->TargetsMonsters()) { - for (int i(0), end(battle->MaxMonsters()); i < end; ++i) { - positions.push_back(battle->MonsterAt(i).Position()); - } - } 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); } }