diff --git a/src/states_screens/soccer_setup_screen.cpp b/src/states_screens/soccer_setup_screen.cpp index c3a566f69..cb7457b1b 100644 --- a/src/states_screens/soccer_setup_screen.cpp +++ b/src/states_screens/soccer_setup_screen.cpp @@ -271,6 +271,37 @@ void SoccerSetupScreen::tearDown() Screen::tearDown(); } // tearDown +void SoccerSetupScreen::changeTeam(int player_id, SoccerTeam team) +{ + if (team == SOCCER_TEAM_NONE) + return; + + if (team == m_kart_view_info[player_id].team) + return; + + // Change the kart color + if (m_kart_view_info[player_id].support_colorization) + { + KartRenderType krt = team == SOCCER_TEAM_RED ? KRT_RED : KRT_BLUE; + m_kart_view_info[player_id].view->getModelViewRenderInfo() + ->setKartModelRenderInfo(krt); + } + + for (unsigned int i = 0; i < m_kart_view_info.size(); i++) + { + m_kart_view_info[i].view->unsetBadge(BAD_BADGE); + } + + if (m_kart_view_info.size() == 1) + { + UserConfigParams::m_soccer_default_team = (int)team; + } + + race_manager->setKartSoccerTeam(player_id, team); + m_kart_view_info[player_id].team = team; + updateKartViewsLayout(); +} + // ----------------------------------------------------------------------------- GUIEngine::EventPropagation SoccerSetupScreen::filterActions(PlayerAction action, int deviceID, @@ -283,30 +314,16 @@ GUIEngine::EventPropagation SoccerSetupScreen::filterActions(PlayerAction action ButtonWidget* bt_continue = getWidget("continue"); BubbleWidget* bubble = getWidget("lblLeftRight"); - GUIEngine::EventPropagation result = EVENT_LET; - SoccerTeam team_switch = SOCCER_TEAM_NONE; - int nb_players = (int)m_kart_view_info.size(); - switch(action) + switch (action) { case PA_MENU_LEFT: if ((bt_continue->isFocusedForPlayer(PLAYER_ID_GAME_MASTER) || bubble->isFocusedForPlayer(PLAYER_ID_GAME_MASTER)) && m_kart_view_info[playerId].confirmed == false) { - team_switch = SOCCER_TEAM_RED; - - // Change the kart color - if (m_kart_view_info[playerId].support_colorization) - { - m_kart_view_info[playerId].view->getModelViewRenderInfo() - ->setKartModelRenderInfo(KRT_RED); - } - - for(int i=0 ; i < nb_players ; i++) - { - m_kart_view_info[i].view->unsetBadge(BAD_BADGE); - } + changeTeam(playerId, SOCCER_TEAM_RED); + return EVENT_BLOCK; } break; case PA_MENU_RIGHT: @@ -314,19 +331,8 @@ GUIEngine::EventPropagation SoccerSetupScreen::filterActions(PlayerAction action bubble->isFocusedForPlayer(PLAYER_ID_GAME_MASTER)) && m_kart_view_info[playerId].confirmed == false) { - team_switch = SOCCER_TEAM_BLUE; - - // Change the kart color - if (m_kart_view_info[playerId].support_colorization) - { - m_kart_view_info[playerId].view->getModelViewRenderInfo() - ->setKartModelRenderInfo(KRT_BLUE); - } - - for(int i=0 ; i < nb_players ; i++) - { - m_kart_view_info[i].view->unsetBadge(BAD_BADGE); - } + changeTeam(playerId, SOCCER_TEAM_BLUE); + return EVENT_BLOCK; } break; case PA_MENU_UP: @@ -342,21 +348,21 @@ GUIEngine::EventPropagation SoccerSetupScreen::filterActions(PlayerAction action if (!bt_continue->isFocusedForPlayer(PLAYER_ID_GAME_MASTER) || areAllKartsConfirmed()) { - return result; + return EVENT_LET; } - if (bt_continue->isFocusedForPlayer(PLAYER_ID_GAME_MASTER) && - m_kart_view_info[playerId].confirmed) + if (!m_kart_view_info[playerId].confirmed) { - return EVENT_BLOCK; + // Confirm team selection + m_kart_view_info[playerId].confirmed = true; + m_kart_view_info[playerId].view->setRotateTo( + KART_CONFIRMATION_TARGET_ANGLE, + KART_CONFIRMATION_ROTATION_SPEED); + m_kart_view_info[playerId].view->setBadge(OK_BADGE); + m_kart_view_info[playerId].view->unsetBadge(BAD_BADGE); + SFXManager::get()->quickSound( "wee" ); } - // Confirm team selection - m_kart_view_info[playerId].confirmed = true; - m_kart_view_info[playerId].view->setRotateTo( KART_CONFIRMATION_TARGET_ANGLE, KART_CONFIRMATION_ROTATION_SPEED ); - m_kart_view_info[playerId].view->setBadge(OK_BADGE); - m_kart_view_info[playerId].view->unsetBadge(BAD_BADGE); - SFXManager::get()->quickSound( "wee" ); return EVENT_BLOCK; } case PA_MENU_CANCEL: @@ -364,15 +370,16 @@ GUIEngine::EventPropagation SoccerSetupScreen::filterActions(PlayerAction action if (!bt_continue->isFocusedForPlayer(PLAYER_ID_GAME_MASTER) && playerId == PLAYER_ID_GAME_MASTER) { - return result; + return EVENT_LET; } // Un-confirm team selection m_kart_view_info[playerId].confirmed = false; - m_kart_view_info[playerId].view->setRotateContinuously( KART_CONTINUOUS_ROTATION_SPEED ); + m_kart_view_info[playerId].view->setRotateContinuously( + KART_CONTINUOUS_ROTATION_SPEED); m_kart_view_info[playerId].view->unsetBadge(OK_BADGE); - for(int i=0 ; i < nb_players ; i++) + for (unsigned int i = 0 ; i < m_kart_view_info.size() ; i++) { m_kart_view_info[i].view->unsetBadge(BAD_BADGE); } @@ -383,16 +390,7 @@ GUIEngine::EventPropagation SoccerSetupScreen::filterActions(PlayerAction action break; } - if(team_switch != SOCCER_TEAM_NONE) // A player wants to change his team? - { - if (nb_players == 1) - UserConfigParams::m_soccer_default_team = (int)team_switch; - race_manager->setKartSoccerTeam(playerId, team_switch); - m_kart_view_info[playerId].team = team_switch; - updateKartViewsLayout(); - } - - return result; + return EVENT_LET; } // filterActions // ----------------------------------------------------------------------------- diff --git a/src/states_screens/soccer_setup_screen.hpp b/src/states_screens/soccer_setup_screen.hpp index 3ed84a528..2fb9a7864 100644 --- a/src/states_screens/soccer_setup_screen.hpp +++ b/src/states_screens/soccer_setup_screen.hpp @@ -82,6 +82,7 @@ private: bool areAllKartsConfirmed() const; int getNumConfirmedKarts(); void updateKartViewsLayout(); + void changeTeam(int player_id, SoccerTeam team); }; #endif // HEADER_SOCCER_SETUP_SCREEN_HPP