From e20f805e611d50651c3d33afda3cd1318efda8f4 Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 6 Dec 2009 19:22:57 +0000 Subject: [PATCH] In multiplayer mode, players other than the game master should not be able to select stuff in race setup menus git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4265 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/input/input_manager.cpp | 10 +++++++++- src/input/input_manager.hpp | 6 ++++++ src/race/race_manager.cpp | 1 + src/states_screens/kart_selection.cpp | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index f819ea70d..f30209437 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -59,6 +59,7 @@ InputManager::InputManager() : m_sensed_input(0), m_mode(BOOTSTRAP), m_device_manager->initialize(); m_timer_in_use = false; + m_master_player_only = false; m_timer = 0; } @@ -380,6 +381,9 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID, m_timer = 0.25; } int playerID = (player == NULL ? 0 : player->m_id); + + // If only the master player can act, and this player is not the master, ignore his input + if (m_device_manager->getAssignMode() == ASSIGN && m_master_player_only && playerID != 0) return; GUIEngine::EventHandler::get()->processAction(action, abs(value), type, playerID); } } @@ -390,7 +394,11 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID, handleStaticAction( btnID, value ); } } // input - +//----------------------------------------------------------------------------- +void InputManager::setMasterPlayerOnly(bool enabled) +{ + m_master_player_only = enabled; +} //----------------------------------------------------------------------------- /** * Called on keyboard events [indirectly] by irrLicht diff --git a/src/input/input_manager.hpp b/src/input/input_manager.hpp index 174171139..58b5949a0 100644 --- a/src/input/input_manager.hpp +++ b/src/input/input_manager.hpp @@ -63,6 +63,9 @@ private: InputDriverMode m_mode; + /** When at true, only the master player can play with menus */ + bool m_master_player_only; + /* Helper values to store and track the relative mouse movements. If these * values exceed the deadzone value the input is reported to the game. This * makes the mouse behave like an analog axis on a gamepad/joystick. @@ -86,6 +89,9 @@ public: void setMode(InputDriverMode); bool isInMode(InputDriverMode); + /** When this mode is enabled, only the master player will be able to play with menus (only works in 'assign' mode) */ + void setMasterPlayerOnly(bool enabled); + void update(float dt); /** Returns the ID of the player that plays with the keyboard, or -1 if none */ diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index ef802e63e..2d607079e 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -396,6 +396,7 @@ void RaceManager::exitRace() StateManager::get()->resetActivePlayers(); input_manager->getDeviceList()->setAssignMode(NO_ASSIGN); + input_manager->setMasterPlayerOnly(false); } // exitRace //----------------------------------------------------------------------------- diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 6364a7805..18e8e69d1 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -938,6 +938,9 @@ void KartSelectionScreen::init() // ----------------------------------------------------------------------------- void KartSelectionScreen::allPlayersDone() { + // FIXME: cancel this when leaving back to main menu + input_manager->setMasterPlayerOnly(true); + DynamicRibbonWidget* w = this->getWidget("karts"); assert( w != NULL );