From: Daniel Karbach Date: Sat, 3 Nov 2012 11:27:06 +0000 (+0100) Subject: added menu to status screen X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=559457f14d914f6b1cb5d588a0ccf97529f011d1;p=l2e.git added menu to status screen --- diff --git a/src/main.cpp b/src/main.cpp index 69b4e87..4c350de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -340,6 +340,20 @@ int main(int argc, char **argv) { menuResources.experienceLabel = "NOW EXP"; menuResources.nextLevelLabel = "NEXT LEVEL"; + graphics::MenuProperties statusMenuProperties; + statusMenuProperties.cols = 2; + statusMenuProperties.rows = 1; + statusMenuProperties.charsPerEntry = 6; + statusMenuProperties.rowGap = 0; + statusMenuProperties.colGap = 16; + statusMenuProperties.cursor = &menuCursor; + statusMenuProperties.font = &menuFont; + statusMenuProperties.wrapX = true; + menuResources.statusMenuProperties = &statusMenuProperties; + + menuResources.nextLabel = "NEXT"; + menuResources.returnLabel = "RETURN"; + InitScreen screen(width, height); app::State *state(0); diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 646c049..256fb1f 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -47,7 +47,12 @@ Resources::Resources() , ipLabel(0) , experienceLabel(0) -, nextLevelLabel(0) { +, nextLevelLabel(0) + +, statusMenuProperties(0) + +, nextLabel(0) +, returnLabel(0) { } diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 64198f8..a0c60e1 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -54,6 +54,11 @@ struct Resources { const char *experienceLabel; const char *nextLevelLabel; + graphics::MenuProperties *statusMenuProperties; + + const char *nextLabel; + const char *returnLabel; + Resources(); }; diff --git a/src/menu/StatusMenu.cpp b/src/menu/StatusMenu.cpp index b037703..3a9b38f 100644 --- a/src/menu/StatusMenu.cpp +++ b/src/menu/StatusMenu.cpp @@ -18,6 +18,7 @@ #include "../common/Item.h" #include "../common/Stats.h" #include "../graphics/Font.h" +#include "../graphics/Frame.h" using app::Input; using common::Hero; @@ -25,13 +26,16 @@ using common::Item; using common::Stats; using geometry::Vector; using graphics::Font; +using graphics::Frame; namespace menu { StatusMenu::StatusMenu(PartyMenu *parent, int cursor) : parent(parent) -, cursor(cursor) { - +, cursor(cursor) +, menu(*parent->Res().statusMenuProperties) { + menu.Add(parent->Res().nextLabel, 0); + menu.Add(parent->Res().returnLabel, 1); } @@ -58,16 +62,30 @@ void StatusMenu::OnResize(int width, int height) { void StatusMenu::HandleEvents(const Input &input) { - if (input.JustPressed(Input::ACTION_B)) { - Ctrl().PopState(); - } - if (input.JustPressed(Input::SHOULDER_RIGHT)) { NextHero(); } if (input.JustPressed(Input::SHOULDER_LEFT)) { PreviousHero(); } + + if (input.JustPressed(Input::PAD_LEFT)) { + menu.PreviousItem(); + } + if (input.JustPressed(Input::PAD_RIGHT)) { + menu.NextItem(); + } + + if (input.JustPressed(Input::ACTION_A)) { + if (menu.Selected() == 0) { + NextHero(); + } else if (menu.Selected() == 1) { + Ctrl().PopState(); + } + } + if (input.JustPressed(Input::ACTION_B)) { + Ctrl().PopState(); + } } void StatusMenu::UpdateWorld(float deltaT) { @@ -90,10 +108,13 @@ void StatusMenu::Render(SDL_Surface *screen) { 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); Vector nextLevelOffset( 11 * parent->Res().statusFont->CharWidth(), - 19 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + 20 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); Vector ikariOffset( 17 * parent->Res().statusFont->CharWidth(), 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + Vector menuOffset( + parent->Res().statusFont->CharWidth(), + 23 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); parent->RenderBackground(screen); parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset); @@ -103,6 +124,7 @@ void StatusMenu::Render(SDL_Surface *screen) { RenderExperience(screen, experienceOffset); RenderNextLevel(screen, nextLevelOffset); RenderIkari(screen, ikariOffset); + RenderMenu(screen, menuOffset); } int StatusMenu::Width() const { @@ -214,6 +236,20 @@ void StatusMenu::RenderIkari(SDL_Surface *screen, const geometry::Vector &o font.DrawChar('%', screen, percentOffset); } +void StatusMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + + Vector labelOffset(2 * font.CharWidth(), font.CharHeight()); + frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight()); + font.DrawString(parent->Res().mainMenuStatusText, screen, offset + labelOffset); + + Vector menuFrameOffset(10 * font.CharWidth(), 0); + Vector menuOffset(13 * font.CharWidth(), font.CharHeight()); + frame.Draw(screen, offset + menuFrameOffset, 20 * font.CharWidth(), 3 * font.CharHeight()); + menu.Draw(screen, offset + menuOffset); +} + void StatusMenu::NextHero() { cursor = (cursor + 1) % parent->Game().state->partySize; diff --git a/src/menu/StatusMenu.h b/src/menu/StatusMenu.h index 40fac6b..5f6f986 100644 --- a/src/menu/StatusMenu.h +++ b/src/menu/StatusMenu.h @@ -12,6 +12,7 @@ #include "../app/State.h" #include "../common/fwd.h" #include "../geometry/Vector.h" +#include "../graphics/Menu.h" namespace menu { @@ -53,10 +54,12 @@ private: /// @param offset the top right corner! void RenderNextLevel(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderIkari(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const; private: PartyMenu *parent; int cursor; + graphics::Menu menu; };