Load and show local teams list qmlfrontend
authorunc0rr
Mon, 20 Oct 2014 22:55:12 +0400
branchqmlfrontend
changeset 10442 c58db813240b
parent 10440 b74a7bbe224e
child 10444 47a6231f1fc1
Load and show local teams list
hedgewars/hwLibrary.pas
hedgewars/uFLTeams.pas
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/hwLibrary.pas	Mon Oct 13 23:46:49 2014 +0400
+++ b/hedgewars/hwLibrary.pas	Mon Oct 20 22:55:12 2014 +0400
@@ -43,6 +43,7 @@
     , uFLIPC
     , uPhysFSLayer
     , uFLData
+    , uFLTeams
     ;
 
 {$INCLUDE "config.inc"}
@@ -155,6 +156,7 @@
     getThemesList,
     freeThemesList,
     getThemeIcon,
+    getTeamsList,
     LoadLocaleWrapper,
     HW_versionInfo,
     HW_versionString,
--- a/hedgewars/uFLTeams.pas	Mon Oct 13 23:46:49 2014 +0400
+++ b/hedgewars/uFLTeams.pas	Mon Oct 20 22:55:12 2014 +0400
@@ -96,15 +96,17 @@
     s: shortstring;
     l: Longword;
 begin
-    filesList:= pfsEnumerateFiles('Teams');
+    filesList:= pfsEnumerateFiles('/Config/Teams');
     teamsNumber:= 0;
 
     tmp:= filesList;
     while tmp^ <> nil do
     begin
         s:= shortstring(tmp^);
+        writeln(stderr, '> ', s);
         l:= length(s);
-        if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then inc(teamsNumber)
+        if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then inc(teamsNumber);
+        inc(tmp)
     end;
 
     // TODO: no teams at all?
@@ -121,6 +123,7 @@
                 loadTeam(team^, '/Config/Teams/' + s);
                 inc(team)
             end;
+        inc(tmp)
     end;
 
     pfsFreeList(filesList)
@@ -144,7 +147,8 @@
         l:= length(team^.teamName);
         if l >= 255 then l:= 254;
         team^.teamName[l + 1]:= #0;
-        listOfTeamNames[i]:= @team^.teamName[1]
+        listOfTeamNames[i]:= @team^.teamName[1];
+        inc(team)
     end;
 
     listOfTeamNames[t]:= nil;
--- a/qmlFrontend/hwengine.cpp	Mon Oct 13 23:46:49 2014 +0400
+++ b/qmlFrontend/hwengine.cpp	Mon Oct 20 22:55:12 2014 +0400
@@ -20,6 +20,7 @@
     getThemesList_t *flibGetThemesList;
     freeThemesList_t *flibFreeThemesList;
     getThemeIcon_t *flibGetThemeIcon;
+    getTeamsList_t *flibGetTeamsList;
 }
 
 Q_DECLARE_METATYPE(MessageType);
@@ -48,6 +49,8 @@
     flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
     flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
 
+    flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList");
+
     flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
     flibRegisterGUIMessagesCallback(this, &guiMessagesCallback);
 
@@ -130,3 +133,13 @@
 
     m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel));
 }
+
+void HWEngine::getTeamsList()
+{
+    char ** teams = flibGetTeamsList();
+    for (char **i = teams; *i != NULL; i++) {
+        QString team = QString::fromUtf8(*i);
+
+        emit localTeamAdded(team, 0);
+    }
+}
--- a/qmlFrontend/hwengine.h	Mon Oct 13 23:46:49 2014 +0400
+++ b/qmlFrontend/hwengine.h	Mon Oct 20 22:55:12 2014 +0400
@@ -21,9 +21,11 @@
     Q_INVOKABLE void getPreview();
     Q_INVOKABLE void runQuickGame();
     Q_INVOKABLE QString currentSeed();
+    Q_INVOKABLE void getTeamsList();
     
 signals:
     void previewImageChanged();
+    void localTeamAdded(const QString & teamName, int aiLevel);
     
 public slots:
 
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Mon Oct 13 23:46:49 2014 +0400
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Mon Oct 20 22:55:12 2014 +0400
@@ -1,6 +1,7 @@
 import QtQuick 2.0
 import Hedgewars.Engine 1.0
 
+
 Rectangle {
     HWButton {
         id: btnPreview
@@ -70,4 +71,42 @@
             }
         }
     }
+
+    ListView {
+        id: playingTeamsList
+        x: 440
+        y: 16
+        width: 100
+        height: 192
+        highlight: Rectangle { color: "#eaea00"; radius: 4 }
+        focus: true
+        clip: true
+
+        model: ListModel {
+            id: localTeamsModel
+        }
+
+        delegate: Rectangle {
+            id: teamDelegate
+            height: 24
+            width: parent.width
+            radius: 8
+            border.width: 2
+            border.color: "#eaea00"
+
+            Row {
+                Text { text: name }
+            }
+        }
+
+        Connections {
+            target: HWEngine
+            onLocalTeamAdded: localTeamsModel.append({"aiLevel": aiLevel, "name": teamName})
+        }
+    }
+
+    Component.onCompleted: {
+        HWEngine.getTeamsList()
+        HWEngine.getPreview()
+    }
 }