made counters look nicer
This commit is contained in:
parent
5d40996c0b
commit
ae82996c0e
9 changed files with 59 additions and 51 deletions
|
@ -16,5 +16,5 @@ QT += network svg
|
||||||
#QTPLUGIN += qjpeg
|
#QTPLUGIN += qjpeg
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h src/dlg_editmessages.h
|
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h src/dlg_editmessages.h src/abstractgraphicsitem.h
|
||||||
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp src/dlg_editmessages.cpp
|
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp src/dlg_editmessages.cpp src/abstractgraphicsitem.cpp
|
||||||
|
|
33
cockatrice/src/abstractgraphicsitem.cpp
Normal file
33
cockatrice/src/abstractgraphicsitem.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include "abstractgraphicsitem.h"
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
void AbstractGraphicsItem::paintNumberEllipse(int number, QPainter *painter)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
QString numStr = QString::number(number);
|
||||||
|
QFont font("Times");
|
||||||
|
font.setPixelSize(32);
|
||||||
|
font.setWeight(QFont::Bold);
|
||||||
|
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
double w = fm.width(numStr) * 1.5;
|
||||||
|
double h = fm.height() * 1.5;
|
||||||
|
if (w < h)
|
||||||
|
w = h;
|
||||||
|
|
||||||
|
painter->setPen(QColor(255, 255, 255, 0));
|
||||||
|
QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
|
||||||
|
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
|
||||||
|
grad.setColorAt(0, QColor(255, 255, 255, 200));
|
||||||
|
grad.setColorAt(0.7, QColor(255, 255, 255, 200));
|
||||||
|
grad.setColorAt(1, QColor(255, 255, 255, 0));
|
||||||
|
painter->setBrush(QBrush(grad));
|
||||||
|
painter->drawEllipse(QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h));
|
||||||
|
|
||||||
|
painter->setPen(Qt::black);
|
||||||
|
painter->setFont(font);
|
||||||
|
painter->drawText(boundingRect(), Qt::AlignCenter, numStr);
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
13
cockatrice/src/abstractgraphicsitem.h
Normal file
13
cockatrice/src/abstractgraphicsitem.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef ABSTRACTGRAPHICSITEM_H
|
||||||
|
#define ABSTRACTGRAPHICSITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
|
class AbstractGraphicsItem : public QGraphicsItem {
|
||||||
|
protected:
|
||||||
|
void paintNumberEllipse(int number, QPainter *painter);
|
||||||
|
public:
|
||||||
|
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -8,7 +8,7 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent)
|
CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent), db(_db), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
: AbstractGraphicsItem(parent), db(_db), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
setFlag(ItemIsSelectable);
|
setFlag(ItemIsSelectable);
|
||||||
|
@ -61,23 +61,9 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||||
}
|
}
|
||||||
if (counters) {
|
if (counters)
|
||||||
QString numStr = QString::number(counters);
|
paintNumberEllipse(counters, painter);
|
||||||
QFont font("Times", 32, QFont::Bold);
|
|
||||||
QFontMetrics fm(font);
|
|
||||||
QRect br = fm.boundingRect(numStr);
|
|
||||||
double w = br.width() * 1.42;
|
|
||||||
double h = br.height() * 1.42;
|
|
||||||
if (w < h)
|
|
||||||
w = h;
|
|
||||||
|
|
||||||
painter->setPen(Qt::black);
|
|
||||||
painter->setBrush(QColor(255, 255, 255, 150));
|
|
||||||
painter->drawEllipse(QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h));
|
|
||||||
|
|
||||||
painter->setFont(font);
|
|
||||||
painter->drawText(boundingRect(), Qt::AlignCenter, numStr);
|
|
||||||
}
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
#ifndef CARDITEM_H
|
#ifndef CARDITEM_H
|
||||||
#define CARDITEM_H
|
#define CARDITEM_H
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include "abstractgraphicsitem.h"
|
||||||
|
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class CardDragItem;
|
class CardDragItem;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
|
|
||||||
|
|
||||||
const int CARD_WIDTH = 72;
|
const int CARD_WIDTH = 72;
|
||||||
const int CARD_HEIGHT = 102;
|
const int CARD_HEIGHT = 102;
|
||||||
const int RASTER_WIDTH = 36;
|
const int RASTER_WIDTH = 36;
|
||||||
|
@ -22,7 +21,7 @@ enum CardItemType {
|
||||||
typeOther = QGraphicsItem::UserType + 4
|
typeOther = QGraphicsItem::UserType + 4
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardItem : public QGraphicsItem {
|
class CardItem : public AbstractGraphicsItem {
|
||||||
private:
|
private:
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
QString name;
|
QString name;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
|
|
||||||
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, QGraphicsItem *parent, bool isView)
|
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, QGraphicsItem *parent, bool isView)
|
||||||
: QGraphicsItem(parent), player(_p), name(_name), cards(NULL), view(NULL), menu(NULL), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
|
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(NULL), view(NULL), menu(NULL), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
|
||||||
{
|
{
|
||||||
if (!isView)
|
if (!isView)
|
||||||
player->addZone(this);
|
player->addZone(this);
|
||||||
|
@ -109,26 +109,3 @@ void CardZone::moveAllToZone(const QString &targetZone, int targetX)
|
||||||
for (int i = cards->size() - 1; i >= 0; i--)
|
for (int i = cards->size() - 1; i >= 0; i--)
|
||||||
player->client->moveCard(cards->at(i)->getId(), getName(), targetZone, targetX);
|
player->client->moveCard(cards->at(i)->getId(), getName(), targetZone, targetX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardZone::paintCardNumberEllipse(QPainter *painter)
|
|
||||||
{
|
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QString numStr = QString::number(cards->size());
|
|
||||||
QFont font("Times", 32, QFont::Bold);
|
|
||||||
QFontMetrics fm(font);
|
|
||||||
QRect br = fm.boundingRect(numStr);
|
|
||||||
double w = br.width() * 1.42;
|
|
||||||
double h = br.height() * 1.42;
|
|
||||||
if (w < h)
|
|
||||||
w = h;
|
|
||||||
|
|
||||||
painter->setPen(QPen(QColor("black")));
|
|
||||||
painter->setBrush(QColor(255, 255, 255, 150));
|
|
||||||
painter->drawEllipse(QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h));
|
|
||||||
|
|
||||||
painter->setFont(font);
|
|
||||||
painter->drawText(boundingRect(), Qt::AlignCenter, numStr);
|
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "cardlist.h"
|
#include "cardlist.h"
|
||||||
|
#include "abstractgraphicsitem.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
class ZoneViewZone;
|
class ZoneViewZone;
|
||||||
|
@ -10,7 +11,7 @@ class QMenu;
|
||||||
class QAction;
|
class QAction;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
|
|
||||||
class CardZone : public QGraphicsItem {
|
class CardZone : public AbstractGraphicsItem {
|
||||||
protected:
|
protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -23,7 +24,6 @@ protected:
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void addCardImpl(CardItem *card, int x, int y) = 0;
|
virtual void addCardImpl(CardItem *card, int x, int y) = 0;
|
||||||
void paintCardNumberEllipse(QPainter *painter);
|
|
||||||
public:
|
public:
|
||||||
enum { Type = typeZone };
|
enum { Type = typeZone };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
|
|
|
@ -29,7 +29,7 @@ void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
||||||
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
paintCardNumberEllipse(painter);
|
paintNumberEllipse(cards->size(), painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
|
|
|
@ -26,7 +26,7 @@ void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
paintCardNumberEllipse(painter);
|
paintNumberEllipse(cards->size(), painter);
|
||||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue