diff --git a/ADeditor/ADeditor.pro b/ADeditor/ADeditor.pro index 5ae4fd5..3359d6b 100644 --- a/ADeditor/ADeditor.pro +++ b/ADeditor/ADeditor.pro @@ -15,7 +15,8 @@ SOURCES += main.cpp \ ../player.cpp \ ../game_data.cpp \ triggermodel.cpp \ - mapmodel.cpp + mapmodel.cpp \ + animationmodel.cpp HEADERS += mainwindow.h \ ../loader.h \ alienmodel.h \ @@ -26,7 +27,8 @@ HEADERS += mainwindow.h \ ../player.h \ ../game_data.h \ triggermodel.h \ - mapmodel.h + mapmodel.h \ + animationmodel.h FORMS += mainwindow.ui TRANSLATIONS += adeditor_ru.ts RESOURCES += ADeditor.qrc diff --git a/ADeditor/alienmodel.h b/ADeditor/alienmodel.h index 5630686..be63ae5 100644 --- a/ADeditor/alienmodel.h +++ b/ADeditor/alienmodel.h @@ -6,18 +6,18 @@ class AlienModel : public QAbstractListModel { -Q_OBJECT + Q_OBJECT public: - explicit AlienModel(QList aliens, QObject *parent = 0); + explicit AlienModel(QList aliens, QObject *parent = 0); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; - void refresh(QList aliens); + void refresh(QList aliens); signals: public slots: private: - QList aliens; + QList aliens; }; #endif // ALIENMODEL_H diff --git a/ADeditor/animationmodel.cpp b/ADeditor/animationmodel.cpp new file mode 100644 index 0000000..c07339a --- /dev/null +++ b/ADeditor/animationmodel.cpp @@ -0,0 +1,35 @@ +#include "animationmodel.h" + +AnimationModel::AnimationModel(QList manims, QObject *parent) : + QAbstractListModel(parent) +{ + anims = manims; +} + + +void AnimationModel::refresh(QListmanims) +{ + anims = manims; +} + + +int AnimationModel::rowCount(const QModelIndex &) const +{ + return anims.count(); +} + + +QVariant AnimationModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= anims.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + { + return anims.at(index.row()).id; + } + return QVariant(); +} diff --git a/ADeditor/animationmodel.h b/ADeditor/animationmodel.h new file mode 100644 index 0000000..24bf755 --- /dev/null +++ b/ADeditor/animationmodel.h @@ -0,0 +1,24 @@ +#ifndef ANIMATIONMODEL_H +#define ANIMATIONMODEL_H + +#include +#include "../loader.h" + +class AnimationModel : public QAbstractListModel +{ +Q_OBJECT +public: + explicit AnimationModel(QList anims, QObject *parent = 0); + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + void refresh(QList anims); + +signals: + +public slots: + +private: + QList anims; +}; + +#endif // ANIMATIONMODEL_H diff --git a/ADeditor/mainwindow.cpp b/ADeditor/mainwindow.cpp index 68c9ffe..248bf94 100644 --- a/ADeditor/mainwindow.cpp +++ b/ADeditor/mainwindow.cpp @@ -2,7 +2,7 @@ #include "ui_mainwindow.h" #include - +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -26,6 +26,11 @@ MainWindow::MainWindow(QWidget *parent) : adloader = new Loader(this); adloader->load("data2.xml"); + animModel = new AnimationModel(adloader->animations.values()); + ui->lvAnimations->setModel((QAbstractItemModel * )animModel); + connect(ui->lvAnimations->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(lvAnimations_select(QModelIndex, QModelIndex))); + ui->lvAnimations->selectionModel()->setCurrentIndex(ui->lvAnimations->model()->index(0,0),QItemSelectionModel::ClearAndSelect); + mapScene = new QGraphicsScene(); ui->gvMap->setScene(mapScene); ui->gvMap->scale(10,10); @@ -105,159 +110,185 @@ void MainWindow::on_cbAlRegeneration_toggled(bool checked) } +void MainWindow::lvAnimations_select(QModelIndex index, QModelIndex) +{ + if (index.isValid()) + { + ui->lwImages->clear(); + refresh_lwImages(adloader->animations.values().at(index.row()).pathes); + } +} + + void MainWindow::lvAliens_select(QModelIndex index, QModelIndex) { - tbAlien al = adloader->aliens.values().at(index.row()); - ui->leAlName->setText(al.name); - ui->sbAlHealth->setValue(al.health); - ui->sbAlArmor->setValue(al.armor); - if (al.armor > 0) ui->cbAlArmor->setChecked(true); - else ui->cbAlArmor->setChecked(false); - ui->sbAlSpeed->setValue(al.speed); - ui->sbAlPrise->setValue(al.prise); - ui->sbAlregeneration->setValue(al.regeneration); - if (al.regeneration > 0) ui->cbAlRegeneration->setChecked(true); - else ui->cbAlRegeneration->setChecked(false); - ui->sbAlScore->setValue(al.score); - ui->cbAlIsFly->setChecked(al.isFlying); + if (index.isValid()) + { + tbAlien al = adloader->aliens.values().at(index.row()); + ui->leAlName->setText(al.name); + ui->sbAlHealth->setValue(al.health); + ui->sbAlArmor->setValue(al.armor); + if (al.armor > 0) ui->cbAlArmor->setChecked(true); + else ui->cbAlArmor->setChecked(false); + ui->sbAlSpeed->setValue(al.speed); + ui->sbAlPrise->setValue(al.prise); + ui->sbAlregeneration->setValue(al.regeneration); + if (al.regeneration > 0) ui->cbAlRegeneration->setChecked(true); + else ui->cbAlRegeneration->setChecked(false); + ui->sbAlScore->setValue(al.score); + ui->cbAlIsFly->setChecked(al.isFlying); + } } void MainWindow::lvMaps_select(QModelIndex index, QModelIndex) { - tbMap map = adloader->maps.values().at(index.row()); - ui->leMapName->setText(map.name); - ui->sbMapHei->setValue(map.size.height()); - ui->sbMapWid->setValue(map.size.width()); - ui->sbMapPlayers->setValue(map.maxPlayers); - Map m(map.data,map.size,map.name,map.maxPlayers,map.imgType); - QPixmap pix(map.size); - QPainter p(&pix); - p.fillRect(m.rect(),Qt::white); - for (int i=0; i= 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,200)); - p.setPen(pen); - p.drawPoint(i,j); + if (index.isValid()) + { + tbMap map = adloader->maps.values().at(index.row()); + ui->leMapName->setText(map.name); + ui->sbMapHei->setValue(map.size.height()); + ui->sbMapWid->setValue(map.size.width()); + ui->sbMapPlayers->setValue(map.maxPlayers); + Map m(map.data,map.size,map.name,map.maxPlayers,map.imgType); + QPixmap pix(map.size); + QPainter p(&pix); + p.fillRect(m.rect(),Qt::white); + for (int i=0; i= 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,200)); + p.setPen(pen); + p.drawPoint(i,j); + } } + p.end(); + mapScene->clear(); + mapScene->addPixmap(pix); + ui->gvMap->centerOn(0,0); + //ui->gvMap->resetCachedContent(); + ui->pbMapEdit->setIcon(QIcon(pix)); } - p.end(); - mapScene->clear(); - mapScene->addPixmap(pix); - ui->gvMap->centerOn(0,0); - //ui->gvMap->resetCachedContent(); - ui->pbMapEdit->setIcon(QIcon(pix)); } void MainWindow::lvTowers_select(QModelIndex index, QModelIndex) { - tbTower tw = adloader->towers.values().at(index.row()); - ui->sbTwBuildTime->setValue(tw.buildTime); - ui->sbTwCost->setValue(tw.cost); - ui->sbTwExpByDam->setValue(tw.expByDamage); - if (tw.expByDamage > 0) - ui->cbTwExpByDam->setChecked(true); - else - ui->cbTwExpByDam->setChecked(false); - ui->sbTwExpByKill->setValue(tw.expByKill); - if (tw.expByKill > 0) - ui->cbTwExpByKill->setChecked(true); - else - ui->cbTwExpByKill->setChecked(false); - ui->sbTwExpByShot->setValue(tw.expByShot); - if (tw.expByShot > 0) - ui->cbTwExpByShot->setChecked(true); - else - ui->cbTwExpByShot->setChecked(false); - ui->leTwName->setText(tw.name); - ui->sbTwRadius->setValue(tw.radius); - ui->sbTwReload->setValue(tw.reload); - ui->cbTwSplash->setCurrentIndex(adloader->splashes.keys().indexOf(tw.splashId)); + if (index.isValid()) + { + tbTower tw = adloader->towers.values().at(index.row()); + ui->sbTwBuildTime->setValue(tw.buildTime); + ui->sbTwCost->setValue(tw.cost); + ui->sbTwExpByDam->setValue(tw.expByDamage); + if (tw.expByDamage > 0) + ui->cbTwExpByDam->setChecked(true); + else + ui->cbTwExpByDam->setChecked(false); + ui->sbTwExpByKill->setValue(tw.expByKill); + if (tw.expByKill > 0) + ui->cbTwExpByKill->setChecked(true); + else + ui->cbTwExpByKill->setChecked(false); + ui->sbTwExpByShot->setValue(tw.expByShot); + if (tw.expByShot > 0) + ui->cbTwExpByShot->setChecked(true); + else + ui->cbTwExpByShot->setChecked(false); + ui->leTwName->setText(tw.name); + ui->sbTwRadius->setValue(tw.radius); + ui->sbTwReload->setValue(tw.reload); + ui->cbTwSplash->setCurrentIndex(adloader->splashes.keys().indexOf(tw.splashId)); + } } void MainWindow::lvSplashes_select(QModelIndex index, QModelIndex) { - tbSplash spl = adloader->splashes.values().at(index.row()); - ui->sbSplLifeTime->setValue(spl.lifetime); - ui->sbSplSpeed->setValue(spl.speed); - ui->cbSplAutoControl->setChecked(spl.autoControl); - ui->leSplName->setText(spl.name); + if (index.isValid()) + { + tbSplash spl = adloader->splashes.values().at(index.row()); + ui->sbSplLifeTime->setValue(spl.lifetime); + ui->sbSplSpeed->setValue(spl.speed); + ui->cbSplAutoControl->setChecked(spl.autoControl); + ui->leSplName->setText(spl.name); + } } void MainWindow::lvTriggers_select(QModelIndex index, QModelIndex) { - tbTrigger trig = adloader->triggers.values().at(index.row()); - ui->sbTrigCount->setValue(trig.count); - if (trig.count > 0) - ui->cbTrigCount->setChecked(true); - else - ui->cbTrigCount->setChecked(false); - ui->sbTrigDamage->setValue(trig.damage); - if (trig.damage > 0) - ui->cbTrigDamage->setChecked(true); - else - ui->cbTrigDamage->setChecked(false); - ui->sbTrigDamRadius->setValue(trig.radius); - if (trig.radius > 0) - ui->cbTrigDamRad->setChecked(true); - else - ui->cbTrigDamRad->setChecked(false); - ui->sbTrigChance->setValue(trig.chance); - if (trig.chance == 100) - ui->cbTrigChance->setChecked(false); - else - ui->cbTrigChance->setChecked(true); - ui->sbTrigRandomRadius->setValue(trig.randomPosRadius); - if (trig.randomPosRadius > 0) - ui->cbTrigRandRadius->setChecked(true); - else - ui->cbTrigRandRadius->setChecked(false); - ui->sbTrigTimer->setValue(trig.timer); - switch (trig.type) + if (index.isValid()) { - case srcTriggerType::onDestination : - ui->cbTrigType->setCurrentIndex(0); - break; - case srcTriggerType::onAlienInRadius : - ui->cbTrigType->setCurrentIndex(1); - break; - case srcTriggerType::onTimer : - ui->cbTrigType->setCurrentIndex(2); - break; + tbTrigger trig = adloader->triggers.values().at(index.row()); + ui->sbTrigCount->setValue(trig.count); + if (trig.count > 0) + ui->cbTrigCount->setChecked(true); + else + ui->cbTrigCount->setChecked(false); + ui->sbTrigDamage->setValue(trig.damage); + if (trig.damage > 0) + ui->cbTrigDamage->setChecked(true); + else + ui->cbTrigDamage->setChecked(false); + ui->sbTrigDamRadius->setValue(trig.radius); + if (trig.radius > 0) + ui->cbTrigDamRad->setChecked(true); + else + ui->cbTrigDamRad->setChecked(false); + ui->sbTrigChance->setValue(trig.chance); + if (trig.chance == 100) + ui->cbTrigChance->setChecked(false); + else + ui->cbTrigChance->setChecked(true); + ui->sbTrigRandomRadius->setValue(trig.randomPosRadius); + if (trig.randomPosRadius > 0) + ui->cbTrigRandRadius->setChecked(true); + else + ui->cbTrigRandRadius->setChecked(false); + + ui->sbTrigTimer->setValue(trig.timer); + switch (trig.type) + { + case srcTriggerType::onDestination : + ui->cbTrigType->setCurrentIndex(0); + break; + case srcTriggerType::onAlienInRadius : + ui->cbTrigType->setCurrentIndex(1); + break; + case srcTriggerType::onTimer : + ui->cbTrigType->setCurrentIndex(2); + break; + } + if (trig.type != srcTriggerType::onTimer) + { + ui->lbTrigTimer->setVisible(false); + ui->sbTrigTimer->setVisible(false); + } else { + ui->lbTrigTimer->setVisible(true); + ui->sbTrigTimer->setVisible(true); + } + switch (trig.childAim) + { + case srcTriggerType::noAim : + ui->cbTrigChildAim->setCurrentIndex(0); + break; + case srcTriggerType::allSide : + ui->cbTrigChildAim->setCurrentIndex(1); + break; + case srcTriggerType::parentAim : + ui->cbTrigChildAim->setCurrentIndex(2); + break; + case srcTriggerType::nearlestAlien : + ui->cbTrigChildAim->setCurrentIndex(3); + break; + } + ui->leTrigName->setText(trig.name); } - if (trig.type != srcTriggerType::onTimer) - { - ui->lbTrigTimer->setVisible(false); - ui->sbTrigTimer->setVisible(false); - } else { - ui->lbTrigTimer->setVisible(true); - ui->sbTrigTimer->setVisible(true); - } - switch (trig.childAim) - { - case srcTriggerType::noAim : - ui->cbTrigChildAim->setCurrentIndex(0); - break; - case srcTriggerType::allSide : - ui->cbTrigChildAim->setCurrentIndex(1); - break; - case srcTriggerType::parentAim : - ui->cbTrigChildAim->setCurrentIndex(2); - break; - case srcTriggerType::nearlestAlien : - ui->cbTrigChildAim->setCurrentIndex(3); - break; - } - ui->leTrigName->setText(trig.name); } @@ -906,6 +937,7 @@ void MainWindow::on_cbTrigType_currentIndexChanged(int index) } else { ui->lbTrigTimer->setVisible(true); ui->sbTrigTimer->setVisible(true); + ui->sbTrigTimer->setValue(adloader->triggers[id].timer); } isSaved = false; } @@ -917,3 +949,37 @@ void MainWindow::on_cbTrigChildAim_currentIndexChanged(int index) adloader->triggers[id].childAim = (srcTriggerType::aimType)ui->cbTrigChildAim->itemData(index).toInt(); isSaved = false; } + + +void MainWindow::on_pbImgAdd_clicked() +{ + int id = adloader->animations.values().at(ui->lvAnimations->currentIndex().row()).id; + QFileDialog fd; + fd.setNameFilter(tr("Images (*.png)")); + fd.setFileMode(QFileDialog::ExistingFiles); + if (fd.exec()) + { + adloader->animations[id].pathes.append(fd.selectedFiles()); + refresh_lwImages(adloader->animations.value(id).pathes); + isSaved = false; + } +} + + +void MainWindow::refresh_lwImages(QStringList pathes) +{ + ui->lwImages->clear(); + for (int i=0; ilwImages->addItem(new QListWidgetItem(QIcon(pathes.at(i)),pathes.at(i))); + } +} + + +void MainWindow::on_pbImgDel_clicked() +{ + int id = adloader->animations.values().at(ui->lvAnimations->currentIndex().row()).id; + for (int i=0; ilwImages->selectedItems().size(); ++i) + adloader->animations[id].pathes.removeOne(ui->lwImages->selectedItems().at(i)->text()); + refresh_lwImages(adloader->animations.value(id).pathes); +} diff --git a/ADeditor/mainwindow.h b/ADeditor/mainwindow.h index 2afffac..fd6bdee 100644 --- a/ADeditor/mainwindow.h +++ b/ADeditor/mainwindow.h @@ -12,6 +12,7 @@ #include "splashmodel.h" #include "triggermodel.h" #include "mapmodel.h" +#include "animationmodel.h" namespace Ui { class MainWindow; @@ -34,13 +35,17 @@ private: SplashModel * splModel; TriggerModel* trigModel; MapModel * mapModel; + AnimationModel * animModel; QGraphicsScene * mapScene; bool isSaved; + void refresh_lwImages(QStringList pathes); void closeEvent(QCloseEvent *); private slots: - void on_cbTrigChildAim_currentIndexChanged(int index); + void on_pbImgDel_clicked(); + void on_pbImgAdd_clicked(); + void on_cbTrigChildAim_currentIndexChanged(int index); void on_cbTrigType_currentIndexChanged(int index); void on_cbTrigCount_toggled(bool checked); void on_leTrigName_editingFinished(); @@ -91,6 +96,7 @@ private slots: void on_sbAlHealth_valueChanged(double ); void on_pbSave_clicked(); void lvAliens_select(QModelIndex, QModelIndex); + void lvAnimations_select(QModelIndex, QModelIndex); void lvTowers_select(QModelIndex, QModelIndex); void lvSplashes_select(QModelIndex, QModelIndex); void lvTriggers_select(QModelIndex, QModelIndex); diff --git a/ADeditor/mainwindow.ui b/ADeditor/mainwindow.ui index 30b8fec..6ee205d 100644 --- a/ADeditor/mainwindow.ui +++ b/ADeditor/mainwindow.ui @@ -24,13 +24,6 @@ 2 - - - - Save - - - @@ -38,380 +31,396 @@ + + + + Save + + + - 4 + 5 Aliens - - - - - QAbstractItemView::AllEditTriggers + + + + + Qt::Horizontal + + + + + + QAbstractItemView::AllEditTriggers + + + + + + + 20 + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Delete + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + 0 + + + + Name + + + Qt::AlignCenter + + + + + + + + + + + + + + + 0 + 0 + + + + Health + + + Qt::AlignCenter + + + + + + + 1 + + + 0.000000000000000 + + + 999999999.000000000000000 + + + 10.000000000000000 + + + 99.000000000000000 + + + + + + + + + + + + 0 + 0 + + + + Armor + + + + + + + false + + + 999999999.000000000000000 + + + + + + + + + + + + 0 + 0 + + + + Regeneration + + + + + + + false + + + 1 + + + 999999999.000000000000000 + + + 5.000000000000000 + + + + + + + + + + + + 0 + 0 + + + + Speed + + + Qt::AlignCenter + + + + + + + + + + 5 + + + 0.000010000000000 + + + 99.000000000000000 + + + 0.010000000000000 + + + 0.010000000000000 + + + + + + + + + + + + 0 + 0 + + + + Prize + + + Qt::AlignCenter + + + + + + + 0 + + + 999999999 + + + + + + + + + + + + 0 + 0 + + + + Score + + + Qt::AlignCenter + + + + + + + 1 + + + 999999999 + + + + + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Is Flying + + + + + + + + + + + + 0 + 0 + + + + Image + + + Qt::AlignCenter + + + + + + + true + + + + 0 + 0 + + + + + 48 + 32 + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - 0 - 0 - - - - Name - - - Qt::AlignCenter - - - - - - - - - - - - - - - 0 - 0 - - - - Health - - - Qt::AlignCenter - - - - - - - 1 - - - 0.000000000000000 - - - 999999999.000000000000000 - - - 10.000000000000000 - - - 99.000000000000000 - - - - - - - - - - - - 0 - 0 - - - - Armor - - - - - - - false - - - 999999999.000000000000000 - - - - - - - - - - - - 0 - 0 - - - - Regeneration - - - - - - - false - - - 1 - - - 999999999.000000000000000 - - - 5.000000000000000 - - - - - - - - - - - - 0 - 0 - - - - Speed - - - Qt::AlignCenter - - - - - - - - - - 5 - - - 0.000010000000000 - - - 99.000000000000000 - - - 0.010000000000000 - - - 0.010000000000000 - - - - - - - - - - - - 0 - 0 - - - - Prize - - - Qt::AlignCenter - - - - - - - 0 - - - 999999999 - - - - - - - - - - - - 0 - 0 - - - - Score - - - Qt::AlignCenter - - - - - - - 1 - - - 999999999 - - - - - - - - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Is Flying - - - - - - - - - - - - 0 - 0 - - - - Image - - - Qt::AlignCenter - - - - - - - true - - - - 0 - 0 - - - - - 48 - 32 - - - - ... - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 20 - - - - - - 0 - 0 - - - - Add - - - - - - - - 0 - 0 - - - - Delete - - - - - @@ -1637,6 +1646,107 @@ + + + Animations + + + + + + Qt::Horizontal + + + + + + + + + + 20 + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Delete + + + + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::ExtendedSelection + + + + + + + 20 + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Delete + + + + + + + + + + + diff --git a/ad_graphics.cpp b/ad_graphics.cpp index 1d3cf10..ebaf762 100644 --- a/ad_graphics.cpp +++ b/ad_graphics.cpp @@ -4,7 +4,6 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(parent) { - loadImages(); data = adcore->addata; core = adcore; //scale(cellSize, cellSize); @@ -41,8 +40,8 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(paren // } 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,50)); - brush.setColor(QColor(qAbs(cel+2)*345%255,(qAbs(cel+2)*721)%255,(qAbs(cel+2)*75)%255,50)); + 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); @@ -50,7 +49,7 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(paren } } - startTimer(25); + startTimer(50); show(); } @@ -143,7 +142,7 @@ void AD_Graphics::drawBackground(QPainter * p, const QRectF & ) p->setBrush(brush); p->drawRect(-20,-20,40,40); } else { - p->drawImage(QRect(-20,-20,40,40), images[itTowers][(*i).imgType]->at(0)); + p->drawImage(QRect(-20,-20,40,40), *data->curAnimations.at((*i).imgType).images.at((*i).animIndex)); } p->resetTransform(); } @@ -158,7 +157,10 @@ void AD_Graphics::drawBackground(QPainter * p, const QRectF & ) //p->translate(-rec.height()/2, -rec.width()/2); p->translate((*i).pos * cellSize+QPointF(10,10)); p->rotate((*i).angle); - p->drawImage(QRect(-20,-20,40,40), images[itAliens][0]->at(0)); + p->drawImage(QRect(-20,-20,40,40), *data->curAnimations.at((*i).imgType).images.at((*i).animIndex)); + (*i).animIndex++; + if ((*i).animIndex >= data->curAnimations.at((*i).imgType).images.size()) + (*i).animIndex = 0; p->resetTransform(); } //qDebug() << "s:" << data->curSplashes.size(); @@ -178,7 +180,12 @@ void AD_Graphics::drawBackground(QPainter * p, const QRectF & ) //p->setBrush(brush); //p->setPen(QColor(0,0,0,0)); //p->drawEllipse(QPoint(),5,5); - p->drawImage(QPoint(-(images[itSplashes][(*i).imgType]->at(0).size().width()/2),-(images[itSplashes][(*i).imgType]->at(0).size().height()/2)), images[itSplashes][(*i).imgType]->at(0)); + QImage img; + img = *data->curAnimations.at((*i).imgType).images.at((*i).animIndex); + p->drawImage(QPoint(-(img.size().width()/2),-(img.size().height()/2)), img); + (*i).animIndex++; + if ((*i).animIndex >= data->curAnimations.at((*i).imgType).images.size()) + (*i).animIndex = 0; p->resetTransform(); } } @@ -190,25 +197,3 @@ void AD_Graphics::draw() //resetCachedContent(); //repaint(); } - - -void AD_Graphics::loadImages() -{ - images.resize(3); - for (int i = 0; i < images.size(); i++) { - switch ((imagesType)i) { - case itAliens: - images[i].push_back(new Animation(":/images/images/Aliens/Al_00_0.png")); - break; - case itTowers: - images[i].push_back(new Animation(":/images/images/Towers/01_6.png")); - images[i].push_back(new Animation(":/images/images/Towers/00_0.png")); - case itSplashes: - images[i].push_back(new Animation(":/images/images/Splashes/Rocket.png")); - images[i].push_back(new Animation(":/images/images/Splashes/Shot_0.png")); - images[i].push_back(new Animation(":/images/images/Splashes/Smoke_01.png")); - images[i].push_back(new Animation(":/images/images/Splashes/expl.png")); - default: break; - } - } -} diff --git a/ad_graphics.h b/ad_graphics.h index 3a84331..0a4189d 100644 --- a/ad_graphics.h +++ b/ad_graphics.h @@ -6,7 +6,6 @@ #include #include "adcore.h" -#include "animation.h" const float cellSize = 20.f; @@ -18,11 +17,8 @@ public: ~AD_Graphics(); private: - enum imagesType {itAliens, itTowers, itSplashes}; - void draw(); void drawBackground(QPainter * p, const QRectF &); - void loadImages(); void mouseDoubleClickEvent(QMouseEvent *); void mousePressEvent(QMouseEvent *event); @@ -30,7 +26,6 @@ private: Game_Data * data; AD_Core * core; QImage * mapimg; - QVector > images; //QGraphicsWidget * gsw; protected: diff --git a/aliendefender.pro b/aliendefender.pro index 9779b30..0442c8b 100644 --- a/aliendefender.pro +++ b/aliendefender.pro @@ -7,9 +7,7 @@ HEADERS += base_types.h \ adcore.h \ player.h \ loader.h \ - animation.h \ - ad_graphics.h \ - graphicsalien.h + ad_graphics.h SOURCES += map.cpp \ game_data.cpp \ aliens.cpp \ @@ -19,12 +17,9 @@ SOURCES += map.cpp \ adcore.cpp \ player.cpp \ loader.cpp \ - animation.cpp \ - ad_graphics.cpp \ - graphicsalien.cpp + ad_graphics.cpp RESOURCES += images.qrc -OTHER_FILES += data.xml \ - schema.xml \ +OTHER_FILES += schema.xml \ data2.xml QT += core \ gui \ diff --git a/aliens.cpp b/aliens.cpp index 29a4b0b..432263d 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -24,7 +24,7 @@ void Aliens::addAlien(int srcId) al.path = gameData->map->createPath(al.pos.toPoint(),al.finish); al.pathIndex = 1; al.angle = 180.0f*(- std::atan2( al.pos.x() - al.path.at(al.pathIndex).x(),al.pos.y() - al.path.at(al.pathIndex).y()))/M_PI; - al.animIndex = 0.f; + al.animIndex = 0; if (al.path.isEmpty()) { qCritical("ERROR create path"); diff --git a/animation.cpp b/animation.cpp deleted file mode 100644 index 8fc3ee3..0000000 --- a/animation.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "animation.h" -#include -#include - - -Animation::Animation(const QString & path) -{ -// int i = 0; -// QString s = path + QString::number(i) + ".png"; -// //qDebug() << "check " << s; -// while (QFile::exists(s)) { -// images.push_back(new QImage(s)); -// s = path + QString::number(++i) + ".png"; -// } -// qDebug() << "found " << images.size() << " images"; - if (QFile::exists(path)) - { - images.push_back(new QImage(path)); - } -} - - -Animation::~Animation() -{ - -} - diff --git a/animation.h b/animation.h deleted file mode 100644 index cef64f6..0000000 --- a/animation.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef ANIMATION_H -#define ANIMATION_H -#include -#include - -class Animation -{ -public: - explicit Animation(const QString & path); - ~Animation(); - - QImage & at(int index) const {return *(images[index]);}; - -private: - QVector images; - -}; - -#endif // ANIMATION_H diff --git a/base_types.h b/base_types.h index 8fcc000..8ecd101 100644 --- a/base_types.h +++ b/base_types.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include struct srcAlienType @@ -41,7 +43,7 @@ struct AlienType QVector path; int pathIndex; int imgType; - float animIndex; + int animIndex; }; @@ -108,6 +110,7 @@ struct SplashType { int id; int imgType; + int animIndex; int src; QPoint TowerId; // parent tower (-1;-1) for null parent int srcTower; @@ -147,6 +150,7 @@ struct TowerType int oldAim; int PlayerId; // tower's owner int imgType; + int animIndex; QPoint pos; // not QPointF because tower fixed on grid float angle; // -180 .. 180 unsigned int reload; // time for reload in ticks @@ -155,6 +159,12 @@ struct TowerType }; +struct AnimationType +{ + QList images; +}; + + struct WaveType { QList types; // some types of aliens (e.g. 2 fly and 3 grount in one wave) diff --git a/data.xml b/data.xml deleted file mode 100644 index 6283cd1..0000000 --- a/data.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/data2.xml b/data2.xml index 3aa66d7..b2a2956 100644 --- a/data2.xml +++ b/data2.xml @@ -1,15 +1,15 @@ - - + + - - + + @@ -25,17 +25,25 @@ - + + + + + + + + + @@ -65,22 +73,22 @@ - - - - - - + + + + + + - - - + + + - + @@ -94,4 +102,13 @@ + + + + + + + + + diff --git a/game_data.h b/game_data.h index 94a675b..9fcd96d 100644 --- a/game_data.h +++ b/game_data.h @@ -18,6 +18,7 @@ public: QHash curTowers; QList waves; QList players; + QList curAnimations; Map * map; int curWave; int missingAliens; diff --git a/graphicsalien.cpp b/graphicsalien.cpp deleted file mode 100644 index aa36339..0000000 --- a/graphicsalien.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "graphicsalien.h" - -GraphicsAlien::GraphicsAlien(QGraphicsItem *grItem) : QGraphicsItem(grItem) -{ - -} - - -QRectF GraphicsAlien::boundingRect() -{ - return QRectF(0,0,10,10); -} - - -void GraphicsAlien::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - -} diff --git a/graphicsalien.h b/graphicsalien.h deleted file mode 100644 index 84c9efe..0000000 --- a/graphicsalien.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GRAPHICSALIEN_H -#define GRAPHICSALIEN_H - -#include - -class GraphicsAlien : public QGraphicsItem -{ -public: - GraphicsAlien(QGraphicsItem * grItem= 0); - QRectF boundingRect(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); -}; - -#endif // GRAPHICSALIEN_H diff --git a/loader.cpp b/loader.cpp index 01297d5..6ef6df3 100644 --- a/loader.cpp +++ b/loader.cpp @@ -21,6 +21,7 @@ void Loader::load(QString filename) file->close(); qFatal("Error parsing data.xml"); } + readAnimations(); readAliens(); readMaps(); readLevels(); @@ -206,6 +207,7 @@ void Loader::save(QString filename) { case srcTriggerType::onTimer : elem.setAttribute("type","onTimer"); + elem.setAttribute("timer",trig.timer); break; case srcTriggerType::onDestination : elem.setAttribute("type","onDestination"); @@ -238,6 +240,16 @@ void Loader::save(QString filename) elem.setAttribute("level",tol.levelId); elem.setAttribute("tower",tol.towerId); } + child = data.createElement("animations"); + root.appendChild(child); + for (int i=0; i wplist; QList alienIds; + QList animIds; for (int i=0; imaxPlayers(); ++k) gd->players[k]->srcTowers.append(stt); qDebug() << tr("Tower %1 trig=%2 splash=%3").arg(stt.name).arg(stt.triggers.size()).arg(stt.splashes.size()) << tr("chain lenght %1").arg(recursiveCheck); } + for (int i=0; icurAnimations.append(anim); + } return gd; } -void Loader::fillTowerChains(QList * chlist, QList * trigIds, srcTowerType * stt, int parId, int parIndex, int * recursiveCheck) +void Loader::fillTowerChains(QList * animIds, QList * chlist, + QList * trigIds, srcTowerType * stt, + int parId, int parIndex, int * recursiveCheck) { if (*recursiveCheck > 100) { @@ -385,14 +415,16 @@ void Loader::fillTowerChains(QList * chlist, QList * trigIds, sr tbSplash tbs = splashes.value(chlist->at(i).childSplashId); srcSplashType sst; sst.autoControl = tbs.autoControl; - sst.imgType = tbs.imgType; + if (!animIds->contains(tbs.imgType)) + animIds->append(tbs.imgType); + sst.imgType = animIds->indexOf(tbs.imgType); sst.lifetime = tbs.lifetime; sst.name = tbs.name; sst.speed = tbs.speed; stt->splashes.append(sst); stt->triggers[stt->splashes.at(parIndex).triggerIndexes.size()-1].childId = stt->splashes.size() - 1; *recursiveCheck += 1; - fillTowerChains(chlist,trigIds,stt,chlist->at(i).childSplashId, stt->splashes.size()-1,recursiveCheck); + fillTowerChains(animIds,chlist,trigIds,stt,chlist->at(i).childSplashId, stt->splashes.size()-1,recursiveCheck); } } } @@ -441,21 +473,30 @@ void Loader::readAliens() QDomNodeList alelems = doc->elementsByTagName("alien"); for (int i=0; ielementsByTagName("splash"); for (int i=0; ielementsByTagName("animation"); + for (int i=0; i towers; QHash triggers; QHash waves; + QHash animations; QMultiHash levWaves; QMultiHash waveParts; QMultiHash chains; @@ -176,8 +183,9 @@ private: void readLevWaves(); void readWaveParts(); void readUpgrades(); + void readAnimations(); - void fillTowerChains(QList * chlist, QList * trigIds, srcTowerType * stt, int parId, int parIndex, int * recursiveCheck); + void fillTowerChains(QList * animIds, QList * chlist, QList * trigIds, srcTowerType * stt, int parId, int parIndex, int * recursiveCheck); void validate(QString filename); QString createMapExample(); }; diff --git a/schema.xml b/schema.xml index c9e29a2..96db649 100644 --- a/schema.xml +++ b/schema.xml @@ -81,6 +81,13 @@ + + + + + + + @@ -217,5 +224,10 @@ + + + + + diff --git a/splashes.cpp b/splashes.cpp index 7bb749b..e9478d5 100644 --- a/splashes.cpp +++ b/splashes.cpp @@ -27,6 +27,7 @@ void Splashes::addSplash(int player, int srcTower, int srcId, QPointF pos, QPoin } spl.angle = 180.0f*(- std::atan2(spl.pos.x() - spl.destination.x(),spl.pos.y() - spl.destination.y()))/M_PI; spl.imgType = src.imgType; + spl.animIndex = 0; spl.life = 0; spl.src = srcId; srcTriggerType trig; diff --git a/towers.cpp b/towers.cpp index 328a20e..87918f8 100644 --- a/towers.cpp +++ b/towers.cpp @@ -28,6 +28,7 @@ bool Towers::addTower(int playerId, int srcId, QPoint pos) TowerType tw; tw.src = srcId; tw.imgType = gameData->players.at(playerId)->srcTowers.at(srcId).imgType; + tw.animIndex = 0; tw.PlayerId = playerId; tw.angle = 0; tw.build = 0;