fixed few critical bugs
This commit is contained in:
131
ad_graphics.cpp
131
ad_graphics.cpp
@@ -6,65 +6,65 @@
|
||||
|
||||
AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(parent)
|
||||
{
|
||||
data = adcore->addata;
|
||||
core = adcore;
|
||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
scene = new QGraphicsScene();
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
core->setScene(scene);
|
||||
setScene(scene);
|
||||
//setCacheMode();
|
||||
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
mapimg = new QImage(data->map->rect().size()*cellSize,QImage::Format_ARGB32);
|
||||
//setDragMode(RubberBandDrag);
|
||||
QPainter p(mapimg);
|
||||
for (int i=0; i<data->map->cells().size(); i++) {
|
||||
for (int j=0; j<data->map->cells().at(i).size(); j++) {
|
||||
QPen pen;
|
||||
QBrush brush;
|
||||
pen.setColor(Qt::white);
|
||||
brush.setColor(Qt::white);
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
int cel = data->map->cells().at(i).at(j);
|
||||
if (cel == Map::Wall)
|
||||
{
|
||||
pen.setColor(Qt::black);
|
||||
brush.setColor(Qt::black);
|
||||
}
|
||||
if (cel >= Map::Free || (cel <= Map::PlayerTower && cel !=Map::Wall))
|
||||
{
|
||||
pen.setColor(QColor(qAbs(cel+2)*345%255,(qAbs(cel+2)*721)%255,(qAbs(cel+2)*75)%255,150));
|
||||
brush.setColor(QColor(qAbs(cel+2)*345%255,(qAbs(cel+2)*721)%255,(qAbs(cel+2)*75)%255,80));
|
||||
}
|
||||
p.setPen(pen);
|
||||
p.setBrush(brush);
|
||||
p.drawRect(i*cellSize,j*cellSize,cellSize,cellSize);
|
||||
}
|
||||
}
|
||||
p.end();
|
||||
scene->setSceneRect(mapimg->rect());
|
||||
data = adcore->addata;
|
||||
core = adcore;
|
||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
scene = new QGraphicsScene();
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
core->setScene(scene);
|
||||
setScene(scene);
|
||||
//setCacheMode();
|
||||
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
mapimg = new QImage(data->map->rect().size()*cellSize,QImage::Format_ARGB32);
|
||||
//setDragMode(RubberBandDrag);
|
||||
QPainter p(mapimg);
|
||||
for (int i=0; i<data->map->cells().size(); i++) {
|
||||
for (int j=0; j<data->map->cells().at(i).size(); j++) {
|
||||
QPen pen;
|
||||
QBrush brush;
|
||||
pen.setColor(Qt::white);
|
||||
brush.setColor(Qt::white);
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
int cel = data->map->cells().at(i).at(j);
|
||||
if (cel == Map::Wall)
|
||||
{
|
||||
pen.setColor(Qt::black);
|
||||
brush.setColor(Qt::black);
|
||||
}
|
||||
if (cel >= Map::Free || (cel <= Map::PlayerTower && cel !=Map::Wall))
|
||||
{
|
||||
pen.setColor(QColor(qAbs(cel+2)*345%255,(qAbs(cel+2)*721)%255,(qAbs(cel+2)*75)%255,150));
|
||||
brush.setColor(QColor(qAbs(cel+2)*345%255,(qAbs(cel+2)*721)%255,(qAbs(cel+2)*75)%255,80));
|
||||
}
|
||||
p.setPen(pen);
|
||||
p.setBrush(brush);
|
||||
p.drawRect(i*cellSize,j*cellSize,cellSize,cellSize);
|
||||
}
|
||||
}
|
||||
p.end();
|
||||
scene->setSceneRect(mapimg->rect());
|
||||
scene->setBackgroundBrush(*mapimg);
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
resize(mapimg->size());
|
||||
// startTimer(50);
|
||||
startTimer(50);
|
||||
}
|
||||
|
||||
|
||||
AD_Graphics::~AD_Graphics()
|
||||
{
|
||||
delete scene;
|
||||
delete scene;
|
||||
}
|
||||
|
||||
|
||||
void AD_Graphics::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
scene->clearSelection();
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
scene->clearSelection();
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
if (m_building) emit add_tow((QPointF(event->pos())/cellSize).toPoint());
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
QList<QGraphicsItem*> list = scene->items(event->pos(), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder);
|
||||
ADItem * al = 0;
|
||||
foreach(QGraphicsItem* x, list)
|
||||
@@ -87,17 +87,18 @@ void AD_Graphics::mousePressEvent(QMouseEvent *event)
|
||||
emit alien_select(al->id());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event->button() == Qt::RightButton)
|
||||
emit cancel();
|
||||
}
|
||||
}
|
||||
if (event->button() == Qt::RightButton)
|
||||
emit cancel();
|
||||
}
|
||||
|
||||
|
||||
//void AD_Graphics::timerEvent(QTimerEvent * )
|
||||
//{
|
||||
// scene->update();
|
||||
//}
|
||||
void AD_Graphics::timerEvent(QTimerEvent * )
|
||||
{
|
||||
if (!core->isWaveEnd())
|
||||
scene->update();
|
||||
}
|
||||
|
||||
|
||||
void AD_Graphics::drawBackground(QPainter * p, const QRectF & )
|
||||
@@ -108,16 +109,16 @@ void AD_Graphics::drawBackground(QPainter * p, const QRectF & )
|
||||
|
||||
void AD_Graphics::drawForeground(QPainter *p, const QRectF &rect)
|
||||
{
|
||||
QList <QGraphicsItem *> l = scene->items();
|
||||
foreach(QGraphicsItem * g,l)
|
||||
{
|
||||
ADItem * i = qgraphicsitem_cast<ADItem *>(g);
|
||||
if (i->isBarVisible())
|
||||
{
|
||||
p->setPen(Qt::black);
|
||||
p->setBrush(QBrush(QColor(qRound(255*(1-i->value())),qRound(255*i->value()),0)));
|
||||
p->drawRect(i->pos().x()-cellSize,i->pos().y()-cellSize*1.25,cellSize*2*i->value(),cellSize/4);
|
||||
}
|
||||
}
|
||||
QList <QGraphicsItem *> l = scene->items();
|
||||
foreach(QGraphicsItem * g,l)
|
||||
{
|
||||
ADItem * i = qgraphicsitem_cast<ADItem *>(g);
|
||||
if (i->isBarVisible())
|
||||
{
|
||||
p->setPen(Qt::black);
|
||||
p->setBrush(QBrush(QColor(qRound(255*(1-i->value())),qRound(255*i->value()),0)));
|
||||
p->drawRect(i->pos().x()-cellSize,i->pos().y()-cellSize*1.25,cellSize*2*i->value(),cellSize/4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user