Frontend:
authorsmxx
Sat, 10 Apr 2010 21:36:40 +0000
changeset 3333 560e2766c445
parent 3332 3c90a923f156
child 3334 f94a52a763d4
Frontend: * Hedgewars will now use a sub directory of "My Documents" like other games instead of "%userprofile%/.hedgewars" under Windows * Teams are now saved in ini format to allow easier addition of future stats/properties * Due to those changes old files/settings/teams will be ignored
QTfrontend/gameuiconfig.cpp
QTfrontend/main.cpp
QTfrontend/team.cpp
hedgewars/uStore.pas
--- a/QTfrontend/gameuiconfig.cpp	Sat Apr 10 20:48:09 2010 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Sat Apr 10 21:36:40 2010 +0000
@@ -94,10 +94,12 @@
 
 QStringList GameUIConfig::GetTeamsList()
 {
-    QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
+    QDir teamdir;
+    teamdir.cd(cfgdir->absolutePath() + "/Teams");
+    QStringList teamslist = teamdir.entryList(QStringList("*.ini"));
     QStringList cleanedList;
     for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
-            QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1");
+            QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.ini$"), "\\1");
             cleanedList.push_back(tmpTeamStr);
     }
     return cleanedList;
--- a/QTfrontend/main.cpp	Sat Apr 10 20:48:09 2010 +0000
+++ b/QTfrontend/main.cpp	Sat Apr 10 21:36:40 2010 +0000
@@ -28,6 +28,10 @@
 #include "hwform.h"
 #include "hwconsts.h"
 
+#ifdef _WIN32
+#include <Shlobj.h>
+#endif
+
 bool checkForDir(const QString & dir)
 {
     QDir tmpdir;
@@ -307,13 +311,38 @@
         {
             checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos");
             checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves");
+            checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Teams");
         }
         cfgdir->cd("Library/Application Support/Hedgewars");
+#elif defined _WIN32
+        char path[1024];
+        if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path))
+        {
+            cfgdir->cd(path);
+            if (checkForDir(cfgdir->absolutePath() + "/Hedgewars"))
+            {
+                checkForDir(cfgdir->absolutePath() + "/Hedgewars/Demos");
+                checkForDir(cfgdir->absolutePath() + "/Hedgewars/Saves");
+                checkForDir(cfgdir->absolutePath() + "/Hedgewars/Teams");
+            }
+            cfgdir->cd("Hedgewars");
+        }
+        else
+        {
+            if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
+            {
+                checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
+                checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
+                checkForDir(cfgdir->absolutePath() + "/.hedgewars/Teams");
+            }
+            cfgdir->cd(".hedgewars");
+        }
 #else
         if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
         {
             checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
             checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
+            checkForDir(cfgdir->absolutePath() + "/.hedgewars/Teams");
         }
         cfgdir->cd(".hedgewars");
 #endif
@@ -324,6 +353,7 @@
         {
             checkForDir(cfgdir->absolutePath() + "/Demos");
             checkForDir(cfgdir->absolutePath() + "/Saves");
+            checkForDir(cfgdir->absolutePath() + "/Teams");
         }
     }
 
--- a/QTfrontend/team.cpp	Sat Apr 10 20:48:09 2010 +0000
+++ b/QTfrontend/team.cpp	Sat Apr 10 21:36:40 2010 +0000
@@ -22,6 +22,7 @@
 #include <QStringList>
 #include <QLineEdit>
 #include <QCryptographicHash>
+#include <QSettings>
 #include "team.h"
 #include "hwform.h"
 #include "pages.h"
@@ -101,82 +102,26 @@
 
 bool HWTeam::LoadFromFile()
 {
-    numHedgehogs=4;
-    QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg");
-    if (!cfgfile.open(QIODevice::ReadOnly)) return false;
-    QTextStream stream(&cfgfile);
-    stream.setCodec("UTF-8");
-    QString str;
-    QString action;
-
-    while (!stream.atEnd())
+    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".ini", QSettings::IniFormat, 0);
+    teamfile.setIniCodec("UTF-8");
+    TeamName = teamfile.value("Team/Name", TeamName).toString();
+    Grave = teamfile.value("Team/Grave", "Statue").toString();
+    Fort = teamfile.value("Team/Fort", "Plane").toString();
+    Voicepack = teamfile.value("Team/Voicepack", "Default").toString();
+    Flag = teamfile.value("Team/Flag", "hedgewars").toString();
+    difficulty = teamfile.value("Team/Difficulty", 0).toInt();
+    for(int i = 0; i < 8; i++)
     {
-        str = stream.readLine();
-        if (str.startsWith(";")) continue;
-        /*if (str.startsWith("name team "))
-        {
-            str.remove(0, 10);
-            TeamName = str;
-        } else*/
-        if (str.startsWith("name hh"))
-        {
-            str.remove(0, 7);
-            long i = str.left(1).toLong();
-            if ((i < 0) || (i > 7)) continue;
-            str.remove(0, 2);
-            HHName[i] = str;
-        } else
-        if (str.startsWith("hat"))
-        {
-            str.remove(0, 3);
-            long i = str.left(1).toLong();
-            if ((i < 0) || (i > 7)) continue;
-            str.remove(0, 2);
-            HHHat[i] = str;
-// Somehow claymore managed an empty hat.  Until we figure out how, this should avoid a repeat
-            if (HHHat[i].length() == 0) HHHat[i] = "NoHat"; 
-        } else
-        if (str.startsWith("grave "))
-        {
-            str.remove(0, 6);
-            Grave = str;
-        } else
-        if (str.startsWith("fort "))
-        {
-            str.remove(0, 5);
-            Fort = str;
-        } else
-        if (str.startsWith("flag "))
-        {
-            str.remove(0, 5);
-            Flag = str;
-        } else
-        if (str.startsWith("voicepack "))
-        {
-            str.remove(0, 10);
-            Voicepack = str;
-        } else
-        if (str.startsWith("bind "))
-        {
-            str.remove(0, 5);
-            action = str.section(' ', 1);
-            str = str.section(' ', 0, 0);
-            str.truncate(15);
-            for (int i = 0; i < BINDS_NUMBER; i++)
-                if (action == binds[i].action)
-                {
-                    binds[i].strbind = str;
-                    break;
-                }
-        } else
-        if (str.startsWith("difficulty "))
-        {
-          str.remove(0, 11);
-          difficulty=str.toUInt();
-          if (difficulty>5) difficulty=0; // this shouldn't normally happen
-        }
+        QString hh = QString("Hedgehog%1/").arg(i);
+        HHName[i] = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i)).toString();
+        HHHat[i] = teamfile.value(hh + "Hat", "NoHat").toString();
+        //teamfile.setValue(hh + "Kills", 0);
+        //teamfile.setValue(hh + "Deaths", 0);
+        //teamfile.setValue(hh + "Rounds", 0);
+        //teamfile.setValue(hh + "Suicides", 0);
     }
-    cfgfile.close();
+    for(int i = 0; i < BINDS_NUMBER; i++)
+        binds[i].action = teamfile.value(QString("Binds/%1").arg(binds[i].strbind), cbinds[i].action).toString();
     return true;
 }
 
@@ -184,11 +129,8 @@
 {
     if(m_isNetTeam)
         return false;
-
-    QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg");
+    QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".ini");
     cfgfile.remove();
-
-        
     return true;
 }
 
@@ -196,31 +138,30 @@
 {
     if (OldTeamName != TeamName)
     {
-        QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg");
+        QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + OldTeamName + ".ini");
         cfgfile.remove();
         OldTeamName = TeamName;
     }
-    QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg");
-    if (!cfgfile.open(QIODevice::WriteOnly)) return false;
-    QTextStream stream(&cfgfile);
-    stream.setCodec("UTF-8");
-    stream << "; Generated by Hedgewars, do not modify" << endl;
-    stream << "name team " << TeamName << endl;
-    for (int i = 0; i < 8; i++)
+    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".ini", QSettings::IniFormat, 0);
+    teamfile.setIniCodec("UTF-8");
+    teamfile.setValue("Team/Name", TeamName);
+    teamfile.setValue("Team/Grave", Grave);
+    teamfile.setValue("Team/Fort", Fort);
+    teamfile.setValue("Team/Voicepack", Voicepack);
+    teamfile.setValue("Team/Flag", Flag);
+    teamfile.setValue("Team/Difficulty", difficulty);
+    for(int i = 0; i < 8; i++)
     {
-        stream << "name hh" << i << " " << HHName[i] << endl;
-        stream << "hat" << i << " " << HHHat[i] << endl;
+        QString hh = QString("Hedgehog%1/").arg(i);
+        teamfile.setValue(hh + "Name", HHName[i]);
+        teamfile.setValue(hh + "Hat", HHHat[i]);
+        teamfile.setValue(hh + "Kills", 0);
+        teamfile.setValue(hh + "Deaths", 0);
+        teamfile.setValue(hh + "Rounds", 0);
+        teamfile.setValue(hh + "Suicides", 0);
     }
-    stream << "grave " << Grave << endl;
-    stream << "fort " << Fort << endl;
-    stream << "voicepack " << Voicepack << endl;
-    stream << "flag " << Flag << endl;
     for(int i = 0; i < BINDS_NUMBER; i++)
-    {
-        stream << "bind " << binds[i].strbind << " " << binds[i].action << endl;
-    }
-    stream << "difficulty " << difficulty << endl;
-    cfgfile.close();
+        teamfile.setValue(QString("Binds/%1").arg(binds[i].strbind), binds[i].action);
     return true;
 }
 
--- a/hedgewars/uStore.pas	Sat Apr 10 20:48:09 2010 +0000
+++ b/hedgewars/uStore.pas	Sat Apr 10 21:36:40 2010 +0000
@@ -1107,15 +1107,18 @@
 begin
 {$IFDEF IPHONEOS}
     glLoadExtension:= false;
+{$IFDEF DEBUGFILE}
+    AddFileLog('OpenGL - "' + extension + '" skipped')
+{$ENDIF}
 {$ELSE}
     glLoadExtension:= glext_LoadExtension(extension);
-{$ENDIF}
 {$IFDEF DEBUGFILE}
     if not glLoadExtension then
         AddFileLog('OpenGL - "' + extension + '" failed to load')
     else
         AddFileLog('OpenGL - "' + extension + '" loaded');
 {$ENDIF}
+{$ENDIF}
 end;
 
 procedure SetupOpenGL;