added triggers onTimer
added map view in ADeditor
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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
35
ADeditor/mapmodel.cpp
Normal 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
23
ADeditor/mapmodel.h
Normal 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
|
||||
Reference in New Issue
Block a user