tools/MissionsEditor/editor.cpp
author unc0rr
Sun, 25 Oct 2009 12:40:47 +0000
changeset 2584 cc049fbb65ef
parent 2583 f8da275981e5
child 2594 0047e16dbacb
permissions -rw-r--r--
Change mission file format to allow more flexible config
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
     1
#include <QtGui>
2572
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     2
#include "editor.h"
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     3
#include "ui_editor.h"
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     4
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     5
editor::editor(QWidget *parent)
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     6
    : QMainWindow(parent), ui(new Ui::editor)
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     7
{
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     8
    ui->setupUi(this);
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
     9
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    10
    cbFlags
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    11
        << ui->cbForts
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    12
        << ui->cbMultiWeapon
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    13
        << ui->cbSolidLand
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    14
        << ui->cbBorder
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    15
        << ui->cbDivideTeams
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    16
        << ui->cbLowGravity
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    17
        << ui->cbLaserSight
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    18
        << ui->cbInvulnerable
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    19
        << ui->cbMines
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    20
        << ui->cbVampiric
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    21
        << ui->cbKarma
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    22
        << ui->cbArtillery
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    23
        << ui->cbOneClanMode
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    24
        ;
2572
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    25
}
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    26
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    27
editor::~editor()
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    28
{
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    29
    delete ui;
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    30
}
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    31
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    32
void editor::on_actionLoad_triggered()
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    33
{
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    34
    QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)");
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    35
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    36
    if(!fileName.isEmpty())
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    37
        load(fileName);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    38
}
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    39
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    40
void editor::load(const QString & fileName)
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    41
{
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    42
    QFile file(fileName);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    43
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    44
    if(!file.open(QIODevice::ReadOnly))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    45
    {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    46
        QMessageBox::warning(this, "File error", "No such file");
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    47
        return ;
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    48
    }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    49
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    50
    QTextStream stream(&file);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    51
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    52
    while(!stream.atEnd())
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    53
    {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    54
        QString line = stream.readLine();
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    55
        if (line.startsWith("seed"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    56
            ui->leSeed->setText(line.mid(5));
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    57
        else
2584
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    58
        if (line.startsWith("map"))
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    59
            ui->leMap->setText(line.mid(4));
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    60
        else
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    61
        if (line.startsWith("theme"))
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    62
            ui->leTheme->setText(line.mid(6));
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    63
        else
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    64
        if (line.startsWith("$turntime"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    65
            ui->sbTurnTime->setValue(line.mid(10).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    66
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    67
        if (line.startsWith("$casefreq"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    68
            ui->sbCrateDrops->setValue(line.mid(10).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    69
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    70
        if (line.startsWith("$damagepct"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    71
            ui->sbDamageModifier->setValue(line.mid(11).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    72
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    73
        if (line.startsWith("$gmflags"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    74
        {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    75
            quint32 flags = line.mid(9).toInt();
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    76
            foreach(QCheckBox * cb, cbFlags)
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    77
            {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    78
                cb->setChecked(flags & 1);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    79
                flags >>= 1;
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    80
            }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    81
        }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    82
    }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    83
}