Ammo schemes list, almost works qmlfrontend
authorunc0rr
Wed, 08 Apr 2015 23:39:18 +0300
branchqmlfrontend
changeset 10888 a04e04aaf599
parent 10886 99273b7afbff
child 10890 24e68c7d2e79
Ammo schemes list, almost works
hedgewars/CMakeLists.txt
hedgewars/hwLibrary.pas
hedgewars/uFLGameConfig.pas
hedgewars/uFLScripts.pas
hedgewars/uFLTypes.pas
hedgewars/uPhysFSLayer.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/CMakeLists.txt	Thu Apr 02 21:09:56 2015 +0300
+++ b/hedgewars/CMakeLists.txt	Wed Apr 08 23:39:18 2015 +0300
@@ -104,6 +104,7 @@
     uGearsUtils.pas
     uTeams.pas
 
+    uFLAmmo.pas
     uFLData.pas
     uFLGameConfig.pas
     uFLIPC.pas
--- a/hedgewars/hwLibrary.pas	Thu Apr 02 21:09:56 2015 +0300
+++ b/hedgewars/hwLibrary.pas	Wed Apr 08 23:39:18 2015 +0300
@@ -46,6 +46,7 @@
     , uFLTeams
     , uFLScripts
     , uFLSchemes
+    , uFLAmmo
     ;
 
 {$INCLUDE "config.inc"}
@@ -159,11 +160,13 @@
     setTheme,
     setScript,
     setScheme,
+    setAmmo,
     getThemesList,
     freeThemesList,
     getThemeIcon,
     getScriptsList,
     getSchemesList,
+    getAmmosList,
     getTeamsList,
     tryAddTeam,
     tryRemoveTeam,
--- a/hedgewars/uFLGameConfig.pas	Thu Apr 02 21:09:56 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Wed Apr 08 23:39:18 2015 +0300
@@ -14,13 +14,14 @@
 procedure setTheme(themeName: PChar); cdecl;
 procedure setScript(scriptName: PChar); cdecl;
 procedure setScheme(schemeName: PChar); cdecl;
+procedure setAmmo(ammoName: PChar); cdecl;
 
 procedure tryAddTeam(teamName: PChar); cdecl;
 procedure tryRemoveTeam(teamName: PChar); cdecl;
 procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
 
 implementation
-uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes;
+uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo;
 
 var guiCallbackPointer: pointer;
     guiCallbackFunction: TGUICallback;
@@ -35,6 +36,7 @@
             theme: shortstring;
             script: shortstring;
             scheme: TScheme;
+            ammo: ansistring;
             mapgen: Longint;
             gameType: TGameType;
             teams: array[0..7] of TTeam;
@@ -336,4 +338,13 @@
         currentConfig.scheme:= scheme^
 end;
 
+procedure setAmmo(ammoName: PChar); cdecl;
+var ammo: PAmmo;
+begin
+    ammo:= ammoByName(ammoName);
+
+    if ammo <> nil then
+        currentConfig.ammo:= ammo^.ammoStr
+end;
+
 end.
--- a/hedgewars/uFLScripts.pas	Thu Apr 02 21:09:56 2015 +0300
+++ b/hedgewars/uFLScripts.pas	Wed Apr 08 23:39:18 2015 +0300
@@ -60,7 +60,6 @@
     while tmp^ <> nil do
     begin
         s:= shortstring(tmp^);
-        writeln(stderr, '> ', s);
         l:= length(s);
         if (l > 4) and (copy(s, l - 3, 4) = '.lua') then inc(scriptsNumber);
         inc(tmp)
--- a/hedgewars/uFLTypes.pas	Thu Apr 02 21:09:56 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Wed Apr 08 23:39:18 2015 +0300
@@ -75,6 +75,11 @@
             , worldedge: LongInt
         end;
     PScheme = ^TScheme;
+    TAmmo = record
+            ammoName: shortstring;
+            ammoStr: shortstring;
+        end;
+    PAmmo = ^TAmmo;
 
 implementation
 
--- a/hedgewars/uPhysFSLayer.pas	Thu Apr 02 21:09:56 2015 +0300
+++ b/hedgewars/uPhysFSLayer.pas	Wed Apr 08 23:39:18 2015 +0300
@@ -23,6 +23,7 @@
 
 function pfsOpenRead(fname: shortstring): PFSFile;
 function pfsClose(f: PFSFile): boolean;
+function pfsSeek(f: PFSFile; pos: QWord): boolean;
 
 procedure pfsReadLn(f: PFSFile; var s: shortstring);
 procedure pfsReadLnA(f: PFSFile; var s: ansistring);
@@ -50,6 +51,7 @@
 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
