mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-28 09:58:15 +01:00
Favorite players: new "Default" column, for automatic inclusion in a new game
This commit is contained in:
parent
094af979c7
commit
eaf536b3ba
4 changed files with 47 additions and 18 deletions
|
@ -1035,13 +1035,16 @@ void MainWindow::onSettingsFavPlayers()
|
||||||
{
|
{
|
||||||
QDialog *dialog = new QDialog(this);
|
QDialog *dialog = new QDialog(this);
|
||||||
dialog->setWindowTitle(_q("Favorite players"));
|
dialog->setWindowTitle(_q("Favorite players"));
|
||||||
dialog->resize(400, 500);
|
dialog->resize(480, 550);
|
||||||
|
dialog->setMinimumSize(200, 200);
|
||||||
|
|
||||||
QVBoxLayout *vLayout = new QVBoxLayout;
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
||||||
dialog->setLayout(vLayout);
|
dialog->setLayout(vLayout);
|
||||||
QLabel *label = new QLabel(_q("The favorite players listed below are "
|
QLabel *label = new QLabel(_q("The favorite players listed below can be "
|
||||||
"used in the \"New game\" dialog, to add "
|
"used in the \"New game\" dialog, to add "
|
||||||
"players quickly."));
|
"players quickly. Those marked as \"Default\" "
|
||||||
|
"will appear there directly (useful if you "
|
||||||
|
"often play with the same players)."));
|
||||||
label->setWordWrap(true);
|
label->setWordWrap(true);
|
||||||
vLayout->addWidget(label);
|
vLayout->addWidget(label);
|
||||||
QLabel *label2 = new QLabel(_q("To add or remove a player, use the buttons "
|
QLabel *label2 = new QLabel(_q("To add or remove a player, use the buttons "
|
||||||
|
@ -1068,7 +1071,7 @@ void MainWindow::onSettingsFavPlayers()
|
||||||
connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||||
|
|
||||||
PlayersTableHelper *helper =
|
PlayersTableHelper *helper =
|
||||||
new PlayersTableHelper(dialog, tableFav, buttonAdd, buttonRemove);
|
new PlayersTableHelper(dialog, tableFav, buttonAdd, buttonRemove, true);
|
||||||
helper->addPopupRemoveAction();
|
helper->addPopupRemoveAction();
|
||||||
helper->addPlayers(helper->getFavPlayers());
|
helper->addPlayers(helper->getFavPlayers());
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,19 @@ NewGame::NewGame(QWidget *iParent)
|
||||||
defLevel = 100;
|
defLevel = 100;
|
||||||
|
|
||||||
// Initialize the model of the default players
|
// Initialize the model of the default players
|
||||||
m_helper->addPlayer(PlayerDef(_q("Player %1").arg(1), _q(kHUMAN), ""));
|
QList<PlayerDef> fav = PlayersTableHelper::getFavPlayers();
|
||||||
m_helper->addPlayer(PlayerDef(_q("Eliot"), _q(kAI), QString("%1").arg(defLevel)));
|
Q_FOREACH(const PlayerDef &def, fav)
|
||||||
|
{
|
||||||
|
if (def.isDefault)
|
||||||
|
m_helper->addPlayer(def);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default of the default :)
|
||||||
|
if (m_helper->getRowCount() == 0)
|
||||||
|
{
|
||||||
|
m_helper->addPlayer(PlayerDef(_q("Player %1").arg(1), _q(kHUMAN), "", false));
|
||||||
|
m_helper->addPlayer(PlayerDef(_q("Eliot"), _q(kAI), QString("%1").arg(defLevel), false));
|
||||||
|
}
|
||||||
|
|
||||||
// Enable the Ok button only if there are enough players for the
|
// Enable the Ok button only if there are enough players for the
|
||||||
// current mode
|
// current mode
|
||||||
|
@ -198,7 +209,7 @@ void NewGame::enablePlayers(bool checked)
|
||||||
|
|
||||||
void NewGame::addSelectedToFav()
|
void NewGame::addSelectedToFav()
|
||||||
{
|
{
|
||||||
QList<PlayerDef> fav = m_helper->getFavPlayers();
|
QList<PlayerDef> fav = PlayersTableHelper::getFavPlayers();
|
||||||
const QList<PlayerDef> &selected = m_helper->getPlayers(true);
|
const QList<PlayerDef> &selected = m_helper->getPlayers(true);
|
||||||
Q_FOREACH(const PlayerDef &def, selected)
|
Q_FOREACH(const PlayerDef &def, selected)
|
||||||
{
|
{
|
||||||
|
@ -223,7 +234,7 @@ void NewGame::addFavoritePlayers()
|
||||||
connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||||
|
|
||||||
PlayersTableHelper *helper = new PlayersTableHelper(dialog, tableFav);
|
PlayersTableHelper *helper = new PlayersTableHelper(dialog, tableFav);
|
||||||
helper->addPlayers(m_helper->getFavPlayers());
|
helper->addPlayers(PlayersTableHelper::getFavPlayers());
|
||||||
|
|
||||||
if (dialog->exec() == QDialog::Accepted)
|
if (dialog->exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,13 +49,14 @@ uint qHash(const PlayerDef &key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PlayerDef::PlayerDef(QString iName, QString iType, QString iLevel)
|
PlayerDef::PlayerDef(QString iName, QString iType, QString iLevel, bool iIsDefault)
|
||||||
: name(iName), type(iType), level(iLevel)
|
: name(iName), type(iType), level(iLevel), isDefault(iIsDefault)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerDef::operator==(const PlayerDef &iOther) const
|
bool PlayerDef::operator==(const PlayerDef &iOther) const
|
||||||
{
|
{
|
||||||
|
// Ignore the "isDefault" flag
|
||||||
return name == iOther.name
|
return name == iOther.name
|
||||||
&& type == iOther.type
|
&& type == iOther.type
|
||||||
&& level == iOther.level;
|
&& level == iOther.level;
|
||||||
|
@ -65,15 +66,18 @@ bool PlayerDef::operator==(const PlayerDef &iOther) const
|
||||||
PlayersTableHelper::PlayersTableHelper(QObject *parent,
|
PlayersTableHelper::PlayersTableHelper(QObject *parent,
|
||||||
QTableWidget *tablePlayers,
|
QTableWidget *tablePlayers,
|
||||||
QPushButton *addButton,
|
QPushButton *addButton,
|
||||||
QPushButton *removeButton)
|
QPushButton *removeButton,
|
||||||
|
bool showDefaultColumn)
|
||||||
: QObject(parent), m_tablePlayers(tablePlayers),
|
: QObject(parent), m_tablePlayers(tablePlayers),
|
||||||
m_buttonAdd(addButton), m_buttonRemove(removeButton)
|
m_buttonAdd(addButton), m_buttonRemove(removeButton),
|
||||||
|
m_showDefaultColumn(showDefaultColumn)
|
||||||
{
|
{
|
||||||
// Initialize the table headers
|
// Initialize the table headers
|
||||||
tablePlayers->setColumnCount(3);
|
tablePlayers->setColumnCount(m_showDefaultColumn ? 4 : 3);
|
||||||
tablePlayers->setHorizontalHeaderItem(0, new QTableWidgetItem(_("Name")));
|
tablePlayers->setHorizontalHeaderItem(0, new QTableWidgetItem(_("Name")));
|
||||||
tablePlayers->setHorizontalHeaderItem(1, new QTableWidgetItem(_("Type")));
|
tablePlayers->setHorizontalHeaderItem(1, new QTableWidgetItem(_("Type")));
|
||||||
tablePlayers->setHorizontalHeaderItem(2, new QTableWidgetItem(_("Level")));
|
tablePlayers->setHorizontalHeaderItem(2, new QTableWidgetItem(_("Level")));
|
||||||
|
tablePlayers->setHorizontalHeaderItem(3, new QTableWidgetItem(_("Default")));
|
||||||
QHeaderView *header = tablePlayers->horizontalHeader();
|
QHeaderView *header = tablePlayers->horizontalHeader();
|
||||||
header->setHighlightSections(false);
|
header->setHighlightSections(false);
|
||||||
header->setStretchLastSection(true);
|
header->setStretchLastSection(true);
|
||||||
|
@ -81,6 +85,7 @@ PlayersTableHelper::PlayersTableHelper(QObject *parent,
|
||||||
header->resizeSection(0, 200);
|
header->resizeSection(0, 200);
|
||||||
header->resizeSection(1, 100);
|
header->resizeSection(1, 100);
|
||||||
header->resizeSection(2, 50);
|
header->resizeSection(2, 50);
|
||||||
|
header->resizeSection(3, 70);
|
||||||
tablePlayers->verticalHeader()->setVisible(false);
|
tablePlayers->verticalHeader()->setVisible(false);
|
||||||
|
|
||||||
// Set other table properties
|
// Set other table properties
|
||||||
|
@ -175,7 +180,7 @@ void PlayersTableHelper::removeSelectedRows()
|
||||||
|
|
||||||
void PlayersTableHelper::addRow()
|
void PlayersTableHelper::addRow()
|
||||||
{
|
{
|
||||||
addPlayer(PlayerDef(_q("New player"), _q(kHUMAN), ""),
|
addPlayer(PlayerDef(_q("New player"), _q(kHUMAN), "", false),
|
||||||
true, true);
|
true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +193,11 @@ QList<PlayerDef> PlayersTableHelper::getPlayers(bool onlySelected) const
|
||||||
{
|
{
|
||||||
if (onlySelected && !selModel->isRowSelected(i, QModelIndex()))
|
if (onlySelected && !selModel->isRowSelected(i, QModelIndex()))
|
||||||
continue;
|
continue;
|
||||||
|
const QVariant & data = m_tablePlayers->model()->data(m_tablePlayers->model()->index(i, 3));
|
||||||
PlayerDef playerDef(m_tablePlayers->item(i, 0)->text(),
|
PlayerDef playerDef(m_tablePlayers->item(i, 0)->text(),
|
||||||
m_tablePlayers->item(i, 1)->text(),
|
m_tablePlayers->item(i, 1)->text(),
|
||||||
m_tablePlayers->item(i, 2)->text());
|
m_tablePlayers->item(i, 2)->text(),
|
||||||
|
data.toBool());
|
||||||
playersList.push_back(playerDef);
|
playersList.push_back(playerDef);
|
||||||
}
|
}
|
||||||
return playersList;
|
return playersList;
|
||||||
|
@ -263,6 +270,9 @@ void PlayersTableHelper::addRow(const PlayerDef &iDef)
|
||||||
m_tablePlayers->setItem(row, 0, new QTableWidgetItem(iDef.name));
|
m_tablePlayers->setItem(row, 0, new QTableWidgetItem(iDef.name));
|
||||||
m_tablePlayers->setItem(row, 1, new QTableWidgetItem(iDef.type));
|
m_tablePlayers->setItem(row, 1, new QTableWidgetItem(iDef.type));
|
||||||
m_tablePlayers->setItem(row, 2, new QTableWidgetItem(iDef.level));
|
m_tablePlayers->setItem(row, 2, new QTableWidgetItem(iDef.level));
|
||||||
|
QTableWidgetItem *item = new QTableWidgetItem;
|
||||||
|
item->setData(Qt::DisplayRole, iDef.isDefault);
|
||||||
|
m_tablePlayers->setItem(row, 3, item);
|
||||||
emit rowCountChanged();
|
emit rowCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +287,8 @@ QList<PlayerDef> PlayersTableHelper::getFavPlayers()
|
||||||
qs.setArrayIndex(i);
|
qs.setArrayIndex(i);
|
||||||
PlayerDef playerDef(qs.value("name").toString(),
|
PlayerDef playerDef(qs.value("name").toString(),
|
||||||
qs.value("type").toString(),
|
qs.value("type").toString(),
|
||||||
qs.value("level").toString());
|
qs.value("level").toString(),
|
||||||
|
qs.value("default").toBool());
|
||||||
playersList.push_back(playerDef);
|
playersList.push_back(playerDef);
|
||||||
}
|
}
|
||||||
qs.endArray();
|
qs.endArray();
|
||||||
|
@ -295,6 +306,7 @@ void PlayersTableHelper::saveFavPlayers(const QList<PlayerDef> &iFavPlayers)
|
||||||
qs.setValue("name", iFavPlayers.at(i).name);
|
qs.setValue("name", iFavPlayers.at(i).name);
|
||||||
qs.setValue("type", iFavPlayers.at(i).type);
|
qs.setValue("type", iFavPlayers.at(i).type);
|
||||||
qs.setValue("level", iFavPlayers.at(i).level);
|
qs.setValue("level", iFavPlayers.at(i).level);
|
||||||
|
qs.setValue("default", iFavPlayers.at(i).isDefault);
|
||||||
}
|
}
|
||||||
qs.endArray();
|
qs.endArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,11 @@ class QPoint;
|
||||||
|
|
||||||
struct PlayerDef
|
struct PlayerDef
|
||||||
{
|
{
|
||||||
PlayerDef(QString name, QString type, QString level);
|
PlayerDef(QString name, QString type, QString level, bool isDefault);
|
||||||
QString name;
|
QString name;
|
||||||
QString type;
|
QString type;
|
||||||
QString level;
|
QString level;
|
||||||
|
bool isDefault;
|
||||||
|
|
||||||
bool operator==(const PlayerDef &) const;
|
bool operator==(const PlayerDef &) const;
|
||||||
};
|
};
|
||||||
|
@ -59,7 +60,8 @@ public:
|
||||||
PlayersTableHelper(QObject *parent,
|
PlayersTableHelper(QObject *parent,
|
||||||
QTableWidget *tableWidget,
|
QTableWidget *tableWidget,
|
||||||
QPushButton *addButton = 0,
|
QPushButton *addButton = 0,
|
||||||
QPushButton *removeButton = 0);
|
QPushButton *removeButton = 0,
|
||||||
|
bool showDefaultColumn = false);
|
||||||
|
|
||||||
QList<PlayerDef> getPlayers(bool onlySelected) const;
|
QList<PlayerDef> getPlayers(bool onlySelected) const;
|
||||||
void addPlayers(const QList<PlayerDef> &iList);
|
void addPlayers(const QList<PlayerDef> &iList);
|
||||||
|
@ -90,6 +92,7 @@ private:
|
||||||
QPushButton *m_buttonAdd;
|
QPushButton *m_buttonAdd;
|
||||||
QPushButton *m_buttonRemove;
|
QPushButton *m_buttonRemove;
|
||||||
QList<QAction*> m_popupActions;
|
QList<QAction*> m_popupActions;
|
||||||
|
bool m_showDefaultColumn;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue