Updated game view
+ removed password column + added a lock svg to restrictions if pw is needed + added "password" to restrictions if pw is needed + added user pawn to creator tab + reformatted code for easy adaptation later
This commit is contained in:
parent
0daa7a8809
commit
1406a27775
2 changed files with 133 additions and 63 deletions
|
@ -1,11 +1,15 @@
|
|||
#include "gamesmodel.h"
|
||||
#include "pb/serverinfo_game.pb.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
#include <QSettings>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
static const enum {ROOM, CREATED, DESCRIPTION, CREATOR, GAME_TYPE, RESTRICTIONS, PLAYERS, SPECTATORS};
|
||||
|
||||
namespace {
|
||||
const unsigned SECS_PER_MIN = 60;
|
||||
const unsigned SECS_PER_HOUR = 60 * 60;
|
||||
|
@ -75,15 +79,16 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
if (role == Qt::UserRole)
|
||||
return index.row();
|
||||
if (role != Qt::DisplayRole && role != SORT_ROLE)
|
||||
if (role != Qt::DisplayRole && role != SORT_ROLE && role != Qt::DecorationRole && role != Qt::TextAlignmentRole)
|
||||
return QVariant();
|
||||
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
|
||||
return QVariant();
|
||||
|
||||
const ServerInfo_Game &g = gameList[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0: return rooms.value(g.room_id());
|
||||
case 1: {
|
||||
case ROOM:
|
||||
return rooms.value(g.room_id());
|
||||
case CREATED: {
|
||||
QDateTime then;
|
||||
then.setTime_t(g.start_time());
|
||||
unsigned int secs = then.secsTo(QDateTime::currentDateTime());
|
||||
|
@ -91,32 +96,98 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
switch (role) {
|
||||
case Qt::DisplayRole: return prettyPrintSecsAgo(secs);
|
||||
case SORT_ROLE: return QVariant(secs);
|
||||
default: {
|
||||
qDebug() << "Returning data for col 1 of games model when role != display, role != sort";
|
||||
return QVariant(); // Shouldn't ever be reached.
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
case DESCRIPTION:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(g.description());
|
||||
case Qt::TextAlignmentRole:
|
||||
Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case 2: return QString::fromStdString(g.description());
|
||||
case 3: return QString::fromStdString(g.creator_info().name());
|
||||
case 4: {
|
||||
case CREATOR: {
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(g.creator_info().name());
|
||||
case Qt::DecorationRole:
|
||||
switch(g.creator_info().user_level()) {
|
||||
case 1: {
|
||||
QPixmap avatarPixmap = UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)g.creator_info().user_level());
|
||||
return QIcon(avatarPixmap);
|
||||
}
|
||||
case 3:{
|
||||
QPixmap avatarPixmap = UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)g.creator_info().user_level());
|
||||
return QIcon(avatarPixmap);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case GAME_TYPE:
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
QStringList result;
|
||||
GameTypeMap gameTypeMap = gameTypes.value(g.room_id());
|
||||
for (int i = g.game_types_size() - 1; i >= 0; --i)
|
||||
result.append(gameTypeMap.value(g.game_types(i)));
|
||||
return result.join(", ");
|
||||
}
|
||||
case 5: return g.with_password() ? ((g.spectators_need_password() || !g.spectators_allowed()) ? tr("yes") : tr("yes, free for spectators")) : tr("no");
|
||||
case 6: {
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case RESTRICTIONS:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
QStringList result;
|
||||
if (g.only_buddies())
|
||||
result.append(tr("buddies only"));
|
||||
if (g.only_registered())
|
||||
result.append(tr("reg. users only"));
|
||||
if (g.with_password())
|
||||
result.append(tr("password"));
|
||||
return result.join(", ");
|
||||
}
|
||||
case 7: return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
||||
case 8: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
|
||||
case Qt::DecorationRole:{
|
||||
return g.with_password() ? QIcon(":/resources/lock.svg") : QVariant();
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case PLAYERS:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case SPECTATORS:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
@ -131,10 +202,9 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
|
|||
case 2: return tr("Description");
|
||||
case 3: return tr("Creator");
|
||||
case 4: return tr("Game Type");
|
||||
case 5: return tr("Password");
|
||||
case 6: return tr("Restrictions");
|
||||
case 7: return tr("Players");
|
||||
case 8: return tr("Spectators");
|
||||
case 5: return tr("Restrictions");
|
||||
case 6: return tr("Players");
|
||||
case 7: return tr("Spectators");
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ private:
|
|||
QMap<int, QString> rooms;
|
||||
QMap<int, GameTypeMap> gameTypes;
|
||||
|
||||
static const int NUM_COLS = 9;
|
||||
static const int NUM_COLS = 8;
|
||||
public:
|
||||
static const int SORT_ROLE = Qt::UserRole+1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue