Color player counts in the multiplayer public lobby list
- Full lobbies have their player count displayed in red. - Lobbies with one slot left have their player count displayed in orange. - Empty lobbies have their player count grayed out.
This commit is contained in:
parent
8ddfecfbae
commit
8e0f97ac96
|
@ -193,13 +193,30 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant data(int role) const override {
|
QVariant data(int role) const override {
|
||||||
if (role != Qt::DisplayRole) {
|
switch (role) {
|
||||||
return LobbyItem::data(role);
|
case Qt::DisplayRole: {
|
||||||
}
|
|
||||||
auto members = data(MemberListRole).toList();
|
auto members = data(MemberListRole).toList();
|
||||||
return QStringLiteral("%1 / %2 ")
|
return QStringLiteral("%1 / %2 ")
|
||||||
.arg(QString::number(members.size()), data(MaxPlayerRole).toString());
|
.arg(QString::number(members.size()), data(MaxPlayerRole).toString());
|
||||||
}
|
}
|
||||||
|
case Qt::ForegroundRole: {
|
||||||
|
auto members = data(MemberListRole).toList();
|
||||||
|
auto max_players = data(MaxPlayerRole).toInt();
|
||||||
|
if (members.size() >= max_players) {
|
||||||
|
return QBrush(QColor(255, 48, 32));
|
||||||
|
} else if (members.size() == (max_players - 1)) {
|
||||||
|
return QBrush(QColor(255, 140, 32));
|
||||||
|
} else if (members.size() == 0) {
|
||||||
|
return QBrush(QColor(128, 128, 128));
|
||||||
|
}
|
||||||
|
// FIXME: How to return a value that tells Qt not to modify the
|
||||||
|
// text color from the default (as if Qt::ForegroundRole wasn't overridden)?
|
||||||
|
return QBrush(nullptr);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return LobbyItem::data(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool operator<(const QStandardItem& other) const override {
|
bool operator<(const QStandardItem& other) const override {
|
||||||
// sort by rooms that have the most players
|
// sort by rooms that have the most players
|
||||||
|
|
Reference in New Issue