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
This commit is contained in:
rforder 2009-08-12 19:04:01 +00:00
parent db1c53fa94
commit f3cab7c2b3
4 changed files with 19 additions and 10 deletions

View File

@ -282,8 +282,9 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
// Player is unjoining // Player is unjoining
if ((player != NULL) && (action == PA_RESCUE)) if ((player != NULL) && (action == PA_RESCUE))
{ {
KartSelectionScreen::playerPressedRescue( player ); // returns true if the event was handled
return; // we're done here if (KartSelectionScreen::playerPressedRescue( player ))
return; // we're done here
} }
// New player is joining // New player is joining

View File

@ -405,14 +405,15 @@ class KartHoverListener : public RibbonGridHoverListener
}; };
KartHoverListener* karthoverListener = NULL; KartHoverListener* karthoverListener = NULL;
void firePressedOnNewDevice(InputDevice* device) // Return true if event was handled successfully
bool firePressedOnNewDevice(InputDevice* device)
{ {
std::cout << "===== firePressedOnNewDevice =====\n"; std::cout << "===== firePressedOnNewDevice =====\n";
if(device == NULL) if(device == NULL)
{ {
std::cout << "I don't know which device was pressed :'(\n"; std::cout << "I don't know which device was pressed :'(\n";
return; return false;
} }
else if(device->getType() == DT_KEYBOARD) 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 ); 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; PlayerKartWidget* removedWidget = NULL;
void playerPressedRescue(ActivePlayer* player) // Return true if event was handled succesfully
bool playerPressedRescue(ActivePlayer* player)
{ {
int playerID = -1; int playerID = -1;
if (g_player_karts.size() <= 1) return false; // can't back out last player
for (int n=0; n<g_player_karts.size(); n++) for (int n=0; n<g_player_karts.size(); n++)
{ {
if (g_player_karts[n].m_associatedPlayer == player) if (g_player_karts[n].m_associatedPlayer == player)
@ -503,7 +507,8 @@ void playerPressedRescue(ActivePlayer* player)
} }
if (playerID == -1) if (playerID == -1)
{ {
std::cerr << "void playerPressedRescue(ActivePlayer* player) : cannot find passed player\n"; std::cout << "void playerPressedRescue(ActivePlayer* player) : cannot find passed player\n";
return false;
} }
removedWidget = g_player_karts.remove(playerID); removedWidget = g_player_karts.remove(playerID);
@ -514,7 +519,8 @@ void playerPressedRescue(ActivePlayer* player)
Widget* fullarea = getCurrentScreen()->getWidget("playerskarts"); Widget* fullarea = getCurrentScreen()->getWidget("playerskarts");
const int splitWidth = fullarea->w / amount; const int splitWidth = fullarea->w / amount;
assert( amount == StateManager::get()->activePlayerCount() ); // TODO: fix this
//assert( amount == StateManager::get()->activePlayerCount() );
for (int n=0; n<amount; n++) for (int n=0; n<amount; n++)
{ {
@ -523,6 +529,7 @@ void playerPressedRescue(ActivePlayer* player)
} }
removedWidget->move( removedWidget->x + removedWidget->w/2, fullarea->y + fullarea->h, removedWidget->move( removedWidget->x + removedWidget->w/2, fullarea->y + fullarea->h,
0, 0); 0, 0);
return true;
} }
void kartSelectionUpdate(float delta) void kartSelectionUpdate(float delta)

View File

@ -29,8 +29,8 @@ class ActivePlayer;
namespace KartSelectionScreen namespace KartSelectionScreen
{ {
void setPlayer0Device(InputDevice* device); void setPlayer0Device(InputDevice* device);
void firePressedOnNewDevice(InputDevice* device); bool firePressedOnNewDevice(InputDevice* device);
void playerPressedRescue(ActivePlayer* player); bool playerPressedRescue(ActivePlayer* player);
void kartSelectionUpdate(float delta); void kartSelectionUpdate(float delta);

View File

@ -432,6 +432,7 @@ void StateManager::escapePressed()
{ {
// TODO : show in-game menu // TODO : show in-game menu
resetAndGoToMenu("main.stkgui"); resetAndGoToMenu("main.stkgui");
input_manager->setMode(InputManager::MENU);
} }
// In menus // In menus
else else