- Allow to delete teams from config qmlfrontend
authorunc0rr
Sat, 01 Nov 2014 00:23:22 +0300
branchqmlfrontend
changeset 10448 4cb727e029fa
parent 10446 7ae44f42a689
child 10450 bf9e30b4ef9b
- Allow to delete teams from config - Manage team colors (internally, no gui so far) - 'Play' button on local game page (works!)
hedgewars/hwLibrary.pas
hedgewars/hwengine.pas
hedgewars/uFLData.pas
hedgewars/uFLGameConfig.pas
hedgewars/uFLTeams.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/hwLibrary.pas	Fri Oct 31 00:36:08 2014 +0300
+++ b/hedgewars/hwLibrary.pas	Sat Nov 01 00:23:22 2014 +0300
@@ -145,8 +145,8 @@
     Game;
 {$ELSE}
 exports
-    RunEngine,
     runQuickGame,
+    runLocalGame,
     getPreview,
     registerGUIMessagesCallback,
     flibInit,
@@ -159,6 +159,8 @@
     getTeamsList,
     tryAddTeam,
     tryRemoveTeam,
+    // dunno what these are
+    RunEngine,
     LoadLocaleWrapper,
     HW_versionInfo,
     HW_versionString,
--- a/hedgewars/hwengine.pas	Fri Oct 31 00:36:08 2014 +0300
+++ b/hedgewars/hwengine.pas	Sat Nov 01 00:23:22 2014 +0300
@@ -444,6 +444,7 @@
     uLandPainted.initModule;        // computes drawn land
     uIO.initModule;                 // sets up sockets
     uScript.initModule;
+    uTeams.initModule;              // clear CurrentTeam variable
 
     if complete then
     begin
@@ -467,7 +468,6 @@
         uStats.initModule;
         uStore.initModule;
         uRender.initModule;
-        uTeams.initModule;
         uVisualGears.initModule;
         uVisualGearsHandlers.initModule;
         uWorld.initModule;
--- a/hedgewars/uFLData.pas	Fri Oct 31 00:36:08 2014 +0300
+++ b/hedgewars/uFLData.pas	Sat Nov 01 00:23:22 2014 +0300
@@ -5,6 +5,17 @@
 procedure freeThemesList(list: PPChar); cdecl;
 function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
 
+const colorsSet: array[0..8] of shortstring = (
+                                               '16712196'
+                                               , '4817089'
+                                               , '1959610'
+                                               , '11878895'
+                                               , '10526880'
+                                               , '2146048'
+                                               , '16681742'
+                                               , '6239749'
+                                               , '16776961');
+
 implementation
 uses uPhysFSLayer;
 
--- a/hedgewars/uFLGameConfig.pas	Fri Oct 31 00:36:08 2014 +0300
+++ b/hedgewars/uFLGameConfig.pas	Sat Nov 01 00:23:22 2014 +0300
@@ -4,6 +4,7 @@
 
 procedure resetGameConfig; cdecl;
 procedure runQuickGame; cdecl;
+procedure runLocalGame; cdecl;
 procedure getPreview; cdecl;
 
 procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
@@ -15,7 +16,7 @@
 procedure tryRemoveTeam(teamName: PChar);
 
 implementation
-uses uFLIPC, hwengine, uFLUtils, uFLTeams;
+uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData;
 
 var guiCallbackPointer: pointer;
     guiCallbackFunction: TGUICallback;
@@ -104,11 +105,34 @@
     currentConfig.seed:= seed
 end;
 
+
 function getSeed: PChar; cdecl;
 begin
     getSeed:= str2PChar(currentConfig.seed)
 end;
 
+function getUnusedColor: shortstring;
+var i, c: Longword;
+    fColorMatched: boolean;
+begin
+    c:= 0;
+    i:= 0;
+    repeat
+        repeat
+            fColorMatched:= (currentConfig.teams[i].hogsNumber > 0) and (currentConfig.teams[i].color = colorsSet[c]);
+            inc(i)
+        until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched;
+
+        if fColorMatched then
+        begin
+            i:= 0;
+            inc(c)
+        end;
+    until not fColorMatched;
+
+    getUnusedColor:= colorsSet[c]
+end;
+
 procedure runQuickGame; cdecl;
 begin
     with currentConfig do
@@ -116,19 +140,20 @@
         gameType:= gtLocal;
         arguments[0]:= '';
         arguments[1]:= '--internal';
-        arguments[2]:= '--nosound';
+        arguments[2]:= '--nomusic';
         argumentsNumber:= 3;
 
         teams[0]:= createRandomTeam;
-        teams[0].color:= '6341088';
+        teams[0].color:= colorsSet[0];
         teams[1]:= createRandomTeam;
-        teams[1].color:= '2113696';
+        teams[1].color:= colorsSet[1];
         teams[1].botLevel:= 1;
 
         queueExecution;
     end;
 end;
 
