X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FCapsuleChangeMenu.cpp;h=47c7b2eb5d57bdae5ccbd8a696a907477b75f5de;hb=f6548c2aabfb371bd81382d7800e6e2cdb826e06;hp=3b161ad9df6ff6e0839a90c70166c52ce50a66f2;hpb=67f6bb1d9727e7d1e2140cf2913aa89ebba84bf5;p=l2e.git diff --git a/src/menu/CapsuleChangeMenu.cpp b/src/menu/CapsuleChangeMenu.cpp index 3b161ad..47c7b2e 100644 --- a/src/menu/CapsuleChangeMenu.cpp +++ b/src/menu/CapsuleChangeMenu.cpp @@ -10,12 +10,14 @@ #include "../common/GameState.h" #include "../graphics/Font.h" #include "../graphics/Frame.h" +#include "../graphics/Texture.h" +#include "../math/Vector.h" using app::Input; using common::Capsule; using common::Inventory; using common::Item; -using geometry::Vector; +using math::Vector; using graphics::Font; using graphics::Frame; @@ -50,12 +52,61 @@ void CapsuleChangeMenu::OnResize(int width, int height) { void CapsuleChangeMenu::HandleEvents(const Input &input) { - if (input.JustPressed(Input::ACTION_B)) { + if (input.JustPressed(Input::ACTION_A) + || input.JustPressed(Input::ACTION_B)) { Ctrl().PopState(); } + + if (input.JustPressed(Input::PAD_UP)) { + NextClass(); + } + if (input.JustPressed(Input::PAD_RIGHT)) { + NextCapsule(); + } + if (input.JustPressed(Input::PAD_DOWN)) { + PreviousClass(); + } + if (input.JustPressed(Input::PAD_LEFT)) { + PreviousCapsule(); + } +} + +void CapsuleChangeMenu::NextCapsule() { + int storedClass = parent->Game().state->GetCapsule().ClassIndex(); + int &index = parent->Game().state->capsule; + ++index; + index %= parent->Game().state->NumCapsules(); + // skip unexplored + while (parent->Game().state->GetCapsule().MaxClass() <= 0) { + ++index; + index %= parent->Game().state->NumCapsules(); + } + parent->Game().state->GetCapsule().SetClass(storedClass); +} + +void CapsuleChangeMenu::PreviousCapsule() { + int storedClass = parent->Game().state->GetCapsule().ClassIndex(); + int &index = parent->Game().state->capsule; + --index; + if (index < 0) index += parent->Game().state->NumCapsules(); + // skip unexplored + while (GetCapsule().MaxClass() <= 0) { + --index; + if (index < 0) index += parent->Game().state->NumCapsules(); + } + parent->Game().state->GetCapsule().SetClass(storedClass); +} + +void CapsuleChangeMenu::NextClass() { + GetCapsule().NextClass(); +} + +void CapsuleChangeMenu::PreviousClass() { + GetCapsule().PreviousClass(); } -void CapsuleChangeMenu::UpdateWorld(float deltaT) { + +void CapsuleChangeMenu::UpdateWorld(Uint32 deltaT) { } @@ -69,18 +120,76 @@ void CapsuleChangeMenu::Render(SDL_Surface *screen) { 12 * font.CharWidth(), 2 * font.CharHeight() - font.CharHeight() / 8); // TODO: wheel offset: top left, center, or center bottom? - const Vector wheelOffset; + const Vector wheelOffset( + 6 * font.CharWidth(), + 19 * font.CharHeight() - font.CharHeight() / 8); + const Vector classesOffset( + 12 * font.CharWidth(), + 13 * font.CharHeight() - font.CharHeight() / 8); const Vector menuOffset( - font.CharWidth(), - 24 * font.CharHeight() - font.CharHeight() / 8); + font.CharWidth(), + 24 * font.CharHeight() - font.CharHeight() / 8); parent->RenderBackground(screen); parent->RenderCapsule(screen, offset + capsuleOffset); parent->RenderInfo(screen, offset + infoOffset); parent->RenderWheel(screen, offset + wheelOffset); + RenderClasses(screen, offset + classesOffset); parent->RenderMenu(screen, offset + menuOffset); } +void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector &offset) const { + Vector cursor(offset); + + int numClasses = 0; + for (int i = 0; i < parent->Game().state->NumCapsules(); ++i) { + if (numClasses < parent->Game().state->capsules[i].NumClasses()) { + numClasses = parent->Game().state->capsules[i].NumClasses(); + } + } + + parent->Res().capsuleSelectTopLeft->Draw(screen, cursor); + cursor.Y() += parent->Res().capsuleSelectTopLeft->Height(); + Vector target( + cursor.X() + parent->Res().capsuleSelectTopLeft->Width(), + cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height()); + parent->Res().capsuleSelectLeftRepeat->Draw(screen, cursor, target); + cursor.Y() = target.Y(); + parent->Res().capsuleSelectBottomLeft->Draw(screen, cursor); + cursor.X() += parent->Res().capsuleSelectTopLeft->Width(); + + for (int i = 0; i < parent->Game().state->NumCapsules(); ++i) { + cursor.Y() = offset.Y(); + parent->Res().capsuleSelectTopRepeat->Draw(screen, cursor); + cursor.Y() += parent->Res().capsuleSelectTopRepeat->Height(); + for (int j = numClasses - 1; j >= 0; --j) { + parent->Res().capsuleSelectLadder->Draw( + screen, cursor, + j < parent->Game().state->capsules[i].MaxClass(), j); + if (i == parent->Game().state->capsule + && parent->Game().state->capsules[i].CurrentClass() == j) { + parent->Res().capsuleSelectCursor->Draw(screen, cursor); + } + cursor.Y() += parent->Res().capsuleSelectLadder->Height(); + } + parent->Res().capsuleSelectBottomRepeat->Draw(screen, cursor); + if (parent->Game().state->capsules[i].AlignmentSprite()) { + parent->Game().state->capsules[i].AlignmentSprite()->Draw(screen, cursor); + } + cursor.X() += parent->Res().capsuleSelectLadder->Width(); + } + + cursor.Y() = offset.Y(); + parent->Res().capsuleSelectTopRight->Draw(screen, cursor); + cursor.Y() += parent->Res().capsuleSelectTopRight->Height(); + target = Vector( + cursor.X() + parent->Res().capsuleSelectTopRight->Width(), + cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height()); + parent->Res().capsuleSelectRightRepeat->Draw(screen, cursor, target); + cursor.Y() = target.Y(); + parent->Res().capsuleSelectBottomRight->Draw(screen, cursor); +} + int CapsuleChangeMenu::Width() const { return parent->Width(); @@ -90,6 +199,10 @@ int CapsuleChangeMenu::Height() const { return parent->Height(); } +Capsule &CapsuleChangeMenu::GetCapsule() { + return parent->GetCapsule(); +} + const Capsule &CapsuleChangeMenu::GetCapsule() const { return parent->GetCapsule(); }