From 368a7ebd134873c26086c8b7eff9c49d2fef3466 Mon Sep 17 00:00:00 2001 From: auria Date: Mon, 24 Jan 2011 01:41:55 +0000 Subject: [PATCH] In single-player mode, the user can now use all input devices git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7518 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/input/device_manager.cpp | 14 ++++++++++++-- src/input/device_manager.hpp | 8 ++++++++ src/states_screens/kart_selection.cpp | 14 ++++++++++++++ src/states_screens/main_menu_screen.cpp | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index cfb18e309..ec1edb187 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -39,6 +39,7 @@ DeviceManager::DeviceManager() { m_latest_used_device = NULL; m_assign_mode = NO_ASSIGN; + m_single_player = NULL; } // DeviceManager // ----------------------------------------------------------------------------- @@ -269,7 +270,12 @@ InputDevice* DeviceManager::mapKeyboardInput( int btnID, InputManager::InputDriv if (keyboard->processAndMapInput(btnID, mode, action)) { //std::cout << " binding found in keyboard #" << (n+1) << "; action is " << KartActionStrings[*action] << "\n"; - if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode + if (m_single_player != NULL) + { + //printf("Single player\n"); + *player = m_single_player; + } + else if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode { *player = NULL; } @@ -301,7 +307,11 @@ InputDevice *DeviceManager::mapGamepadInput( Input::InputType type, { if (gPad->processAndMapInput(type, btnID, value, mode, gPad->getPlayer(), action)) { - if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode + if (m_single_player != NULL) + { + *player = m_single_player; + } + else if (m_assign_mode == NO_ASSIGN) // Don't set the player in NO_ASSIGN mode { *player = NULL; } diff --git a/src/input/device_manager.hpp b/src/input/device_manager.hpp index f86815040..569255bd1 100644 --- a/src/input/device_manager.hpp +++ b/src/input/device_manager.hpp @@ -76,6 +76,9 @@ private: StateManager::ActivePlayer **player /* out */, PlayerAction *action /* out */); + /** Will be non-null in single-player mode */ + StateManager::ActivePlayer* m_single_player; + /** * Helper method, only used internally. Takes care of analyzing keyboard input. * @@ -147,6 +150,11 @@ public: void clearLatestUsedDevice(); InputDevice* getLatestUsedDevice(); + + StateManager::ActivePlayer* getSinglePlayer() { return m_single_player; } + void setSinglePlayer(StateManager::ActivePlayer* p) { m_single_player = p; } + + bool initialize(); void serialize(); }; diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 1f0aa7024..4616c9484 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1107,6 +1107,11 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer) newPlayerWidget->m_player_ident_spinner->setFocusForPlayer(new_player_id); } + if (!m_multiplayer) + { + input_manager->getDeviceList()->setSinglePlayer( StateManager::get()->getActivePlayer(0) ); + } + return true; } @@ -1502,6 +1507,15 @@ void KartSelectionScreen::allPlayersDone() // ---- Switch to assign mode input_manager->getDeviceList()->setAssignMode(ASSIGN); + if (!m_multiplayer) + { + input_manager->getDeviceList()->setSinglePlayer( StateManager::get()->getActivePlayer(0) ); + } + else + { + input_manager->getDeviceList()->setSinglePlayer( NULL ); + } + StateManager::get()->pushScreen( RaceSetupScreen::getInstance() ); } diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 93a4c11af..6904aac4c 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -80,6 +80,7 @@ void MainMenuScreen::init() // reset in case we're coming back from a race StateManager::get()->resetActivePlayers(); input_manager->getDeviceList()->setAssignMode(NO_ASSIGN); + input_manager->getDeviceList()->setSinglePlayer( NULL ); input_manager->setMasterPlayerOnly(false); // Avoid incorrect behaviour in certain race circumstances: