1 #include <QtGui> |
|
2 #include <QObject> |
|
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); |
|
10 |
|
11 reset(); |
|
12 |
|
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 ; |
|
28 } |
|
29 |
|
30 editor::~editor() |
|
31 { |
|
32 delete ui; |
|
33 } |
|
34 |
|
35 void editor::reset() |
|
36 { |
|
37 for(int i = 0; i < 6; ++i) |
|
38 { |
|
39 ui->twTeams->setTabEnabled(i, false); |
|
40 ui->twTeams->widget(i)->setEnabled(false); |
|
41 } |
|
42 } |
|
43 |
|
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 { |
|
54 int currTeam = -1; |
|
55 |
|
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 |
|
72 if (line.startsWith("map")) |
|
73 ui->leMap->setText(line.mid(4)); |
|
74 else |
|
75 if (line.startsWith("theme")) |
|
76 ui->leTheme->setText(line.mid(6)); |
|
77 else |
|
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 } |
|
96 else |
|
97 if (line.startsWith("addteam") && (currTeam < 5)) |
|
98 { |
|
99 ++currTeam; |
|
100 ui->twTeams->setTabEnabled(currTeam, true); |
|
101 ui->twTeams->widget(currTeam)->setEnabled(true); |
|
102 |
|
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)); |
|
109 te->setTeam(teamName, teamColor); |
|
110 } |
|
111 else |
|
112 if (line.startsWith("addhh") && (currTeam >= 0)) |
|
113 { |
|
114 line = line.mid(6); |
|
115 quint32 level = line.left(1).toUInt(); |
|
116 line = line.mid(2); |
|
117 int spacePos = line.indexOf('\x20'); |
|
118 quint32 health = line.left(spacePos).toUInt(); |
|
119 QString hhName = line.mid(spacePos + 1); |
|
120 |
|
121 TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam)); |
|
122 te->addHedgehog(level, health, hhName); |
|
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 |
|
131 if (line.startsWith("hat") && (currTeam >= 0)) |
|
132 { |
|
133 TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam)); |
|
134 te->setLastHHHat(line.mid(4)); |
|
135 } |
|
136 else |
|
137 if (line.startsWith("hhcoords") && (currTeam >= 0)) |
|
138 { |
|
139 line = line.mid(9); |
|
140 int spacePos = line.indexOf('\x20'); |
|
141 int x = line.left(spacePos).toUInt(); |
|
142 int y = line.mid(spacePos + 1).toInt(); |
|
143 |
|
144 TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam)); |
|
145 te->setLastHHCoords(x, y); |
|
146 } |
|
147 else |
|
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 } |
|
159 } |
|
160 } |
|