+
 procedure getPreview; cdecl;
 begin
     with currentConfig do
@@ -143,6 +168,21 @@
     end;
 end;
 
+procedure runLocalGame; cdecl;
+begin
+    with currentConfig do
+    begin
+        gameType:= gtLocal;
+        arguments[0]:= '';
+        arguments[1]:= '--internal';
+        arguments[2]:= '--nomusic';
+        argumentsNumber:= 3;
+
+        queueExecution;
+    end;
+end;
+
+
 procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
 begin
     if len = 128 * 256 then guiCallbackFunction(guiCallbackPointer, mtPreview, msg, len)
@@ -161,6 +201,7 @@
 var msg: ansistring;
     i, hn, hedgehogsNumber: Longword;
     team: PTeam;
+    c: shortstring;
 begin
     with currentConfig do
     begin
@@ -179,11 +220,15 @@
         team:= teamByName(teamName);
         if team = nil then exit;
 
+        c:= getUnusedColor;
+
         teams[i]:= team^;
 
         if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
         if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
         teams[i].hogsNumber:= hn;
+
+        teams[i].color:= c;
     end;
 
 
@@ -196,9 +241,31 @@
     guiCallbackFunction(guiCallbackPointer, mtRemoveTeam, @msg[1], length(msg))
 end;
 
+
 procedure tryRemoveTeam(teamName: PChar);
 var msg: ansistring;
+    i: Longword;
+    tn: shortstring;
 begin
+    with currentConfig do
+    begin
+        i:= 0;
+        tn:= teamName;
+        while (i < 8) and (teams[i].teamName <> tn) do
+            inc(i);
+
+        // team not found???
+        if (i > 7) then exit;
+
+        while (i < 7) and (teams[i + 1].hogsNumber > 0) do
+        begin
+            teams[i]:= teams[i + 1];
+            inc(i)
+        end;
+
+        teams[i].hogsNumber:= 0
+    end;
+
     msg:= teamName;
 
     guiCallbackFunction(guiCallbackPointer, mtRemovePlayingTeam, @msg[1], length(msg));
--- a/hedgewars/uFLTeams.pas	Fri Oct 31 00:36:08 2014 +0300
+++ b/hedgewars/uFLTeams.pas	Sat Nov 01 00:23:22 2014 +0300
@@ -86,6 +86,7 @@
                 team.flag:= midStr(l, 6)
         end;
         // TODO: load hedgehogs and other stuff
+        team.botLevel:= 1
     end;
 
     pfsClose(f)
--- a/qmlFrontend/flib.h	Fri Oct 31 00:36:08 2014 +0300
+++ b/qmlFrontend/flib.h	Sat Nov 01 00:23:22 2014 +0300
@@ -30,6 +30,7 @@
 typedef void registerGUIMessagesCallback_t(void * context, void (*)(void * context, MessageType mt, const char * msg, uint32_t len));
 typedef void getPreview_t();
 typedef void runQuickGame_t();
+typedef void runLocalGame_t();
 typedef void setSeed_t(const char * seed);
 typedef char *getSeed_t();
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
--- a/qmlFrontend/hwengine.cpp	Fri Oct 31 00:36:08 2014 +0300
+++ b/qmlFrontend/hwengine.cpp	Sat Nov 01 00:23:22 2014 +0300
@@ -15,6 +15,7 @@
     getSeed_t *flibGetSeed;
     getPreview_t *flibGetPreview;
     runQuickGame_t *flibRunQuickGame;
+    runLocalGame_t *flibRunLocalGame;
     flibInit_t *flibInit;
     flibFree_t *flibFree;
     getThemesList_t *flibGetThemesList;
@@ -44,6 +45,7 @@
     flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed");
     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");
 
@@ -81,6 +83,12 @@
     flibRunQuickGame();
 }
 
+void HWEngine::runLocalGame()
+{
+    flibRunLocalGame();
+}
+
+
 static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
 {
     Q_UNUSED(scriptEngine)
--- a/qmlFrontend/hwengine.h	Fri Oct 31 00:36:08 2014 +0300
+++ b/qmlFrontend/hwengine.h	Sat Nov 01 00:23:22 2014 +0300
@@ -20,6 +20,7 @@
     static void exposeToQML();
     Q_INVOKABLE void getPreview();
     Q_INVOKABLE void runQuickGame();
+    Q_INVOKABLE void runLocalGame();
     Q_INVOKABLE QString currentSeed();
     Q_INVOKABLE void getTeamsList();
 
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Fri Oct 31 00:36:08 2014 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sat Nov 01 00:23:22 2014 +0300
@@ -27,6 +27,16 @@
         }
     }
 
+    HWButton {
+        id: btnRunGame
+        x: 600
+        y: 440
+        width: 32
+        height: 32
+
+        onClicked: HWEngine.runLocalGame()
+    }
+
     Rectangle {
         x: 320
         y: 16