added triggers onTimer

added map view in ADeditor
This commit is contained in:
2010-09-02 23:34:39 +04:00
parent 7752f7be12
commit c898f978da
10 changed files with 169 additions and 15 deletions

View File

@@ -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

View File

@@ -58,6 +58,7 @@
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
<value key="QtVersionId" type="int">0</value>
<value key="ToolChain" type="int">0</value>
<value key="addQDumper" type=""></value>
<value key="buildConfiguration" type="int">2</value>
</valuemap>
</data>
@@ -66,6 +67,7 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
<value key="QtVersionId" type="int">0</value>
<value key="addQDumper" type=""></value>
<value key="buildConfiguration" type="int">0</value>
</valuemap>
</data>

View File

@@ -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<m.cells().size(); i++) {
for (int j=0; j<m.cells().at(i).size(); j++) {
QPen pen;
pen.setColor(Qt::white);
int cel = m.cells().at(i).at(j);
if (cel == Map::Wall)
pen.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,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());

View File

@@ -5,11 +5,13 @@
#include <QDebug>
#include <QListWidgetItem>
#include <QCloseEvent>
#include <QGraphicsScene>
#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);
};

View File

@@ -1474,17 +1474,14 @@
<item>
<widget class="QGraphicsView" name="gvMap">
<property name="backgroundBrush">
<brush brushstyle="Dense6Pattern">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
<red>193</red>
<green>199</green>
<blue>189</blue>
</color>
</brush>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="dragMode">
<enum>QGraphicsView::ScrollHandDrag</enum>
</property>
@@ -1611,7 +1608,7 @@
<number>20</number>
</property>
<item>
<widget class="QPushButton" name="pbTrigAdd_2">
<widget class="QPushButton" name="pbMapAdd">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -1624,7 +1621,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pbTrigDel_2">
<widget class="QPushButton" name="pbMapDelete">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>

35
ADeditor/mapmodel.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "mapmodel.h"
MapModel::MapModel(QList <tbMap> mmaps, QObject *parent) :
QAbstractListModel(parent)
{
maps = mmaps;
}
void MapModel::refresh(QList <tbMap> 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();
}

23
ADeditor/mapmodel.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef MAPMODEL_H
#define MAPMODEL_H
#include <QAbstractListModel>
#include "../loader.h"
class MapModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit MapModel(QList <tbMap> maps, QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
void refresh(QList <tbMap> maps);
signals:
public slots:
private:
QList <tbMap> maps;
};
#endif // MAPMODEL_H

View File

@@ -69,7 +69,7 @@
<splash speed="0.2" imageType="0" lifetime="9999" autoControl="true" id="2" name="smart rocket"/>
<splash speed="0.1" imageType="1" lifetime="9999" autoControl="true" id="3" name="bullet"/>
<splash speed="0" imageType="3" lifetime="5" id="4" name="bum"/>
<splash speed="0" imageType="2" lifetime="3" id="5" name="smoke"/>
<splash speed="0" imageType="2" lifetime="8" id="5" name="smoke"/>
<splash speed="0.1" imageType="-1074795776" lifetime="50" autoControl="true" id="6" name="Снаряд"/>
</splashes>
<towers>
@@ -80,7 +80,7 @@
<triggers>
<trigger damage="5" childAim="noAim" delParent="true" type="onDestination" id="2" name="shot"/>
<trigger damage="21" childAim="noAim" radius="2.5" delParent="true" count="1" type="onDestination" id="3" name="explosion"/>
<trigger childAim="noAim" count="1" type="onTimer" id="4" name="smoke"/>
<trigger childAim="noAim" count="1" type="onTimer" timer="2" id="4" name="smoke"/>
</triggers>
<chains>
<chain tower="1" trigger="3" child="4" parent="2"/>

View File

@@ -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 <int> deadIndexes;
// FIXME : rewrite loop with iterators, and correct onTrigTimer()
for (int i=0; i<gameData->curSplashes.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<int> *deadIndexes)
{
for (int k=0; k<spl->trigsOnTimer.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; j<strig.count; ++j)
{
// TODO: randomRadiusPos
addSplash(spl->PlayerId,spl->srcTower,strig.childId,
spl->pos,spl->destination,-1,spl->TowerId);
}
}
}
}
}
void Splashes::doTriggerOnDest(const SplashType &spl, QList<int> *deadIndexes,
bool badAl)
{

View File

@@ -20,7 +20,9 @@ private:
Game_Data *gameData;
int nextId;
void doTriggerOnDest(const SplashType &spl, QList <int> * deadIndexes, bool badAl);
void doTriggerOnDest(const SplashType &spl, QList <int> * deadIndexes,
bool badAl);
void doTriggerOnTimer(SplashType * spl, QList <int> * deadIndexes);
};
#endif // SPLASHES_H