From f3cab7c2b3766ba9003f46c21f9371fb00a0351e Mon Sep 17 00:00:00 2001 From: rforder Date: Wed, 12 Aug 2009 19:04:01 +0000 Subject: [PATCH] Cleaning up multi-player handling in the kart selection screen git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3843 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/input/input_manager.cpp | 5 +++-- src/states_screens/kart_selection.cpp | 19 +++++++++++++------ src/states_screens/kart_selection.hpp | 4 ++-- src/states_screens/state_manager.cpp | 1 + 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 6074dde0a..34e65c564 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -282,8 +282,9 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi // Player is unjoining if ((player != NULL) && (action == PA_RESCUE)) { - KartSelectionScreen::playerPressedRescue( player ); - return; // we're done here + // returns true if the event was handled + if (KartSelectionScreen::playerPressedRescue( player )) + return; // we're done here } // New player is joining diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 41fe7db28..84421b3c2 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -405,14 +405,15 @@ class KartHoverListener : public RibbonGridHoverListener }; KartHoverListener* karthoverListener = NULL; -void firePressedOnNewDevice(InputDevice* device) +// Return true if event was handled successfully +bool firePressedOnNewDevice(InputDevice* device) { std::cout << "===== firePressedOnNewDevice =====\n"; if(device == NULL) { std::cout << "I don't know which device was pressed :'(\n"; - return; + return false; } else if(device->getType() == DT_KEYBOARD) { @@ -449,7 +450,7 @@ void firePressedOnNewDevice(InputDevice* device) g_player_karts[n].move( fullarea->x + splitWidth*n, fullarea->y, splitWidth, fullarea->h ); } - + return true; } /** @@ -489,10 +490,13 @@ void setPlayer0Device(InputDevice* device) PlayerKartWidget* removedWidget = NULL; -void playerPressedRescue(ActivePlayer* player) +// Return true if event was handled succesfully +bool playerPressedRescue(ActivePlayer* player) { int playerID = -1; + if (g_player_karts.size() <= 1) return false; // can't back out last player + for (int n=0; ngetWidget("playerskarts"); const int splitWidth = fullarea->w / amount; - assert( amount == StateManager::get()->activePlayerCount() ); + // TODO: fix this + //assert( amount == StateManager::get()->activePlayerCount() ); for (int n=0; nmove( removedWidget->x + removedWidget->w/2, fullarea->y + fullarea->h, 0, 0); + return true; } void kartSelectionUpdate(float delta) diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index f024ab5bb..f6e0f872f 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -29,8 +29,8 @@ class ActivePlayer; namespace KartSelectionScreen { void setPlayer0Device(InputDevice* device); - void firePressedOnNewDevice(InputDevice* device); - void playerPressedRescue(ActivePlayer* player); + bool firePressedOnNewDevice(InputDevice* device); + bool playerPressedRescue(ActivePlayer* player); void kartSelectionUpdate(float delta); diff --git a/src/states_screens/state_manager.cpp b/src/states_screens/state_manager.cpp index 470134ca4..a6c046f98 100644 --- a/src/states_screens/state_manager.cpp +++ b/src/states_screens/state_manager.cpp @@ -432,6 +432,7 @@ void StateManager::escapePressed() { // TODO : show in-game menu resetAndGoToMenu("main.stkgui"); + input_manager->setMode(InputManager::MENU); } // In menus else