Script combobox.wiki qmlfrontend
authorunc0rr
Thu, 04 Dec 2014 00:34:40 +0300
branchqmlfrontend
changeset 10612 eb3c1a289a23
parent 10610 eadf2cea55e0
child 10614 4afb4c4bf495
Script combobox.wiki
hedgewars/hwLibrary.pas
hedgewars/uFLGameConfig.pas
hedgewars/uFLScripts.pas
hedgewars/uFLTeams.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/hwLibrary.pas	Wed Dec 03 23:36:18 2014 +0300
+++ b/hedgewars/hwLibrary.pas	Thu Dec 04 00:34:40 2014 +0300
@@ -156,6 +156,7 @@
     setSeed,
     getSeed,
     setTheme,
+    setScript,
     getThemesList,
     freeThemesList,
     getThemeIcon,
@@ -164,7 +165,7 @@
     tryAddTeam,
     tryRemoveTeam,
     changeTeamColor,
-    
+
     // dunno what these are
     RunEngine,
     LoadLocaleWrapper,
--- a/hedgewars/uFLGameConfig.pas	Wed Dec 03 23:36:18 2014 +0300
+++ b/hedgewars/uFLGameConfig.pas	Thu Dec 04 00:34:40 2014 +0300
@@ -12,6 +12,7 @@
 procedure setSeed(seed: PChar); cdecl;
 function  getSeed: PChar; cdecl;
 procedure setTheme(themeName: PChar); cdecl;
+procedure setScript(scriptName: PChar); cdecl;
 
 procedure tryAddTeam(teamName: PChar); cdecl;
 procedure tryRemoveTeam(teamName: PChar); cdecl;
@@ -52,13 +53,18 @@
 begin
     case gameType of
     gtPreview: begin
+            if script <> '' then
+                ipcToEngine('escript ' + script);
             ipcToEngine('eseed ' + seed);
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
         end;
     gtLocal: begin
+            if script <> '' then
+                ipcToEngine('escript ' + script);
             ipcToEngine('eseed ' + seed);
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
             ipcToEngine('e$theme ' + theme);
+
             i:= 0;
             while (i < 8) and (teams[i].hogsNumber > 0) do
                 begin
@@ -309,4 +315,12 @@
     currentConfig.theme:= themeName
 end;
 
+procedure setScript(scriptName: PChar); cdecl;
+begin
+    if scriptName <> 'Normal' then
+        currentConfig.script:= '/Scripts/Multiplayer/' + scriptName + '.lua'
+    else
+        currentConfig.script:= ''
+end;
+
 end.
--- a/hedgewars/uFLScripts.pas	Wed Dec 03 23:36:18 2014 +0300
+++ b/hedgewars/uFLScripts.pas	Thu Dec 04 00:34:40 2014 +0300
@@ -54,7 +54,7 @@
     l: Longword;
 begin
     filesList:= pfsEnumerateFiles('/Scripts/Multiplayer');
-    scriptsNumber:= 0;
+    scriptsNumber:= 1;
 
     tmp:= filesList;
     while tmp^ <> nil do
@@ -66,9 +66,16 @@
         inc(tmp)
     end;
 
-    scriptsList:= GetMem(sizeof(scriptsList^) * scriptsNumber);
+    scriptsList:= GetMem(sizeof(scriptsList^) * (scriptsNumber + 1));
 
     script:= scriptsList;
+
+    // add 'normal' script
+    script^.scriptName:= 'Normal';
+    script^.description:= 'Normal gameplay';
+    inc(script);
+
+    // fill the rest from *.lua list
     tmp:= filesList;
     while tmp^ <> nil do
     begin
--- a/hedgewars/uFLTeams.pas	Wed Dec 03 23:36:18 2014 +0300
+++ b/hedgewars/uFLTeams.pas	Thu Dec 04 00:34:40 2014 +0300
@@ -50,8 +50,8 @@
         ipcToEngine('eaddteam <hash> ' + colorsSet[color] + ' ' + teamName);
         for i:= 0 to Pred(hogsNumber) do
         begin
-            ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 ' + hedgehogs[i].name);
-            ipcToEngine('ehat ' + hedgehogs[i].hat);
+            ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 hog');// + hedgehogs[i].name);
+            //ipcToEngine('ehat ' + hedgehogs[i].hat);
         end;
     end
 end;
--- a/qmlFrontend/flib.h	Wed Dec 03 23:36:18 2014 +0300
+++ b/qmlFrontend/flib.h	Thu Dec 04 00:34:40 2014 +0300
@@ -35,7 +35,8 @@
 typedef void resetGameConfig_t();
 typedef void setSeed_t(const char * seed);
 typedef char *getSeed_t();
