X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSwapHeroes.cpp;h=af867477bc3d44477ebf933dddbc67656e3bc94e;hb=0b11a24a8b08c49d6e4301573602fb6d01e7a8c8;hp=5c83f7403cbfee69c369f99c0a036f733f55157e;hpb=0542849dfccfec1ce1477265fa0fee2401a8fb23;p=l2e.git diff --git a/src/battle/states/SwapHeroes.cpp b/src/battle/states/SwapHeroes.cpp index 5c83f74..af86747 100644 --- a/src/battle/states/SwapHeroes.cpp +++ b/src/battle/states/SwapHeroes.cpp @@ -1,43 +1,54 @@ -/* - * SwapHeroes.cpp - * - * Created on: Aug 10, 2012 - * Author: holy - */ - #include "SwapHeroes.h" #include "SelectMoveAction.h" #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" +#include "../../math/Vector.h" using app::Application; using app::Input; -using geometry::Vector; +using math::Vector; using std::vector; namespace battle { -void SwapHeroes::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; +void SwapHeroes::OnEnterState(SDL_Surface *screen) { + OnResize(screen->w, screen->h); } -void SwapHeroes::ExitState(Application &c, SDL_Surface *screen) { - ctrl = 0; +void SwapHeroes::OnExitState(SDL_Surface *screen) { + } -void SwapHeroes::ResumeState(Application &ctrl, SDL_Surface *screen) { +void SwapHeroes::OnResumeState(SDL_Surface *screen) { } -void SwapHeroes::PauseState(Application &ctrl, SDL_Surface *screen) { +void SwapHeroes::OnPauseState(SDL_Surface *screen) { } -void SwapHeroes::Resize(int width, int height) { +void SwapHeroes::OnResize(int width, int height) { + Vector offset(battle->ScreenOffset()); + // offset the cursor by 1/8th to the left and bottom + cursorOffset = Vector(battle->Res().swapCursor->Width() / -8, battle->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( + 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 + + offset); + } } @@ -54,7 +65,7 @@ void SwapHeroes::HandleEvents(const Input &input) { if (cursor == selected) { selected = -1; } else { - ctrl->PopState(); + Ctrl().PopState(); } } @@ -110,36 +121,26 @@ void SwapHeroes::MoveLeft() { } -void SwapHeroes::UpdateWorld(float deltaT) { +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 geometry::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); + battle->Res().swapCursor->DrawTopRight(screen, positions[i]); } } } flipFlop = !flipFlop; - battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset); + battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset); } }