#include "Options.h" #include "Defines.h" Options::Options(SDL_Surface* pScreen, Config* pConfig) : m_pScreen(pScreen), m_nOptionsIndex(0), m_pConfig(pConfig) { m_pFont = nSDL_LoadFont(NSDL_FONT_THIN, 0, 0, 0); nSDL_SetFontSpacing(m_pFont, 0, 3); } Options::~Options() { nSDL_FreeFont(m_pFont); } bool Options::Loop() { //Handle keypresses if( PollEvents() == false ) return false; UpdateDisplay(); return true; } bool Options::PollEvents() { SDL_Event event; /* Poll for events. SDL_PollEvent() returns 0 when there are no */ /* more events on the event queue, our while loop will exit when */ /* that occurs. */ while( SDL_PollEvent( &event ) ) { /* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */ switch( event.type ) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: return false; break; case SDLK_SPACE: case SDLK_RETURN: case SDLK_LCTRL: ToggleCurrentOption(); break; case SDLK_UP: case SDLK_8: Move(OP_Up); break; case SDLK_DOWN: case SDLK_2: Move(OP_Down); break; default: break; } break; //Called when the mouse moves case SDL_MOUSEMOTION: break; case SDL_KEYUP: break; default: break; } } return true; } void Options::ToggleCurrentOption() { if( m_nOptionsIndex == 0 ) { m_pConfig->SetAllowMouse(!m_pConfig->GetAllowMouse()); } else if( m_nOptionsIndex == 1 ) { m_pConfig->ResetPlayerStanding(); } if( m_nOptionsIndex == 2 ) { m_pConfig->SetBlinkDuration(m_pConfig->GetBlinkDuration() >= 5 ? 3 : 5); } } void Options::Move(Option_Direction eDirection) { if( eDirection == OP_Down && m_nOptionsIndex < 2 ) { m_nOptionsIndex++; } else if( eDirection == OP_Up && m_nOptionsIndex > 0 ) { m_nOptionsIndex--; } } void Options::UpdateDisplay() { //Draw background SDL_FillRect(m_pScreen, NULL, SDL_MapRGB(m_pScreen->format, 153, 153, 255)); nSDL_DrawString(m_pScreen, m_pFont, (SCREEN_WIDTH-nSDL_GetStringWidth(m_pFont, "Options:"))/2, 15, "Options:"); char buffer[256] = "Allow Mouse: "; if( m_pConfig->GetAllowMouse() ) { strcat(buffer, "Allowed"); } else { strcat(buffer, "Denied"); } strcat(buffer, "\n\ During gameplay you can use the \n\ calculator's touchpad to select cases\n\ but you can also play the whole thing\n\ with the arrows and number keys."); nSDL_DrawString(m_pScreen, m_pFont, 12, 45, buffer); if( m_nOptionsIndex == 0 ) { if( is_classic ) { draw_rectangle(m_pScreen, SDL_MapRGB(m_pScreen->format, 255, 255, 255), 7, 40, 312, 70, 1); } else { draw_rectangle(m_pScreen, SDL_MapRGB(m_pScreen->format, 255, 0, 0), 7, 40, 312, 70, 1); } } strcpy(buffer, "Reset Player Standing\n"); strcat(buffer, "Current points: "); char buf[10]; Deal_itoa(m_pConfig->GetPlayerStanding(), buf, 10); strcat(buffer, buf); strcat(buffer, "\n\ As you do better you get more points!\n\ This is just to make the game more fun.\n\ This just resets those points."); nSDL_DrawString(m_pScreen, m_pFont, 12, 125, buffer); if( m_nOptionsIndex == 1 ) { if( is_classic ) { draw_rectangle(m_pScreen, SDL_MapRGB(m_pScreen->format, 255, 255, 255), 7, 120, 312, 65, 1); } else { draw_rectangle(m_pScreen, SDL_MapRGB(m_pScreen->format, 255, 0, 0), 7, 120, 312, 65, 1); } } strcpy(buffer, "Label Blink Duaration: "); if( m_pConfig->GetBlinkDuration() >= 5 ) { strcat(buffer, "Long"); } else { strcat(buffer, "Short"); } strcat(buffer, "\n\ As you open cases; the labels to the\n\ sides blink. This options adjusts how\n\ long they blink for."); nSDL_DrawString(m_pScreen, m_pFont, 12, 190, buffer); if( m_nOptionsIndex == 2 ) { if( is_classic ) { draw_rectangle(m_pScreen, SDL_MapRGB(m_pScreen->format, 255, 255, 255), 7, 183, 312, 52, 1); } else { draw_rectangle(m_pScreen, SDL_MapRGB(m_pScreen->format, 255, 0, 0), 7, 183, 312, 52, 1); } } SDL_UpdateRect(m_pScreen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); }