X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FCapsuleChangeMenu.cpp;h=47c7b2eb5d57bdae5ccbd8a696a907477b75f5de;hb=3aca2860c95bb4d30569a23ab88a5286c3b9b757;hp=cac2056aecab713fe075f0c5fb3205010cb0b996;hpb=6dff93b1a6e9b727dbe26747456f4b23efca86da;p=l2e.git diff --git a/src/menu/CapsuleChangeMenu.cpp b/src/menu/CapsuleChangeMenu.cpp index cac2056..47c7b2e 100644 --- a/src/menu/CapsuleChangeMenu.cpp +++ b/src/menu/CapsuleChangeMenu.cpp @@ -11,12 +11,13 @@ #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; @@ -51,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::UpdateWorld(float deltaT) { +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(Uint32 deltaT) { } @@ -103,7 +153,7 @@ void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector &of Vector target( cursor.X() + parent->Res().capsuleSelectTopLeft->Width(), cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height()); - parent->Res().capsuleSelectLeftRepeat->Render(screen, cursor, target); + parent->Res().capsuleSelectLeftRepeat->Draw(screen, cursor, target); cursor.Y() = target.Y(); parent->Res().capsuleSelectBottomLeft->Draw(screen, cursor); cursor.X() += parent->Res().capsuleSelectTopLeft->Width(); @@ -116,7 +166,7 @@ void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector &of parent->Res().capsuleSelectLadder->Draw( screen, cursor, j < parent->Game().state->capsules[i].MaxClass(), j); - if (&parent->Game().state->capsules[i] == parent->Game().state->capsule + if (i == parent->Game().state->capsule && parent->Game().state->capsules[i].CurrentClass() == j) { parent->Res().capsuleSelectCursor->Draw(screen, cursor); } @@ -135,7 +185,7 @@ void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector &of target = Vector( cursor.X() + parent->Res().capsuleSelectTopRight->Width(), cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height()); - parent->Res().capsuleSelectRightRepeat->Render(screen, cursor, target); + parent->Res().capsuleSelectRightRepeat->Draw(screen, cursor, target); cursor.Y() = target.Y(); parent->Res().capsuleSelectBottomRight->Draw(screen, cursor); } @@ -149,6 +199,10 @@ int CapsuleChangeMenu::Height() const { return parent->Height(); } +Capsule &CapsuleChangeMenu::GetCapsule() { + return parent->GetCapsule(); +} + const Capsule &CapsuleChangeMenu::GetCapsule() const { return parent->GetCapsule(); }