tools/MissionsEditor/editor.cpp
author unc0rr
Fri, 30 Oct 2009 19:28:44 +0000
changeset 2594 0047e16dbacb
parent 2584 cc049fbb65ef
child 2596 41b46f83d088
permissions -rw-r--r--
Add loading team parameters
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>
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
     2
#include <QObject>
2572
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     3
#include "editor.h"
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     4
#include "ui_editor.h"
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     5
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     6
editor::editor(QWidget *parent)
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     7
    : QMainWindow(parent), ui(new Ui::editor)
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     8
{
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
     9
    ui->setupUi(this);
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    10
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    11
    cbFlags
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    12
        << ui->cbForts
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    13
        << ui->cbMultiWeapon
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    14
        << ui->cbSolidLand
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    15
        << ui->cbBorder
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    16
        << ui->cbDivideTeams
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    17
        << ui->cbLowGravity
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    18
        << ui->cbLaserSight
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    19
        << ui->cbInvulnerable
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    20
        << ui->cbMines
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    21
        << ui->cbVampiric
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    22
        << ui->cbKarma
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    23
        << ui->cbArtillery
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    24
        << ui->cbOneClanMode
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    25
        ;
2572
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    26
}
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    27
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    28
editor::~editor()
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    29
{
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    30
    delete ui;
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    31
}
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    32
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    33
void editor::on_actionLoad_triggered()
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    34
{
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    35
    QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)");
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    36
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    37
    if(!fileName.isEmpty())
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    38
        load(fileName);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    39
}
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    40
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    41
void editor::load(const QString & fileName)
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    42
{
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    43
    int currTeam = -1;
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    44
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    45
    QFile file(fileName);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    46
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    47
    if(!file.open(QIODevice::ReadOnly))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    48
    {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    49
        QMessageBox::warning(this, "File error", "No such file");
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    50
        return ;
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    51
    }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    52
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    53
    QTextStream stream(&file);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    54
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    55
    while(!stream.atEnd())
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    56
    {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    57
        QString line = stream.readLine();
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    58
        if (line.startsWith("seed"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    59
            ui->leSeed->setText(line.mid(5));
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    60
        else
2584
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    61
        if (line.startsWith("map"))
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    62
            ui->leMap->setText(line.mid(4));
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    63
        else
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    64
        if (line.startsWith("theme"))
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    65
            ui->leTheme->setText(line.mid(6));
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    66
        else
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    67
        if (line.startsWith("$turntime"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    68
            ui->sbTurnTime->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("$casefreq"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    71
            ui->sbCrateDrops->setValue(line.mid(10).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("$damagepct"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    74
            ui->sbDamageModifier->setValue(line.mid(11).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    75
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    76
        if (line.startsWith("$gmflags"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    77
        {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    78
            quint32 flags = line.mid(9).toInt();
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    79
            foreach(QCheckBox * cb, cbFlags)
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    80
            {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    81
                cb->setChecked(flags & 1);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    82
                flags >>= 1;
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    83
            }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    84
        }
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    85
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    86
        if (line.startsWith("addteam") && (currTeam < 5))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    87
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    88
            ++currTeam;
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    89
            line = line.mid(8);
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    90
            int spacePos = line.indexOf('\x20');
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    91
            quint32 teamColor = line.left(spacePos).toUInt();
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    92
            QString teamName = line.mid(spacePos + 1);
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    93
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    94
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    95
            te->addTeam(teamName, teamColor);
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    96
        }
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    97
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    98
        if (line.startsWith("fort") && (currTeam >= 0))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    99
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   100
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   101
            te->setFort(line.mid(5));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   102
        }
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   103
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   104
        if (line.startsWith("grave") && (currTeam >= 0))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   105
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   106
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   107
            te->setGrave(line.mid(6));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   108
        }
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   109
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   110
        if (line.startsWith("voicepack") && (currTeam >= 0))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   111
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   112
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   113
            te->setVoicepack(line.mid(10));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   114
        }
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
   115
    }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
   116
}