+function PHYSFS_seek(f: PFSFile; pos: QWord): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName;
@@ -87,6 +89,11 @@
     exit(PHYSFS_close(f))
 end;
 
+function pfsSeek(f: PFSFile; pos: QWord): boolean;
+begin
+    exit(PHYSFS_seek(f, 0));
+end;
+
 function pfsExists(fname: shortstring): boolean;
 begin
     exit(PHYSFS_exists(Str2PChar(fname)))
--- a/qmlFrontend/flib.h	Thu Apr 02 21:09:56 2015 +0300
+++ b/qmlFrontend/flib.h	Wed Apr 08 23:39:18 2015 +0300
@@ -38,6 +38,7 @@
 typedef void setTheme_t(const char * themeName);
 typedef void setScript_t(const char * scriptName);
 typedef void setScheme_t(const char * schemeName);
+typedef void setAmmo_t(const char * ammoName);
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
 typedef void flibFree_t();
 
@@ -47,6 +48,7 @@
 
 typedef char **getScriptsList_t();
 typedef char **getSchemesList_t();
+typedef char **getAmmosList_t();
 
 typedef char **getTeamsList_t();
 typedef void tryAddTeam_t(const char * teamName);
--- a/qmlFrontend/hwengine.cpp	Thu Apr 02 21:09:56 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Wed Apr 08 23:39:18 2015 +0300
@@ -16,6 +16,7 @@
     setTheme_t *flibSetTheme;
     setScript_t *flibSetScript;
     setScheme_t *flibSetScheme;
+    setAmmo_t *flibSetAmmo;
     getPreview_t *flibGetPreview;
     runQuickGame_t *flibRunQuickGame;
     runLocalGame_t *flibRunLocalGame;
@@ -27,6 +28,7 @@
     getThemeIcon_t *flibGetThemeIcon;
     getScriptsList_t *flibGetScriptsList;
     getSchemesList_t *flibGetSchemesList;
+    getAmmosList_t *flibGetAmmosList;
     getTeamsList_t *flibGetTeamsList;
     tryAddTeam_t * flibTryAddTeam;
     tryRemoveTeam_t * flibTryRemoveTeam;
@@ -59,6 +61,7 @@
     flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme");
     flibSetScript = (setScript_t*) hwlib.resolve("setScript");
     flibSetScheme = (setScheme_t*) hwlib.resolve("setScheme");
+    flibSetAmmo = (setAmmo_t*) hwlib.resolve("setAmmo");
 
     flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
     flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
@@ -66,6 +69,7 @@
 
     flibGetScriptsList = (getScriptsList_t*) hwlib.resolve("getScriptsList");
     flibGetSchemesList = (getSchemesList_t*) hwlib.resolve("getSchemesList");
+    flibGetAmmosList = (getAmmosList_t*) hwlib.resolve("getAmmosList");
 
     flibResetGameConfig = (resetGameConfig_t*) hwlib.resolve("resetGameConfig");
     flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList");
@@ -194,6 +198,13 @@
         resultModel << QString::fromUtf8(*i);
 
     m_engine->rootContext()->setContextProperty("schemesModel", QVariant::fromValue(resultModel));
+
+    // ammos model
+    resultModel.clear();
+    for (char **i = flibGetAmmosList(); *i != NULL; i++)
+        resultModel << QString::fromUtf8(*i);
+
+    m_engine->rootContext()->setContextProperty("ammosModel", QVariant::fromValue(resultModel));
 }
 
 void HWEngine::getTeamsList()
@@ -240,3 +251,8 @@
 {
     flibSetScheme(scheme.toUtf8().constData());
 }
+
+void HWEngine::setAmmo(const QString &ammo)
+{
+    flibSetAmmo(ammo.toUtf8().constData());
+}
--- a/qmlFrontend/hwengine.h	Thu Apr 02 21:09:56 2015 +0300
+++ b/qmlFrontend/hwengine.h	Wed Apr 08 23:39:18 2015 +0300
@@ -28,6 +28,7 @@
     Q_INVOKABLE void setTheme(const QString & theme);
     Q_INVOKABLE void setScript(const QString & script);
     Q_INVOKABLE void setScheme(const QString & scheme);
+    Q_INVOKABLE void setAmmo(const QString & ammo);
 
     Q_INVOKABLE void tryAddTeam(const QString & teamName);
     Q_INVOKABLE void tryRemoveTeam(const QString & teamName);
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Thu Apr 02 21:09:56 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Wed Apr 08 23:39:18 2015 +0300
@@ -141,7 +141,7 @@
         width: 256
         height: 64
 
-        model: ammoModel
+        model: ammosModel
         delegate: Rectangle {
             height: 25
             width: 100