Partially implement loading mission options
authorunc0rr
Sun, 25 Oct 2009 12:19:47 +0000
changeset 2583 f8da275981e5
parent 2582 e16668bac20f
child 2584 cc049fbb65ef
Partially implement loading mission options
hedgewars/uConsts.pas
tools/MissionsEditor/editor.cpp
tools/MissionsEditor/editor.h
tools/MissionsEditor/editor.ui
--- a/hedgewars/uConsts.pas	Sun Oct 25 10:39:12 2009 +0000
+++ b/hedgewars/uConsts.pas	Sun Oct 25 12:19:47 2009 +0000
@@ -265,7 +265,7 @@
 	gfVampiric     = $00000200;
 	gfKarma        = $00000400;
 	gfArtillery    = $00000800;
-	gfOneClanMode  = $10000000;
+	gfOneClanMode  = $00001000;
 
 	gstDrowning       = $00000001;
 	gstHHDriven       = $00000002;
--- a/tools/MissionsEditor/editor.cpp	Sun Oct 25 10:39:12 2009 +0000
+++ b/tools/MissionsEditor/editor.cpp	Sun Oct 25 12:19:47 2009 +0000
@@ -1,3 +1,4 @@
+#include <QtGui>
 #include "editor.h"
 #include "ui_editor.h"
 
@@ -5,9 +6,72 @@
     : QMainWindow(parent), ui(new Ui::editor)
 {
     ui->setupUi(this);
+
+    cbFlags
+        << ui->cbForts
+        << ui->cbMultiWeapon
+        << ui->cbSolidLand
+        << ui->cbBorder
+        << ui->cbDivideTeams
+        << ui->cbLowGravity
+        << ui->cbLaserSight
+        << ui->cbInvulnerable
+        << ui->cbMines
+        << ui->cbVampiric
+        << ui->cbKarma
+        << ui->cbArtillery
+        << ui->cbOneClanMode
+        ;
 }
 
 editor::~editor()
 {
     delete ui;
 }
+
+void editor::on_actionLoad_triggered()
+{
+    QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)");
+
+    if(!fileName.isEmpty())
+        load(fileName);
+}
+
+void editor::load(const QString & fileName)
+{
+    QFile file(fileName);
+
+    if(!file.open(QIODevice::ReadOnly))
+    {
+        QMessageBox::warning(this, "File error", "No such file");
+        return ;
+    }
+
+    QTextStream stream(&file);
+
+    while(!stream.atEnd())
+    {
+        QString line = stream.readLine();
+        if (line.startsWith("seed"))
+            ui->leSeed->setText(line.mid(5));
+        else
+        if (line.startsWith("$turntime"))
+            ui->sbTurnTime->setValue(line.mid(10).toInt());
+        else
+        if (line.startsWith("$casefreq"))
+            ui->sbCrateDrops->setValue(line.mid(10).toInt());
+        else
+        if (line.startsWith("$damagepct"))
+            ui->sbDamageModifier->setValue(line.mid(11).toInt());
+        else
+        if (line.startsWith("$gmflags"))
+        {
+            quint32 flags = line.mid(9).toInt();
+            foreach(QCheckBox * cb, cbFlags)
+            {
+                cb->setChecked(flags & 1);
+                flags >>= 1;
+            }
+        }
+    }
+}
--- a/tools/MissionsEditor/editor.h	Sun Oct 25 10:39:12 2009 +0000
+++ b/tools/MissionsEditor/editor.h	Sun Oct 25 12:19:47 2009 +0000
@@ -8,6 +8,8 @@
     class editor;
 }
 
+class QCheckBox;
+
 class editor : public QMainWindow
 {
     Q_OBJECT
@@ -18,6 +20,12 @@
 
 private:
     Ui::editor *ui;
+    QList<QCheckBox  *> cbFlags;
+
+    void load(const QString & fileName);
+
+private slots:
+    void on_actionLoad_triggered();
 };
 
 #endif // EDITOR_H
--- a/tools/MissionsEditor/editor.ui	Sun Oct 25 10:39:12 2009 +0000
+++ b/tools/MissionsEditor/editor.ui	Sun Oct 25 12:19:47 2009 +0000
@@ -18,8 +18,35 @@
     <item row="0" column="0">
      <widget class="QTabWidget" name="tabWidget">
       <property name="currentIndex">
-       <number>0</number>
+       <number>1</number>
       </property>
+      <widget class="QWidget" name="tab_4">
+       <attribute name="title">
+        <string>Mission</string>
+       </attribute>
+       <layout class="QGridLayout" name="gridLayout_3">
+        <item row="0" column="0">
+         <widget class="QLabel" name="label_4">
+          <property name="text">
+           <string>Name</string>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="1">
+         <widget class="QLineEdit" name="lineEdit"/>
+        </item>
+        <item row="1" column="0">
+         <widget class="QLabel" name="label_5">
+          <property name="text">
+           <string>Description</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="1">
+         <widget class="QTextEdit" name="textEdit"/>
+        </item>
+       </layout>
+      </widget>
       <widget class="QWidget" name="tab">
        <attribute name="title">
         <string>Options</string>
@@ -232,6 +259,11 @@
         </item>
        </layout>
       </widget>
+      <widget class="QWidget" name="tab_3">
+       <attribute name="title">
+        <string>Teams</string>
+       </attribute>
+      </widget>
       <widget class="QWidget" name="tab_2">
        <attribute name="title">
         <string>Triggers</string>
@@ -254,25 +286,25 @@
     <property name="title">
      <string>&amp;File</string>
     </property>
-    <addaction name="action_Load"/>
-    <addaction name="action_Save"/>
+    <addaction name="actionLoad"/>
+    <addaction name="actionSave"/>
     <addaction name="separator"/>
-    <addaction name="action_Quit"/>
+    <addaction name="actionQuit"/>
    </widget>
    <addaction name="menuFile"/>
   </widget>
   <widget class="QStatusBar" name="statusBar"/>
-  <action name="action_Load">
+  <action name="actionLoad">
    <property name="text">
     <string>&amp;Load...</string>
    </property>
   </action>
-  <action name="action_Save">
+  <action name="actionSave">
    <property name="text">
     <string>&amp;Save</string>
    </property>
   </action>
-  <action name="action_Quit">
+  <action name="actionQuit">
    <property name="text">
     <string>&amp;Quit</string>
    </property>