X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSwapHeroes.cpp;h=799cff8d07213cd56d8d4dee59f1e9cb59240feb;hb=087783315ac5955c17bb3b051c9351f321653df6;hp=c9fad2dbbbb4501452200c3bd039e890ca046763;hpb=092a2dd175a4001a495c84ee85211734fb928c83;p=l2e.git diff --git a/src/battle/states/SwapHeroes.cpp b/src/battle/states/SwapHeroes.cpp index c9fad2d..799cff8 100644 --- a/src/battle/states/SwapHeroes.cpp +++ b/src/battle/states/SwapHeroes.cpp @@ -1,10 +1,3 @@ -/* - * SwapHeroes.cpp - * - * Created on: Aug 10, 2012 - * Author: holy - */ - #include "SwapHeroes.h" #include "SelectMoveAction.h" @@ -20,8 +13,18 @@ using std::vector; namespace battle { -void SwapHeroes::OnEnterState(SDL_Surface *screen) { +SwapHeroes::SwapHeroes(Battle *battle, SelectMoveAction *parent) +: battle(battle) +, parent(parent) +, cursor(0) +, selected(-1) +, flipFlop(true) { + +} + +void SwapHeroes::OnEnterState(SDL_Surface *screen) { + OnResize(screen->w, screen->h); } void SwapHeroes::OnExitState(SDL_Surface *screen) { @@ -38,7 +41,24 @@ void SwapHeroes::OnPauseState(SDL_Surface *screen) { void SwapHeroes::OnResize(int width, int height) { + Vector offset(parent->ScreenOffset()); + // offset the cursor by 1/8th to the left and bottom + cursorOffset = Vector(parent->Res().swapCursor->Width() / -8, parent->Res().swapCursor->Height() / 8); + indicatorOffset = Vector(0, 0); + positions.clear(); + positions.reserve(battle->NumHeroes()); + for (int i(0), end(battle->NumHeroes()); i < end; ++i) { + Vector positionCorrection( + parent->Res().swapCursor->Width() / 2, + parent->HeroTagAt(i).HeroSprite()->Height() - parent->Res().swapCursor->Height() / 2); + // indicator offsets are inverted for heroes + positionCorrection -= cursorOffset; + positions.push_back(parent->HeroTagPositionAt(i) + + parent->HeroTagAt(i).HeroOffset() + + positionCorrection + + offset); + } } @@ -116,31 +136,21 @@ void SwapHeroes::UpdateWorld(Uint32 deltaT) { } void SwapHeroes::Render(SDL_Surface *screen) { - Vector offset(battle->CalculateScreenOffset(screen)); parent->Render(screen); - RenderCursors(screen, offset); + RenderCursors(screen); } -void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector &offset) { - // offset the cursor by 1/8th to the left and bottom - Vector cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8); - Vector indicatorOffset(0, 0); - vector > positions; - for (int i(0), end(battle->NumHeroes()); i < end; ++i) { - Vector positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2); - // indicator offsets are inverted for heroes - positionCorrection -= cursorOffset; - positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection); - } +void SwapHeroes::RenderCursors(SDL_Surface *screen) { 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 (selected == int(i)) { - battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset); + parent->Res().swapCursor->DrawTopRight(screen, positions[i]); } } } flipFlop = !flipFlop; - battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset); + parent->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset); } }