From 2f422f5a20cd36fda53c9702c9a499982fa3623d Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 11 Oct 2010 17:45:52 +0200 Subject: [PATCH] avatar changes --- cockatrice/src/player.cpp | 15 +++++++++++---- cockatrice/src/player.h | 8 +++++--- cockatrice/src/playertarget.cpp | 10 ++++++---- cockatrice/src/playertarget.h | 4 +--- cockatrice/src/tab_game.cpp | 8 ++++---- cockatrice/src/tab_game.h | 3 ++- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 8eee6880..a6885755 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -20,8 +20,8 @@ #include #include -Player::Player(const QString &_name, int _id, bool _local, TabGame *_parent) - : QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), name(_name), id(_id), active(false), local(_local), mirrored(false), dialogSemaphore(false) +Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent) + : QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), userInfo(new ServerInfo_User(info)), id(_id), active(false), local(_local), mirrored(false), dialogSemaphore(false) { setCacheMode(DeviceCoordinateCache); @@ -29,7 +29,8 @@ Player::Player(const QString &_name, int _id, bool _local, TabGame *_parent) connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap())); updateBgPixmap(); - playerTarget = new PlayerTarget(name, CARD_WIDTH + counterAreaWidth + 5, this); +// playerTarget = new PlayerTarget(CARD_WIDTH + counterAreaWidth + 5, this); + playerTarget = new PlayerTarget(this); playerTarget->setPos(QPointF(0, 0)); QPointF base = QPointF(counterAreaWidth, 50); @@ -239,6 +240,7 @@ Player::~Player() clearCounters(); delete playerMenu; + delete userInfo; } void Player::rearrangeZones() @@ -289,7 +291,7 @@ void Player::retranslateUi() { aViewGraveyard->setText(tr("&View graveyard")); aViewRfg->setText(tr("&View exile")); - playerMenu->setTitle(tr("Player \"%1\"").arg(name)); + playerMenu->setTitle(tr("Player \"%1\"").arg(userInfo->getName())); graveMenu->setTitle(tr("&Graveyard")); rfgMenu->setTitle(tr("&Exile")); @@ -1270,6 +1272,11 @@ QMenu *Player::getCardMenu() const return 0; } +QString Player::getName() const +{ + return userInfo->getName(); +} + qreal Player::getMinimumWidth() const { qreal result = table->getMinimumWidth() + CARD_WIDTH + 5 + counterAreaWidth; diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index fc263c59..b9dafe3b 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -17,6 +17,7 @@ class CardZone; class TableZone; class HandZone; class PlayerTarget; +class ServerInfo_User; class ServerInfo_Player; class ServerInfo_Arrow; class ServerInfo_Counter; @@ -115,7 +116,7 @@ private: int defaultNumberTopCards; QString lastTokenName, lastTokenColor, lastTokenPT, lastTokenAnnotation; bool lastTokenDestroy; - QString name; + ServerInfo_User *userInfo; int id; bool active; bool local; @@ -183,12 +184,13 @@ public: void clearArrows(); PlayerTarget *getPlayerTarget() const { return playerTarget; } - Player(const QString &_name, int _id, bool _local, TabGame *_parent); + Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent); ~Player(); void retranslateUi(); QMenu *getPlayerMenu() const { return playerMenu; } int getId() const { return id; } - QString getName() const { return name; } + QString getName() const; + ServerInfo_User *getUserInfo() const { return userInfo; } bool getLocal() const { return local; } bool getMirrored() const { return mirrored; } const QMap &getZones() const { return zones; } diff --git a/cockatrice/src/playertarget.cpp b/cockatrice/src/playertarget.cpp index b8d6ab3f..ff674142 100644 --- a/cockatrice/src/playertarget.cpp +++ b/cockatrice/src/playertarget.cpp @@ -1,9 +1,10 @@ #include "playertarget.h" #include "player.h" +#include "protocol_datastructures.h" #include -PlayerTarget::PlayerTarget(const QString &_name, int _maxWidth, Player *_owner) - : ArrowTarget(_owner, _owner), name(_name), maxWidth(_maxWidth) +PlayerTarget::PlayerTarget(Player *_owner) + : ArrowTarget(_owner, _owner) { font = QFont("Times"); font.setStyleHint(QFont::Serif); @@ -12,13 +13,14 @@ PlayerTarget::PlayerTarget(const QString &_name, int _maxWidth, Player *_owner) QRectF PlayerTarget::boundingRect() const { - return QRectF(0, 0, maxWidth, 30); + return QRectF(0, 0, 64, 64); } void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) { + ServerInfo_User *info = owner->getUserInfo(); painter->fillRect(boundingRect(), QColor(255, 255, 255, 100)); painter->setFont(font); painter->setPen(Qt::black); - painter->drawText(boundingRect(), Qt::AlignCenter, name); + painter->drawText(boundingRect(), Qt::AlignCenter, info->getName()); } diff --git a/cockatrice/src/playertarget.h b/cockatrice/src/playertarget.h index b6eb9534..f784db77 100644 --- a/cockatrice/src/playertarget.h +++ b/cockatrice/src/playertarget.h @@ -8,14 +8,12 @@ class Player; class PlayerTarget : public ArrowTarget { private: - QString name; QFont font; - int maxWidth; public: enum { Type = typePlayerTarget }; int type() const { return Type; } - PlayerTarget(const QString &_name, int _maxWidth, Player *parent = 0); + PlayerTarget(Player *parent = 0); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); }; diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 6e20e1ab..d069f517 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -320,10 +320,10 @@ void TabGame::actRemoveLocalArrows() } } -Player *TabGame::addPlayer(int playerId, const QString &playerName) +Player *TabGame::addPlayer(int playerId, ServerInfo_User *info) { bool local = ((clients.size() > 1) || (playerId == localPlayerId)); - Player *newPlayer = new Player(playerName, playerId, local, this); + Player *newPlayer = new Player(info, playerId, local, this); scene->addPlayer(newPlayer); connect(newPlayer, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *))); @@ -494,7 +494,7 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event, GameEventCont } else { Player *player = players.value(prop->getPlayerId(), 0); if (!player) { - player = addPlayer(prop->getPlayerId(), prop->getUserInfo()->getName()); + player = addPlayer(prop->getPlayerId(), prop->getUserInfo()); playerListWidget->addPlayer(prop); } player->processPlayerInfo(pl); @@ -560,7 +560,7 @@ void TabGame::eventJoin(Event_Join *event, GameEventContext * /*context*/) messageLog->logJoinSpectator(playerInfo->getUserInfo()->getName()); playerListWidget->addPlayer(playerInfo); } else { - Player *newPlayer = addPlayer(playerInfo->getPlayerId(), playerInfo->getUserInfo()->getName()); + Player *newPlayer = addPlayer(playerInfo->getPlayerId(), playerInfo->getUserInfo()); messageLog->logJoin(newPlayer); playerListWidget->addPlayer(playerInfo); } diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index dd836f91..23f85818 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -43,6 +43,7 @@ class TabGame; class DeckList; class QVBoxLayout; class QHBoxLayout; +class ServerInfo_User; class ReadyStartButton : public QPushButton { Q_OBJECT @@ -111,7 +112,7 @@ private: QMenu *playersMenu; QAction *aConcede, *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; - Player *addPlayer(int playerId, const QString &playerName); + Player *addPlayer(int playerId, ServerInfo_User *info); void startGame(); void stopGame();