Compete loading teams/hedgehogs part from mission config
authorunc0rr
Sun, 01 Nov 2009 17:19:55 +0000
changeset 2596 41b46f83d088
parent 2595 d57af3defd56
child 2597 f777ac80ffef
Compete loading teams/hedgehogs part from mission config
tools/MissionsEditor/MissionsEditor.pro
tools/MissionsEditor/editor.cpp
tools/MissionsEditor/editor.h
tools/MissionsEditor/editor.ui
tools/MissionsEditor/hedgehogedit.cpp
tools/MissionsEditor/hedgehogedit.h
tools/MissionsEditor/hedgehogedit.ui
tools/MissionsEditor/teamedit.cpp
tools/MissionsEditor/teamedit.h
tools/MissionsEditor/teamedit.ui
--- a/tools/MissionsEditor/MissionsEditor.pro	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/MissionsEditor.pro	Sun Nov 01 17:19:55 2009 +0000
@@ -5,8 +5,11 @@
 TEMPLATE = app
 SOURCES += main.cpp \
     editor.cpp \
-    teamedit.cpp
+    teamedit.cpp \
+    hedgehogedit.cpp
 HEADERS += editor.h \
-    teamedit.h
+    teamedit.h \
+    hedgehogedit.h
 FORMS += editor.ui \
-    teamedit.ui
+    teamedit.ui \
+    hedgehogedit.ui
--- a/tools/MissionsEditor/editor.cpp	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/editor.cpp	Sun Nov 01 17:19:55 2009 +0000
@@ -8,6 +8,8 @@
 {
     ui->setupUi(this);
 
+    reset();
+
     cbFlags
         << ui->cbForts
         << ui->cbMultiWeapon
@@ -30,6 +32,15 @@
     delete ui;
 }
 
+void editor::reset()
+{
+    for(int i = 0; i < 6; ++i)
+    {
+        ui->twTeams->setTabEnabled(i, false);
+        ui->twTeams->widget(i)->setEnabled(false);
+    }
+}
+
 void editor::on_actionLoad_triggered()
 {
     QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), "Missions (*.txt)");
@@ -86,13 +97,29 @@
         if (line.startsWith("addteam") && (currTeam < 5))
         {
             ++currTeam;
+            ui->twTeams->setTabEnabled(currTeam, true);
+            ui->twTeams->widget(currTeam)->setEnabled(true);
+
             line = line.mid(8);
             int spacePos = line.indexOf('\x20');
             quint32 teamColor = line.left(spacePos).toUInt();
             QString teamName = line.mid(spacePos + 1);
 
             TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
-            te->addTeam(teamName, teamColor);
+            te->setTeam(teamName, teamColor);
+        }
+        else
+        if (line.startsWith("addhh") && (currTeam >= 0))
+        {
+            line = line.mid(6);
+            quint32 level = line.left(1).toUInt();
+            line = line.mid(2);
+            int spacePos = line.indexOf('\x20');
+            quint32 health = line.left(spacePos).toUInt();
+            QString hhName = line.mid(spacePos + 1);
+
+            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
+            te->addHedgehog(level, health, hhName);
         }
         else
         if (line.startsWith("fort") && (currTeam >= 0))
@@ -101,6 +128,23 @@
             te->setFort(line.mid(5));
         }
         else
+        if (line.startsWith("hat") && (currTeam >= 0))
+        {
+            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
+            te->setLastHHHat(line.mid(4));
+        }
+        else
+        if (line.startsWith("hhcoords") && (currTeam >= 0))
+        {
+            line = line.mid(9);
+            int spacePos = line.indexOf('\x20');
+            int x = line.left(spacePos).toUInt();
+            int y = line.mid(spacePos + 1).toInt();
+
+            TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
+            te->setLastHHCoords(x, y);
+        }
+        else
         if (line.startsWith("grave") && (currTeam >= 0))
         {
             TeamEdit * te = qobject_cast<TeamEdit *>(ui->twTeams->widget(currTeam));
--- a/tools/MissionsEditor/editor.h	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/editor.h	Sun Nov 01 17:19:55 2009 +0000
@@ -23,6 +23,7 @@
     QList<QCheckBox  *> cbFlags;
 
     void load(const QString & fileName);
+    void reset();
 
 private slots:
     void on_actionLoad_triggered();
--- a/tools/MissionsEditor/editor.ui	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/editor.ui	Sun Nov 01 17:19:55 2009 +0000
@@ -306,6 +306,9 @@
         </item>
         <item row="1" column="0" colspan="2">
          <widget class="QTabWidget" name="twTeams">
+          <property name="enabled">
+           <bool>true</bool>
+          </property>
           <property name="currentIndex">
            <number>0</number>
           </property>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/MissionsEditor/hedgehogedit.cpp	Sun Nov 01 17:19:55 2009 +0000
@@ -0,0 +1,43 @@
+#include "hedgehogedit.h"
+#include "ui_hedgehogedit.h"
+
+HedgehogEdit::HedgehogEdit(QWidget *parent) :
+    QFrame(parent),
+    m_ui(new Ui::HedgehogEdit)
+{
+    m_ui->setupUi(this);
+}
+
+HedgehogEdit::~HedgehogEdit()
+{
+    delete m_ui;
+}
+
+void HedgehogEdit::changeEvent(QEvent *e)
+{
+    QWidget::changeEvent(e);
+    switch (e->type()) {
+    case QEvent::LanguageChange:
+        m_ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+void HedgehogEdit::setHedgehog(quint32 level, quint32 health, const QString & name)
+{
+    m_ui->cbLevel->setCurrentIndex(level);
+    m_ui->sbHealth->setValue(health);
+    m_ui->leName->setText(name);
+}
+
+void HedgehogEdit::setHat(const QString & name)
+{
+    m_ui->leHat->setText(name);
+}
+
+void HedgehogEdit::setCoordinates(int x, int y)
+{
+    m_ui->pbCoordinates->setText(QString("%1x%2").arg(x).arg(y));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/MissionsEditor/hedgehogedit.h	Sun Nov 01 17:19:55 2009 +0000
@@ -0,0 +1,27 @@
+#ifndef HEDGEHOGEDIT_H
+#define HEDGEHOGEDIT_H
+
+#include <QtGui/QFrame>
+
+namespace Ui {
+    class HedgehogEdit;
+}
+
+class HedgehogEdit : public QFrame {
+    Q_OBJECT
+public:
+    HedgehogEdit(QWidget *parent = 0);
+    ~HedgehogEdit();
+
+    void setHedgehog(quint32 level = 0, quint32 health = 100, const QString & name = QString());
+    void setHat(const QString & name);
+    void setCoordinates(int x, int y);
+
+protected:
+    void changeEvent(QEvent *e);
+
+private:
+    Ui::HedgehogEdit *m_ui;
+};
+
+#endif // HEDGEHOGEDIT_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/MissionsEditor/hedgehogedit.ui	Sun Nov 01 17:19:55 2009 +0000
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>HedgehogEdit</class>
+ <widget class="QFrame" name="HedgehogEdit">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <property name="frameShape">
+   <enum>QFrame::StyledPanel</enum>
+  </property>
+  <property name="frameShadow">
+   <enum>QFrame::Raised</enum>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <property name="margin">
+    <number>3</number>
+   </property>
+   <property name="spacing">
+    <number>3</number>
+   </property>
+   <item row="0" column="1" colspan="2">
+    <widget class="QLineEdit" name="leName"/>
+   </item>
+   <item row="0" column="3">
+    <widget class="QToolButton" name="toolButton">
+     <property name="text">
+      <string>X</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QComboBox" name="cbLevel">
+     <property name="currentIndex">
+      <number>0</number>
+     </property>
+     <item>
+      <property name="text">
+       <string>Human</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Level 5</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Level 4</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Level 3</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Level 2</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Level 1</string>
+      </property>
+     </item>
+    </widget>
+   </item>
+   <item row="3" column="1">
+    <widget class="QLineEdit" name="leHat"/>
+   </item>
+   <item row="0" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Name</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="label_2">
+     <property name="text">
+      <string>Level</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1">
+    <widget class="QSpinBox" name="sbHealth">
+     <property name="minimum">
+      <number>1</number>
+     </property>
+     <property name="maximum">
+      <number>300</number>
+     </property>
+     <property name="value">
+      <number>100</number>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <widget class="QLabel" name="label_3">
+     <property name="text">
+      <string>Health</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <widget class="QLabel" name="label_4">
+     <property name="text">
+      <string>Hat</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1">
+    <widget class="QPushButton" name="pbCoordinates">
+     <property name="text">
+      <string>Random</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0">
+    <widget class="QLabel" name="label_5">
+     <property name="text">
+      <string>Place</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--- a/tools/MissionsEditor/teamedit.cpp	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/teamedit.cpp	Sun Nov 01 17:19:55 2009 +0000
@@ -6,6 +6,8 @@
     m_ui(new Ui::TeamEdit)
 {
     m_ui->setupUi(this);
+
+    reset();
 }
 
 TeamEdit::~TeamEdit()
@@ -25,7 +27,15 @@
     }
 }
 
-void TeamEdit::addTeam(const QString & teamName, quint32 color)
+void TeamEdit::reset()
+{
+   QLayout * l = m_ui->scrollArea->widget()->layout();
+
+   for(int i = 0; i < 8; ++i)
+       l->itemAt(i)->widget()->setVisible(false);
+}
+
+void TeamEdit::setTeam(const QString & teamName, quint32 color)
 {
     m_ui->leTeamName->setText(teamName);
 }
@@ -45,3 +55,44 @@
     m_ui->leVoicepack->setText(name);
 }
 
+void TeamEdit::addHedgehog(quint32 level, quint32 health, const QString & name)
+{
+   QLayout * l = m_ui->scrollArea->widget()->layout();
+
+   int i = 0;
+   while((i < 8) && (l->itemAt(i)->widget()->isVisible())) ++i;
+
+   if(i < 8)
+   {
+       HedgehogEdit * he = qobject_cast<HedgehogEdit *>(l->itemAt(i)->widget());
+       he->setHedgehog(level, health, name);
+       l->itemAt(i)->widget()->setVisible(true);
+   }
+}
+
+void TeamEdit::setLastHHHat(const QString & name)
+{
+   QLayout * l = m_ui->scrollArea->widget()->layout();
+
+   int i = 0;
+   while((i < 8) && (l->itemAt(i)->widget()->isVisible())) ++i;
+
+   --i;
+
+   HedgehogEdit * he = qobject_cast<HedgehogEdit *>(l->itemAt(i)->widget());
+   he->setHat(name);
+}
+
+void TeamEdit::setLastHHCoords(int x, int y)
+{
+   QLayout * l = m_ui->scrollArea->widget()->layout();
+
+   int i = 0;
+   while((i < 8) && (l->itemAt(i)->widget()->isVisible())) ++i;
+
+   --i;
+
+   HedgehogEdit * he = qobject_cast<HedgehogEdit *>(l->itemAt(i)->widget());
+   he->setCoordinates(x ,y);
+}
+
--- a/tools/MissionsEditor/teamedit.h	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/teamedit.h	Sun Nov 01 17:19:55 2009 +0000
@@ -13,9 +13,13 @@
     TeamEdit(QWidget *parent = 0);
     ~TeamEdit();
 
-    void addTeam(const QString & teamName = QString(), quint32 color = 0xdd0000);
+    void reset();
+    void setTeam(const QString & teamName = QString(), quint32 color = 0xdd0000);
+    void addHedgehog(quint32 level = 0, quint32 health = 100, const QString & name = QString());
     void setFort(const QString & name);
     void setGrave(const QString & name);
+    void setLastHHHat(const QString & name);
+    void setLastHHCoords(int x, int y);
     void setVoicepack(const QString & name);
 protected:
     void changeEvent(QEvent *e);
--- a/tools/MissionsEditor/teamedit.ui	Fri Oct 30 19:41:39 2009 +0000
+++ b/tools/MissionsEditor/teamedit.ui	Sun Nov 01 17:19:55 2009 +0000
@@ -68,23 +68,66 @@
      </item>
     </layout>
    </item>
-   <item row="1" column="0" rowspan="4">
-    <widget class="QTreeWidget" name="treeWidget">
-     <column>
-      <property name="text">
-       <string>Name</string>
+   <item row="1" column="0" rowspan="3">
+    <widget class="QScrollArea" name="scrollArea">
+     <property name="widgetResizable">
+      <bool>true</bool>
+     </property>
+     <widget class="QWidget" name="scrollAreaWidgetContents">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>301</width>
+        <height>235</height>
+       </rect>
       </property>
-     </column>
-     <column>
-      <property name="text">
-       <string>Health</string>
-      </property>
-     </column>
-     <column>
-      <property name="text">
-       <string>Spawn pos</string>
-      </property>
-     </column>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <property name="spacing">
+        <number>3</number>
+       </property>
+       <property name="margin">
+        <number>4</number>
+       </property>
+       <item>
+        <widget class="HedgehogEdit" name="widget" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_3" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_4" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_5" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_6" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_7" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_8" native="true"/>
+       </item>
+       <item>
+        <widget class="HedgehogEdit" name="widget_2" native="true"/>
+       </item>
+       <item>
+        <spacer name="verticalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>120</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
    <item row="1" column="1">
@@ -95,13 +138,6 @@
     </widget>
    </item>
    <item row="2" column="1">
-    <widget class="QPushButton" name="pbDeleteHedgehog">
-     <property name="text">
-      <string>Delete hedgehog</string>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="1">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
@@ -114,7 +150,7 @@
      </property>
     </spacer>
    </item>
-   <item row="4" column="1">
+   <item row="3" column="1">
     <widget class="QPushButton" name="pbDeleteTeam">
      <property name="text">
       <string>Delete team</string>
@@ -123,6 +159,14 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>HedgehogEdit</class>
+   <extends>QWidget</extends>
+   <header>hedgehogedit.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>