tools/MissionsEditor/editor.cpp
author sheepluva
Fri, 05 Nov 2010 13:03:55 +0100
changeset 4116 bf129ab572c6
parent 2596 41b46f83d088
permissions -rw-r--r--
some changelog changes
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
2596
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    11
    reset();
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    12
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    13
    cbFlags
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    14
        << ui->cbForts
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    15
        << ui->cbMultiWeapon
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    16
        << ui->cbSolidLand
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    17
        << ui->cbBorder
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    18
        << ui->cbDivideTeams
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    19
        << ui->cbLowGravity
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    20
        << ui->cbLaserSight
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    21
        << ui->cbInvulnerable
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    22
        << ui->cbMines
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    23
        << ui->cbVampiric
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    24
        << ui->cbKarma
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    25
        << ui->cbArtillery
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    26
        << ui->cbOneClanMode
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    27
        ;
2572
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    28
}
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    29
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    30
editor::~editor()
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    31
{
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    32
    delete ui;
af96861683f8 Start work on missions/trainings editor
unc0rr
parents:
diff changeset
    33
}
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    34
2596
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    35
void editor::reset()
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    36
{
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    37
    for(int i = 0; i < 6; ++i)
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    38
    {
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    39
        ui->twTeams->setTabEnabled(i, false);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    40
        ui->twTeams->widget(i)->setEnabled(false);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    41
    }
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    42
}
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
    43
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    44
void editor::on_actionLoad_triggered()
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    45
{
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    46
    QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)");
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    47
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    48
    if(!fileName.isEmpty())
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    49
        load(fileName);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    50
}
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    51
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    52
void editor::load(const QString & fileName)
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    53
{
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    54
    int currTeam = -1;
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    55
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    56
    QFile file(fileName);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    57
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    58
    if(!file.open(QIODevice::ReadOnly))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    59
    {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    60
        QMessageBox::warning(this, "File error", "No such file");
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    61
        return ;
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    62
    }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    63
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    64
    QTextStream stream(&file);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    65
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    66
    while(!stream.atEnd())
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    67
    {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    68
        QString line = stream.readLine();
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    69
        if (line.startsWith("seed"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    70
            ui->leSeed->setText(line.mid(5));
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    71
        else
2584
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    72
        if (line.startsWith("map"))
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    73
            ui->leMap->setText(line.mid(4));
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    74
        else
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    75
        if (line.startsWith("theme"))
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    76
            ui->leTheme->setText(line.mid(6));
cc049fbb65ef Change mission file format to allow more flexible config
unc0rr
parents: 2583
diff changeset
    77
        else
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    78
        if (line.startsWith("$turntime"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    79
            ui->sbTurnTime->setValue(line.mid(10).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    80
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    81
        if (line.startsWith("$casefreq"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    82
            ui->sbCrateDrops->setValue(line.mid(10).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    83
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    84
        if (line.startsWith("$damagepct"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    85
            ui->sbDamageModifier->setValue(line.mid(11).toInt());
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    86
        else
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    87
        if (line.startsWith("$gmflags"))
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    88
        {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    89
            quint32 flags = line.mid(9).toInt();
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    90
            foreach(QCheckBox * cb, cbFlags)
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    91
            {
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    92
                cb->setChecked(flags & 1);
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    93
                flags >>= 1;
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    94
            }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
    95
        }
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    96
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    97
        if (line.startsWith("addteam") && (currTeam < 5))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    98
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
    99
            ++currTeam;
2596
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   100
            ui->twTeams->setTabEnabled(currTeam, true);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   101
            ui->twTeams->widget(currTeam)->setEnabled(true);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   102
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   103
            line = line.mid(8);
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   104
            int spacePos = line.indexOf('\x20');
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   105
            quint32 teamColor = line.left(spacePos).toUInt();
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   106
            QString teamName = line.mid(spacePos + 1);
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   107
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   108
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
2596
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   109
            te->setTeam(teamName, teamColor);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   110
        }
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   111
        else
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   112
        if (line.startsWith("addhh") && (currTeam >= 0))
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   113
        {
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   114
            line = line.mid(6);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   115
            quint32 level = line.left(1).toUInt();
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   116
            line = line.mid(2);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   117
            int spacePos = line.indexOf('\x20');
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   118
            quint32 health = line.left(spacePos).toUInt();
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   119
            QString hhName = line.mid(spacePos + 1);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   120
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   121
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   122
            te->addHedgehog(level, health, hhName);
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   123
        }
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   124
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   125
        if (line.startsWith("fort") && (currTeam >= 0))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   126
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   127
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   128
            te->setFort(line.mid(5));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   129
        }
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   130
        else
2596
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   131
        if (line.startsWith("hat") && (currTeam >= 0))
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   132
        {
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   133
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   134
            te->setLastHHHat(line.mid(4));
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   135
        }
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   136
        else
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   137
        if (line.startsWith("hhcoords") && (currTeam >= 0))
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   138
        {
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   139
            line = line.mid(9);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   140
            int spacePos = line.indexOf('\x20');
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   141
            int x = line.left(spacePos).toUInt();
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   142
            int y = line.mid(spacePos + 1).toInt();
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   143
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   144
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   145
            te->setLastHHCoords(x, y);
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   146
        }
41b46f83d088 Compete loading teams/hedgehogs part from mission config
unc0rr
parents: 2594
diff changeset
   147
        else
2594
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   148
        if (line.startsWith("grave") && (currTeam >= 0))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   149
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   150
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   151
            te->setGrave(line.mid(6));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   152
        }
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   153
        else
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   154
        if (line.startsWith("voicepack") && (currTeam >= 0))
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   155
        {
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   156
            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   157
            te->setVoicepack(line.mid(10));
0047e16dbacb Add loading team parameters
unc0rr
parents: 2584
diff changeset
   158
        }
2583
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
   159
    }
f8da275981e5 Partially implement loading mission options
unc0rr
parents: 2572
diff changeset
   160
}