-typedef void setTheme_t(const char * theme);
+typedef void setTheme_t(const char * themeName);
+typedef void setScript_t(const char * scriptName);
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
 typedef void flibFree_t();
 
--- a/qmlFrontend/hwengine.cpp	Wed Dec 03 23:36:18 2014 +0300
+++ b/qmlFrontend/hwengine.cpp	Thu Dec 04 00:34:40 2014 +0300
@@ -14,6 +14,7 @@
     setSeed_t *flibSetSeed;
     getSeed_t *flibGetSeed;
     setTheme_t *flibSetTheme;
+    setScript_t *flibSetScript;
     getPreview_t *flibGetPreview;
     runQuickGame_t *flibRunQuickGame;
     runLocalGame_t *flibRunLocalGame;
@@ -45,15 +46,17 @@
 
     flibRunEngine = (RunEngine_t*) hwlib.resolve("RunEngine");
     flibRegisterGUIMessagesCallback = (registerGUIMessagesCallback_t*) hwlib.resolve("registerGUIMessagesCallback");
-    flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
     flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed");
-    flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme");
     flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview");
     flibRunQuickGame = (runQuickGame_t*) hwlib.resolve("runQuickGame");
     flibRunLocalGame = (runLocalGame_t*) hwlib.resolve("runLocalGame");
     flibInit = (flibInit_t*) hwlib.resolve("flibInit");
     flibFree = (flibFree_t*) hwlib.resolve("flibFree");
 
+    flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
+    flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme");
+    flibSetScript = (setScript_t*) hwlib.resolve("setScript");
+
     flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
     flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
     flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
@@ -176,6 +179,17 @@
     flibFreeThemesList(themes);
 
     m_engine->rootContext()->setContextProperty("themesModel", QVariant::fromValue(resultModel));
+
+    resultModel.clear();
+    char ** scripts = flibGetScriptsList();
+
+    for (char **i = scripts; *i != NULL; i++) {
+        QString script = QString::fromUtf8(*i);
+
+        resultModel << script;
+    }
+
+    m_engine->rootContext()->setContextProperty("scriptsModel", QVariant::fromValue(resultModel));
 }
 
 void HWEngine::getTeamsList()
@@ -212,3 +226,8 @@
 {
     flibSetTheme(theme.toUtf8().constData());
 }
+
+void HWEngine::setScript(const QString &script)
+{
+    flibSetScript(script.toUtf8().constData());
+}
--- a/qmlFrontend/hwengine.h	Wed Dec 03 23:36:18 2014 +0300
+++ b/qmlFrontend/hwengine.h	Thu Dec 04 00:34:40 2014 +0300
@@ -24,7 +24,9 @@
     Q_INVOKABLE QString currentSeed();
     Q_INVOKABLE void getTeamsList();
     Q_INVOKABLE void resetGameConfig();
+
     Q_INVOKABLE void setTheme(const QString & theme);
+    Q_INVOKABLE void setScript(const QString & script);
 
     Q_INVOKABLE void tryAddTeam(const QString & teamName);
     Q_INVOKABLE void tryRemoveTeam(const QString & teamName);
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Wed Dec 03 23:36:18 2014 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Thu Dec 04 00:34:40 2014 +0300
@@ -69,24 +69,38 @@
         }
     }
 
-/*    Rectangle {
-        x: 320
-        y: 16
-        width: 100
-        height: 256
-        color: "#15193a"
-        radius: 8
-        border.width: 4
-        border.color: "#eaea00"
-        Image {
-            id: themeImage
-            x: 0
-            y: 0
-            width: 64
-            height: 64
-            fillMode: Image.Pad
+    HWComboBox {
+        id: cbScript
+        x: 50
+        y: 256
+        width: 256
+        height: 64
+
+        model: scriptsModel
+        delegate: Rectangle {
+            height: 25
+            width: 100
+            color: "transparent"
+
+            property string itemIconSource: ""
+            property alias itemText: scriptName.text
+
+            Row {
+                //Image {id: themeIcon; width: height; height: parent.height; source: "image://theme/" + modelData}
+                Text {id: scriptName; text: modelData }
+            }
+
+            MouseArea {
+                 z: 1
+                 anchors.fill: parent
+                 onClicked: {
+                     cbScript.currentIndex = index
+                     HWEngine.setScript(scriptName.text)
+                 }
+            }
         }
-*/
+    }
+
 
     ListView {
         id: playingTeamsList