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