From 4edd9176dda47311a0bad36f7223c497406dcd06 Mon Sep 17 00:00:00 2001 From: deveee Date: Tue, 24 Sep 2013 11:57:50 +0000 Subject: [PATCH] Both teams should have at least one kart. Still to do: user should be informed that he can't choose this team. Not tested in more than 2 karts. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14146 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/states_screens/soccer_setup_screen.cpp | 31 +++++++++++++++++++++- src/states_screens/soccer_setup_screen.hpp | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/states_screens/soccer_setup_screen.cpp b/src/states_screens/soccer_setup_screen.cpp index 0e9962e64..78490aa90 100644 --- a/src/states_screens/soccer_setup_screen.cpp +++ b/src/states_screens/soccer_setup_screen.cpp @@ -56,7 +56,7 @@ void SoccerSetupScreen::eventCallback(Widget* widget, const std::string& name, c if(name == "continue") { StateManager::get()->pushScreen( ArenasScreen::getInstance() ); - race_manager->setMaxGoal(getWidget("goalamount")->getValue()); + race_manager->setMaxGoal(getWidget("goalamount")->getValue()); input_manager->setMasterPlayerOnly(true); } else if (name == "back") @@ -216,6 +216,11 @@ GUIEngine::EventPropagation SoccerSetupScreen::filterActions( PlayerAction acti if (!bt_continue->isFocusedForPlayer(PLAYER_ID_GAME_MASTER) || areAllKartsConfirmed()) return result; + if(getNumConfirmedKarts() > nb_players-2 && + (getNumKartsInTeam(SOCCER_TEAM_RED) == 0 || + getNumKartsInTeam(SOCCER_TEAM_BLUE) == 0)) + return EVENT_BLOCK; + // Confirm team selection for(int i=0 ; i < nb_players ; i++) { @@ -301,6 +306,30 @@ bool SoccerSetupScreen::areAllKartsConfirmed() const return all_confirmed; } +int SoccerSetupScreen::getNumKartsInTeam(int team) +{ + int karts_in_team = 0; + int nb_players = m_kart_view_info.size(); + for(int i=0 ; i < nb_players ; i++) + { + if(m_kart_view_info[i].team == team) + karts_in_team++; + } + return karts_in_team; +} + +int SoccerSetupScreen::getNumConfirmedKarts() +{ + int confirmed_karts = 0; + int nb_players = m_kart_view_info.size(); + for(int i=0 ; i < nb_players ; i++) + { + if(m_kart_view_info[i].confirmed == true) + confirmed_karts++; + } + return confirmed_karts; +} + void SoccerSetupScreen::updateKartViewsLayout() { Widget* central_div = getWidget("central_div"); diff --git a/src/states_screens/soccer_setup_screen.hpp b/src/states_screens/soccer_setup_screen.hpp index 0934cd8bf..cee2cb5e9 100644 --- a/src/states_screens/soccer_setup_screen.hpp +++ b/src/states_screens/soccer_setup_screen.hpp @@ -72,6 +72,8 @@ public: private: bool areAllKartsConfirmed() const; + int SoccerSetupScreen::getNumKartsInTeam(int team); + int SoccerSetupScreen::getNumConfirmedKarts(); void updateKartViewsLayout(); };