]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SwapHeroes.cpp
cached some of the battle coordinates
[l2e.git] / src / battle / states / SwapHeroes.cpp
index 74770277c808eedead551aa5c5f6f49ba274f38d..af867477bc3d44477ebf933dddbc67656e3bc94e 100644 (file)
@@ -14,7 +14,7 @@ using std::vector;
 namespace battle {
 
 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SwapHeroes::OnExitState(SDL_Surface *screen) {
@@ -31,7 +31,24 @@ void SwapHeroes::OnPauseState(SDL_Surface *screen) {
 
 
 void SwapHeroes::OnResize(int width, int height) {
+       Vector<int> offset(battle->ScreenOffset());
+       // offset the cursor by 1/8th to the left and bottom
+       cursorOffset = Vector<int>(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
+       indicatorOffset = Vector<int>(0, 0);
 
+       positions.clear();
+       positions.reserve(battle->NumHeroes());
+       for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
+               Vector<int> 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);
+       }
 }
 
 
@@ -109,31 +126,21 @@ void SwapHeroes::UpdateWorld(Uint32 deltaT) {
 }
 
 void SwapHeroes::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
        parent->Render(screen);
-       RenderCursors(screen, offset);
+       RenderCursors(screen);
 }
 
-void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
-       // offset the cursor by 1/8th to the left and bottom
-       Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
-       Vector<int> indicatorOffset(0, 0);
-       vector<Vector<int> > positions;
-       for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
-               Vector<int> 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<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
+               for (vector<Vector<int> >::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);
 }
 
 }