mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 18:43:55 -07:00
generalized user information
This commit is contained in:
parent
adaa1d5323
commit
f9446f9822
61 changed files with 3710 additions and 175 deletions
|
|
@ -26,7 +26,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
ServerInfo_Game *g = gameList[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0: return g->getDescription();
|
||||
case 1: return g->getCreatorName();
|
||||
case 1: return g->getCreatorInfo()->getName();
|
||||
case 2: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
|
||||
case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
|
||||
case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
|
||||
|
|
@ -56,7 +56,7 @@ ServerInfo_Game *GamesModel::getGame(int row)
|
|||
|
||||
void GamesModel::updateGameList(ServerInfo_Game *_game)
|
||||
{
|
||||
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), _game->getCreatorName(), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
|
||||
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), new ServerInfo_User(_game->getCreatorInfo()), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
|
||||
for (int i = 0; i < gameList.size(); i++)
|
||||
if (gameList[i]->getGameId() == game->getGameId()) {
|
||||
if (game->getPlayerCount() == 0) {
|
||||
|
|
|
|||
|
|
@ -16,3 +16,8 @@ LocalServerInterface *LocalServer::newConnection()
|
|||
addClient(lsi);
|
||||
return lsi;
|
||||
}
|
||||
|
||||
ServerInfo_User *LocalServer::getUserData(const QString &name)
|
||||
{
|
||||
return new ServerInfo_User(name);
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@ public:
|
|||
int getMaxPlayerInactivityTime() const { return 9999999; }
|
||||
|
||||
LocalServerInterface *newConnection();
|
||||
protected:
|
||||
ServerInfo_User *getUserData(const QString &name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -34,14 +34,12 @@
|
|||
#include "dlg_settings.h"
|
||||
#include "carddatabase.h"
|
||||
#include "settingscache.h"
|
||||
#include "pingpixmapgenerator.h"
|
||||
|
||||
//Q_IMPORT_PLUGIN(qjpeg)
|
||||
|
||||
CardDatabase *db;
|
||||
QTranslator *translator, *qtTranslator;
|
||||
SettingsCache *settingsCache;
|
||||
PingPixmapGenerator *pingPixmapGenerator;
|
||||
|
||||
void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
||||
{
|
||||
|
|
@ -87,7 +85,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
settingsCache = new SettingsCache;
|
||||
db = new CardDatabase;
|
||||
pingPixmapGenerator = new PingPixmapGenerator;
|
||||
|
||||
qtTranslator = new QTranslator;
|
||||
translator = new QTranslator;
|
||||
|
|
@ -125,7 +122,6 @@ int main(int argc, char *argv[])
|
|||
app.exec();
|
||||
}
|
||||
|
||||
delete pingPixmapGenerator;
|
||||
delete db;
|
||||
delete settingsCache;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
#include "pingpixmapgenerator.h"
|
||||
#include <QPainter>
|
||||
|
||||
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
|
||||
{
|
||||
int key = size * 1000000 + max * 1000 + value;
|
||||
if (pmCache.contains(key))
|
||||
return pmCache.value(key);
|
||||
|
||||
QPixmap pixmap(size, size);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
QColor color;
|
||||
if ((max == -1) || (value == -1))
|
||||
color = Qt::black;
|
||||
else
|
||||
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
|
||||
|
||||
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
|
||||
g.setColorAt(0, color);
|
||||
g.setColorAt(1, Qt::transparent);
|
||||
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
|
||||
|
||||
pmCache.insert(key, pixmap);
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef PINGPIXMAPGENERATOR_H
|
||||
#define PINGPIXMAPGENERATOR_H
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
|
||||
class PingPixmapGenerator {
|
||||
private:
|
||||
QMap<int, QPixmap> pmCache;
|
||||
public:
|
||||
QPixmap generatePixmap(int size, int value, int max);
|
||||
};
|
||||
|
||||
extern PingPixmapGenerator *pingPixmapGenerator;
|
||||
|
||||
#endif
|
||||
52
cockatrice/src/pixmapgenerator.cpp
Normal file
52
cockatrice/src/pixmapgenerator.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "pixmapgenerator.h"
|
||||
#include <QPainter>
|
||||
#include <QSvgRenderer>
|
||||
#include <math.h>
|
||||
|
||||
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
|
||||
{
|
||||
int key = size * 1000000 + max * 1000 + value;
|
||||
if (pmCache.contains(key))
|
||||
return pmCache.value(key);
|
||||
|
||||
QPixmap pixmap(size, size);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
QColor color;
|
||||
if ((max == -1) || (value == -1))
|
||||
color = Qt::black;
|
||||
else
|
||||
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
|
||||
|
||||
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
|
||||
g.setColorAt(0, color);
|
||||
g.setColorAt(1, Qt::transparent);
|
||||
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
|
||||
|
||||
pmCache.insert(key, pixmap);
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QMap<int, QPixmap> PingPixmapGenerator::pmCache;
|
||||
|
||||
QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countryCode)
|
||||
{
|
||||
if (countryCode.size() != 2)
|
||||
return QPixmap();
|
||||
QString key = countryCode + QString::number(height);
|
||||
if (pmCache.contains(key))
|
||||
return pmCache.value(key);
|
||||
|
||||
QSvgRenderer svg(QString(":/resources/countries/" + countryCode + ".svg"));
|
||||
double aspect = (double) svg.defaultSize().width() / (double) svg.defaultSize().height();
|
||||
QPixmap pixmap((int) round(aspect * height), height);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
svg.render(&painter, QRectF(0, 0, aspect * height, height));
|
||||
|
||||
pmCache.insert(key, pixmap);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
||||
21
cockatrice/src/pixmapgenerator.h
Normal file
21
cockatrice/src/pixmapgenerator.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef PINGPIXMAPGENERATOR_H
|
||||
#define PINGPIXMAPGENERATOR_H
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
|
||||
class PingPixmapGenerator {
|
||||
private:
|
||||
static QMap<int, QPixmap> pmCache;
|
||||
public:
|
||||
static QPixmap generatePixmap(int size, int value, int max);
|
||||
};
|
||||
|
||||
class CountryPixmapGenerator {
|
||||
private:
|
||||
static QMap<QString, QPixmap> pmCache;
|
||||
public:
|
||||
static QPixmap generatePixmap(int height, const QString &countryCode);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
#include <QHeaderView>
|
||||
#include "playerlistwidget.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include "pingpixmapgenerator.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include <QDebug>
|
||||
|
||||
PlayerListWidget::PlayerListWidget(QWidget *parent)
|
||||
: QTreeWidget(parent), gameStarted(false)
|
||||
|
|
@ -44,14 +45,16 @@ void PlayerListWidget::updatePlayerProperties(ServerInfo_PlayerProperties *prop)
|
|||
|
||||
player->setIcon(1, prop->getSpectator() ? spectatorIcon : playerIcon);
|
||||
player->setIcon(2, gameStarted ? (prop->getConceded() ? concededIcon : QIcon()) : (prop->getReadyStart() ? readyIcon : notReadyIcon));
|
||||
player->setText(3, prop->getName());
|
||||
player->setText(3, prop->getUserInfo()->getName());
|
||||
if (!prop->getUserInfo()->getCountry().isEmpty())
|
||||
player->setIcon(3, QIcon(CountryPixmapGenerator::generatePixmap(10, prop->getUserInfo()->getCountry())));
|
||||
|
||||
QString deckText;
|
||||
if (!prop->getSpectator())
|
||||
switch (prop->getDeckId()) {
|
||||
case -2: deckText = tr("no deck"); break;
|
||||
case -1: deckText = tr("local deck"); break;
|
||||
default: deckText = tr("ID #%1").arg(prop->getDeckId());
|
||||
case -2: deckText = tr("---"); break;
|
||||
case -1: deckText = tr("local"); break;
|
||||
default: deckText = tr("#%1").arg(prop->getDeckId());
|
||||
}
|
||||
player->setText(4, deckText);
|
||||
}
|
||||
|
|
@ -81,7 +84,7 @@ void PlayerListWidget::updatePing(int playerId, int pingTime)
|
|||
QTreeWidgetItem *twi = players.value(playerId, 0);
|
||||
if (!twi)
|
||||
return;
|
||||
twi->setIcon(0, QIcon(pingPixmapGenerator->generatePixmap(10, pingTime, 10)));
|
||||
twi->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(10, pingTime, 10)));
|
||||
}
|
||||
|
||||
void PlayerListWidget::setGameStarted(bool _gameStarted)
|
||||
|
|
|
|||
|
|
@ -77,15 +77,15 @@ void TabChatChannel::processChatEvent(ChatEvent *event)
|
|||
|
||||
void TabChatChannel::processListPlayersEvent(Event_ChatListPlayers *event)
|
||||
{
|
||||
const QList<ServerInfo_ChatUser *> &players = event->getPlayerList();
|
||||
const QList<ServerInfo_User *> &players = event->getPlayerList();
|
||||
for (int i = 0; i < players.size(); ++i)
|
||||
playerList->addItem(players[i]->getName());
|
||||
}
|
||||
|
||||
void TabChatChannel::processJoinChannelEvent(Event_ChatJoinChannel *event)
|
||||
{
|
||||
textEdit->append(tr("%1 has joined the channel.").arg(event->getPlayerName()));
|
||||
playerList->addItem(event->getPlayerName());
|
||||
textEdit->append(tr("%1 has joined the channel.").arg(event->getUserInfo()->getName()));
|
||||
playerList->addItem(event->getUserInfo()->getName());
|
||||
emit userEvent();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -488,13 +488,13 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event, GameEventCont
|
|||
ServerInfo_PlayerProperties *prop = pl->getProperties();
|
||||
if (prop->getSpectator()) {
|
||||
if (!spectators.contains(prop->getPlayerId())) {
|
||||
spectators.insert(prop->getPlayerId(), prop->getName());
|
||||
spectators.insert(prop->getPlayerId(), prop->getUserInfo()->getName());
|
||||
playerListWidget->addPlayer(prop);
|
||||
}
|
||||
} else {
|
||||
Player *player = players.value(prop->getPlayerId(), 0);
|
||||
if (!player) {
|
||||
player = addPlayer(prop->getPlayerId(), prop->getName());
|
||||
player = addPlayer(prop->getPlayerId(), prop->getUserInfo()->getName());
|
||||
playerListWidget->addPlayer(prop);
|
||||
}
|
||||
player->processPlayerInfo(pl);
|
||||
|
|
@ -554,11 +554,11 @@ void TabGame::eventJoin(Event_Join *event, GameEventContext * /*context*/)
|
|||
{
|
||||
ServerInfo_PlayerProperties *playerInfo = event->getPlayer();
|
||||
if (playerInfo->getSpectator()) {
|
||||
spectators.insert(playerInfo->getPlayerId(), playerInfo->getName());
|
||||
messageLog->logJoinSpectator(playerInfo->getName());
|
||||
spectators.insert(playerInfo->getPlayerId(), playerInfo->getUserInfo()->getName());
|
||||
messageLog->logJoinSpectator(playerInfo->getUserInfo()->getName());
|
||||
playerListWidget->addPlayer(playerInfo);
|
||||
} else {
|
||||
Player *newPlayer = addPlayer(playerInfo->getPlayerId(), playerInfo->getName());
|
||||
Player *newPlayer = addPlayer(playerInfo->getPlayerId(), playerInfo->getUserInfo()->getName());
|
||||
messageLog->logJoin(newPlayer);
|
||||
playerListWidget->addPlayer(playerInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "tab_game.h"
|
||||
#include "tab_deck_storage.h"
|
||||
#include "protocol_items.h"
|
||||
#include "pingpixmapgenerator.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include <QDebug>
|
||||
|
||||
TabSupervisor:: TabSupervisor(QWidget *parent)
|
||||
|
|
@ -97,10 +97,10 @@ void TabSupervisor::stop()
|
|||
|
||||
clear();
|
||||
|
||||
delete tabServer;
|
||||
tabServer->deleteLater();
|
||||
tabServer = 0;
|
||||
|
||||
delete tabDeckStorage;
|
||||
tabDeckStorage->deleteLater();
|
||||
tabDeckStorage = 0;
|
||||
|
||||
QMapIterator<QString, TabChatChannel *> chatChannelIterator(chatChannelTabs);
|
||||
|
|
@ -119,7 +119,7 @@ void TabSupervisor::updatePingTime(int value, int max)
|
|||
if (!tabServer)
|
||||
return;
|
||||
|
||||
setTabIcon(0, QIcon(pingPixmapGenerator->generatePixmap(15, value, max)));
|
||||
setTabIcon(0, QIcon(PingPixmapGenerator::generatePixmap(15, value, max)));
|
||||
}
|
||||
|
||||
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue