ADeditor can edit Aliens

This commit is contained in:
2010-08-25 13:40:33 +04:00
parent d897bb8fa2
commit 02acdc4d2b
12 changed files with 175 additions and 152 deletions

Binary file not shown.

View File

@@ -1,12 +1,18 @@
#include "alienmodel.h"
AlienModel::AlienModel(QList<tbAlien>maliens, QObject *parent) :
AlienModel::AlienModel(QList <tbAlien> maliens, QObject *parent) :
QAbstractListModel(parent)
{
aliens = maliens;
}
void AlienModel::refresh(QList <tbAlien> maliens)
{
aliens = maliens;
}
int AlienModel::rowCount(const QModelIndex &) const
{
return aliens.count();

View File

@@ -11,7 +11,7 @@ public:
explicit AlienModel(QList<tbAlien> aliens, QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
void refresh(QList<tbAlien> aliens);
signals:
public slots:

Binary file not shown.

View File

@@ -1,64 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data>
<ADdata>
<aliens>
<alien speed="0.01" score="50" imageType="1" prise="1" id="1" name="al fly" health="40" flying="true"/>
<alien speed="0.012" score="100" imageType="1" prise="0" id="10" name="my alien" health="100"/>
<alien speed="0.0099" score="350" imageType="1" prise="1" id="12" name="MONSTR" health="200" armor="1.5" regeneration="3"/>
</aliens>
<maps>
<map imageType="1" id="1" data="AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=" name="My Map" width="16" height="16" maxPlayers="2"/>
</maps>
<waves>
<wave id="1" timeout="20000" prise="100"/>
<wave id="2" timeout="20000" prise="200"/>
<wave id="3" timeout="20000" prise="220"/>
</waves>
<levels>
<level id="1" map="1" name="First Level"/>
</levels>
<waveParts>
<wavePart wave="1" alien="10" count="4"/>
<wavePart wave="1" alien="12" count="5"/>
<wavePart wave="1" alien="10" count="10"/>
<wavePart wave="2" alien="10" count="9"/>
<wavePart wave="3" alien="10" count="1"/>
<wavePart wave="3" alien="10" count="2"/>
<wavePart wave="3" alien="12" count="3"/>
<wavePart wave="3" alien="12" count="4"/>
</waveParts>
<wavesOnLevels>
<waveOnLevel level="1" wave="1"/>
<waveOnLevel level="1" wave="2"/>
<waveOnLevel level="1" wave="3"/>
</wavesOnLevels>
<splashes>
<splash speed="0.2" imageType="1" id="1" name="rocket" lifetime="9999"/>
<splash speed="0.2" imageType="1" id="2" name="smart rocket" lifetime="9999" autoControl="true"/>
<splash speed="100" imageType="2" id="3" name="bullet" lifetime="100" autoControl="true"/>
<splash speed="1" imageType="3" id="4" name="bum" lifetime="10"/>
<splash speed="0" imageType="4" id="5" name="smoke" lifetime="10"/>
</splashes>
<towers>
<tower id="1" imageType="1" name="rocket launcher" cost="30" buildTime="50" reload="20" splash="1" radius="3" expByDamage="0.04" expByKill="0.1" expByShot="0.15"/>
<tower id="3" imageType="1" name="rocket launcher 2" cost="30" buildTime="50" reload="20" splash="1" radius="3" expByDamage="0.04" expByKill="0.1" expByShot="0.15"/>
<tower id="2" imageType="2" name="gun" cost="10" buildTime="25" reload="5" splash="3" radius="1.5" expByDamage="0.1" expByShot="0.1" expByKill="0.2"/>
</towers>
<triggers>
<trigger id="2" name="shot" type="onDestination" delParent="true" damage="5"/>
<trigger id="3" name="explosion" type="onDestination" count="1" delParent="true" damage="5" radius="1.5"/>
<trigger id="4" name="smoke" type="onTimer" timer="2" count="1"/>
</triggers>
<chains>
<chain tower="1" parent="1" trigger="3" child="4"/>
<chain tower="1" parent="1" trigger="4" child="5"/>
<chain tower="3" parent="2" trigger="3" child="4"/>
<chain tower="3" parent="2" trigger="4" child="5"/>
<chain tower="2" parent="3" trigger="2"/>
</chains>
<towersOnLevels>
<towerOnLevel level="1" tower="1"/>
<towerOnLevel level="1" tower="2"/>
<towerOnLevel level="1" tower="3"/>
</towersOnLevels>
</ADdata>

View File

@@ -1,9 +1,10 @@
<!DOCTYPE data>
<ADdata>
<aliens>
<alien flying="true" speed="0.01" imageType="1" prise="1" id="1" score="50" name="al fly" health="40"/>
<alien speed="0.012" imageType="1" prise="0" id="10" score="100" name="my alien" health="100"/>
<alien regeneration="3" speed="0.0099" imageType="1" prise="1" armor="1.5" id="12" score="350" name="MONSTR" health="200"/>
<alien flying="true" speed="0.03" imageType="31" prise="15" id="2" score="12" name="Monstr" health="150"/>
<alien flying="true" speed="0.01" imageType="-1078580008" prise="1" id="4" score="10" name="test" health="60"/>
<alien speed="0.06" imageType="1" prise="4" id="10" score="99" name="first" health="100"/>
<alien regeneration="3" speed="0.0099" imageType="1" prise="10" armor="1.5" id="12" score="99" name="MONSTR" health="99.99"/>
</aliens>
<maps>
<map width="16" imageType="1" height="16" id="1" data="AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=" name="My Map" maxPlayers="2"/>
@@ -14,7 +15,7 @@
<wave prise="220" timeout="20000" id="3"/>
</waves>
<levels>
<level map="1" id="1" score="144665064" name="First Level"/>
<level map="1" id="1" score="152921560" name="First Level"/>
</levels>
<waveParts>
<wavePart alien="10" count="4" wave="1"/>

View File

@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "alienmodel.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
@@ -10,8 +11,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
adloader = new Loader(this);
adloader->load("data2.xml");
QAbstractItemModel * model = new AlienModel(adloader->aliens.values());
ui->lvAliens->setModel(model);
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)));
ui->lvAliens->selectionModel()->setCurrentIndex(ui->lvAliens->model()->index(0,0),QItemSelectionModel::Select);
}
@@ -38,13 +39,19 @@ void MainWindow::changeEvent(QEvent *e)
void MainWindow::on_cbAlArmor_toggled(bool checked)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
ui->sbAlArmor->setEnabled(checked);
if (checked) adloader->aliens[id].armor = ui->sbAlArmor->value();
else adloader->aliens[id].armor = 0;
}
void MainWindow::on_cbAlRegeneration_toggled(bool checked)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
ui->sbAlregeneration->setEnabled(checked);
if (checked) adloader->aliens[id].regeneration = ui->sbAlregeneration->value();
else adloader->aliens[id].regeneration = 0;
}
@@ -70,7 +77,88 @@ void MainWindow::on_pbSave_clicked()
{
adloader->save("data2.xml");
adloader->load("data2.xml");
QAbstractItemModel * model = new AlienModel(adloader->aliens.values());
ui->lvAliens->setModel(model);
ui->lvAliens->selectionModel()->setCurrentIndex(ui->lvAliens->model()->index(0,0),QItemSelectionModel::Select);
alModel->refresh(adloader->aliens.values());
}
void MainWindow::on_sbAlHealth_valueChanged(double value)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].health = value;
}
void MainWindow::on_sbAlArmor_valueChanged(double value)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].armor = value;
}
void MainWindow::on_sbAlregeneration_valueChanged(double value)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].regeneration = value;
}
void MainWindow::on_sbAlSpeed_valueChanged(double value)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].speed = value;
}
void MainWindow::on_sbAlPrise_valueChanged(int val)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].prise = val;
}
void MainWindow::on_sbAlScore_valueChanged(int val)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].score = val;
}
void MainWindow::on_cbAlIsFly_clicked(bool checked)
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].isFlying = checked;
}
void MainWindow::on_leAlName_editingFinished()
{
int id = adloader->aliens.values().at(ui->lvAliens->currentIndex().row()).id;
adloader->aliens[id].name = ui->leAlName->text();
alModel->refresh(adloader->aliens.values());
ui->lvAliens->setModel((QAbstractItemModel * )alModel);
}
void MainWindow::on_pbAlAdd_clicked()
{
int i = 1;
while (adloader->aliens.contains(i)) i++;
tbAlien al;
al.id = i;
adloader->aliens.insert(al.id,al);
int index = adloader->aliens.keys().indexOf(i);
alModel->refresh(adloader->aliens.values());
ui->lvAliens->setModel((QAbstractItemModel * )alModel);
ui->lvAliens->reset();
ui->lvAliens->selectionModel()->setCurrentIndex(ui->lvAliens->model()->index(index,0),QItemSelectionModel::Select);
}
void MainWindow::on_pbAlDel_clicked()
{
QMessageBox msgBox;
int id = adloader->aliens.keys().at(ui->lvAliens->currentIndex().row());
msgBox.setText(tr("Delete alien %1 id=%2").arg(adloader->aliens.value(id).name).arg(id));
msgBox.setInformativeText(tr("Are you sure?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
if (ret == QMessageBox::Ok)
{
adloader->aliens.remove(id);
alModel->refresh(adloader->aliens.values());
ui->lvAliens->setModel((QAbstractItemModel * )alModel);
ui->lvAliens->reset();
ui->lvAliens->selectionModel()->setCurrentIndex(ui->lvAliens->model()->index(0,0),QItemSelectionModel::Select);
}
}

View File

@@ -5,7 +5,8 @@
#include <QDebug>
#include <QListWidgetItem>
#include "../loader.h"
#include "alienmodel.h"
namespace Ui {
class MainWindow;
@@ -23,9 +24,20 @@ protected:
private:
Ui::MainWindow *ui;
Loader * adloader;
AlienModel * alModel;
private slots:
void on_pbSave_clicked();
void on_pbAlDel_clicked();
void on_pbAlAdd_clicked();
void on_leAlName_editingFinished();
void on_cbAlIsFly_clicked(bool checked);
void on_sbAlScore_valueChanged(int );
void on_sbAlPrise_valueChanged(int );
void on_sbAlSpeed_valueChanged(double );
void on_sbAlregeneration_valueChanged(double );
void on_sbAlArmor_valueChanged(double );
void on_sbAlHealth_valueChanged(double );
void on_pbSave_clicked();
void lvAliens_select(QModelIndex, QModelIndex);
void on_cbAlRegeneration_toggled(bool checked);
void on_cbAlArmor_toggled(bool checked);

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>516</width>
<height>435</height>
<height>468</height>
</rect>
</property>
<property name="windowTitle">
@@ -76,7 +76,20 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="sbAlHealth"/>
<widget class="QDoubleSpinBox" name="sbAlHealth">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
<property name="singleStep">
<double>10.000000000000000</double>
</property>
<property name="value">
<double>99.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
@@ -100,6 +113,9 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
@@ -124,6 +140,15 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
<property name="singleStep">
<double>5.000000000000000</double>
</property>
</widget>
</item>
</layout>
@@ -147,7 +172,23 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="sbAlSpeed"/>
<widget class="QDoubleSpinBox" name="sbAlSpeed">
<property name="suffix">
<string/>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>99.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.010000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
@@ -170,7 +211,11 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="sbAlPrise"/>
<widget class="QSpinBox" name="sbAlPrise">
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
</layout>
</item>
@@ -193,7 +238,11 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="sbAlScore"/>
<widget class="QSpinBox" name="sbAlScore">
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
</layout>
</item>

View File

@@ -1,69 +0,0 @@
/****************************************************************************
** Meta object code from reading C++ file 'alientablemodel.h'
**
** Created: Tue Aug 24 14:03:38 2010
** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "alientablemodel.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'alientablemodel.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 62
#error "This file was generated using the moc from 4.6.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_AlienTableModel[] = {
// content:
4, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
0 // eod
};
static const char qt_meta_stringdata_AlienTableModel[] = {
"AlienTableModel\0"
};
const QMetaObject AlienTableModel::staticMetaObject = {
{ &QAbstractTableModel::staticMetaObject, qt_meta_stringdata_AlienTableModel,
qt_meta_data_AlienTableModel, 0 }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &AlienTableModel::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *AlienTableModel::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *AlienTableModel::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_AlienTableModel))
return static_cast<void*>(const_cast< AlienTableModel*>(this));
return QAbstractTableModel::qt_metacast(_clname);
}
int AlienTableModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QAbstractTableModel::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
return _id;
}
QT_END_MOC_NAMESPACE

Binary file not shown.

Binary file not shown.