From c898f978dac93248e19c2267bb7986c63414d489 Mon Sep 17 00:00:00 2001 From: buull Date: Thu, 2 Sep 2010 23:34:39 +0400 Subject: [PATCH] added triggers onTimer added map view in ADeditor --- ADeditor/ADeditor.pro | 6 ++-- ADeditor/ADeditor.pro.user | 2 ++ ADeditor/mainwindow.cpp | 56 ++++++++++++++++++++++++++++++++++++++ ADeditor/mainwindow.h | 5 ++++ ADeditor/mainwindow.ui | 15 ++++------ ADeditor/mapmodel.cpp | 35 ++++++++++++++++++++++++ ADeditor/mapmodel.h | 23 ++++++++++++++++ data2.xml | 4 +-- splashes.cpp | 34 ++++++++++++++++++++++- splashes.h | 4 ++- 10 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 ADeditor/mapmodel.cpp create mode 100644 ADeditor/mapmodel.h diff --git a/ADeditor/ADeditor.pro b/ADeditor/ADeditor.pro index e882194..5ae4fd5 100644 --- a/ADeditor/ADeditor.pro +++ b/ADeditor/ADeditor.pro @@ -14,7 +14,8 @@ SOURCES += main.cpp \ ../map.cpp \ ../player.cpp \ ../game_data.cpp \ - triggermodel.cpp + triggermodel.cpp \ + mapmodel.cpp HEADERS += mainwindow.h \ ../loader.h \ alienmodel.h \ @@ -24,7 +25,8 @@ HEADERS += mainwindow.h \ ../map.h \ ../player.h \ ../game_data.h \ - triggermodel.h + triggermodel.h \ + mapmodel.h FORMS += mainwindow.ui TRANSLATIONS += adeditor_ru.ts RESOURCES += ADeditor.qrc diff --git a/ADeditor/ADeditor.pro.user b/ADeditor/ADeditor.pro.user index 8049e5d..61855d0 100644 --- a/ADeditor/ADeditor.pro.user +++ b/ADeditor/ADeditor.pro.user @@ -58,6 +58,7 @@ Debug 0 0 + 2 @@ -66,6 +67,7 @@ Release 0 + 0 diff --git a/ADeditor/mainwindow.cpp b/ADeditor/mainwindow.cpp index 169bfa0..68c9ffe 100644 --- a/ADeditor/mainwindow.cpp +++ b/ADeditor/mainwindow.cpp @@ -9,9 +9,32 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + ui->pbSave->setIcon(QIcon::fromTheme("filesave")); + ui->pbReload->setIcon(QIcon::fromTheme("edit-undo")); + ui->pbAlAdd->setIcon(QIcon::fromTheme("add")); + ui->pbAlDel->setIcon(QIcon::fromTheme("remove")); + ui->pbTrigAdd->setIcon(QIcon::fromTheme("add")); + ui->pbTrigDel->setIcon(QIcon::fromTheme("remove")); + ui->pbTwAdd->setIcon(QIcon::fromTheme("add")); + ui->pbTwDel->setIcon(QIcon::fromTheme("remove")); + ui->pbMapAdd->setIcon(QIcon::fromTheme("add")); + ui->pbMapDelete->setIcon(QIcon::fromTheme("remove")); + ui->pbSplAdd->setIcon(QIcon::fromTheme("add")); + ui->pbSlpDel->setIcon(QIcon::fromTheme("remove")); + ui->pbTwSplashEdit->setIcon(QIcon::fromTheme("forward")); + ui->pbMapEdit->setIcon(QIcon::fromTheme("forward")); adloader = new Loader(this); adloader->load("data2.xml"); + mapScene = new QGraphicsScene(); + ui->gvMap->setScene(mapScene); + ui->gvMap->scale(10,10); + + mapModel = new MapModel(adloader->maps.values()); + ui->lvMaps->setModel((QAbstractItemModel * )mapModel); + connect(ui->lvMaps->selectionModel(),SIGNAL(currentChanged(QModelIndex, QModelIndex)),this,SLOT(lvMaps_select(QModelIndex, QModelIndex))); + ui->lvMaps->selectionModel()->setCurrentIndex(ui->lvMaps->model()->index(0,0),QItemSelectionModel::ClearAndSelect); + alModel = new AlienModel(adloader->aliens.values()); ui->lvAliens->setModel((QAbstractItemModel * )alModel); connect(ui->lvAliens->selectionModel(),SIGNAL(currentChanged(QModelIndex, QModelIndex)),this,SLOT(lvAliens_select(QModelIndex, QModelIndex))); @@ -100,6 +123,39 @@ void MainWindow::lvAliens_select(QModelIndex index, QModelIndex) } +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); + } + } + 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()); diff --git a/ADeditor/mainwindow.h b/ADeditor/mainwindow.h index e069d73..2afffac 100644 --- a/ADeditor/mainwindow.h +++ b/ADeditor/mainwindow.h @@ -5,11 +5,13 @@ #include #include #include +#include #include "alienmodel.h" #include "towermodel.h" #include "splashmodel.h" #include "triggermodel.h" +#include "mapmodel.h" namespace Ui { class MainWindow; @@ -31,6 +33,8 @@ private: TowerModel * twModel; SplashModel * splModel; TriggerModel* trigModel; + MapModel * mapModel; + QGraphicsScene * mapScene; bool isSaved; @@ -90,6 +94,7 @@ private slots: void lvTowers_select(QModelIndex, QModelIndex); void lvSplashes_select(QModelIndex, QModelIndex); void lvTriggers_select(QModelIndex, QModelIndex); + void lvMaps_select(QModelIndex, QModelIndex); void on_cbAlRegeneration_toggled(bool checked); void on_cbAlArmor_toggled(bool checked); }; diff --git a/ADeditor/mainwindow.ui b/ADeditor/mainwindow.ui index 8033b2c..30b8fec 100644 --- a/ADeditor/mainwindow.ui +++ b/ADeditor/mainwindow.ui @@ -1474,17 +1474,14 @@ - + - 0 - 0 - 0 + 193 + 199 + 189 - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - QGraphicsView::ScrollHandDrag @@ -1611,7 +1608,7 @@ 20 - + 0 @@ -1624,7 +1621,7 @@ - + 0 diff --git a/ADeditor/mapmodel.cpp b/ADeditor/mapmodel.cpp new file mode 100644 index 0000000..a219445 --- /dev/null +++ b/ADeditor/mapmodel.cpp @@ -0,0 +1,35 @@ +#include "mapmodel.h" + +MapModel::MapModel(QList mmaps, QObject *parent) : + QAbstractListModel(parent) +{ + maps = mmaps; +} + + +void MapModel::refresh(QList mmaps) +{ + maps = mmaps; +} + + +int MapModel::rowCount(const QModelIndex &) const +{ + return maps.count(); +} + + +QVariant MapModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= maps.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + { + return maps.at(index.row()).name; + } + return QVariant(); +} diff --git a/ADeditor/mapmodel.h b/ADeditor/mapmodel.h new file mode 100644 index 0000000..2bac171 --- /dev/null +++ b/ADeditor/mapmodel.h @@ -0,0 +1,23 @@ +#ifndef MAPMODEL_H +#define MAPMODEL_H + +#include +#include "../loader.h" + +class MapModel : public QAbstractListModel +{ +Q_OBJECT +public: + explicit MapModel(QList maps, QObject *parent = 0); + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + void refresh(QList maps); + +signals: + +public slots: +private: + QList maps; +}; + +#endif // MAPMODEL_H diff --git a/data2.xml b/data2.xml index 1766af4..3aa66d7 100644 --- a/data2.xml +++ b/data2.xml @@ -69,7 +69,7 @@ - + @@ -80,7 +80,7 @@ - + diff --git a/splashes.cpp b/splashes.cpp index 5160200..7bb749b 100644 --- a/splashes.cpp +++ b/splashes.cpp @@ -48,7 +48,7 @@ void Splashes::addSplash(int player, int srcTower, int srcId, QPointF pos, QPoin break; case srcTriggerType::onTimer : tot.src = src.triggerIndexes.at(i); - tot.timer = trig.timer; + tot.timer = 0; spl.trigsOnTimer.append(tot); break; } @@ -72,6 +72,7 @@ void Splashes::addSplash(QPoint curTowerId) void Splashes::update() { QList deadIndexes; + // FIXME : rewrite loop with iterators, and correct onTrigTimer() for (int i=0; icurSplashes.size(); i++) { float arctg,angl; @@ -82,6 +83,10 @@ void Splashes::update() spl.life++; if (spl.life > src.lifetime) deadIndexes.append(spl.id); + if (!spl.trigsOnTimer.isEmpty()) + { + doTriggerOnTimer(&spl,&deadIndexes); + } if (src.autoControl) { bool badAl = false; @@ -133,6 +138,33 @@ void Splashes::delSplash(int Id) } +void Splashes::doTriggerOnTimer(SplashType *spl, QList *deadIndexes) +{ + for (int k=0; ktrigsOnTimer.size(); k++) + { + srcTriggerType strig = gameData->players. + at(spl->PlayerId)->srcTowers. + at(spl->srcTower).triggers. + at(spl->trigsOnTimer.at(k).src); + spl->trigsOnTimer[k].timer++; + if (spl->trigsOnTimer.at(k).timer >= strig.timer) + { + spl->trigsOnTimer[k].timer = 0; + if (strig.delParent) deadIndexes->append(spl->id); + if (strig.count > 0 && strig.childId > 0) + { + for (int j=0; jPlayerId,spl->srcTower,strig.childId, + spl->pos,spl->destination,-1,spl->TowerId); + } + } + } + } +} + + void Splashes::doTriggerOnDest(const SplashType &spl, QList *deadIndexes, bool badAl) { diff --git a/splashes.h b/splashes.h index 636e6da..c5e24b2 100644 --- a/splashes.h +++ b/splashes.h @@ -20,7 +20,9 @@ private: Game_Data *gameData; int nextId; - void doTriggerOnDest(const SplashType &spl, QList * deadIndexes, bool badAl); + void doTriggerOnDest(const SplashType &spl, QList * deadIndexes, + bool badAl); + void doTriggerOnTimer(SplashType * spl, QList * deadIndexes); }; #endif // SPLASHES_H