tools/MissionsEditor/editor.cpp
changeset 2583 f8da275981e5
parent 2572 af96861683f8
child 2584 cc049fbb65ef
equal deleted inserted replaced
2582:e16668bac20f 2583:f8da275981e5
       
     1 #include <QtGui>
     1 #include "editor.h"
     2 #include "editor.h"
     2 #include "ui_editor.h"
     3 #include "ui_editor.h"
     3 
     4 
     4 editor::editor(QWidget *parent)
     5 editor::editor(QWidget *parent)
     5     : QMainWindow(parent), ui(new Ui::editor)
     6     : QMainWindow(parent), ui(new Ui::editor)
     6 {
     7 {
     7     ui->setupUi(this);
     8     ui->setupUi(this);
       
     9 
       
    10     cbFlags
       
    11         << ui->cbForts
       
    12         << ui->cbMultiWeapon
       
    13         << ui->cbSolidLand
       
    14         << ui->cbBorder
       
    15         << ui->cbDivideTeams
       
    16         << ui->cbLowGravity
       
    17         << ui->cbLaserSight
       
    18         << ui->cbInvulnerable
       
    19         << ui->cbMines
       
    20         << ui->cbVampiric
       
    21         << ui->cbKarma
       
    22         << ui->cbArtillery
       
    23         << ui->cbOneClanMode
       
    24         ;
     8 }
    25 }
     9 
    26 
    10 editor::~editor()
    27 editor::~editor()
    11 {
    28 {
    12     delete ui;
    29     delete ui;
    13 }
    30 }
       
    31 
       
    32 void editor::on_actionLoad_triggered()
       
    33 {
       
    34     QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)");
       
    35 
       
    36     if(!fileName.isEmpty())
       
    37         load(fileName);
       
    38 }
       
    39 
       
    40 void editor::load(const QString & fileName)
       
    41 {
       
    42     QFile file(fileName);
       
    43 
       
    44     if(!file.open(QIODevice::ReadOnly))
       
    45     {
       
    46         QMessageBox::warning(this, "File error", "No such file");
       
    47         return ;
       
    48     }
       
    49 
       
    50     QTextStream stream(&file);
       
    51 
       
    52     while(!stream.atEnd())
       
    53     {
       
    54         QString line = stream.readLine();
       
    55         if (line.startsWith("seed"))
       
    56             ui->leSeed->setText(line.mid(5));
       
    57         else
       
    58         if (line.startsWith("$turntime"))
       
    59             ui->sbTurnTime->setValue(line.mid(10).toInt());
       
    60         else
       
    61         if (line.startsWith("$casefreq"))
       
    62             ui->sbCrateDrops->setValue(line.mid(10).toInt());
       
    63         else
       
    64         if (line.startsWith("$damagepct"))
       
    65             ui->sbDamageModifier->setValue(line.mid(11).toInt());
       
    66         else
       
    67         if (line.startsWith("$gmflags"))
       
    68         {
       
    69             quint32 flags = line.mid(9).toInt();
       
    70             foreach(QCheckBox * cb, cbFlags)
       
    71             {
       
    72                 cb->setChecked(flags & 1);
       
    73                 flags >>= 1;
       
    74             }
       
    75         }
       
    76     }
       
    77 }