author | smxx |
Fri, 26 Mar 2010 12:34:18 +0000 | |
changeset 3075 | b4ef08187d22 |
parent 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 |
|
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 | 13 |
cbFlags |
14 |
<< ui->cbForts |
|
15 |
<< ui->cbMultiWeapon |
|
16 |
<< ui->cbSolidLand |
|
17 |
<< ui->cbBorder |
|
18 |
<< ui->cbDivideTeams |
|
19 |
<< ui->cbLowGravity |
|
20 |
<< ui->cbLaserSight |
|
21 |
<< ui->cbInvulnerable |
|
22 |
<< ui->cbMines |
|
23 |
<< ui->cbVampiric |
|
24 |
<< ui->cbKarma |
|
25 |
<< ui->cbArtillery |
|
26 |
<< ui->cbOneClanMode |
|
27 |
; |
|
2572 | 28 |
} |
29 |
||
30 |
editor::~editor() |
|
31 |
{ |
|
32 |
delete ui; |
|
33 |
} |
|
2583 | 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 | 44 |
void editor::on_actionLoad_triggered() |
45 |
{ |
|
46 |
QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)"); |
|
47 |
||
48 |
if(!fileName.isEmpty()) |
|
49 |
load(fileName); |
|
50 |
} |
|
51 |
||
52 |
void editor::load(const QString & fileName) |
|
53 |
{ |
|
2594 | 54 |
int currTeam = -1; |
55 |
||
2583 | 56 |
QFile file(fileName); |
57 |
||
58 |
if(!file.open(QIODevice::ReadOnly)) |
|
59 |
{ |
|
60 |
QMessageBox::warning(this, "File error", "No such file"); |
|
61 |
return ; |
|
62 |
} |
|
63 |
||
64 |
QTextStream stream(&file); |
|
65 |
||
66 |
while(!stream.atEnd()) |
|
67 |
{ |
|
68 |
QString line = stream.readLine(); |
|
69 |
if (line.startsWith("seed")) |
|
70 |
ui->leSeed->setText(line.mid(5)); |
|
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 | 78 |
if (line.startsWith("$turntime")) |
79 |
ui->sbTurnTime->setValue(line.mid(10).toInt()); |
|
80 |
else |
|
81 |
if (line.startsWith("$casefreq")) |
|
82 |
ui->sbCrateDrops->setValue(line.mid(10).toInt()); |
|
83 |
else |
|
84 |
if (line.startsWith("$damagepct")) |
|
85 |
ui->sbDamageModifier->setValue(line.mid(11).toInt()); |
|
86 |
else |
|
87 |
if (line.startsWith("$gmflags")) |
|
88 |
{ |
|
89 |
quint32 flags = line.mid(9).toInt(); |
|
90 |
foreach(QCheckBox * cb, cbFlags) |
|
91 |
{ |
|
92 |
cb->setChecked(flags & 1); |
|
93 |
flags >>= 1; |
|
94 |
} |
|
95 |
} |
|
2594 | 96 |
else |
97 |
if (line.startsWith("addteam") && (currTeam < 5)) |
|
98 |
{ |
|
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 | 103 |
line = line.mid(8); |
104 |
int spacePos = line.indexOf('\x20'); |
|
105 |
quint32 teamColor = line.left(spacePos).toUInt(); |
|
106 |
QString teamName = line.mid(spacePos + 1); |
|
107 |
||
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 | 123 |
} |
124 |
else |
|
125 |
if (line.startsWith("fort") && (currTeam >= 0)) |
|
126 |
{ |
|
127 |
TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam)); |
|
128 |
te->setFort(line.mid(5)); |
|
129 |
} |
|
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 | 148 |
if (line.startsWith("grave") && (currTeam >= 0)) |
149 |
{ |
|
150 |
TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam)); |
|
151 |
te->setGrave(line.mid(6)); |
|
152 |
} |
|
153 |
else |
|
154 |
if (line.startsWith("voicepack") && (currTeam >= 0)) |
|
155 |
{ |
|
156 |
TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam)); |
|
157 |
te->setVoicepack(line.mid(10)); |
|
158 |
} |
|
2583 | 159 |
} |
160 |
} |