From a115853500fdaf2715ce3dceef568fed3884d163 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 29 Nov 2012 15:25:35 +0100 Subject: [PATCH] completed config menu I didn't clone the music bug, as I don't think anyone would want that ;) --- src/main.cpp | 1 + src/menu/ConfigMenu.cpp | 109 +++++++++++++++++++++++++++++++++++++++- src/menu/Resources.cpp | 1 + src/menu/Resources.h | 1 + 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 68446d3..580c5db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,6 +302,7 @@ int main(int argc, char **argv) { graphics::Font menuInactiveFont(&menuInactiveFontSprite, 0, -2); menuResources.normalFont = &menuFont; + menuResources.inactiveFont = &menuInactiveFont; graphics::Sprite menuCursor(IMG_Load("test-data/menu-cursor.png"), 32, 16); menuResources.menuCursor = &menuCursor; diff --git a/src/menu/ConfigMenu.cpp b/src/menu/ConfigMenu.cpp index 62eed32..b5a2b7d 100644 --- a/src/menu/ConfigMenu.cpp +++ b/src/menu/ConfigMenu.cpp @@ -15,6 +15,7 @@ #include "../graphics/Frame.h" using app::Input; +using common::GameState; using geometry::Vector; using graphics::Font; using graphics::Frame; @@ -72,6 +73,34 @@ void ConfigMenu::HandleEvents(const Input &input) { if (input.JustPressed(Input::PAD_UP)) { configMenu.PreviousRow(); } + + GameState &state(*parent->Game().state); + int *property(0); + int mod(0); + switch (configMenu.Selected()) { + case 0: + property = &state.messageSpeed; + mod = 3; + break; + case 1: + property = &state.battleCursor; + mod = 2; + break; + case 2: + property = &state.statusCursor; + mod = 2; + break; + case 3: + property = &state.music; + mod = 2; + break; + } + if (input.JustPressed(Input::ACTION_A) || input.JustPressed(Input::PAD_RIGHT)) { + *property = (*property + 1) % mod; + } + if (input.JustPressed(Input::PAD_LEFT)) { + *property = (*property + mod - 1) % mod; + } } void ConfigMenu::UpdateWorld(float deltaT) { @@ -102,13 +131,89 @@ void ConfigMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector } void ConfigMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const { - const Font &font(*parent->Res().normalFont); - const Frame &frame(*parent->Res().statusFrame); + const Resources &res(parent->Res()); + const Font &font(*res.normalFont); + const Font &inactiveFont(*res.inactiveFont); + const Frame &frame(*res.statusFrame); + const GameState &state(*parent->Game().state); const Vector menuOffset( 3 * font.CharWidth(), 2 * font.CharHeight()); frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight()); configMenu.Draw(screen, offset + menuOffset); + + Vector lineOffset( + menuOffset.X() + configMenu.Width() + 2 * font.CharWidth(), + menuOffset.Y()); + Vector colOffset(lineOffset); + + if (state.messageSpeed == GameState::MESSAGE_SPEED_FAST) { + font.DrawString(res.configMessageSpeedFast, screen, offset + colOffset); + colOffset.X() += font.StringWidth(res.configMessageSpeedFast) + font.CharWidth(); + } else { + inactiveFont.DrawString(res.configMessageSpeedFast, screen, offset + colOffset); + colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedFast) + inactiveFont.CharWidth(); + } + if (state.messageSpeed == GameState::MESSAGE_SPEED_NORMAL) { + font.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset); + colOffset.X() += font.StringWidth(res.configMessageSpeedNormal) + font.CharWidth(); + } else { + inactiveFont.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset); + colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedNormal) + inactiveFont.CharWidth(); + } + if (state.messageSpeed == GameState::MESSAGE_SPEED_SLOW) { + font.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset); + } else { + inactiveFont.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset); + } + + lineOffset.Y() += configMenu.RowHeight(); + colOffset = lineOffset; + + if (state.battleCursor == GameState::CURSOR_CLEAR) { + font.DrawString(res.configCursorClear, screen, offset + colOffset); + colOffset.X() += font.StringWidth(res.configCursorClear) + 2 * font.CharWidth(); + } else { + inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset); + colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth(); + } + if (state.battleCursor == GameState::CURSOR_MEMORY) { + font.DrawString(res.configCursorMemory, screen, offset + colOffset); + } else { + inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset); + } + + lineOffset.Y() += configMenu.RowHeight(); + colOffset = lineOffset; + + if (state.statusCursor == GameState::CURSOR_CLEAR) { + font.DrawString(res.configCursorClear, screen, offset + colOffset); + colOffset.X() += font.StringWidth(res.configCursorClear) + 2 * font.CharWidth(); + } else { + inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset); + colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth(); + } + if (state.statusCursor == GameState::CURSOR_MEMORY) { + font.DrawString(res.configCursorMemory, screen, offset + colOffset); + } else { + inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset); + } + + lineOffset.Y() += configMenu.RowHeight(); + colOffset = lineOffset; + + if (state.music == GameState::MUSIC_STEREO) { + font.DrawString(res.configMusicStereo, screen, offset + colOffset); + colOffset.X() += font.StringWidth(res.configMusicStereo) + font.CharWidth(); + } else { + inactiveFont.DrawString(res.configMusicStereo, screen, offset + colOffset); + colOffset.X() += inactiveFont.StringWidth(res.configMusicStereo) + inactiveFont.CharWidth(); + } + if (state.music == GameState::MUSIC_MONO) { + font.DrawString(res.configMusicMono, screen, offset + colOffset); + } else { + inactiveFont.DrawString(res.configMusicMono, screen, offset + colOffset); + } } } diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 14158f3..83daa10 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -12,6 +12,7 @@ namespace menu { Resources::Resources() : menubg(0) , normalFont(0) +, inactiveFont(0) , statusFont(0) , menuCursor(0) diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 8778cb5..026e3da 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -17,6 +17,7 @@ struct Resources { graphics::Texture *menubg; graphics::Font *normalFont; + graphics::Font *inactiveFont; graphics::Font *statusFont; graphics::Sprite *menuCursor; -- 2.39.2