added morphs, fix some bugs, new images
added onAlienInRadius trigger but it not work right((
This commit is contained in:
@@ -4,16 +4,24 @@
|
||||
|
||||
|
||||
|
||||
AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(parent)
|
||||
AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(parent) , color_curve(QEasingCurve::InQuad)
|
||||
{
|
||||
focus_item = select_tow = select_al = 0;
|
||||
data = adcore->addata;
|
||||
core = adcore;
|
||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
setMouseTracking(true);
|
||||
scene = new QGraphicsScene();
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
core->setScene(scene);
|
||||
setScene(scene);
|
||||
selection_al = new ADItem(-1, ADItem::Other, core->addata->alienSelect.images);
|
||||
selection_al->hide();
|
||||
selection_tow = new ADItem(-1, ADItem::Other, core->addata->towerSelect.images);
|
||||
selection_tow->hide();
|
||||
scene->addItem(selection_al);
|
||||
scene->addItem(selection_tow);
|
||||
//setCacheMode();
|
||||
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
mapimg = new QImage(data->map->rect().size()*cellSize,QImage::Format_ARGB32);
|
||||
@@ -46,6 +54,7 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(paren
|
||||
scene->setSceneRect(mapimg->rect());
|
||||
scene->setBackgroundBrush(*mapimg);
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
setRenderHints(QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
||||
resize(mapimg->size());
|
||||
startTimer(50);
|
||||
}
|
||||
@@ -53,13 +62,15 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(paren
|
||||
|
||||
AD_Graphics::~AD_Graphics()
|
||||
{
|
||||
delete selection_tow;
|
||||
delete selection_al;
|
||||
delete scene;
|
||||
}
|
||||
|
||||
|
||||
void AD_Graphics::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
scene->clearSelection();
|
||||
// scene->clearSelection();
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
if (m_building) emit add_tow((QPointF(event->pos())/cellSize).toPoint());
|
||||
@@ -72,8 +83,9 @@ void AD_Graphics::mousePressEvent(QMouseEvent *event)
|
||||
ADItem * i = qgraphicsitem_cast<ADItem*>(x);
|
||||
if (i->itemType() == ADItem::Tower)
|
||||
{
|
||||
i->setSelected(true);
|
||||
emit tower_select(i->tid());
|
||||
// i->setSelected(true);
|
||||
select_tow = i;
|
||||
emit selected_tower_changed(i->tid());
|
||||
return;
|
||||
}
|
||||
if (i->itemType() == ADItem::Alien)
|
||||
@@ -83,19 +95,37 @@ void AD_Graphics::mousePressEvent(QMouseEvent *event)
|
||||
}
|
||||
if (al != 0)
|
||||
{
|
||||
al->setSelected(true);
|
||||
emit alien_select(al->id());
|
||||
// al->setSelected(true);
|
||||
select_al = al;
|
||||
core->addata->players.at(0)->selectAlienId = select_al->id();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event->button() == Qt::RightButton)
|
||||
{
|
||||
select_al = 0;
|
||||
select_tow = 0;
|
||||
emit selected_tower_changed(QPoint());
|
||||
emit cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AD_Graphics::timerEvent(QTimerEvent * )
|
||||
{
|
||||
if (select_al != 0)
|
||||
{
|
||||
selection_al->setPos(select_al->pos());
|
||||
selection_al->show();
|
||||
} else selection_al->hide();
|
||||
if (select_tow != 0)
|
||||
{
|
||||
selection_tow->setPos(select_tow->pos());
|
||||
selection_tow->show();
|
||||
} else selection_tow->hide();
|
||||
selection_tow->next();
|
||||
selection_al->next();
|
||||
if (!core->isWaveEnd())
|
||||
scene->update();
|
||||
}
|
||||
@@ -116,9 +146,38 @@ void AD_Graphics::drawForeground(QPainter *p, const QRectF &rect)
|
||||
if (i->isBarVisible())
|
||||
{
|
||||
p->setPen(Qt::black);
|
||||
p->setBrush(QBrush(QColor(qRound(255*(1-i->value())),qRound(255*i->value()),0)));
|
||||
p->setBrush(Qt::NoBrush);
|
||||
p->drawRect(i->pos().x()-cellSize-1,i->pos().y()-cellSize*1.25-1,cellSize*2+2,cellSize/4+2);
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(QBrush(QColor::fromHsv(120*color_curve.valueForProgress(i->value()),230,230)));
|
||||
p->drawRect(i->pos().x()-cellSize,i->pos().y()-cellSize*1.25,cellSize*2*i->value(),cellSize/4);
|
||||
}
|
||||
}
|
||||
if (focus_item != 0)
|
||||
{
|
||||
if (focus_item->itemType() == ADItem::Tower)
|
||||
{
|
||||
float r = core->addata->curTowers[focus_item->tid()].src->radius*cellSize;
|
||||
p->setPen(Qt::black);
|
||||
p->setBrush(Qt::NoBrush);
|
||||
p->drawEllipse(focus_item->pos(), r, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AD_Graphics::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QList<QGraphicsItem * > li = scene->items(event->pos(), Qt::IntersectsItemBoundingRect, Qt::DescendingOrder);
|
||||
foreach (QGraphicsItem * i, li) {
|
||||
if (qgraphicsitem_cast<ADItem *>(i)->itemType() == ADItem::Tower) {
|
||||
focus_item = qgraphicsitem_cast<ADItem *>(i);
|
||||
// selection_tow->setPos(focus_item->pos());
|
||||
// selection_tow->show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// selection_tow->hide();
|
||||
focus_item = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user