mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
improved counters
This commit is contained in:
parent
939ab62273
commit
3388804e8f
18 changed files with 158 additions and 80 deletions
|
|
@ -6,12 +6,13 @@
|
|||
#include "gravezone.h"
|
||||
#include "rfgzone.h"
|
||||
#include "sideboardzone.h"
|
||||
#include "counter.h"
|
||||
#include <QPainter>
|
||||
|
||||
PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), player(_player)
|
||||
{
|
||||
QPointF base = QPointF(20, 50);
|
||||
QPointF base = QPointF(55, 50);
|
||||
|
||||
LibraryZone *deck = new LibraryZone(_player, this);
|
||||
deck->setPos(base);
|
||||
|
|
@ -27,7 +28,7 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
|||
SideboardZone *sb = new SideboardZone(_player, this);
|
||||
sb->setVisible(false);
|
||||
|
||||
base = QPointF(deck->boundingRect().width() + 40, 0);
|
||||
base = QPointF(deck->boundingRect().width() + 60, 0);
|
||||
|
||||
CardZone *hand = new HandZone(_player, this);
|
||||
hand->setPos(base);
|
||||
|
|
@ -42,7 +43,7 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
|||
|
||||
PlayerArea::~PlayerArea()
|
||||
{
|
||||
|
||||
clearCounters();
|
||||
}
|
||||
|
||||
QRectF PlayerArea::boundingRect() const
|
||||
|
|
@ -58,7 +59,51 @@ void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||
|
||||
painter->setFont(QFont("Times", 16, QFont::Bold));
|
||||
painter->setPen(QPen(QColor("black")));
|
||||
painter->drawText(QRectF(0, 0, CARD_WIDTH + 40, 40), Qt::AlignCenter, player->getName());
|
||||
painter->drawText(QRectF(0, 0, CARD_WIDTH + 60, 40), Qt::AlignCenter, player->getName());
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
Counter *PlayerArea::getCounter(const QString &name, bool remove)
|
||||
{
|
||||
for (int i = 0; i < counterList.size(); i++) {
|
||||
Counter *temp = counterList.at(i);
|
||||
if (temp->getName() == name) {
|
||||
if (remove)
|
||||
counterList.removeAt(i);
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PlayerArea::addCounter(const QString &name, QColor color, int value)
|
||||
{
|
||||
counterList.append(new Counter(player, name, color, value, this));
|
||||
rearrangeCounters();
|
||||
}
|
||||
|
||||
void PlayerArea::delCounter(const QString &name)
|
||||
{
|
||||
delete getCounter(name, true);
|
||||
rearrangeCounters();
|
||||
}
|
||||
|
||||
void PlayerArea::clearCounters()
|
||||
{
|
||||
for (int i = 0; i < counterList.size(); i++)
|
||||
delete counterList.at(i);
|
||||
counterList.clear();
|
||||
}
|
||||
|
||||
void PlayerArea::rearrangeCounters()
|
||||
{
|
||||
const int counterAreaWidth = 55;
|
||||
int y = 50;
|
||||
for (int i = 0; i < counterList.size(); i++) {
|
||||
Counter *temp = counterList.at(i);
|
||||
QRectF br = temp->boundingRect();
|
||||
temp->setPos((counterAreaWidth - br.width()) / 2, y);
|
||||
y += br.height() + 10;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue