avatar changes

This commit is contained in:
Max-Wilhelm Bruker 2010-10-11 17:45:52 +02:00
parent 28a77f10e4
commit 2f422f5a20
6 changed files with 29 additions and 19 deletions

View file

@ -20,8 +20,8 @@
#include <QMenu>
#include <QDebug>
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;

View file

@ -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<QString, CardZone *> &getZones() const { return zones; }

View file

@ -1,9 +1,10 @@
#include "playertarget.h"
#include "player.h"
#include "protocol_datastructures.h"
#include <QPainter>
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());
}

View file

@ -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);
};

View file

@ -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);
}

View file

@ -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();