Commit 311e7f84 authored by Alexander Schuch's avatar Alexander Schuch Committed by Nemanja Hiršl
Browse files

When adding a new player to the game, the default player controller is

always the very first registered player controller (human player). Now,
the used player is either the default one if no players are added yet,
or the player controller of the last added player.

BUG:175618
FIXED-IN:4.12
REVIEW:113114
parent 424e89dd
......@@ -146,19 +146,7 @@ public:
{
QString text = value.toString();
// We only know the GUI name of player controller class to
// add. Search all registered player controllers for that name
// and then create an instance.
Player *newPlayer = 0;
foreach (PlayerGui *playerGui, m_selectablePlayer) {
if (text == playerGui->guiName()) {
newPlayer = playerGui->createInstance(player->game(), player->name(), player->color());
newPlayer->setGuiName(text);
break;
}
}
Player *newPlayer = getNewPlayerByGuiName(text, player->name(), player->color());
if (newPlayer) {
m_players[row] = newPlayer;
......@@ -181,21 +169,27 @@ public:
{
Player *player = NULL;
int players = m_players.count();
if (players < MAX_PLAYERS)
{
if ((!m_availablePlayerId.empty()) && (!m_selectablePlayer.empty())) {
beginInsertRows(QModelIndex(), players, players);
/**
* @todo If for some reason no player controller is available, do
* nothing here and show an error message.
*/
// Get the player controller of the last added player. If no player
// has been added yet, use the very first registered player
// controller as default.
player = m_selectablePlayer.at(0)->createInstance(m_game, m_availablePlayerId.front().second, m_availablePlayerId.front().first);
player->setGuiName(m_selectablePlayer.at(0)->guiName());
QString guiName = m_selectablePlayer.front()->guiName();
m_availablePlayerId.pop_front();
m_players.append(player);
m_game->setPlayers(m_players);
if (!m_players.isEmpty()) {
guiName = m_players.last()->guiName();
}
player = getNewPlayerByGuiName(guiName, m_availablePlayerId.front().second, m_availablePlayerId.front().first);
if (player) {
m_availablePlayerId.pop_front();
m_players.append(player);
m_game->setPlayers(m_players);
}
endInsertRows();
}
......@@ -222,6 +216,30 @@ public:
return player;
}
private:
/**
* Search the list of registered player controllers and return either a new
* instance of that controller or NULL if it cannot be found.
*
* @note The GUI name of the player instance gets set.
*/
Player *getNewPlayerByGuiName(const QString &guiName, const QString &playerName, const QColor &color) const
{
Player *newPlayer = 0;
foreach (PlayerGui *playerGui, m_selectablePlayer) {
if (guiName == playerGui->guiName()) {
newPlayer = playerGui->createInstance(m_game, playerName, color);
newPlayer->setGuiName(guiName);
break;
}
}
return newPlayer;
}
private:
Game *m_game;
QList<Player *> m_players;
......@@ -387,8 +405,9 @@ NewGameDlg::init()
QString playerType = config.readEntry(keyType,QString());
model->addPlayer();
if (!playerName.isEmpty())
if (!playerName.isEmpty()) {
model->setData(model->index(i, 0), playerName, Qt::EditRole);
}
model->setData(model->index(i, 1), playerType, Qt::EditRole);
}
updateOwnerCB();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment