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()
|
||||
{
|
||||
qDebug(QString("AbstractCardItem destructor: %1").arg(name).toLatin1());
|
||||
qDebug() << "AbstractCardItem destructor:" << name;
|
||||
}
|
||||
|
||||
QRectF AbstractCardItem::boundingRect() const
|
||||
|
@ -61,9 +61,11 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
|||
|
||||
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
|
||||
} else {
|
||||
QFont f("Times");
|
||||
f.setStyleHint(QFont::Serif);
|
||||
f.setPixelSize(12);
|
||||
QFont f;
|
||||
int fontSize = h / 6;
|
||||
if (fontSize < 9)
|
||||
fontSize = 9;
|
||||
f.setPixelSize(fontSize);
|
||||
painter->setFont(f);
|
||||
QString colorStr;
|
||||
if (!color.isEmpty())
|
||||
|
@ -103,7 +105,17 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
|||
painter->setPen(pen);
|
||||
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
||||
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();
|
||||
|
||||
|
|
|
@ -25,31 +25,6 @@ DeckListModel::~DeckListModel()
|
|||
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()
|
||||
{
|
||||
root->clearTree();
|
||||
|
|
|
@ -52,8 +52,6 @@ private:
|
|||
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
||||
void emitRecursiveUpdates(const QModelIndex &index);
|
||||
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);
|
||||
|
||||
|
|
|
@ -29,11 +29,10 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
|
|||
connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap()));
|
||||
updateBgPixmap();
|
||||
|
||||
// playerTarget = new PlayerTarget(CARD_WIDTH + counterAreaWidth + 5, 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);
|
||||
deck->setPos(base);
|
||||
|
@ -1049,7 +1048,7 @@ void Player::clearArrows()
|
|||
|
||||
void Player::rearrangeCounters()
|
||||
{
|
||||
qreal marginTop = 50;
|
||||
qreal marginTop = 15;
|
||||
qreal marginBottom = 15;
|
||||
|
||||
// Determine total height of bounding rectangles
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
#include "playertarget.h"
|
||||
#include "player.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include <QDebug>
|
||||
|
||||
PlayerTarget::PlayerTarget(Player *_owner)
|
||||
: ArrowTarget(_owner, _owner)
|
||||
{
|
||||
font = QFont("Times");
|
||||
font.setStyleHint(QFont::Serif);
|
||||
font.setPixelSize(20);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
if (!fullPixmap.loadFromData(_owner->getUserInfo()->getAvatarBmp()))
|
||||
fullPixmap = QPixmap();
|
||||
}
|
||||
|
||||
QRectF PlayerTarget::boundingRect() const
|
||||
|
@ -19,8 +23,39 @@ QRectF PlayerTarget::boundingRect() const
|
|||
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
ServerInfo_User *info = owner->getUserInfo();
|
||||
painter->fillRect(boundingRect(), QColor(255, 255, 255, 100));
|
||||
|
||||
painter->save();
|
||||
QRectF translatedRect = painter->combinedTransform().mapRect(boundingRect());
|
||||
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->setPen(Qt::black);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, info->getName());
|
||||
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 <QFont>
|
||||
#include <QPixmap>
|
||||
|
||||
class Player;
|
||||
|
||||
class PlayerTarget : public ArrowTarget {
|
||||
private:
|
||||
QFont font;
|
||||
QPixmap fullPixmap;
|
||||
public:
|
||||
enum { Type = typePlayerTarget };
|
||||
int type() const { return Type; }
|
||||
|
|
|
@ -844,14 +844,16 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co
|
|||
targetZone = targetPlayer->getZones().value(cmd->getTargetZone());
|
||||
if (!startZone || (!targetZone && !playerTarget))
|
||||
return RespNameNotFound;
|
||||
if (startZone->getType() != PublicZone)
|
||||
return RespContextError;
|
||||
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
|
||||
if (!startCard)
|
||||
return RespNameNotFound;
|
||||
Server_Card *targetCard = 0;
|
||||
if (!playerTarget) {
|
||||
targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
|
||||
if ((startZone->getType() != PublicZone) || (targetZone->getType() != PublicZone))
|
||||
if (targetZone->getType() != PublicZone)
|
||||
return RespContextError;
|
||||
targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
|
||||
}
|
||||
|
||||
Server_ArrowTarget *targetItem;
|
||||
|
|
Loading…
Reference in a new issue