Fixed multiplayer kart selection. Now guests are created on demand,
and are not saved to the players.xml file anymore.
This commit is contained in:
parent
e39f2164b5
commit
5c959e07a2
@ -375,10 +375,36 @@ void PlayerManager::addDefaultPlayer()
|
||||
// screen to be shown.
|
||||
m_all_players.push_back(new Online::OnlinePlayerProfile(username.c_str()) );
|
||||
|
||||
// add default guest player
|
||||
m_all_players.push_back(new Online::OnlinePlayerProfile(_LTR("Guest"), /*guest*/true));
|
||||
} // addDefaultPlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Makes sure at least n guest players exist. This is used by the multiplayer
|
||||
* KartSelection screen to make sure enough guest players can be picked by
|
||||
* the players.
|
||||
* \param n Minimum number of guest players that must exist.
|
||||
*/
|
||||
void PlayerManager::createGuestPlayers(int n)
|
||||
{
|
||||
int num_guests = m_all_players.size() - getNumNonGuestPlayers();
|
||||
for(int i=num_guests; i<n; i++)
|
||||
{
|
||||
core::stringw guest_name;
|
||||
if(i==0)
|
||||
{
|
||||
// I18N: Name of first guest player (without number)
|
||||
guest_name = _LTR("Guest");
|
||||
}
|
||||
else
|
||||
{
|
||||
// I18N: Name of further guest players, with a 1, 2, ... attached
|
||||
guest_name = _LTR("Guest %d", i);
|
||||
}
|
||||
PlayerProfile *guest = new Online::OnlinePlayerProfile(guest_name,
|
||||
/*guest*/ true);
|
||||
m_all_players.push_back(guest);
|
||||
}
|
||||
} // createGuestPlayers
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the number of 'real' (non-guest) players.
|
||||
*/
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
unsigned int getUniqueId() const;
|
||||
void addDefaultPlayer();
|
||||
PlayerProfile* addNewPlayer(const irr::core::stringw& name);
|
||||
void createGuestPlayers(int n);
|
||||
void deletePlayer(PlayerProfile *player);
|
||||
void setCurrentPlayer(PlayerProfile *player);
|
||||
const PlayerProfile *getPlayerById(unsigned int id);
|
||||
|
@ -585,7 +585,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
|
||||
|
||||
if (device != NULL)
|
||||
{
|
||||
KartSelectionScreen::getRunningInstance()->playerJoin(device,
|
||||
KartSelectionScreen::getRunningInstance()->joinPlayer(device,
|
||||
false );
|
||||
}
|
||||
}
|
||||
|
@ -1005,7 +1005,7 @@ void KartSelectionScreen::init()
|
||||
else */
|
||||
// For now this is what will happen
|
||||
{
|
||||
playerJoin( input_manager->getDeviceList()->getLatestUsedDevice(),
|
||||
joinPlayer( input_manager->getDeviceList()->getLatestUsedDevice(),
|
||||
true );
|
||||
w->updateItemDisplay();
|
||||
}
|
||||
@ -1063,10 +1063,10 @@ void KartSelectionScreen::unloaded()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Return true if event was handled successfully
|
||||
bool KartSelectionScreen::playerJoin(InputDevice* device, bool first_player)
|
||||
bool KartSelectionScreen::joinPlayer(InputDevice* device, bool first_player)
|
||||
{
|
||||
if (UserConfigParams::logGUI())
|
||||
Log::info("[KartSelectionScreen]", "playerJoin() invoked");
|
||||
Log::info("[KartSelectionScreen]", "joinPlayer() invoked");
|
||||
if (!m_multiplayer && !first_player) return false;
|
||||
|
||||
assert (g_dispatcher != NULL);
|
||||
@ -1074,13 +1074,13 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool first_player)
|
||||
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
|
||||
if (w == NULL)
|
||||
{
|
||||
Log::error("[KartSelectionScreen]", "playerJoin(): Called outside of "
|
||||
Log::error("[KartSelectionScreen]", "joinPlayer(): Called outside of "
|
||||
"kart selection screen.");
|
||||
return false;
|
||||
}
|
||||
else if (device == NULL)
|
||||
{
|
||||
Log::error("[KartSelectionScreen]", "playerJoin(): Received null "
|
||||
Log::error("[KartSelectionScreen]", "joinPlayer(): Received null "
|
||||
"device pointer");
|
||||
return false;
|
||||
}
|
||||
@ -1093,32 +1093,19 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool first_player)
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---- Get available area for karts
|
||||
// make a copy of the area, ands move it to be outside the screen
|
||||
Widget* kartsAreaWidget = getWidget("playerskarts");
|
||||
// start at the rightmost of the screen
|
||||
const int shift = irr_driver->getFrameSize().Width;
|
||||
core::recti kartsArea(kartsAreaWidget->m_x + shift,
|
||||
kartsAreaWidget->m_y,
|
||||
kartsAreaWidget->m_x + shift + kartsAreaWidget->m_w,
|
||||
kartsAreaWidget->m_y + kartsAreaWidget->m_h);
|
||||
|
||||
// ---- Create new active player
|
||||
PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer();
|
||||
|
||||
// Make sure enough guest character exists. At this stage this player has
|
||||
// not been added, so the number of guests requested for the first player
|
||||
// is 0 --> forcing at least one real player.
|
||||
PlayerManager::get()->createGuestPlayers(
|
||||
StateManager::get()->activePlayerCount());
|
||||
if (!first_player)
|
||||
{
|
||||
const int player_profile_count = PlayerManager::get()->getNumPlayers();
|
||||
for (int i=0; i<player_profile_count; i++)
|
||||
{
|
||||
PlayerProfile *player = PlayerManager::get()->getPlayer(i);
|
||||
if (player->isGuestAccount())
|
||||
{
|
||||
profile_to_use = player;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Give each player a different start profile
|
||||
const int num_active_players = StateManager::get()->activePlayerCount();
|
||||
profile_to_use = PlayerManager::get()->getPlayer(num_active_players);
|
||||
|
||||
// Remove multiplayer message
|
||||
if (m_multiplayer_message != NULL)
|
||||
@ -1142,6 +1129,16 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool first_player)
|
||||
std::string selected_kart_group =
|
||||
tabs->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
// ---- Get available area for karts
|
||||
// make a copy of the area, ands move it to be outside the screen
|
||||
Widget* kartsAreaWidget = getWidget("playerskarts");
|
||||
// start at the rightmost of the screen
|
||||
const int shift = irr_driver->getFrameSize().Width;
|
||||
core::recti kartsArea(kartsAreaWidget->m_x + shift,
|
||||
kartsAreaWidget->m_y,
|
||||
kartsAreaWidget->m_x + shift + kartsAreaWidget->m_w,
|
||||
kartsAreaWidget->m_y + kartsAreaWidget->m_h);
|
||||
|
||||
// ---- Create player/kart widget
|
||||
PlayerKartWidget* newPlayerWidget =
|
||||
new PlayerKartWidget(this, aplayer, NULL, kartsArea, m_kart_widgets.size(),
|
||||
@ -1207,7 +1204,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool first_player)
|
||||
}
|
||||
|
||||
return true;
|
||||
} // playerJoin
|
||||
} // joinPlayer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
|
||||
/** \brief Called when a player hits 'fire'/'select' on his device to
|
||||
* join the game */
|
||||
bool playerJoin(InputDevice* device, bool first_player);
|
||||
bool joinPlayer(InputDevice* device, bool first_player);
|
||||
|
||||
/**
|
||||
* \brief Called when a player hits 'rescue'/'cancel' on his device
|
||||
|
Loading…
Reference in New Issue
Block a user