removed some debugging warnings; fixed card name and player name display; display avatar in game
This commit is contained in:
parent
fbcb34db61
commit
bd06cd5796
7 changed files with 67 additions and 45 deletions
|
@ -28,7 +28,7 @@ AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphi
|
||||||
|
|
||||||
AbstractCardItem::~AbstractCardItem()
|
AbstractCardItem::~AbstractCardItem()
|
||||||
{
|
{
|
||||||
qDebug(QString("AbstractCardItem destructor: %1").arg(name).toLatin1());
|
qDebug() << "AbstractCardItem destructor:" << name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF AbstractCardItem::boundingRect() const
|
QRectF AbstractCardItem::boundingRect() const
|
||||||
|
@ -61,9 +61,11 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
||||||
|
|
||||||
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
|
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
|
||||||
} else {
|
} else {
|
||||||
QFont f("Times");
|
QFont f;
|
||||||
f.setStyleHint(QFont::Serif);
|
int fontSize = h / 6;
|
||||||
f.setPixelSize(12);
|
if (fontSize < 9)
|
||||||
|
fontSize = 9;
|
||||||
|
f.setPixelSize(fontSize);
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
QString colorStr;
|
QString colorStr;
|
||||||
if (!color.isEmpty())
|
if (!color.isEmpty())
|
||||||
|
@ -103,7 +105,17 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
||||||
painter->setPen(textColor);
|
painter->setPen(textColor);
|
||||||
painter->drawText(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, name);
|
|
||||||
|
QRectF textRect = painter->combinedTransform().mapRect(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15));
|
||||||
|
painter->resetTransform();
|
||||||
|
QTransform pixmapTransform;
|
||||||
|
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
|
||||||
|
pixmapTransform.rotate(tapAngle);
|
||||||
|
QPointF transPoint = QPointF(-w / 2, -h / 2);
|
||||||
|
pixmapTransform.translate(transPoint.x(), transPoint.y());
|
||||||
|
painter->setTransform(pixmapTransform);
|
||||||
|
|
||||||
|
painter->drawText(textRect, Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name);
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
|
|
@ -25,31 +25,6 @@ DeckListModel::~DeckListModel()
|
||||||
delete deckList;
|
delete deckList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeckListModel::debugIndexInfo(const QString &func, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid())
|
|
||||||
qDebug(QString("debugIndexInfo: %1: index invalid").arg(func).toLatin1());
|
|
||||||
else if (InnerDecklistNode *node = getNode<InnerDecklistNode *>(index))
|
|
||||||
qDebug(QString("debugIndexInfo: %1: INNER index '%2', row=%3, col=%4").arg(func).arg(node->getName()).arg(index.row()).arg(index.column()).toLatin1());
|
|
||||||
else if (DecklistModelCardNode *node = getNode<DecklistModelCardNode *>(index))
|
|
||||||
qDebug(QString("debugIndexInfo: %1: CARD index '%2', row=%3, col=%4").arg(func).arg(node->getName()).arg(index.row()).arg(index.column()).toLatin1());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckListModel::debugShowTree(InnerDecklistNode *node, int depth) const
|
|
||||||
{
|
|
||||||
for (int i = 0; i < node->size(); i++) {
|
|
||||||
DecklistModelCardNode *foo = dynamic_cast<DecklistModelCardNode *>(node->at(i));
|
|
||||||
if (!foo) {
|
|
||||||
InnerDecklistNode *bar = dynamic_cast<InnerDecklistNode *>(node->at(i));
|
|
||||||
qDebug(QString("%1%2").arg(QString(depth * 4, ' ')).arg(bar->getName()).toLatin1());
|
|
||||||
debugShowTree(bar, depth + 1);
|
|
||||||
} else
|
|
||||||
qDebug(QString("%1%2 %3").arg(QString(depth * 4, ' ')).arg(foo->getNumber()).arg(foo->getName()).toLatin1());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DeckListModel::rebuildTree()
|
void DeckListModel::rebuildTree()
|
||||||
{
|
{
|
||||||
root->clearTree();
|
root->clearTree();
|
||||||
|
|
|
@ -52,8 +52,6 @@ private:
|
||||||
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
||||||
void emitRecursiveUpdates(const QModelIndex &index);
|
void emitRecursiveUpdates(const QModelIndex &index);
|
||||||
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
||||||
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
|
||||||
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
|
||||||
|
|
||||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,10 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
|
||||||
connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap()));
|
connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap()));
|
||||||
updateBgPixmap();
|
updateBgPixmap();
|
||||||
|
|
||||||
// playerTarget = new PlayerTarget(CARD_WIDTH + counterAreaWidth + 5, this);
|
|
||||||
playerTarget = new PlayerTarget(this);
|
playerTarget = new PlayerTarget(this);
|
||||||
playerTarget->setPos(QPointF(0, 0));
|
playerTarget->setPos(QPointF(counterAreaWidth + (CARD_WIDTH + 5 - playerTarget->boundingRect().width()) / 2.0, 5));
|
||||||
|
|
||||||
QPointF base = QPointF(counterAreaWidth, 50);
|
QPointF base = QPointF(counterAreaWidth, 5 + playerTarget->boundingRect().height() + 10);
|
||||||
|
|
||||||
PileZone *deck = new PileZone(this, "deck", true, false, this);
|
PileZone *deck = new PileZone(this, "deck", true, false, this);
|
||||||
deck->setPos(base);
|
deck->setPos(base);
|
||||||
|
@ -1049,7 +1048,7 @@ void Player::clearArrows()
|
||||||
|
|
||||||
void Player::rearrangeCounters()
|
void Player::rearrangeCounters()
|
||||||
{
|
{
|
||||||
qreal marginTop = 50;
|
qreal marginTop = 15;
|
||||||
qreal marginBottom = 15;
|
qreal marginBottom = 15;
|
||||||
|
|
||||||
// Determine total height of bounding rectangles
|
// Determine total height of bounding rectangles
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
#include "playertarget.h"
|
#include "playertarget.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "protocol_datastructures.h"
|
#include "protocol_datastructures.h"
|
||||||
|
#include "pixmapgenerator.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
PlayerTarget::PlayerTarget(Player *_owner)
|
PlayerTarget::PlayerTarget(Player *_owner)
|
||||||
: ArrowTarget(_owner, _owner)
|
: ArrowTarget(_owner, _owner)
|
||||||
{
|
{
|
||||||
font = QFont("Times");
|
setCacheMode(DeviceCoordinateCache);
|
||||||
font.setStyleHint(QFont::Serif);
|
|
||||||
font.setPixelSize(20);
|
if (!fullPixmap.loadFromData(_owner->getUserInfo()->getAvatarBmp()))
|
||||||
|
fullPixmap = QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PlayerTarget::boundingRect() const
|
QRectF PlayerTarget::boundingRect() const
|
||||||
|
@ -19,8 +23,39 @@ QRectF PlayerTarget::boundingRect() const
|
||||||
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
{
|
{
|
||||||
ServerInfo_User *info = owner->getUserInfo();
|
ServerInfo_User *info = owner->getUserInfo();
|
||||||
painter->fillRect(boundingRect(), QColor(255, 255, 255, 100));
|
|
||||||
painter->setFont(font);
|
painter->save();
|
||||||
painter->setPen(Qt::black);
|
QRectF translatedRect = painter->combinedTransform().mapRect(boundingRect());
|
||||||
painter->drawText(boundingRect(), Qt::AlignCenter, info->getName());
|
QSize translatedSize = translatedRect.size().toSize();
|
||||||
|
QPixmap cachedPixmap;
|
||||||
|
const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" + QString::number(fullPixmap.cacheKey());
|
||||||
|
#if QT_VERSION >= 0x040600
|
||||||
|
if (!QPixmapCache::find(cacheKey, &cachedPixmap)) {
|
||||||
|
#else
|
||||||
|
if (!QPixmapCache::find(cacheKey, cachedPixmap)) {
|
||||||
|
#endif
|
||||||
|
if (fullPixmap.isNull())
|
||||||
|
cachedPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), info->getUserLevel());
|
||||||
|
else
|
||||||
|
cachedPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
QPixmapCache::insert(cacheKey, cachedPixmap);
|
||||||
|
}
|
||||||
|
painter->resetTransform();
|
||||||
|
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
|
||||||
|
|
||||||
|
QString name = info->getName();
|
||||||
|
if (name.size() > 13)
|
||||||
|
name = name.mid(0, 10) + "...";
|
||||||
|
|
||||||
|
QFont font;
|
||||||
|
font.setPixelSize(qMax(translatedSize.height() / 4, 9));
|
||||||
|
painter->setFont(font);
|
||||||
|
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||||
|
painter->setBackground(QColor(0, 0, 0, 100));
|
||||||
|
painter->setPen(Qt::white);
|
||||||
|
painter->drawText(translatedRect, Qt::AlignHCenter | Qt::AlignTop | Qt::TextWrapAnywhere, name);
|
||||||
|
painter->restore();
|
||||||
|
|
||||||
|
if (getBeingPointedAt())
|
||||||
|
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
|
|
||||||
#include "arrowtarget.h"
|
#include "arrowtarget.h"
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
class PlayerTarget : public ArrowTarget {
|
class PlayerTarget : public ArrowTarget {
|
||||||
private:
|
private:
|
||||||
QFont font;
|
QPixmap fullPixmap;
|
||||||
public:
|
public:
|
||||||
enum { Type = typePlayerTarget };
|
enum { Type = typePlayerTarget };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
|
|
|
@ -844,14 +844,16 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co
|
||||||
targetZone = targetPlayer->getZones().value(cmd->getTargetZone());
|
targetZone = targetPlayer->getZones().value(cmd->getTargetZone());
|
||||||
if (!startZone || (!targetZone && !playerTarget))
|
if (!startZone || (!targetZone && !playerTarget))
|
||||||
return RespNameNotFound;
|
return RespNameNotFound;
|
||||||
|
if (startZone->getType() != PublicZone)
|
||||||
|
return RespContextError;
|
||||||
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
|
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
|
||||||
if (!startCard)
|
if (!startCard)
|
||||||
return RespNameNotFound;
|
return RespNameNotFound;
|
||||||
Server_Card *targetCard = 0;
|
Server_Card *targetCard = 0;
|
||||||
if (!playerTarget) {
|
if (!playerTarget) {
|
||||||
targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
|
if (targetZone->getType() != PublicZone)
|
||||||
if ((startZone->getType() != PublicZone) || (targetZone->getType() != PublicZone))
|
|
||||||
return RespContextError;
|
return RespContextError;
|
||||||
|
targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server_ArrowTarget *targetItem;
|
Server_ArrowTarget *targetItem;
|
||||||
|
|
Loading…
Reference in a new issue