added animation

but not full in ADeditor
This commit is contained in:
2010-09-05 16:25:23 +04:00
parent c898f978da
commit 8fa6b8e2a6
24 changed files with 924 additions and 725 deletions

View File

@@ -2,7 +2,7 @@
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFileDialog>
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<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);
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<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));
}
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; i<pathes.size(); ++i)
{
ui->lwImages->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; i<ui->lwImages->selectedItems().size(); ++i)
adloader->animations[id].pathes.removeOne(ui->lwImages->selectedItems().at(i)->text());
refresh_lwImages(adloader->animations.value(id).pathes);
}