controlsetupstate.cpp
来自「Source code (C++) of the Amoebax game fo」· C++ 代码 · 共 835 行 · 第 1/2 页
CPP
835 行
/// \brief Tells if the waiting input if for joystick.////// \return \a true if we are waiting input for joystick, \a false otherwise.///inline boolControlSetupState::isWaitingJoystickInput (void) const{ return isWaitingForInput () && ( ( 0 == getSelectedPlayer () && Options::JoystickControls == m_LeftPlayerControls.controlsType ) || ( 1 == getSelectedPlayer () && Options::JoystickControls == m_RightPlayerControls.controlsType));}////// \brief Tells if the waiting input if for joystick.////// \return \a true if we are waiting input for joystick, \a false otherwise.///inline boolControlSetupState::isWaitingKeyboardInput (void) const{ return isWaitingForInput () && ( ( 0 == getSelectedPlayer () && Options::KeyboardControls == m_LeftPlayerControls.controlsType ) || ( 1 == getSelectedPlayer () && Options::KeyboardControls == m_RightPlayerControls.controlsType));}voidControlSetupState::joyMotion (uint8_t joystick, uint8_t axis, int16_t value){ if ( (value > Joystick::k_DeadZone || value < -Joystick::k_DeadZone) && isWaitingForInput () && isWaitingJoystickInput () && getSelectedControl () < k_FirstJoystickButtonControlIndex && isJoystickIndexValid (joystick) ) { assignJoystickToCurrentControl (value < 0 ? -axis - 1 : axis + 1); }}voidControlSetupState::joyDown (uint8_t joystick, uint8_t button){ if ( isWaitingForInput () && isWaitingJoystickInput () && getSelectedControl () >= k_FirstJoystickButtonControlIndex && isJoystickIndexValid (joystick) ) { assignJoystickToCurrentControl (button); }}voidControlSetupState::joyUp (uint8_t joystick, uint8_t button){}#if !defined (IS_GP2X_HOST)|| defined (__SYMBIAN32__)voidControlSetupState::keyDown (uint32_t key){ if ( isWaitingForInput () ) { if ( isWaitingKeyboardInput () && isKeyValidForControl (key) ) { assignKeyToCurrentControl (key); } else if ( SDLK_ESCAPE == key ) { cancelWaitingForInput (); } } else { switch (key) { case SDLK_DOWN: selectNextControl (); break; case SDLK_ESCAPE: selectCancelOrExit (); break; case SDLK_LEFT:
case SDLK_PAGEDOWN: selectPreviousPlayer (); break; case SDLK_F5: case SDLK_RETURN: activateCurrentControl (); break; case SDLK_RIGHT: case SDLK_PAGEUP:
selectNextPlayer (); break; case SDLK_UP: selectPreviousControl (); break; } }}voidControlSetupState::keyUp (uint32_t key){}#endif // !IS_GP2X_HOST////// \brief Loads all graphic resources.///voidControlSetupState::loadGraphicResources (void){ const float screenScale = System::getInstance ().getScreenScaleFactor ();
#if defined (IS_GP2X_HOST)
const float originalScale = screenScale;
#else // !IS_GP2X_HOST
const float originalScale = 1.0f;
#endif // IS_GP2X_HOST
m_Background.reset (Surface::fromFile ( File::getGraphicsFilePath ("menuBackground.png"))); { std::auto_ptr<Surface> title (Surface::fromFile ( File::getGraphicsFilePath ("playerscontrolsetup.png"))); title->blit (m_Background->getWidth () / 2 - title->getWidth () / 2, 0, m_Background->toSDLSurface ()); std::auto_ptr<Surface> controls (Surface::fromFile ( File::getGraphicsFilePath ("controls.png"))); controls->blit ((k_ControlTitlesX*originalScale), (originalScale*k_FirstControlY), m_Background->toSDLSurface ()); std::auto_ptr<Surface> leftPlayer (Surface::fromFile ( File::getGraphicsFilePath ("leftplayer.png"))); leftPlayer->blit ((originalScale*k_LeftPlayerControlsX) - leftPlayer->getWidth (), (originalScale*k_PlayersTitleY), m_Background->toSDLSurface ()); std::auto_ptr<Surface> rightPlayer (Surface::fromFile ( File::getGraphicsFilePath ("rightplayer.png"))); rightPlayer->blit ((originalScale*k_RightPlayerControlsX) - rightPlayer->getWidth (), (originalScale*k_PlayersTitleY), m_Background->toSDLSurface ()); } m_Background->resize (screenScale); m_Font.reset (Font::fromFile (File::getFontFilePath ("fontMenu"))); m_FontSelected.reset (Font::fromFile ( File::getFontFilePath ("fontMenuSelected")));}voidControlSetupState::redrawBackground (SDL_Rect *region, SDL_Surface *screen){ m_Background->blit (region->x, region->y, region->w, region->h, region->x, region->y, screen);}////// \brief Reads the players' controls from the options.///voidControlSetupState::readPlayersControls (void){ m_LeftPlayerControls = Options::getInstance ().getPlayerControls (IPlayer::LeftSide); m_LeftPlayerControls.controlsType = m_LeftPlayerControlsOriginal.controlsType; m_LeftPlayerControls.joystick.index = m_LeftPlayerControlsOriginal.joystick.index; m_RightPlayerControls = Options::getInstance ().getPlayerControls (IPlayer::RightSide); m_RightPlayerControls.controlsType = m_RightPlayerControlsOriginal.controlsType; m_RightPlayerControls.joystick.index = m_RightPlayerControlsOriginal.joystick.index;}////// \brief Removes the state from the system, if not already removed.///voidControlSetupState::removeState (void){ if ( !m_StateRemoved ) { System::getInstance ().removeActiveState (); m_StateRemoved = true; }}voidControlSetupState::render (SDL_Surface *screen){ const float screenScale = System::getInstance ().getScreenScaleFactor (); // Draw left player's current control. drawControls (Options::KeyboardControls == m_LeftPlayerControls.controlsType, 0, static_cast<uint16_t> (screenScale * k_LeftPlayerControlsX), screenScale, screen); // Draw right player's current control. drawControls (Options::KeyboardControls == m_RightPlayerControls.controlsType, k_NumControls, static_cast<uint16_t> (screenScale * k_RightPlayerControlsX), screenScale, screen); // Draw the accept and cancel options. uint16_t y = static_cast<uint16_t> (k_FirstControlY * screenScale) + (k_NumControls + 1) * m_Font->getHeight (); Font *font = m_Font.get (); if ( getSelectedGlobalControl () == k_DefaultsControlIndex ) { font = m_FontSelected.get (); } font->write ("set defaults", y, screen); y += font->getHeight (); font = m_Font.get (); if ( getSelectedGlobalControl () == k_AcceptControlIndex ) { font = m_FontSelected.get (); } font->write ("accept", y, screen); y += font->getHeight (); font = m_Font.get (); if ( getSelectedGlobalControl () == k_CancelControlIndex ) { font = m_FontSelected.get (); } font->write ("cancel", y, screen);}////// \brief Selects the cancel control or exits, if it's already selected.///voidControlSetupState::selectCancelOrExit (void){ if ( k_CancelControlIndex == getSelectedGlobalControl () ) { removeState (); } else { setSelectedPlayer (0); setSelectedControl (k_CancelControlIndex); }}////// \brief Selects the next control.///voidControlSetupState::selectNextControl (void){ if ( isRegularMenuSelected () ) { if ( getSelectedControl () < k_CancelControlIndex ) { setSelectedControl (getSelectedControl () + 1); } } else { if ( getSelectedControl () < (k_NumControls - 1) ) { setSelectedControl (getSelectedControl () + 1); } else { setSelectedControl (k_DefaultsControlIndex); setSelectedPlayer (0); } }}////// \brief Selects the next player.///voidControlSetupState::selectNextPlayer (void){ if ( !isRegularMenuSelected () ) { if ( 0 == getSelectedPlayer () ) { setSelectedPlayer (getSelectedPlayer () + 1); } }}////// \brief Selectes the previous control.///voidControlSetupState::selectPreviousControl (void){ if ( isRegularMenuSelected () ) { if ( getSelectedControl () > k_DefaultsControlIndex ) { setSelectedControl (getSelectedControl () - 1); } else { setSelectedControl (k_NumControls - 1); } } else { if ( 0 < getSelectedControl () ) { setSelectedControl (getSelectedControl () - 1); } }}////// \brief Selects the previous player.///voidControlSetupState::selectPreviousPlayer (void){ if ( !isRegularMenuSelected () ) { if ( 0 < getSelectedPlayer () ) { setSelectedPlayer (getSelectedPlayer () - 1); } }}////// \brief Sets the visibility of the current selected control.////// \param visible \a true if the current selected control must be visible,/// \a false otherwise.///inline voidControlSetupState::setCurrentControlVisible (bool visible){ m_CurrentControlVisible = visible;}////// \brief Sets the selected control.////// \param control The index of the selected control, from 0 to/// k_NumControls - 1.///inline voidControlSetupState::setSelectedControl (uint16_t control){ m_SelectedControl = control;}////// \brief Sets the selected player.////// \param player The index of the selected player: 0 left player,/// 1 right player.///inline voidControlSetupState::setSelectedPlayer (uint16_t player){ m_SelectedPlayer = player;}////// \brief Sets the time the selected control is visible.////// \param time The time the selected control is visible while waiting/// for input.///inline voidControlSetupState::setVisibleTime (int32_t time){ m_VisibleTime = time;}////// \brief Sets if a control is waiting for input.////// \param waiting Tells if the selected control is waiting for input///inline voidControlSetupState::setWaitingForInput (bool waiting){ m_WaitingForInput = waiting;}voidControlSetupState::update (uint32_t elapsedTime){ if ( isWaitingForInput () ) { setVisibleTime (getVisibleTime () - elapsedTime); if ( 0 > getVisibleTime () ) { setCurrentControlVisible (!isCurrentControlVisible ()); setVisibleTime (k_VisibleTime); } }}voidControlSetupState::videoModeChanged (void){ loadGraphicResources ();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?