Moved various function calls involved in the initialization of the kart selection screen from different places in the code into the "init"

section of the kart selection call back.  This will prevent some problems that were occuring when returning to the kart select screen 
from the track select screen (and it just makes more sense to find them there).  Renamed playerPressedRescue and firePressedOnNewDevice 
to playerQuit and playerJoin respectively, to more accurately describe the behavior of the functions.  Removed the now superfluous 
setPlayer0Device function.



git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3853 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
rforder 2009-08-13 17:38:01 +00:00
parent 0fa6343023
commit 7db3295936
5 changed files with 27 additions and 58 deletions

View File

@ -281,7 +281,7 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
if ((player != NULL) && (action == PA_RESCUE))
{
// returns true if the event was handled
if (KartSelectionScreen::playerPressedRescue( player ))
if (KartSelectionScreen::playerQuit( player ))
return; // we're done here
}
@ -306,7 +306,7 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
device = m_device_manager->getGamePadFromIrrID(deviceID);
if (device != NULL)
KartSelectionScreen::firePressedOnNewDevice( device );
KartSelectionScreen::playerJoin( device );
}
return; // we're done here, ignore devices that aren't associated with players
}

View File

@ -190,7 +190,10 @@ void RaceManager::startNew()
if(UserConfigParams::m_no_start_screen == true)
{
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
KartSelectionScreen::setPlayer0Device(device);
ActivePlayer* newPlayer = new ActivePlayer(UserConfigParams::m_all_players.get(0));
StateManager::get()->addActivePlayer( newPlayer );
newPlayer->setDevice(device);
device->setPlayer(newPlayer);
}
if(m_major_mode==MAJOR_MODE_GRAND_PRIX) // GP: get tracks and laps from grand prix
{

View File

@ -182,6 +182,7 @@ namespace KartSelectionScreen
{
if (StateManager::get()->getActivePlayers().get(newPlayerID) != m_associatedPlayer)
{
printf("Player: %p\nIndex: %d\nm_associatedPlayer: %p\n", StateManager::get()->getActivePlayers().get(newPlayerID), newPlayerID, m_associatedPlayer);
std::cerr << "Internal inconsistency, PlayerKartWidget has IDs and pointers that do not correspond to one player\n";
assert(false);
}
@ -406,14 +407,14 @@ class KartHoverListener : public RibbonGridHoverListener
KartHoverListener* karthoverListener = NULL;
// Return true if event was handled successfully
bool firePressedOnNewDevice(InputDevice* device)
bool playerJoin(InputDevice* device)
{
std::cout << "===== firePressedOnNewDevice =====\n";
std::cout << "===== playerJoin =====\n";
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
if (w == NULL )
{
std::cout << "firePressedOnNewDevice() called outside of kart selection screen.\n";
std::cout << "playerJoin() called outside of kart selection screen.\n";
return false;
}
@ -460,49 +461,15 @@ bool firePressedOnNewDevice(InputDevice* device)
return true;
}
/**
* Called before this screen is inited to tell which device was used to trigger "new game"; this
* device will be assigned to player 0.
*/
void setPlayer0Device(InputDevice* device)
{
std::cout << "===== setPlayer0Device =====\n";
if(device == NULL)
{
std::cout << "I don't know which device to assign to player 0 :'(\n";
return;
}
else if(device->getType() == DT_KEYBOARD)
{
std::cout << "Player 0 is using a keyboard\n";
}
else if(device->getType() == DT_GAMEPAD)
{
std::cout << "Player 0 is using a gamepad\n";
}
// Use player profile 0 by default; user can later change this by using the arrows
ActivePlayer* newPlayer = new ActivePlayer(UserConfigParams::m_all_players.get(0));
StateManager::get()->addActivePlayer( newPlayer );
newPlayer->setDevice(device);
device->setPlayer(newPlayer);
input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
// TODO : fall back in no-assign mode when aborting a game and going back to the menu
// how to revert assign mode :
// StateManager::resetActivePlayers();
// input_manager->getDeviceList()->setNoAssignMode(true);
}
PlayerKartWidget* removedWidget = NULL;
// Return true if event was handled succesfully
bool playerPressedRescue(ActivePlayer* player)
bool playerQuit(ActivePlayer* player)
{
int playerID = -1;
if (g_player_karts.size() <= 1) return false; // can't back out last player
// If last player quits, return to main menu
if (g_player_karts.size() <= 1) return false;
for (int n=0; n<g_player_karts.size(); n++)
{
@ -514,7 +481,7 @@ bool playerPressedRescue(ActivePlayer* player)
}
if (playerID == -1)
{
std::cout << "void playerPressedRescue(ActivePlayer* player) : cannot find passed player\n";
std::cout << "void playerQuit(ActivePlayer* player) : cannot find passed player\n";
return false;
}
@ -529,7 +496,7 @@ bool playerPressedRescue(ActivePlayer* player)
// TODO: fix this
//assert( amount == StateManager::get()->activePlayerCount() );
for (int n=0; n<amount; n++)
for (int n=0; n < amount; n++)
{
g_player_karts[n].setPlayerID(n);
g_player_karts[n].move( fullarea->x + splitWidth*n, fullarea->y, splitWidth, fullarea->h );
@ -573,12 +540,14 @@ void menuEventKarts(Widget* widget, const std::string& name)
}
else if(name == "init")
{
g_player_karts.clearWithoutDeleting();
//g_player_karts.clearWithoutDeleting();
// Always switch to detect_new when the kart selection screen is active??
//input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
g_player_karts.clearAndDeleteAll();
StateManager::get()->resetActivePlayers();
input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
assert( w != NULL );
@ -589,7 +558,7 @@ void menuEventKarts(Widget* widget, const std::string& name)
w->registerHoverListener(karthoverListener);
}
Widget* area = getCurrentScreen()->getWidget("playerskarts");
//Widget* area = getCurrentScreen()->getWidget("playerskarts");
if(!getCurrentScreen()->m_inited)
{
@ -624,12 +593,15 @@ void menuEventKarts(Widget* widget, const std::string& name)
getCurrentScreen()->m_inited = true;
}
/*
PlayerKartWidget* playerKart1 = new PlayerKartWidget(StateManager::get()->getActivePlayers().get(0),
area, 0 /* first player */);
area, 0); // first player
getCurrentScreen()->manualAddWidget(playerKart1);
playerKart1->add();
g_player_karts.push_back(playerKart1);
*/
playerJoin( input_manager->getDeviceList()->getLatestUsedDevice() );
w->updateItemDisplay();
@ -651,7 +623,7 @@ void menuEventKarts(Widget* widget, const std::string& name)
race_manager->setNumPlayers( players.size() );
race_manager->setNumLocalPlayers( players.size() );
g_player_karts.clearAndDeleteAll();
//g_player_karts.clearAndDeleteAll();
race_manager->setLocalKartInfo(0, w->getSelectionIDString());
// TODO : assign karts to other players too

View File

@ -28,11 +28,8 @@ class ActivePlayer;
namespace KartSelectionScreen
{
void setPlayer0Device(InputDevice* device);
bool firePressedOnNewDevice(InputDevice* device);
bool playerPressedRescue(ActivePlayer* player);
bool playerJoin(InputDevice* device);
bool playerQuit(ActivePlayer* player);
void kartSelectionUpdate(float delta);
void menuEventKarts(GUIEngine::Widget* widget, const std::string& name);
}

View File

@ -105,9 +105,6 @@ void StateManager::menuEventMain(Widget* widget, const std::string& name)
if(selection == "new")
{
resetActivePlayers();
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
KartSelectionScreen::setPlayer0Device(device);
pushMenu("karts.stkgui");
}
else if(selection == "options")